1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/kanboard_ynh.git synced 2024-09-03 19:36:17 +02:00
kanboard_ynh/sources/app/Console/LocaleSync.php
2015-10-26 14:48:28 +01:00

53 lines
1.7 KiB
PHP

<?php
namespace Kanboard\Console;
use DirectoryIterator;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class LocaleSync extends Base
{
const REF_LOCALE = 'fr_FR';
protected function configure()
{
$this
->setName('locale:sync')
->setDescription('Synchronize all translations based on the '.self::REF_LOCALE.' locale');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$reference_file = 'app/Locale/'.self::REF_LOCALE.'/translations.php';
$reference = include $reference_file;
foreach (new DirectoryIterator('app/Locale') as $fileInfo) {
if (! $fileInfo->isDot() && $fileInfo->isDir() && $fileInfo->getFilename() !== self::REF_LOCALE) {
$filename = 'app/Locale/'.$fileInfo->getFilename().'/translations.php';
echo $fileInfo->getFilename().' ('.$filename.')'.PHP_EOL;
file_put_contents($filename, $this->updateFile($reference, $filename));
}
}
}
public function updateFile(array $reference, $outdated_file)
{
$outdated = include $outdated_file;
$output = '<?php'.PHP_EOL.PHP_EOL;
$output .= 'return array('.PHP_EOL;
foreach ($reference as $key => $value) {
if (! empty($outdated[$key])) {
$output .= " '".str_replace("'", "\'", $key)."' => '".str_replace("'", "\'", $outdated[$key])."',\n";
} else {
$output .= " // '".str_replace("'", "\'", $key)."' => '',\n";
}
}
$output .= ");\n";
return $output;
}
}