(Bug 44987) Allow n=form in plural syntax
authorSanthosh Thottingal <santhosh.thottingal@gmail.com>
Thu, 14 Feb 2013 09:19:23 +0000 (14:49 +0530)
committerSanthosh Thottingal <santhosh.thottingal@gmail.com>
Thu, 14 Feb 2013 10:02:46 +0000 (15:32 +0530)
phpunit testcases included

Change-Id: I7be51e24a0b953dcd1f9cb21f54af9b4127a5cdb

languages/Language.php
tests/phpunit/languages/LanguageTest.php

index ffb3268..7611e54 100644 (file)
@@ -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] );
                        }
index 9507714..eba63dc 100644 (file)
@@ -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',
+                       ) ),
                );
        }