*/
public static function isValidBuiltInCode( $code ) {
- if( !is_string($code) ) {
+ if ( !is_string( $code ) ) {
$type = gettype( $code );
- if( $type === 'object' ) {
+ if ( $type === 'object' ) {
$addmsg = " of class " . get_class( $code );
} else {
$addmsg = '';
$names = array();
- if( $inLanguage ) {
+ if ( $inLanguage ) {
# TODO: also include when $inLanguage is null, when this code is more efficient
wfRunHooks( 'LanguageGetTranslatedLanguageNames', array( &$names, $inLanguage ) );
}
$returnMw = array();
$coreCodes = array_keys( $mwNames );
- foreach( $coreCodes as $coreCode ) {
+ foreach ( $coreCodes as $coreCode ) {
$returnMw[$coreCode] = $names[$coreCode];
}
- if( $include === 'mwfile' ) {
+ if ( $include === 'mwfile' ) {
$namesMwFile = array();
# We do this using a foreach over the codes instead of a directory
# loop so that messages files in extensions will work correctly.
if ( !count( $forms ) ) {
return '';
}
- $forms = $this->preConvertPlural( $forms, 2 );
-
- return ( $count == 1 ) ? $forms[0] : $forms[1];
+ $pluralForm = $this->getPluralForm( $count );
+ $pluralForm = min( $pluralForm, count( $forms ) - 1 );
+ return $forms[$pluralForm];
}
/**
public function getConvRuleTitle() {
return $this->mConverter->getConvRuleTitle();
}
+
+ /**
+ * Get the compiled plural rules for the language
+ * @since 1.20
+ * @return array Associative array with plural form, and plural rule as key-value pairs
+ */
+ public function getCompiledPluralRules() {
+ return self::$dataCache->getItem( strtolower( $this->mCode ), 'compiledPluralRules' );
+ }
+
+ /**
+ * Get the plural rules for the language
+ * @since 1.20
+ * @return array Associative array with plural form, and plural rule as key-value pairs
+ */
+ public function getPluralRules() {
+ return self::$dataCache->getItem( strtolower( $this->mCode ), 'pluralRules' );
+ }
+
+ /**
+ * Find the plural form matching to the given number
+ * It return the form index.
+ * @return int The index of the plural form
+ */
+ private function getPluralForm( $number ) {
+ $pluralRules = $this->getCompiledPluralRules();
+ $form = CLDRPluralRuleEvaluator::evaluateCompiled( $number, $pluralRules );
+ return $form;
+ }
+
}