From 495e44e76c15d43eb847dd73317bdb9d6926ff31 Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Thu, 1 Aug 2013 19:54:51 +0200 Subject: [PATCH] Update l10n.php to read plural_forms string --- lib/l10n.php | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/l10n.php b/lib/l10n.php index 8348962cc1..d24717a23a 100644 --- a/lib/l10n.php +++ b/lib/l10n.php @@ -54,6 +54,11 @@ class OC_L10N{ */ private $translations = array(); + /** + * Plural forms + */ + private $plural_forms = ""; + /** * Localization */ @@ -138,6 +143,9 @@ class OC_L10N{ } } } + if(isset($PLURAL_FORMS)) { + $this->plural_forms = $PLURAL_FORMS; + } } if(file_exists(OC::$SERVERROOT.'/core/l10n/l10n-'.$lang.'.php')) { @@ -177,18 +185,13 @@ 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 + * The correct plural is determined by the plural_forms-function + * provided by the po file. * - * Example: - * - * [...] - * 'selectplural' => function($i){return $i == 1 ? 0 : $i == 2 ? 1 : 2}, - * [...] */ 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)) { + if( array_key_exists($this->translations, $identifier)) { return new OC_L10N_String( $this, $identifier, $parameters, $count ); } else{ @@ -235,6 +238,17 @@ class OC_L10N{ return $this->translations; } + /** + * @brief getPluralForms + * @returns Fetches the gettext "Plural-Forms"-string + * + * Returns a string like "nplurals=2; plural=(n != 1);" + */ + public function getPluralForms() { + $this->init(); + return $this->plural_forms; + } + /** * @brief get localizations * @returns Fetch all localizations