31. März 2015 17:55
" "
' '
< <
> >
& &
function CreateXLF
{
function WriteToFile
{
out-file C:\Temp\ENU_FRA_V4.xlf -inputobject $args -force -append -Width 500 -Encoding utf8
}
$lines = Get-Content C:\Temp\File1.txt | Measure-Object –Line
$Nooflines = $lines.Lines
write-host "File 1 has $Nooflines lines"
if (Test-Path C:\Temp\File2.txt) {Write-Host File 2 exists}
if (Test-Path C:\Temp\ENU_FRA_V4.xlf) {Remove-Item C:\Temp\ENU_FRA_V4.xlf}
$CurrLine = "<xliff version='1.2' xmlns='urn:oasis:names:tc:xliff:document:1.2'>"
# out-file C:\Temp\Translations.xlf -inputobject $Currline -force -append -Width 500 -Encoding utf8
writetoFile $CurrLine
$CurrLine = " <file original='File1.txt' source-language='en' target-language='fr' datatype='plaintext'>"
writetoFile $CurrLine
$CurrLine = " <body>"
writetoFile $CurrLine
for ($i = 0; $i -lt $lines.Lines; $i++)
{
$SourceCaption = (Get-Content C:\Temp\File1.txt)[$i]
$TargetCaption = (Get-Content C:\Temp\File2.txt)[$i]
$SourceCaption = $SourceCaption -replace '&','&'
$TargetCaption = $TargetCaption -replace '&','&'
$SourceCaption = $SourceCaption -replace '<','<'
$TargetCaption = $TargetCaption -replace '<','<'
$SourceCaption = $SourceCaption -replace '>','>'
$TargetCaption = $TargetCaption -replace '>','>'
$SourceCaption = $SourceCaption -replace '"','"'
$TargetCaption = $TargetCaption -replace '"','"'
$SourceCaption = $SourceCaption -replace $([char]39),'''
$TargetCaption = $TargetCaption -replace $([char]39),'''
#<trans-unit id="1">
$j = $i + 1
$CurrLine = " <trans-unit id=$([char]34)$j$([char]34)>"
writetoFile $CurrLine
$CurrLine = " <source xml:lang=$([char]34)en$([char]34)>$SourceCaption</source>"
writetoFile $CurrLine
$CurrLine = " <target xml:lang=$([char]34)fr$([char]34)>$TargetCaption</target>"
#<source xml:lang="en">Cannot find the file.</source>
writetoFile $CurrLine
#<target xml:lang="fr">Fichier non trouvé.</target>
$CurrLine = ' </trans-unit>'
writetoFile $CurrLine
if ($i%10 -eq 0) {Write-Host "Writing $i of $Nooflines"}
}
$CurrLine = ' </body>'
writetoFile $CurrLine
$CurrLine = ' </file>'
writetoFile $CurrLine
$CurrLine = '</xliff>'
writetoFile $CurrLine
}
function CreateXLFCDATA
{
function WriteToFile
{
out-file C:\Temp\ENU_FRA_V3.xlf -inputobject $args -force -append -Width 500 -Encoding utf8
}
$lines = Get-Content C:\Temp\File1.txt | Measure-Object –Line
$Nooflines = $lines.Lines
write-host "File 1 has $Nooflines lines"
if (Test-Path C:\Temp\File2.txt) {Write-Host File 2 exists}
if (Test-Path C:\Temp\ENU_FRA_V3.xlf) {Remove-Item C:\Temp\ENU_FRA_V3.xlf}
# $CurrLine = '<?xml version=$'([char]34)+'1.0'+$([char]34)?>'
$CurrLine = "<xliff version='1.2' xmlns='urn:oasis:names:tc:xliff:document:1.2'>"
# out-file C:\Temp\Translations.xlf -inputobject $Currline -force -append -Width 500 -Encoding utf8
writetoFile $CurrLine
$CurrLine = " <file original='File1.txt' source-language='en' target-language='fr' datatype='plaintext'>"
WriteTofile $Currline
$CurrLine = " <body>"
writetoFile $CurrLine
for ($i = 0; $i -lt $lines.Lines; $i++)
{
$SourceCaption = (Get-Content C:\Temp\File1.txt)[$i]
$TargetCaption = (Get-Content C:\Temp\File2.txt)[$i]
#<trans-unit id="1">
$j = $i + 1
$CurrLine = " <trans-unit id=$([char]34)$j$([char]34)>"
writetoFile $CurrLine
$CurrLine = " <source xml:lang=$([char]34)en$([char]34)><![CDATA[$SourceCaption]]></source>"
writetoFile $CurrLine
$CurrLine = " <target xml:lang=$([char]34)fr$([char]34)><![CDATA[$TargetCaption]]></target>"
#<source xml:lang="en">Cannot find the file.</source>
writetoFile $CurrLine
#<target xml:lang="fr">Fichier non trouvé.</target>
$CurrLine = ' </trans-unit>'
writetoFile $CurrLine
if ($i%10 -eq 0) {Write-Host "Writing $i of $Nooflines"}
}
$CurrLine = ' </body>'
writetoFile $CurrLine
$CurrLine = ' </file>'
writetoFile $CurrLine
$CurrLine = '</xliff>'
writetoFile $CurrLine
}
1. April 2015 16:05