|
|
@@ -32,6 +32,7 @@ class I18nData {
|
|
|
* Add a new language. It's a copy of the reference language.
|
|
|
*
|
|
|
* @param string $language
|
|
|
+ * @throws Exception
|
|
|
*/
|
|
|
public function addLanguage($language) {
|
|
|
if (array_key_exists($language, $this->data)) {
|
|
|
@@ -45,6 +46,7 @@ class I18nData {
|
|
|
*
|
|
|
* @param string $key
|
|
|
* @param string $value
|
|
|
+ * @throws Exception
|
|
|
*/
|
|
|
public function addKey($key, $value) {
|
|
|
if (array_key_exists($key, $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)])) {
|
|
|
@@ -53,10 +55,29 @@ class I18nData {
|
|
|
$this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)][$key] = $value;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Add a value for a key for the selected language.
|
|
|
+ *
|
|
|
+ * @param string $key
|
|
|
+ * @param string $value
|
|
|
+ * @param string $language
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public function addValue($key, $value, $language) {
|
|
|
+ if (!in_array($language, $this->getAvailableLanguages())) {
|
|
|
+ throw new Exception('The selected language does not exist.');
|
|
|
+ }
|
|
|
+ if (!array_key_exists($key, $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)])) {
|
|
|
+ throw new Exception('The selected key does not exist for the selected language.');
|
|
|
+ }
|
|
|
+ $this->data[$language][$this->getFilenamePrefix($key)][$key] = $value;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Duplicate a key from the reference language to all other languages
|
|
|
*
|
|
|
* @param string $key
|
|
|
+ * @throws Exception
|
|
|
*/
|
|
|
public function duplicateKey($key) {
|
|
|
if (!array_key_exists($key, $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)])) {
|
|
|
@@ -68,7 +89,7 @@ class I18nData {
|
|
|
continue;
|
|
|
}
|
|
|
if (array_key_exists($key, $this->data[$language][$this->getFilenamePrefix($key)])) {
|
|
|
- throw new Exception(sprintf('The selected key already exist in %s.', $language));
|
|
|
+ continue;
|
|
|
}
|
|
|
$this->data[$language][$this->getFilenamePrefix($key)][$key] = $value;
|
|
|
}
|
|
|
@@ -78,6 +99,7 @@ class I18nData {
|
|
|
* Remove a key in all languages
|
|
|
*
|
|
|
* @param string $key
|
|
|
+ * @throws Exception
|
|
|
*/
|
|
|
public function removeKey($key) {
|
|
|
if (!array_key_exists($key, $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)])) {
|