Last active
October 28, 2016 14:46
-
-
Save macbre/00d42cc38e627c6f041097b1f5a4228a to your computer and use it in GitHub Desktop.
SUS-1121
This file contains hidden or 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
#!/usr/bin/env php | |
<?php | |
$msgFile = '/extensions/wikia/Oasis/Oasis.i18n.php'; | |
function write_i18n_file($file, Array $messages) { | |
global $IP; | |
$extension = str_replace($IP, '', $file); | |
$extension = str_replace('.i18n.php', '', $extension); | |
$contents = "<?php\n"; | |
$contents .= "/** Internationalization file for $extension extension. */\n"; | |
$contents .= "\$messages = [];\n\n"; | |
foreach ( $messages as $lang => $translations ) { | |
$contents .= "\$messages['$lang'] = [\n"; | |
foreach ( $translations as $key => $text ) { | |
$text = str_replace( "'", "\\'", $text ); | |
$contents .= "\t'$key' => '$text',\n"; | |
} | |
$contents .= "];\n\n"; | |
} | |
# var_dump($file, $extension, substr($contents, 0, 2048)); die; | |
file_put_contents($file, $contents); | |
} | |
$IP = '/home/macbre/Wikia/github/app'; | |
echo "Processing {$msgFile}..."; | |
# process Crowdin i18n file | |
include("$IP/$msgFile.crowdin"); | |
$crowdinMessages = $messages; | |
# process app i18n file | |
include("$IP/$msgFile"); | |
$codeMessages = $messages; | |
# process Crowdin translations | |
foreach($crowdinMessages as $lang => $messages) { | |
echo "{$lang}...\n"; | |
foreach($messages as $name => $message) { | |
if ($crowdinMessages[$lang][$name] != $codeMessages[$lang][$name]) { | |
if (stripos($crowdinMessages[$lang][$name], 'Wikia') !== false || stripos($crowdinMessages[$lang][$name], 'Wikii') !== false) { | |
# we do not want to import i18n strings that still contains "Wikia" | |
echo "\t{$name}[{$lang}] = '{$crowdinMessages[$lang][$name]}'\n"; | |
} | |
else { | |
# update the message in the code | |
$codeMessages[$lang][$name] = $crowdinMessages[$lang][$name]; | |
} | |
} | |
} | |
} | |
write_i18n_file($IP . $msgFile, $codeMessages); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment