diff options
| author | 2025-09-05 16:57:34 -0400 | |
|---|---|---|
| committer | 2025-09-05 22:57:34 +0200 | |
| commit | de624dc8ce63ec819c61216d9d44f828841c293e (patch) | |
| tree | 5c14d7a1984e3ba6ee739a97edd1b2fe86b3c10f /cli/i18n/I18nData.php | |
| parent | 2404a29ee559c953221187111150114ddce3766c (diff) | |
Add new file in i18n (#7917)
When manipulating I18N files, it is now possible to add a new file to all
languages. This action is available both in the manipulation script and
the makefile.
Diffstat (limited to 'cli/i18n/I18nData.php')
| -rw-r--r-- | cli/i18n/I18nData.php | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/cli/i18n/I18nData.php b/cli/i18n/I18nData.php index 7170765b7..981c19e62 100644 --- a/cli/i18n/I18nData.php +++ b/cli/i18n/I18nData.php @@ -110,11 +110,18 @@ class I18nData { * Check if the key is known. */ public function isKnown(string $key): bool { - return array_key_exists($this->getFilenamePrefix($key), $this->data[static::REFERENCE_LANGUAGE]) && + return $this->exists($key) && array_key_exists($key, $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)]); } /** + * Check if the file exists + */ + public function exists(string $file): bool { + return array_key_exists($this->getFilenamePrefix($file), $this->data[static::REFERENCE_LANGUAGE]); + } + + /** * Return the parent key for a specified key. * To get the parent key, you need to remove the last section of the key. Each * is separated into sections. The parent of a section is the concatenation of @@ -187,6 +194,24 @@ class I18nData { } /** + * Add a new translation file to all languages + * @throws Exception + */ + public function addFile(string $file): void { + $file = strtolower($file); + if (!str_ends_with($file, '.php')) { + throw new Exception('The selected file name is not supported.'); + } + if ($this->exists($file)) { + throw new Exception('The selected file exists already.'); + } + + foreach ($this->getAvailableLanguages() as $language) { + $this->data[$language][$this->getFilenamePrefix($file)] = []; + } + } + + /** * Add a new key to all languages. * @throws Exception */ |
