diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-12-11 11:33:40 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-12-11 12:42:21 +0100 |
commit | cbad5c998b260040523ac8e6a2797591d0086938 (patch) | |
tree | f53b611ef5fad393979b5f3cc1c39eac3cd0e729 /lib/private/l10n | |
parent | b33d8a3d60555de3e6e99a92eed3a303e55a3380 (diff) | |
download | nextcloud-server-cbad5c998b260040523ac8e6a2797591d0086938.tar.gz nextcloud-server-cbad5c998b260040523ac8e6a2797591d0086938.zip |
Correctly fallback to english, if the plural case is not translated
Diffstat (limited to 'lib/private/l10n')
-rw-r--r-- | lib/private/l10n/string.php | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/private/l10n/string.php b/lib/private/l10n/string.php index 04eaacab57b..5f5452ad16d 100644 --- a/lib/private/l10n/string.php +++ b/lib/private/l10n/string.php @@ -23,6 +23,11 @@ class OC_L10N_String{ protected $parameters; /** + * @var array + */ + protected $plurals; + + /** * @var integer */ protected $count; @@ -30,11 +35,12 @@ class OC_L10N_String{ /** * @param OC_L10N $l10n */ - public function __construct($l10n, $text, $parameters, $count = 1) { + public function __construct($l10n, $text, $parameters, $count = 1, $plurals = array()) { $this->l10n = $l10n; $this->text = $text; $this->parameters = $parameters; $this->count = $count; + $this->plurals = $plurals; } public function __toString() { @@ -45,7 +51,19 @@ class OC_L10N_String{ if(is_array($translations[$this->text])) { $fn = $this->l10n->getPluralFormFunction(); $id = $fn($this->count); - $text = $translations[$this->text][$id]; + + if ($translations[$this->text][$id] !== '') { + // The translation of this plural case is not empty, so use it + $text = $translations[$this->text][$id]; + } else { + // We didn't find the plural in the language, + // so we fall back to english. + $id = ($id != 0) ? 1 : 0; + if (isset($this->plurals[$id])) { + // Fallback to the english plural + $text = $this->plurals[$id]; + } + } } else{ $text = $translations[$this->text]; |