r107811 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107810‎ | r107811 | r107812 >
Date:09:44, 2 January 2012
Author:santhosh
Status:ok
Tags:i18nreview 
Comment:
Make mw.jqueryMsg understand gender.
Add qunit testcases.
Followup r107808
Modified paths:
  • /trunk/phase3/resources/mediawiki/mediawiki.jqueryMsg.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js
@@ -10,8 +10,29 @@
1111 var parser = mw.jqueryMsg.getMessageFunction();
1212 ok( parser, 'Parser Function initialized' );
1313 ok( mw.messages.set( 'plural-msg', 'Found $1 {{PLURAL:$1|item|items}}' ), 'mw.messages.set: Register' );
14 - equal( parser('plural-msg', 0 ) , 'Found 0 items', 'Plural test for english with zero as count' );
15 - equal( parser('plural-msg', 1 ) , 'Found 1 item', 'Singular test for english' );
16 - equal( parser('plural-msg', 2 ) , 'Found 2 items', 'Plural test for english' );
 14+ equal( parser( 'plural-msg', 0 ) , 'Found 0 items', 'Plural test for english with zero as count' );
 15+ equal( parser( 'plural-msg', 1 ) , 'Found 1 item', 'Singular test for english' );
 16+ equal( parser( 'plural-msg', 2 ) , 'Found 2 items', 'Plural test for english' );
1717 } );
1818
 19+
 20+test( 'mw.jqueryMsg Gender', function() {
 21+ expect( 14 );
 22+ //TODO: These tests should be for mw.msg once mw.msg integrated with mw.jqueryMsg
 23+ var parser = mw.jqueryMsg.getMessageFunction();
 24+ ok( parser, 'Parser Function initialized' );
 25+ //TODO: English may not be the best language for these tests. Use a language like Arabic or Russian
 26+ ok( mw.messages.set( 'gender-msg', '$1 reverted {{GENDER:$2|his|her|their}} last edit' ), 'mw.messages.set: Register' );
 27+ equal( parser( 'gender-msg', 'Bob', 'male' ) , 'Bob reverted his last edit', 'Gender masculine' );
 28+ equal( parser( 'gender-msg', 'Alice', 'female' ) , 'Alice reverted her last edit', 'Gender feminine' );
 29+ equal( parser( 'gender-msg', 'User' ) , 'User reverted their last edit', 'Gender neutral' );
 30+ equal( parser( 'gender-msg', 'User', 'unknown' ) , 'User reverted their last edit', 'Gender neutral' );
 31+ ok( mw.messages.set( 'gender-msg-one-form', '{{GENDER:$1|User}} reverted last $2 {{PLURAL:$2|edit|edits}}' ), 'mw.messages.set: Register' );
 32+ equal( parser( 'gender-msg-one-form', 'male', 10 ) , 'User reverted last 10 edits', 'Gender neutral and plural form' );
 33+ equal( parser( 'gender-msg-one-form', 'female', 1 ) , 'User reverted last 1 edit', 'Gender neutral and singular form' );
 34+ ok( mw.messages.set( 'gender-msg-lowercase', '{{gender:$1|he|she}} is awesome' ), 'mw.messages.set: Register' );
 35+ equal( parser( 'gender-msg-lowercase', 'male' ) , 'he is awesome', 'Gender masculine' );
 36+ equal( parser( 'gender-msg-lowercase', 'female' ) , 'she is awesome', 'Gender feminine' );
 37+ ok( mw.messages.set( 'gender-msg-wrong', '{{gender}} is awesome' ), 'mw.messages.set: Register' );
 38+ equal( parser( 'gender-msg-wrong', 'female' ) , ' is awesome', 'Wrong syntax used, but ignore the {{gender}}' );
 39+} );
Index: trunk/phase3/resources/mediawiki/mediawiki.jqueryMsg.js
@@ -631,8 +631,19 @@
632632 var count = parseInt( this.language.convertNumber( nodes[0], true ), 10 );
633633 var forms = nodes.slice(1);
634634 return forms.length ? this.language.convertPlural( count, forms ) : '';
 635+ },
 636+
 637+ /**
 638+ * Transform parsed structure into gender
 639+ * @param {Array} of nodes, [ {String}, {String}, {String} ... ]
 640+ * @return {String} selected gender form according to current language
 641+ */
 642+ gender: function( nodes ) {
 643+ var gender = nodes[0];
 644+ var forms = nodes.slice(1);
 645+ return this.language.gender( gender, forms );
635646 }
636 -
 647+
637648 };
638649
639650 // TODO figure out a way to make magic work with common globals like wgSiteName, without requiring init from library users...

Follow-up revisions

RevisionCommit summaryAuthorDate
r107824Parser can take mw.user too along with male, female for {{gender:$1|..}}...santhosh12:21, 2 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r107808Add gender support. This method is useful only if we have parser that can und...santhosh09:08, 2 January 2012

Status & tagging log