From ff3df41363be063001b73c376e4dca9b62d0ed77 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Thu, 14 Feb 2013 14:49:23 +0530 Subject: [PATCH] (Bug 44987) Allow n=form in plural syntax phpunit testcases included Change-Id: I7be51e24a0b953dcd1f9cb21f54af9b4127a5cdb --- languages/Language.php | 9 +++++---- tests/phpunit/languages/LanguageTest.php | 12 ++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/languages/Language.php b/languages/Language.php index ffb32687b7..7611e54a72 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -3520,11 +3520,12 @@ class Language { return ''; } - // Handle explicit 0= and 1= forms + // Handle explicit n=pluralform cases foreach ( $forms as $index => $form ) { - if ( isset( $form[1] ) && $form[1] === '=' ) { - if ( $form[0] === (string) $count ) { - return substr( $form, 2 ); + if ( preg_match( '/\d+=/i', $form ) ) { + $pos = strpos( $form, '=' ); + if ( substr( $form, 0, $pos ) === (string) $count ) { + return substr( $form, $pos + 1 ); } unset( $forms[$index] ); } diff --git a/tests/phpunit/languages/LanguageTest.php b/tests/phpunit/languages/LanguageTest.php index 9507714df5..eba63dcf4d 100644 --- a/tests/phpunit/languages/LanguageTest.php +++ b/tests/phpunit/languages/LanguageTest.php @@ -1227,6 +1227,9 @@ class LanguageTest extends LanguageClassesTestCase { function providePluralData() { return array( + array( 'plural', 0, array( + 'singular', 'plural' + ) ), array( 'explicit zero', 0, array( '0=explicit zero', 'singular', 'plural' ) ), @@ -1239,6 +1242,15 @@ class LanguageTest extends LanguageClassesTestCase { array( 'plural', 3, array( '0=explicit zero', '1=explicit one', 'singular', 'plural' ) ), + array( 'explicit elevan', 11, array( + 'singular', 'plural', '11=explicit elevan', + ) ), + array( 'plural', 12, array( + 'singular', 'plural', '11=explicit twelve', + ) ), + array( 'plural', 12, array( + 'singular', 'plural', '=explicit form', + ) ), ); } -- 2.20.1