Support nesting of expressions in parameters of explicit plural forms
authorSanthosh Thottingal <santhosh.thottingal@gmail.com>
Tue, 26 Aug 2014 04:09:17 +0000 (09:39 +0530)
committerJdlrobson <jrobson@wikimedia.org>
Tue, 26 Aug 2014 16:54:53 +0000 (16:54 +0000)
Bug: 69993
Change-Id: I15c167f245ba0842fc77fb4e03e380c40784ee1b

resources/src/mediawiki/mediawiki.jqueryMsg.js
tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js

index 3f778d8..a81730e 100644 (file)
                 * @return {string} selected pluralized form according to current language
                 */
                plural: function ( nodes ) {
-                       var forms, count;
+                       var forms, formIndex, node, count;
                        count = parseFloat( this.language.convertNumber( nodes[0], true ) );
                        forms = nodes.slice( 1 );
+                       for ( formIndex = 0; formIndex < forms.length; formIndex++ ) {
+                               node = forms[formIndex];
+                               if ( node.jquery && node.hasClass( 'mediaWiki_htmlEmitter' )  ) {
+                                       // This is a nested node, already expanded.
+                                       forms[formIndex] = forms[formIndex].html();
+                               }
+                       }
                        return forms.length ? this.language.convertPlural( count, forms ) : '';
                },
 
index afa57ee..906fd27 100644 (file)
@@ -40,7 +40,8 @@
                        'gender-msg-currentuser': '{{GENDER:|blue|pink|green}}',
 
                        'plural-msg': 'Found $1 {{PLURAL:$1|item|items}}',
-
+                       // See https://bugzilla.wikimedia.org/69993
+                       'plural-msg-explicit-forms-nested': 'Found {{PLURAL:$1|$1 results|0=no results in {{SITENAME}}|1=$1 result}}',
                        // Assume the grammar form grammar_case_foo is not valid in any language
                        'grammar-msg': 'Przeszukaj {{GRAMMAR:grammar_case_foo|{{SITENAME}}}}',
 
                );
        } );
 
-       QUnit.test( 'Plural', 3, function ( assert ) {
+       QUnit.test( 'Plural', 6, function ( assert ) {
                assert.equal( formatParse( 'plural-msg', 0 ), 'Found 0 items', 'Plural test for english with zero as count' );
                assert.equal( formatParse( 'plural-msg', 1 ), 'Found 1 item', 'Singular test for english' );
                assert.equal( formatParse( 'plural-msg', 2 ), 'Found 2 items', 'Plural test for english' );
+               assert.equal( formatParse( 'plural-msg-explicit-forms-nested', 6 ), 'Found 6 results', 'Plural message with explicit plural forms' );
+               assert.equal( formatParse( 'plural-msg-explicit-forms-nested', 0 ), 'Found no results in ' + mw.config.get( 'wgSiteName' ), 'Plural message with explicit plural forms, with nested {{SITENAME}}' );
+               assert.equal( formatParse( 'plural-msg-explicit-forms-nested', 1 ), 'Found 1 result', 'Plural message with explicit plural forms with placeholder nested' );
        } );
 
        QUnit.test( 'Gender', 15, function ( assert ) {