summaryrefslogtreecommitdiff
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
parentd7a8160c2b422dcf950093d9d17d90f1e80201de (diff)
Move the script sync-locales.php to cli command
-rw-r--r--app/Console/LocaleSync.php57
-rw-r--r--app/Locale/pl_PL/translations.php4
-rw-r--r--docs/translations.markdown4
-rwxr-xr-xkanboard1
-rwxr-xr-xscripts/sync-locales.php43
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.
diff --git a/kanboard b/kanboard
index f6456ea1..f6176b9f 100755
--- a/kanboard
+++ b/kanboard
@@ -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));
- }
-}