From ff7189971e6685118f41e3567cefae7c333202de Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 21 Jun 2015 12:35:01 -0400 Subject: Move the script sync-locales.php to cli command --- app/Console/LocaleSync.php | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 app/Console/LocaleSync.php (limited to 'app/Console') diff --git a/app/Console/LocaleSync.php b/app/Console/LocaleSync.php new file mode 100644 index 00000000..ab95651b --- /dev/null +++ b/app/Console/LocaleSync.php @@ -0,0 +1,57 @@ +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 = ' $value) { + + if (! empty($outdated[$key])) { + $output .= " '".str_replace("'", "\'", $key)."' => '".str_replace("'", "\'", $outdated[$key])."',\n"; + } + else { + $output .= " // '".str_replace("'", "\'", $key)."' => '',\n"; + } + } + + $output .= ");\n"; + return $output; + } +} -- cgit v1.2.3