Created
August 14, 2017 09:56
-
-
Save Wohlstand/dab7a77418a9914b1148ea96489a2402 to your computer and use it in GitHub Desktop.
Merge Qt Linguist TS files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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