summaryrefslogtreecommitdiff
path: root/app/Console/LocaleSyncCommand.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-04-12 21:26:17 -0400
committerFrederic Guillot <fred@kanboard.net>2016-04-12 21:26:17 -0400
commitaf7027ea31a691e2eea6d813f6aa3cf08f8b9d0a (patch)
tree8524395f06b30f812dca5cd68dd15fa09e3a2410 /app/Console/LocaleSyncCommand.php
parent2a74ed6e63b05627928e1dd6eeb67d824f4c1903 (diff)
Rename CLI classes
Diffstat (limited to 'app/Console/LocaleSyncCommand.php')
-rw-r--r--app/Console/LocaleSyncCommand.php53
1 files changed, 53 insertions, 0 deletions
diff --git a/app/Console/LocaleSyncCommand.php b/app/Console/LocaleSyncCommand.php
new file mode 100644
index 00000000..11cfbde0
--- /dev/null
+++ b/app/Console/LocaleSyncCommand.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace Kanboard\Console;
+
+use DirectoryIterator;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class LocaleSyncCommand extends BaseCommand
+{
+ 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;
+ }
+}