aboutsummaryrefslogtreecommitdiff
path: root/cli/i18n/I18nData.php
diff options
context:
space:
mode:
authorGravatar Alexis Degrugillier <aledeg@users.noreply.github.com> 2020-06-05 20:16:04 +0200
committerGravatar GitHub <noreply@github.com> 2020-06-05 20:16:04 +0200
commit8c4d71da2ef1366c8fcd3e7dfb7f4566d2f905f4 (patch)
tree91c820081a54f8f4fd8f5832a02c4f5e83fc6cde /cli/i18n/I18nData.php
parent36bda2e715ed822cc495ff419ad565084e241f43 (diff)
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
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) {