diff options
author | Jakob Sack <mail@jakobsack.de> | 2013-07-16 22:16:53 +0200 |
---|---|---|
committer | Jakob Sack <mail@jakobsack.de> | 2013-07-16 22:16:53 +0200 |
commit | bb0c5bff5fc493dd24c2c9cbbf27986fd5098de1 (patch) | |
tree | 9aa2eceb270a6f9fbeaba5ec74b3a37f0121a5cc /lib/l10n.php | |
parent | 18fc22b52bdf1d8372a6e9c602872c423ce50eff (diff) | |
download | nextcloud-server-bb0c5bff5fc493dd24c2c9cbbf27986fd5098de1.tar.gz nextcloud-server-bb0c5bff5fc493dd24c2c9cbbf27986fd5098de1.zip |
Add multiple plural forms to the php part
Diffstat (limited to 'lib/l10n.php')
-rw-r--r-- | lib/l10n.php | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/lib/l10n.php b/lib/l10n.php index 03528c22746..8348962cc10 100644 --- a/lib/l10n.php +++ b/lib/l10n.php @@ -176,13 +176,28 @@ class OC_L10N{ * * Returns the translation. If no translation is found, $text will be * returned. %n will be replaced with the number of objects. + * + * In case there is more than one plural form you can add a function + * "selectplural" in core/l10n/l10n-*.php + * + * Example: + * + * [...] + * 'selectplural' => function($i){return $i == 1 ? 0 : $i == 2 ? 1 : 2}, + * [...] */ - public function tp($text_singular, $text_plural, $count, $parameters = array()) { - if($count == 1){ - return new OC_L10N_String($this, $text_singular, $parameters, $count); + public function n($text_singular, $text_plural, $count, $parameters = array()) { + $identifier = "_${text_singular}__${text_plural}_"; + if(array_key_exists( $this->localizations, "selectplural") && array_key_exists($this->translations, $identifier)) { + return new OC_L10N_String( $this, $identifier, $parameters, $count ); } else{ - return new OC_L10N_String($this, $text_plural, $parameters, $count); + if($count === 1) { + return new OC_L10N_String($this, $text_singular, $parameters, $count); + } + else{ + return new OC_L10N_String($this, $text_plural, $parameters, $count); + } } } @@ -221,6 +236,17 @@ class OC_L10N{ } /** + * @brief get localizations + * @returns Fetch all localizations + * + * Returns an associative array with all localizations + */ + public function getLocalizations() { + $this->init(); + return $this->localizations; + } + + /** * @brief Localization * @param $type Type of localization * @param $params parameters for this localization |