diff options
Diffstat (limited to 'languages/Language.php')
-rw-r--r-- | languages/Language.php | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/languages/Language.php b/languages/Language.php index c24dc180..11d91036 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -3633,17 +3633,10 @@ class Language { */ function convertPlural( $count, $forms ) { // Handle explicit n=pluralform cases - foreach ( $forms as $index => $form ) { - if ( preg_match( '/^\d+=/i', $form ) ) { - $pos = strpos( $form, '=' ); - if ( substr( $form, 0, $pos ) === (string)$count ) { - return substr( $form, $pos + 1 ); - } - unset( $forms[$index] ); - } + $forms = $this->handleExplicitPluralForms( $count, $forms ); + if ( is_string( $forms ) ) { + return $forms; } - - $forms = array_values( $forms ); if ( !count( $forms ) ) { return ''; } @@ -3654,6 +3647,34 @@ class Language { } /** + * Handles explicit plural forms for Language::convertPlural() + * + * In {{PLURAL:$1|0=nothing|one|many}}, 0=nothing will be returned if $1 equals zero. + * If an explicitly defined plural form matches the $count, then + * string value returned, otherwise array returned for further consideration + * by CLDR rules or overridden convertPlural(). + * + * @since 1.22.1 + * + * @param int $count non-localized number + * @param array $forms different plural forms + * + * @return array|string + */ + protected function handleExplicitPluralForms( $count, array $forms ) { + foreach ( $forms as $index => $form ) { + if ( preg_match( '/\d+=/i', $form ) ) { + $pos = strpos( $form, '=' ); + if ( substr( $form, 0, $pos ) === (string) $count ) { + return substr( $form, $pos + 1 ); + } + unset( $forms[$index] ); + } + } + return array_values( $forms ); + } + + /** * Checks that convertPlural was given an array and pads it to requested * amount of forms by copying the last one. * |