diff options
-rw-r--r-- | app/Console/LocaleSync.php | 57 | ||||
-rw-r--r-- | app/Locale/pl_PL/translations.php | 4 | ||||
-rw-r--r-- | docs/translations.markdown | 4 | ||||
-rwxr-xr-x | kanboard | 1 | ||||
-rwxr-xr-x | scripts/sync-locales.php | 43 |
5 files changed, 62 insertions, 47 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; + } +} diff --git a/app/Locale/pl_PL/translations.php b/app/Locale/pl_PL/translations.php index 0bdfe57f..41355c9b 100644 --- a/app/Locale/pl_PL/translations.php +++ b/app/Locale/pl_PL/translations.php @@ -787,7 +787,7 @@ return array( 'Custom Stylesheet' => 'Niestandardowy arkusz stylów', 'download' => 'pobierz', 'Do you really want to remove this budget line?' => 'Czy chcesz usunąć tą linię budżetową?', - //'EUR - Euro' => '', + // 'EUR - Euro' => '', 'Expenses' => 'Wydatki', 'GBP - British Pound' => 'GBP - Funt brytyjski', 'INR - Indian Rupee' => 'INR - Rupia indyjska', @@ -797,7 +797,7 @@ return array( 'Remove a budget line' => 'Usuń linię budżetową', 'Remove budget line' => 'Usuń linię budżetową', 'RSD - Serbian dinar' => 'RSD - Dinar serbski', - 'The budget line have been created successfully.' => '', + // 'The budget line have been created successfully.' => '', 'Unable to create the budget line.' => 'Nie można utworzyć linii budżetowej', 'Unable to remove this budget line.' => 'Nie można usunąć tej linii budżetowej', 'USD - US Dollar' => 'USD - Dolar amerykański', diff --git a/docs/translations.markdown b/docs/translations.markdown index 0e01fa9b..faa715c7 100644 --- a/docs/translations.markdown +++ b/docs/translations.markdown @@ -72,7 +72,7 @@ How to synchronize translation files? From a Unix shell run this command: ```bash -./scripts/sync-locales.php +./kanboard locale:sync ``` -The french translation is used a reference for other locales. +The French translation is used a reference for other locales. @@ -15,4 +15,5 @@ $application->add(new Console\TaskExport($container)); $application->add(new Console\ProjectDailySummaryCalculation($container)); $application->add(new Console\ProjectDailySummaryExport($container)); $application->add(new Console\TransitionExport($container)); +$application->add(new Console\LocaleSync($container)); $application->run(); diff --git a/scripts/sync-locales.php b/scripts/sync-locales.php deleted file mode 100755 index 472a6b2b..00000000 --- a/scripts/sync-locales.php +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env php -<?php - -$reference_lang = 'fr_FR'; -$reference_file = 'app/Locale/'.$reference_lang.'/translations.php'; -$reference = include $reference_file; - - -function update_missing_locales(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("'", "\'", $value)."',\n"; - $output .= " '".str_replace("'", "\'", $key)."' => '".str_replace("'", "\'", $outdated[$key])."',\n"; - } - else { - //$output .= " // '".str_replace("'", "\'", $key)."' => '".str_replace("'", "\'", $value)."',\n"; - $output .= " // '".str_replace("'", "\'", $key)."' => '',\n"; - } - } - - $output .= ");\n"; - return $output; -} - - -foreach (new DirectoryIterator('app/Locale') as $fileInfo) { - - if (! $fileInfo->isDot() && $fileInfo->isDir() && $fileInfo->getFilename() !== $reference_lang) { - - $filename = 'app/Locale/'.$fileInfo->getFilename().'/translations.php'; - - echo $fileInfo->getFilename().' ('.$filename.')'.PHP_EOL; - - file_put_contents($filename, update_missing_locales($reference, $filename)); - } -} |