Merge "(Bug 44987) Allow n=form in plural syntax"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 26 Feb 2013 15:27:31 +0000 (15:27 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 26 Feb 2013 15:27:31 +0000 (15:27 +0000)
1  2 
languages/Language.php
tests/phpunit/languages/LanguageTest.php

diff --combined languages/Language.php
@@@ -3007,18 -3007,6 +3007,18 @@@ class Language 
                return $number;
        }
  
 +      /**
 +       * Front-end for non-commafied formatNum
 +       *
 +       * @param mixed $number the string to be formatted, should be an integer
 +       *        or a floating point number.
 +       * @since 1.21
 +       * @return string
 +       */
 +      public function formatNumNoSeparators( $number ) {
 +              return $this->formatNum( $number, true );
 +      }
 +
        /**
         * @param $number string
         * @return string
                        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] );
                        }
@@@ -439,10 -439,10 +439,10 @@@ class LanguageTest extends LanguageClas
  
        function provideLanguageCodes() {
                return array(
 -                      array( 'fr'       , 'Two letters, minor case' ),
 -                      array( 'EN'       , 'Two letters, upper case' ),
 -                      array( 'tyv'      , 'Three letters' ),
 -                      array( 'tokipona'   , 'long language code' ),
 +                      array( 'fr', 'Two letters, minor case' ),
 +                      array( 'EN', 'Two letters, upper case' ),
 +                      array( 'tyv', 'Three letters' ),
 +                      array( 'tokipona', 'long language code' ),
                        array( 'be-tarask', 'With dash' ),
                        array( 'Zh-classical', 'Begin with upper case, dash' ),
                        array( 'Be-x-old', 'With extension (two dashes)' ),
         */
        function testKnownLanguageTag( $code, $message = '' ) {
                $this->assertTrue(
 -                      (bool) Language::isKnownLanguageTag( $code ),
 +                      (bool)Language::isKnownLanguageTag( $code ),
                        "validating code $code - $message"
                );
        }
         */
        function testKnownCldrLanguageTag() {
                if ( !class_exists( 'LanguageNames' ) ) {
 -                      $this->markTestSkipped( 'reason' );
 +                      $this->markTestSkipped( 'The LanguageNames class is not available. The cldr extension is probably not installed.' );
                }
  
                $this->assertTrue(
 -                      (bool) Language::isKnownLanguageTag( 'pal' ),
 +                      (bool)Language::isKnownLanguageTag( 'pal' ),
                        'validating code "pal" an ancient language, which probably will not appear in Names.php, but appears in CLDR in English'
                );
        }
         */
        function testUnknownLanguageTag( $code, $message = '' ) {
                $this->assertFalse(
 -                      (bool) Language::isKnownLanguageTag( $code ),
 +                      (bool)Language::isKnownLanguageTag( $code ),
                        "checking that code $code is invalid - $message"
                );
        }
                        "sprintfDate('$format', '$ts'): $msg"
                );
        }
 +
        /**
         * bug 33454. sprintfDate should always use UTC.
         * @dataProvider provideSprintfDateSamples
        }
  
  
 -
        /**
         * @dataProvider provideFormatDuration
         */
        function testCheckTitleEncoding( $s ) {
                $this->assertEquals(
                        $s,
 -                      $this->getLang()->checkTitleEncoding($s),
 +                      $this->getLang()->checkTitleEncoding( $s ),
                        "checkTitleEncoding('$s')"
                );
        }
  
        function provideCheckTitleEncodingData() {
 -              return array (
 +              return array(
                        array( "" ),
                        array( "United States of America" ), // 7bit ASCII
                        array( rawurldecode( "S%C3%A9rie%20t%C3%A9l%C3%A9vis%C3%A9e" ) ),
                        array( 7000, 'MMMMMMM' ),
                        array( 8000, 'MMMMMMMM' ),
                        array( 9000, 'MMMMMMMMM' ),
 -                      array( 9999, 'MMMMMMMMMCMXCIX'),
 +                      array( 9999, 'MMMMMMMMMCMXCIX' ),
                        array( 10000, 'MMMMMMMMMM' ),
                );
        }
  
        function providePluralData() {
                return array(
+                       array( 'plural', 0, array(
+                               'singular', 'plural'
+                       ) ),
                        array( 'explicit zero', 0, array(
                                '0=explicit zero', 'singular', 'plural'
                        ) ),
                        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',
+                       ) ),
                );
        }
  
                $s = $lang->getMessageFromDB( 'word-separator' );
                $c = $lang->getMessageFromDB( 'comma-separator' );
  
 -              $this->assertEquals( '', $lang->listToText( array( ) ) );
 +              $this->assertEquals( '', $lang->listToText( array() ) );
                $this->assertEquals( 'a', $lang->listToText( array( 'a' ) ) );
                $this->assertEquals( "a{$and}{$s}b", $lang->listToText( array( 'a', 'b' ) ) );
                $this->assertEquals( "a{$c}b{$and}{$s}c", $lang->listToText( array( 'a', 'b', 'c' ) ) );