diff options
Diffstat (limited to 'cli')
| -rw-r--r-- | cli/i18n/I18nData.php | 17 | ||||
| -rw-r--r-- | cli/manipulate.translation.php | 20 |
2 files changed, 31 insertions, 6 deletions
diff --git a/cli/i18n/I18nData.php b/cli/i18n/I18nData.php index a6d260a8f..2f09a5525 100644 --- a/cli/i18n/I18nData.php +++ b/cli/i18n/I18nData.php @@ -133,6 +133,17 @@ class I18nData { } /** + * Check if the key is known. + * + * @param string $key + * @return bool + */ + public function isKnown($key) { + return array_key_exists($this->getFilenamePrefix($key), $this->data[static::REFERENCE_LANGUAGE]) && + array_key_exists($key, $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)]); + } + + /** * Add a new key to all languages. * * @param string $key @@ -140,8 +151,7 @@ class I18nData { * @throws Exception */ public function addKey($key, $value) { - if (array_key_exists($this->getFilenamePrefix($key), $this->data[static::REFERENCE_LANGUAGE]) && - array_key_exists($key, $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)])) { + if ($this->isKnown($key)) { throw new Exception('The selected key already exist.'); } @@ -178,8 +188,7 @@ class I18nData { * @throws Exception */ public function removeKey($key) { - if (!array_key_exists($this->getFilenamePrefix($key), $this->data[static::REFERENCE_LANGUAGE]) || - !array_key_exists($key, $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)])) { + if (!$this->isKnown($key)) { throw new Exception('The selected key does not exist.'); } foreach ($this->getAvailableLanguages() as $language) { diff --git a/cli/manipulate.translation.php b/cli/manipulate.translation.php index c6aa328d9..c1f1132b4 100644 --- a/cli/manipulate.translation.php +++ b/cli/manipulate.translation.php @@ -39,6 +39,19 @@ switch ($options['a']) { exit; } break; + case 'exist': + if (array_key_exists('k', $options)) { + $key = $options['k']; + if ($i18nData->isKnown($key)) { + echo "The '{$key}' key is known.\n\n"; + } else { + echo "The '{$key}' key is unknown.\n\n"; + } + } else { + error('You need to specify the key to check.'); + exit; + } + break; case 'format' : break; case 'ignore' : @@ -85,7 +98,7 @@ DESCRIPTION -a=ACTION select the action to perform. Available actions are add, delete, - format, and ignore. This option is mandatory. + exist, 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. @@ -111,7 +124,10 @@ Exemple 6: ignore a key. It adds the key in the ignore file to mark it as transl php %1\$s -a ignore -k my_key -l my_lang 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 + php %1\$s -a ignore -r -k my_key -l my_lang + +Exemple 8: check if a key exist. + php %1\$s -a exist -k my_key\n\n HELP; $file = str_replace(__DIR__ . '/', '', __FILE__); echo sprintf($help, $file); |
