2014-07-23 12:43:48 +02:00
|
|
|
#!/usr/bin/env php
|
|
|
|
<?php
|
|
|
|
|
2014-10-20 01:14:33 +02:00
|
|
|
$reference_lang = 'fr_FR';
|
|
|
|
$reference_file = '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
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-20 01:14:33 +02:00
|
|
|
foreach (new DirectoryIterator('locales') as $fileInfo) {
|
|
|
|
|
2015-01-30 19:45:23 +01:00
|
|
|
if (! $fileInfo->isDot() && $fileInfo->isDir() && $fileInfo->getFilename() !== $reference_lang && $fileInfo->getFilename() !== 'en_US') {
|
2014-10-20 01:14:33 +02:00
|
|
|
|
|
|
|
$filename = 'locales/'.$fileInfo->getFilename().'/translations.php';
|
|
|
|
|
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
|
|
|
}
|