aboutsummaryrefslogtreecommitdiff
path: root/cli/i18n/I18nData.php
diff options
context:
space:
mode:
Diffstat (limited to 'cli/i18n/I18nData.php')
-rw-r--r--cli/i18n/I18nData.php17
1 files changed, 13 insertions, 4 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) {