Created
September 22, 2017 17:50
-
-
Save sandaru1/66537b8c83542f3c5707d0dbfc103aa3 to your computer and use it in GitHub Desktop.
Simple script to load localizations from the Main storyboards string into a new one after refactoring some view controllers into a new storyboard using Xcode 9.
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 | |
/* | |
Make sure to localize the new storyboard files using Xcode and that should be used as the destination. | |
*/ | |
$src = file($argv[1]); | |
$dst = file($argv[2]); | |
$modified_file = array(); | |
$new_translations = array(); | |
foreach($src as $line) { | |
if (preg_match("/\"(.*)\" = \"(.*)\";/",$line,$matches)) { | |
$new_translations[$matches[1]] = $matches[2]; | |
} | |
} | |
foreach($dst as $line) { | |
if (preg_match("/\"(.*)\" = \"(.*)\";/",$line,$matches)) { | |
if (isset($new_translations[$matches[1]])) { | |
$modified_file[] = '"'.$matches[1].'" = "'.$new_translations[$matches[1]].'";'."\n"; | |
} else { | |
echo "Cannot find : ".$matches[1]." , ".$matches[2]."\n"; | |
$modified_file[] = $line; | |
} | |
} else { | |
$modified_file[] = $line; | |
} | |
} | |
file_put_contents("new/".$argv[2],implode("",$modified_file)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment