summaryrefslogtreecommitdiff
path: root/cli/manipulate.translation.php
diff options
context:
space:
mode:
authorGravatar Alexis Degrugillier <aledeg@users.noreply.github.com> 2019-12-04 08:27:39 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2019-12-04 08:27:39 +0100
commit3e49b44839237693ce1a8151325942704917f6c6 (patch)
tree75a1af8089d48d3bb14de2d9d98c503ee76433e2 /cli/manipulate.translation.php
parentde2b323847e0a91119625e4f506f51ec9d43872f (diff)
Update i18n cli tools (#2673)
* Update i18n cli tools Few things were bugging me when using the cli tool for i18n. So I've modified the tools to be easier to use. First, the tool automatically adds missing keys to all languages. This way, we always have all keys in all languages. Second, the tool detects all untranslated keys and adds automatically the todo comment after the value. Third, when adding a new key, the key is pushed to all languages at once. There is no need to duplicate it manually. Thus making the duplication process obsolete. Fourth, translation and ignore keys are manipulated at the same time. Thus we don't have obsolete ignored strings anymore. * Add i18n rules I find that having the common rules in the Makefile is easier to use, as long as you know they are here. As it is self documented, people will see the new rules when using make. * Use long parameters in Makefile I find that using long parameters in scripts makes it easier to understand what's going on. So I've switched all short parameters to long one. * Format all i18n files I've used the updated version of the cli tools to have some output that can be consistently formated. This commit is a huge formating commit. Nothing was added but some comments were removed in the process.
Diffstat (limited to 'cli/manipulate.translation.php')
-rw-r--r--cli/manipulate.translation.php47
1 files changed, 19 insertions, 28 deletions
diff --git a/cli/manipulate.translation.php b/cli/manipulate.translation.php
index 35405bb89..c6aa328d9 100644
--- a/cli/manipulate.translation.php
+++ b/cli/manipulate.translation.php
@@ -1,5 +1,9 @@
<?php
+require_once __DIR__ . '/i18n/I18nData.php';
+require_once __DIR__ . '/i18n/I18nFile.php';
+require_once __DIR__ . '/i18n/I18nIgnoreFile.php';
+
$options = getopt("a:hk:l:rv:");
if (array_key_exists('h', $options)) {
@@ -10,14 +14,9 @@ if (!array_key_exists('a', $options)) {
error('You need to specify the action to perform.');
}
-if ('ignore' === $options['a']) {
- require_once __DIR__ . '/i18n/I18nIgnoreFile.php';
- $i18nFile = new I18nIgnoreFile();
-} else {
- require_once __DIR__ . '/i18n/I18nFile.php';
- $i18nFile = new I18nFile();
-}
-$i18nData = $i18nFile->load();
+$data = new I18nFile();
+$ignore = new I18nIgnoreFile();
+$i18nData = new I18nData($data->load(), $ignore->load());
switch ($options['a']) {
case 'add' :
@@ -29,6 +28,7 @@ switch ($options['a']) {
$i18nData->addLanguage($options['l']);
} else {
error('You need to specify a valid set of options.');
+ exit;
}
break;
case 'delete' :
@@ -36,32 +36,26 @@ switch ($options['a']) {
$i18nData->removeKey($options['k']);
} else {
error('You need to specify the key to delete.');
- }
- break;
- case 'duplicate' :
- if (array_key_exists('k', $options)) {
- $i18nData->duplicateKey($options['k']);
- } else {
- error('You need to specify the key to duplicate');
+ exit;
}
break;
case 'format' :
- $i18nFile->dump($i18nData);
break;
case 'ignore' :
if (array_key_exists('l', $options) && array_key_exists('k', $options)) {
$i18nData->ignore($options['k'], $options['l'], array_key_exists('r', $options));
} else {
error('You need to specify a valid set of options.');
+ exit;
}
break;
default :
help();
+ exit;
}
-if ($i18nData->hasChanged()) {
- $i18nFile->dump($i18nData);
-}
+$data->dump($i18nData->getData());
+$ignore->dump($i18nData->getIgnore());
/**
* Output error message.
@@ -91,7 +85,7 @@ DESCRIPTION
-a=ACTION
select the action to perform. Available actions are add, delete,
- duplicate, format, and ignore. This option is mandatory.
+ format, and ignore. This option is mandatory.
-k=KEY select the key to work on.
-v=VAL select the value to set.
-l=LANG select the language to work on.
@@ -101,25 +95,22 @@ EXEMPLE
Exemple 1: add a language. It adds a new language by duplicating the referential.
php %1\$s -a add -l my_lang
-Exemple 2: add a new key. It adds the key in the referential.
+Exemple 2: add a new key. It adds the key for all supported languages.
php %1\$s -a add -k my_key -v my_value
Exemple 3: add a new value. It adds a new value for the selected key in the selected language.
php %1\$s -a add -k my_key -v my_value -l my_lang
-Exemple 4: delete a key. It deletes the selected key in every languages.
+Exemple 4: delete a key. It deletes the selected key from all supported languages.
php %1\$s -a delete -k my_key
-Exemple 5: duplicate a key. It duplicates the key from the referential in every languages.
- php %1\$s -a duplicate -k my_key
-
-Exemple 6: format i18n files.
+Exemple 5: format i18n files.
php %1\$s -a format
-Exemple 7: ignore a key. It adds the key in the ignore file to mark it as translated.
+Exemple 6: ignore a key. It adds the key in the ignore file to mark it as translated.
php %1\$s -a ignore -k my_key -l my_lang
-Exemple 8: revert ignore a key. It removes the key from the ignore file.
+Exemple 7: revert ignore a key. It removes the key from the ignore file.
php %1\$s -a ignore -r -k my_key -l my_lang\n\n
HELP;
$file = str_replace(__DIR__ . '/', '', __FILE__);