From 8c4d71da2ef1366c8fcd3e7dfb7f4566d2f905f4 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Fri, 5 Jun 2020 20:16:04 +0200 Subject: Add missing translations (#3034) * Add missing translations * Add a simple way to check if an i18n key exists There is a rule in the makefile to access it directly --- cli/i18n/I18nData.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'cli/i18n/I18nData.php') 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 @@ -132,6 +132,17 @@ class I18nData { $this->data[$language] = $this->data[static::REFERENCE_LANGUAGE]; } + /** + * 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. * @@ -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) { -- cgit v1.2.3