Update l10n.php to read plural_forms string

This commit is contained in:
Jakob Sack 2013-08-01 19:54:51 +02:00
parent e064e53aa3
commit 495e44e76c
1 changed files with 22 additions and 8 deletions

View File

@ -54,6 +54,11 @@ class OC_L10N{
*/ */
private $translations = array(); private $translations = array();
/**
* Plural forms
*/
private $plural_forms = "";
/** /**
* Localization * 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')) { 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 * Returns the translation. If no translation is found, $text will be
* returned. %n will be replaced with the number of objects. * returned. %n will be replaced with the number of objects.
* *
* In case there is more than one plural form you can add a function * The correct plural is determined by the plural_forms-function
* "selectplural" in core/l10n/l10n-*.php * 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()) { public function n($text_singular, $text_plural, $count, $parameters = array()) {
$identifier = "_${text_singular}__${text_plural}_"; $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 ); return new OC_L10N_String( $this, $identifier, $parameters, $count );
} }
else{ else{
@ -235,6 +238,17 @@ class OC_L10N{
return $this->translations; 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 * @brief get localizations
* @returns Fetch all localizations * @returns Fetch all localizations