Index: trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js |
— | — | @@ -10,8 +10,29 @@ |
11 | 11 | var parser = mw.jqueryMsg.getMessageFunction(); |
12 | 12 | ok( parser, 'Parser Function initialized' ); |
13 | 13 | 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' ); |
17 | 17 | } ); |
18 | 18 | |
| 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 @@ |
632 | 632 | var count = parseInt( this.language.convertNumber( nodes[0], true ), 10 ); |
633 | 633 | var forms = nodes.slice(1); |
634 | 634 | 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 ); |
635 | 646 | } |
636 | | - |
| 647 | + |
637 | 648 | }; |
638 | 649 | |
639 | 650 | // TODO figure out a way to make magic work with common globals like wgSiteName, without requiring init from library users... |