2014-07-23 12:43:48 +02:00
|
|
|
<?php
|
|
|
|
|
2014-10-20 01:14:33 +02:00
|
|
|
$reference_lang = 'fr_FR';
|
2016-12-29 02:52:58 +01:00
|
|
|
$reference_file = __DIR__.'/../app/locales/'.$reference_lang.'/translations.php';
|
2014-07-23 12:43:48 +02:00
|
|
|
$reference = include $reference_file;
|
|
|
|
|
|
|
|
|
2014-10-20 01:14:33 +02:00
|
|
|
function update_missing_locales(array $reference, $outdated_file)
|
|
|
|
{
|
|
|
|
$outdated = include $outdated_file;
|
2014-07-23 12:43:48 +02:00
|
|
|
|
2015-01-30 19:45:23 +01:00
|
|
|
$output = "<?php\n\n";
|
|
|
|
$output .= "return array(\n";
|
2014-10-20 01:14:33 +02:00
|
|
|
|
2015-01-30 19:45:23 +01:00
|
|
|
foreach (array_keys($reference) as $key) {
|
|
|
|
$outputKey = str_replace("'", "\'", $key);
|
|
|
|
$outputValue = " // '".$outputKey."' => ''";
|
2014-10-20 01:14:33 +02:00
|
|
|
|
|
|
|
if (isset($outdated[$key])) {
|
2015-01-30 19:45:23 +01:00
|
|
|
if ($key === 'plural') {
|
|
|
|
$outputValue = $outputKey."' => ".getFunctionCode($outdated[$key]);
|
|
|
|
}
|
|
|
|
elseif (is_array($outdated[$key])) {
|
|
|
|
foreach($outdated[$key] as &$value) {
|
|
|
|
$value = str_replace("'", "\'", $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
$outputValue = $outputKey."' => array('".join("', '", $outdated[$key])."')";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$outputValue = $outputKey."' => '".str_replace("'", "\'", $outdated[$key])."'";
|
|
|
|
}
|
|
|
|
|
|
|
|
$outputValue = " '".$outputValue;
|
2014-10-20 01:14:33 +02:00
|
|
|
}
|
2015-01-30 19:45:23 +01:00
|
|
|
|
|
|
|
$output .= $outputValue.",\n";
|
2014-07-23 12:43:48 +02:00
|
|
|
}
|
2014-10-20 01:14:33 +02:00
|
|
|
|
|
|
|
$output .= ");\n";
|
|
|
|
return $output;
|
2014-07-23 12:43:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-19 03:02:49 +02:00
|
|
|
foreach (new DirectoryIterator('app/locales') as $fileInfo) {
|
2015-01-30 19:45:23 +01:00
|
|
|
if (! $fileInfo->isDot() && $fileInfo->isDir() && $fileInfo->getFilename() !== $reference_lang && $fileInfo->getFilename() !== 'en_US') {
|
2016-08-19 03:02:49 +02:00
|
|
|
$filename = 'app/locales/'.$fileInfo->getFilename().'/translations.php';
|
2014-10-20 01:14:33 +02:00
|
|
|
|
2016-05-03 10:45:07 +02:00
|
|
|
echo $fileInfo->getFilename(), ' (', $filename, ')', PHP_EOL;
|
2014-10-20 01:14:33 +02:00
|
|
|
|
|
|
|
file_put_contents($filename, update_missing_locales($reference, $filename));
|
|
|
|
}
|
|
|
|
}
|
2015-01-30 19:45:23 +01:00
|
|
|
|
|
|
|
function getFunctionCode($name)
|
|
|
|
{
|
|
|
|
$reflector = new ReflectionFunction($name);
|
|
|
|
|
|
|
|
$file = new SplFileObject($reflector->getFileName());
|
|
|
|
$file->seek($reflector->getStartLine()-1);
|
|
|
|
|
|
|
|
$sourcecode = '';
|
|
|
|
while ($file->key() < $reflector->getEndLine())
|
|
|
|
{
|
|
|
|
$sourcecode .= $file->current();
|
|
|
|
$file->next();
|
|
|
|
}
|
|
|
|
|
|
|
|
$begin = strpos($sourcecode, 'function');
|
|
|
|
$end = strrpos($sourcecode, '}');
|
|
|
|
|
|
|
|
return substr($sourcecode, $begin, $end - $begin + 1);
|
2015-10-20 03:21:18 +02:00
|
|
|
}
|