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 | Out-Null
    
    $customConfigFile = Join-Path (Get-Item "C:\Program Files\Microsoft Dynamics NAV\*\Service").FullName "CustomSettings.config"
    [xml]$customConfig = [System.IO.File]::ReadAllText($customConfigFile)
    $DatabaseName = $customConfig.SelectSingleNode("//appSettings/add[@key='DatabaseName']").Value
    
    Export-NAVApplicationObject -DatabaseName $DatabaseName -Path "C:\temp\objects.txt" -Filter $filter -Force | Out-Null
    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