TranslationHandling/Remove-ITIObjectTranslation.ps1

<#
.SYNOPSIS
    Removes translation from object TXT file using BC Container
.EXAMPLE
    Remove-ITIObjectTranslation -ContainerName BC14PL -SourceFile ./Apps/table/TAB3.txt
    Remove all languages except for default development language (usually ENU)
 
    Remove-ITIObjectTranslation -ContainerName BC14PL -SourceFile ./Apps/table/TAB3.txt -LanguageIdToKeep "PLK"
    Remove all languages except for PLK
#>


function Remove-ITIObjectTranslation {
  param (
    [Parameter(Mandatory = $true)]
    [string]$ContainerName,
    [string]$SourceFile,
    [Parameter(Mandatory = $false)]
    [string]$LanguageIdToKeep = ""
  )
  
  #Copy object file to the container
  Invoke-ScriptInBcContainer -containerName $ContainerName -scriptblock {
    New-Item -ItemType Directory "C:\temp" -Force -ErrorAction Ignore | Out-Null
  }

  Copy-FileToBcContainer -containerName $ContainerName -localPath $SourceFile -containerPath "C:\temp\objects.txt"
  Invoke-ScriptInBcContainer -containerName $ContainerName -argumentList $LanguageIdToKeep -scriptblock {
    param($LanguageIdToKeep)
    if ($LanguageIdToKeep -eq "") {
      Remove-NAVApplicationObjectLanguage -Source "C:\temp\objects.txt" -Destination "C:\temp\objects.txt" -Force
      return
    }
    Remove-NAVApplicationObjectLanguage -Source "C:\temp\objects.txt" -Destination "C:\temp\objects.txt" -DevelopmentLanguageId $LanguageIdToKeep -Force
  }
  Copy-FileFromBcContainer -containerName $ContainerName -containerPath "C:\temp\objects.txt" -localPath $SourceFile
}

Export-ModuleMember -Function Remove-ITIObjectTranslation