summaryrefslogtreecommitdiff
path: root/app/Console
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-06-21 12:35:01 -0400
committerFrederic Guillot <fred@kanboard.net>2015-06-21 12:35:01 -0400
commitff7189971e6685118f41e3567cefae7c333202de (patch)
tree3ef320155bb07e6ac8a1a0242552d8e02d6bf6b7 /app/Console
parentd7a8160c2b422dcf950093d9d17d90f1e80201de (diff)
Move the script sync-locales.php to cli command
Diffstat (limited to 'app/Console')
-rw-r--r--app/Console/LocaleSync.php57
1 files changed, 57 insertions, 0 deletions
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 @@
+<?php
+
+namespace 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;
+ }
+}