Skip to content

Instantly share code, notes, and snippets.

@sandaru1
Created September 22, 2017 17:50
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 sandaru1/66537b8c83542f3c5707d0dbfc103aa3 to your computer and use it in GitHub Desktop.
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.
<?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