24. August 2015 00:07
function XLFtoNAVtransFile
{
$XLFtransfile = Read-host "Path of XLIFF file"
$FileExtension = [System.IO.Path]::GetExtension($XLFtransfile)
if (!($FileExtension -eq '.xlf')) {Throw 'Please use a XLIFF file with .xlf extension for this script.'}
$NAVoutfile = [System.IO.Path]::GetDirectoryName($XLFtransfile) + "\"+ [System.IO.Path]::GetFileNameWithoutExtension($XLFtransfile) + '.txt'
if ($XLFtransfile -eq $NAVoutfile)
{
Throw "Source and target file are identical. Source: $XLFtransfile Target: $NAVoutfile"
}
if (test-path $NAVoutfile) {remove-item -path $NAVoutfile}
$xml = [xml] (get-content $XLFtransfile -Encoding UTF8)
foreach ($XLFnode in $xml.GetElementsByTagName('trans-unit'))
{
$sourceid = $XLFnode.getAttribute("id")
ForEach ($item in $XLFnode)
{
$sourceLanguage = $item.source.'lang'.ToString()
Switch ($SourceLanguage)
{
"dk" {$NAVSourcelangCode = '-A1030-'}
"de" {$NAVSourcelangCode = '-A1031-'}
"en" {$NAVSourcelangCode = '-A1033-'}
"es" {$NAVSourcelangCode = '-A1034-'}
"fi" {$NAVSourcelangCode = '-A1035-'}
"fr" {$NAVSourcelangCode = '-A1036-'}
"it" {$NAVSourcelangCode = '-A1040-'}
"nl" {$NAVSourcelangCode = '-A1043-'}
"no" {$NAVSourcelangCode = '-A1044-'}
"pl" {$NAVSourcelangCode = '-A1045-'}
"pt" {$NAVSourcelangCode = '-A1046-'}
"se" {$NAVSourcelangCode = '-A1053-'}
"gsw" {$NAVSourcelangCode = '-A2055-'}
"en-gb" {$NAVSourcelangCode = '-A2057-'}
# "de" {$NAVlangCode = '-A3079-'} # activate in AT and deactivate de -> A1031
default {Throw "Please assign a NAV translation code for $NAVSourcelangCode in the script"}
}
$sourceCaption = $item.source.'#text'.ToString()
$sourceline = $sourceid + ':' + $sourcecaption
Out-File $NAVoutfile -inputobject $sourceline -Encoding UTF8 -force -Append -Width 1024
$TargetLanguage = $item.target.'lang'.ToString()
$TargetCaption = $item.target.'#text'.ToString()
Switch ($TargetLanguage)
{
"dk" {$NAVTargetlangCode = '-A1030-'}
"de" {$NAVTargetlangCode = '-A1031-'}
"en" {$NAVTargetlangCode = '-A1033-'}
"es" {$NAVTargetlangCode = '-A1034-'}
"fi" {$NAVTargetlangCode = '-A1035-'}
"fr" {$NAVTargetlangCode = '-A1036-'}
"it" {$NAVTargetlangCode = '-A1040-'}
"nl" {$NAVTargetlangCode = '-A1043-'}
"no" {$NAVTargetlangCode = '-A1044-'}
"pt" {$NAVTargetlangCode = '-A1046-'}
"se" {$NAVTargetlangCode = '-A1053-'}
"gsw" {$NAVTargetlangCode = '-A2055-'}
"en-gb" {$NAVTargetlangCode = '-A2057-'}
# "de" {$NAVlangCode = '-A3079-'} # activate in AT and deactivate de -> A1031
default {Throw "Please assign a NAV translation code for $NAVTargetlangCode in the script"}
}
$targetid = $sourceid -replace $NAVSourcelangCode, $NAVTargetlangCode
$targetline = $targetid + ':' + $targetcaption
Out-File $NAVoutfile -inputobject $targetline -Encoding UTF8 -force -Append -Width 1024
}
}
$sourceEncoding = [System.Text.Encoding]::GetEncoding(65001)
$targetEncoding = [System.Text.Encoding]::GetEncoding(850)
$convertedFileName = [System.IO.Path]::GetDirectoryName($NAVoutfile) + "\"+ [System.IO.Path]::GetFileNameWithoutExtension($NAVoutfile) +"_OEM850" + [System.IO.Path]::GetExtension($NAVoutfile)
if (Test-Path $convertedFileName) {Remove-Item $convertedFileName}
$convertedfile = New-Item -path $convertedFileName -type file
$textfile = [System.IO.File]::ReadAllText($NAVoutfile, $sourceencoding)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
if (Test-Path $NavOutFile) {Remove-Item $NAVoutfile}
Write-host $XLFtransfile 'converted to' $convertedFileName
}
25. Januar 2019 10:01
Do you want to write the source language to the NAV file (yes,no) ?
function XLFtoNAVtransFile2
{
$XLFtransfile = Read-host "Path of XLIFF file"
$FileExtension = [System.IO.Path]::GetExtension($XLFtransfile)
if (!($FileExtension -eq '.xlf')) {Throw 'Please use a XLIFF file with .xlf extension for this script.'}
$NAVoutfile = [System.IO.Path]::GetDirectoryName($XLFtransfile) + "\"+ [System.IO.Path]::GetFileNameWithoutExtension($XLFtransfile) + '.txt'
if ($XLFtransfile -eq $NAVoutfile)
{
Throw "Source and target file are identical. Source: $XLFtransfile Target: $NAVoutfile"
}
if (test-path $NAVoutfile) {remove-item -path $NAVoutfile}
[ValidateSet('yes','no')]$WriteSourceCaptions = Read-Host "Do you want to write the source language to the NAV file (yes,no) ?"
$xml = [xml] (get-content $XLFtransfile -Encoding UTF8)
foreach ($XLFnode in $xml.GetElementsByTagName('trans-unit'))
{
$sourceid = $XLFnode.getAttribute("id")
ForEach ($item in $XLFnode)
{
$sourceLanguage = $item.source.'lang'.ToString()
Switch ($SourceLanguage)
{
"dk" {$NAVSourcelangCode = '-A1030-'}
"de" {$NAVSourcelangCode = '-A1031-'}
"en" {$NAVSourcelangCode = '-A1033-'}
"es" {$NAVSourcelangCode = '-A1034-'}
"fi" {$NAVSourcelangCode = '-A1035-'}
"fr" {$NAVSourcelangCode = '-A1036-'}
"it" {$NAVSourcelangCode = '-A1040-'}
"nl" {$NAVSourcelangCode = '-A1043-'}
"no" {$NAVSourcelangCode = '-A1044-'}
"pl" {$NAVSourcelangCode = '-A1045-'}
"pt" {$NAVSourcelangCode = '-A1046-'}
"se" {$NAVSourcelangCode = '-A1053-'}
"gsw" {$NAVSourcelangCode = '-A2055-'}
"en-gb" {$NAVSourcelangCode = '-A2057-'}
# "de" {$NAVlangCode = '-A3079-'} # activate in AT and deactivate de -> A1031
default {Throw "Please assign a NAV translation code for $NAVSourcelangCode in the script"}
}
$sourceCaption = $item.source.'#text'.ToString()
$sourceline = $sourceid + ':' + $sourcecaption
if ($WriteSourceCaptions -eq 'yes')
{Out-File $NAVoutfile -inputobject $sourceline -Encoding UTF8 -force -Append -Width 1024}
$TargetLanguage = $item.target.'lang'.ToString()
$TargetCaption = $item.target.'#text'.ToString()
Switch ($TargetLanguage)
{
"dk" {$NAVTargetlangCode = '-A1030-'}
"de" {$NAVTargetlangCode = '-A1031-'}
"en" {$NAVTargetlangCode = '-A1033-'}
"es" {$NAVTargetlangCode = '-A1034-'}
"fi" {$NAVTargetlangCode = '-A1035-'}
"fr" {$NAVTargetlangCode = '-A1036-'}
"it" {$NAVTargetlangCode = '-A1040-'}
"nl" {$NAVTargetlangCode = '-A1043-'}
"no" {$NAVTargetlangCode = '-A1044-'}
"pt" {$NAVTargetlangCode = '-A1046-'}
"se" {$NAVTargetlangCode = '-A1053-'}
"gsw" {$NAVTargetlangCode = '-A2055-'}
"en-gb" {$NAVTargetlangCode = '-A2057-'}
# "de" {$NAVlangCode = '-A3079-'} # activate in AT and deactivate de -> A1031
default {Throw "Please assign a NAV translation code for $NAVTargetlangCode in the script"}
}
$targetid = $sourceid -replace $NAVSourcelangCode, $NAVTargetlangCode
$targetline = $targetid + ':' + $targetcaption
Out-File $NAVoutfile -inputobject $targetline -Encoding UTF8 -force -Append -Width 1024
}
}
$sourceEncoding = [System.Text.Encoding]::GetEncoding(65001)
$targetEncoding = [System.Text.Encoding]::GetEncoding(850)
$convertedFileName = [System.IO.Path]::GetDirectoryName($NAVoutfile) + "\"+ [System.IO.Path]::GetFileNameWithoutExtension($NAVoutfile) +"_OEM850" + [System.IO.Path]::GetExtension($NAVoutfile)
if (Test-Path $convertedFileName) {Remove-Item $convertedFileName}
$convertedfile = New-Item -path $convertedFileName -type file
$textfile = [System.IO.File]::ReadAllText($NAVoutfile, $sourceencoding)
[System.IO.File]::WriteAllText($convertedfile, $textfile, $targetencoding)
if (Test-Path $NavOutFile) {Remove-Item $NAVoutfile}
Write-host $XLFtransfile 'converted to' $convertedFileName
}
12. Januar 2023 12:53
12. Januar 2023 13:57
Timo Lässer hat geschrieben:In dem o. g. Script wird die Angabe der Sprachen in dem Element "source" bzw. "target" erwartet.
Bei den in BC21 bereitgestellten Language Modules stehen die Sprachen jedoch einmalig in der dritten Zeile als Parameter ("source-language" / "target-language") des Elements "file".
12. Januar 2023 14:19
Kowa hat geschrieben:die Trans-Unit-IDs sind aber zwischen C/AL und AL inkompatibel (Beispiel in AL: trans-unit id="PageExtension 1255613137 - Property 2879900210)", rückkonvertieren für NAV kann man da ohnehin nichts.