diff options
| author | 2020-06-10 23:14:47 +0200 | |
|---|---|---|
| committer | 2020-06-10 23:14:47 +0200 | |
| commit | 7f76c8e553a498f8235c5fa79622b6d79b86765b (patch) | |
| tree | 9e0db10d5ed0e0c96f285db74a5930b274523857 | |
| parent | f34f1ff8f119f86a0743f78b1a4cbe31476c5df6 (diff) | |
Add a language reference while adding a new one (#3044)
Before, all new languages were generated from the reference language which
was English. It makes sense for new languages but not so much for new language
flavor (ex: French Canadian versus French French)
Now, there is a way to select the reference language while adding a new one.
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | cli/i18n/I18nData.php | 8 | ||||
| -rw-r--r-- | cli/manipulate.translation.php | 11 |
3 files changed, 16 insertions, 5 deletions
@@ -94,7 +94,7 @@ ifndef lang @echo To add a new language, you need to provide one in the "lang" variable. @exit 10 endif - @$(PHP) ./cli/manipulate.translation.php -a add -l $(lang) + $(PHP) ./cli/manipulate.translation.php -a add -l $(lang) -o $(ref) @echo Language added. .PHONY: i18n-add-key diff --git a/cli/i18n/I18nData.php b/cli/i18n/I18nData.php index 2f09a5525..5071c9be9 100644 --- a/cli/i18n/I18nData.php +++ b/cli/i18n/I18nData.php @@ -123,13 +123,17 @@ class I18nData { * Add a new language. It's a copy of the reference language. * * @param string $language + * @param string $reference * @throws Exception */ - public function addLanguage($language) { + public function addLanguage($language, $reference = null) { if (array_key_exists($language, $this->data)) { throw new Exception('The selected language already exist.'); } - $this->data[$language] = $this->data[static::REFERENCE_LANGUAGE]; + if (!is_string($reference) && !array_key_exists($reference, $this->data)) { + $reference = static::REFERENCE_LANGUAGE; + } + $this->data[$language] = $this->data[$reference]; } /** diff --git a/cli/manipulate.translation.php b/cli/manipulate.translation.php index c1f1132b4..b5c37d147 100644 --- a/cli/manipulate.translation.php +++ b/cli/manipulate.translation.php @@ -4,7 +4,7 @@ require_once __DIR__ . '/i18n/I18nData.php'; require_once __DIR__ . '/i18n/I18nFile.php'; require_once __DIR__ . '/i18n/I18nIgnoreFile.php'; -$options = getopt("a:hk:l:rv:"); +$options = getopt("a:hk:l:o:rv:"); if (array_key_exists('h', $options)) { help(); @@ -25,7 +25,11 @@ switch ($options['a']) { } elseif (array_key_exists('k', $options) && array_key_exists('v', $options)) { $i18nData->addKey($options['k'], $options['v']); } elseif (array_key_exists('l', $options)) { - $i18nData->addLanguage($options['l']); + $reference = null; + if (array_key_exists('o', $options) && is_string($options['o'])) { + $reference = $options['o']; + } + $i18nData->addLanguage($options['l'], $reference); } else { error('You need to specify a valid set of options.'); exit; @@ -103,10 +107,13 @@ DESCRIPTION -v=VAL select the value to set. -l=LANG select the language to work on. -h display this help and exit. + -r revert the action (only for ignore action) + -o=LANG select the origin language (only for add language action) EXEMPLE Exemple 1: add a language. It adds a new language by duplicating the referential. php %1\$s -a add -l my_lang + php %1\$s -a add -l my_lang -o ref_lang 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 |
