Skip to content

Instantly share code, notes, and snippets.

@Wohlstand
Created August 14, 2017 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wohlstand/dab7a77418a9914b1148ea96489a2402 to your computer and use it in GitHub Desktop.
Save Wohlstand/dab7a77418a9914b1148ea96489a2402 to your computer and use it in GitHub Desktop.
Merge Qt Linguist TS files
<?php
$tsSrc = "editor_en_old.ts";
$tsToMerge = "editor_en.ts";
$tsDst = "newts.ts";
$xmlOld = simplexml_load_file($tsSrc);
$xmlHoe = simplexml_load_file($tsToMerge);
$countOfChangedPhrazes = 0;
foreach($xmlOld->context as $ctxOld)
{
foreach($xmlHoe->context as $ctxHoe)
{
if(strcmp($ctxOld->name, $ctxHoe->name) == 0)//Find contexts of same name
{
foreach($ctxOld->message as $msgOld)
{
foreach($ctxHoe->message as $msgHoe)
{
if(strcmp($msgOld->source, $msgHoe->source) == 0)//Find messages are translating same source string
{
if(strcmp($msgOld->translation, $msgHoe->translation) != 0)
{
echo "OLD: " . $msgOld->translation . ";\nNEW: " . $msgHoe->translation . "\n\n";
$countOfChangedPhrazes++;
}
$msgOld->translation = $msgHoe->translation;
break;
}
}
}
break;
}
}
}
echo "\n\nTotal count of change phrazes: $countOfChangedPhrazes\n\n";
$new = fopen($tsDst, "w"); // open new file
fwrite($new, $xmlOld->asXML()); //write XML to new file using asXML method
fclose($new); // close the new file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment