TranslationHandling/Export-ITIObjectTranslation.ps1

<#
.SYNOPSIS
    Exports translation from BCContainer Database to a translation TXT file. The file is going to be saved as <LanguageId>.txt
.EXAMPLE
    Export-ITIObjectTranslation -ContainerName BC14PL -Destination ~/MyApp/Translations -LangaugeId "ENU"
#>

function Export-ITIObjectTranslation {
  param (
    [Parameter(Mandatory = $true)]
    [string]$ContainerName,
    [Parameter(Mandatory = $false)]
    [string]$LanguageId = "PLK",
    [string]$Destination = ".\Translations",
    [string]$filter = "Id=1..1999999999"
  )

  if ($filter) {
    if (!($filter.StartsWith('Id=', 'CurrentCultureIgnoreCase') -or $filter.ToLowerInvariant().Contains(';id='))) {
        $filter += ";Id=1..1999999999"
    }
  }
  else {
      $filter = "Id=1..1999999999"
  }

  $Destination = (Get-Item -Path $Destination).FullName

  Invoke-ScriptInBcContainer -containerName $ContainerName -argumentList $LanguageId,$filter -scriptblock {
    param($LanguageId, $filter)
    New-Item -ItemType Directory "C:\temp" -Force -ErrorAction Ignore
    $DatabaseName = Get-NAVServerInstance | Get-NAVServerConfiguration -KeyName DatabaseName
    Export-NAVApplicationObject -DatabaseName $DatabaseName -Path "C:\temp\objects.txt" -Filter $filter -Force
    Export-NAVApplicationObjectLanguage -Source "C:\temp\objects.txt" -Destination "C:\temp\$LanguageId.txt" -LanguageId $LanguageId -Force
  }
  Copy-FileFromBcContainer -containerName $ContainerName -containerPath "C:\temp\$LanguageId.txt" -localPath "$Destination\$LanguageId.txt"

  Invoke-ScriptInBcContainer -containerName $ContainerName -scriptblock {
    Remove-Item -Path "C:\temp" -Recurse -Force -ErrorAction Ignore
  }
}

Export-ModuleMember -Function Export-ITIObjectTranslation