Ver Fonte

Change how updating a key works (#3072)

Before, to update a key from the reference language (en), the key was deleted
then created. This way was unproductive for all keys already translated.
Now, the key is updated in all untranslated languages.

See https://github.com/FreshRSS/FreshRSS/pull/3068#issuecomment-646868894
Alexis Degrugillier há 6 anos atrás
pai
commit
d7d39f0736
2 ficheiros alterados com 11 adições e 3 exclusões
  1. 1 2
      Makefile
  2. 10 1
      cli/i18n/I18nData.php

+ 1 - 2
Makefile

@@ -125,8 +125,7 @@ endif
 ifndef value
 	$(error To update a key, you need to provide its value in the "value" variable)
 endif
-	@$(PHP) ./cli/manipulate.translation.php -a delete -k $(key)
-	@$(PHP) ./cli/manipulate.translation.php -a add -k $(key) -v "$(value)"
+	@$(PHP) ./cli/manipulate.translation.php -a add -k $(key) -v "$(value)" -l en
 	@echo Key updated.
 
 .PHONY: i18n-ignore-key

+ 10 - 1
cli/i18n/I18nData.php

@@ -182,7 +182,16 @@ class I18nData {
 		    !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;
+		if (static::REFERENCE_LANGUAGE === $language) {
+			$previousValue = $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)][$key];
+			foreach ($this->getAvailableLanguages() as $lang) {
+				if ($this->data[$lang][$this->getFilenamePrefix($key)][$key] === $previousValue) {
+					$this->data[$lang][$this->getFilenamePrefix($key)][$key] = $value;
+				}
+			}
+		} else {
+			$this->data[$language][$this->getFilenamePrefix($key)][$key] = $value;
+		}
 	}
 
 	/**