Move the script sync-locales.php to cli command
This commit is contained in:
57
app/Console/LocaleSync.php
Normal file
57
app/Console/LocaleSync.php
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -787,7 +787,7 @@ return array(
|
|||||||
'Custom Stylesheet' => 'Niestandardowy arkusz stylów',
|
'Custom Stylesheet' => 'Niestandardowy arkusz stylów',
|
||||||
'download' => 'pobierz',
|
'download' => 'pobierz',
|
||||||
'Do you really want to remove this budget line?' => 'Czy chcesz usunąć tą linię budżetową?',
|
'Do you really want to remove this budget line?' => 'Czy chcesz usunąć tą linię budżetową?',
|
||||||
//'EUR - Euro' => '',
|
// 'EUR - Euro' => '',
|
||||||
'Expenses' => 'Wydatki',
|
'Expenses' => 'Wydatki',
|
||||||
'GBP - British Pound' => 'GBP - Funt brytyjski',
|
'GBP - British Pound' => 'GBP - Funt brytyjski',
|
||||||
'INR - Indian Rupee' => 'INR - Rupia indyjska',
|
'INR - Indian Rupee' => 'INR - Rupia indyjska',
|
||||||
@@ -797,7 +797,7 @@ return array(
|
|||||||
'Remove a budget line' => 'Usuń linię budżetową',
|
'Remove a budget line' => 'Usuń linię budżetową',
|
||||||
'Remove budget line' => 'Usuń linię budżetową',
|
'Remove budget line' => 'Usuń linię budżetową',
|
||||||
'RSD - Serbian dinar' => 'RSD - Dinar serbski',
|
'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 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',
|
'Unable to remove this budget line.' => 'Nie można usunąć tej linii budżetowej',
|
||||||
'USD - US Dollar' => 'USD - Dolar amerykański',
|
'USD - US Dollar' => 'USD - Dolar amerykański',
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ How to synchronize translation files?
|
|||||||
From a Unix shell run this command:
|
From a Unix shell run this command:
|
||||||
|
|
||||||
```bash
|
```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.
|
||||||
|
|||||||
1
kanboard
1
kanboard
@@ -15,4 +15,5 @@ $application->add(new Console\TaskExport($container));
|
|||||||
$application->add(new Console\ProjectDailySummaryCalculation($container));
|
$application->add(new Console\ProjectDailySummaryCalculation($container));
|
||||||
$application->add(new Console\ProjectDailySummaryExport($container));
|
$application->add(new Console\ProjectDailySummaryExport($container));
|
||||||
$application->add(new Console\TransitionExport($container));
|
$application->add(new Console\TransitionExport($container));
|
||||||
|
$application->add(new Console\LocaleSync($container));
|
||||||
$application->run();
|
$application->run();
|
||||||
|
|||||||
@@ -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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user