Index: trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js |
— | — | @@ -17,13 +17,18 @@ |
18 | 18 | |
19 | 19 | |
20 | 20 | test( 'mw.jqueryMsg Gender', function() { |
21 | | - expect( 14 ); |
| 21 | + expect( 16 ); |
22 | 22 | //TODO: These tests should be for mw.msg once mw.msg integrated with mw.jqueryMsg |
| 23 | + var user = mw.user; |
| 24 | + user.options.set( 'gender', 'male' ); |
23 | 25 | var parser = mw.jqueryMsg.getMessageFunction(); |
24 | 26 | ok( parser, 'Parser Function initialized' ); |
25 | 27 | //TODO: English may not be the best language for these tests. Use a language like Arabic or Russian |
26 | 28 | ok( mw.messages.set( 'gender-msg', '$1 reverted {{GENDER:$2|his|her|their}} last edit' ), 'mw.messages.set: Register' ); |
27 | 29 | equal( parser( 'gender-msg', 'Bob', 'male' ) , 'Bob reverted his last edit', 'Gender masculine' ); |
| 30 | + equal( parser( 'gender-msg', 'Bob', user ) , 'Bob reverted his last edit', 'Gender masculine' ); |
| 31 | + user.options.set( 'gender', 'unknown' ); |
| 32 | + equal( parser( 'gender-msg', 'They', user ) , 'They reverted their last edit', 'Gender masculine' ); |
28 | 33 | equal( parser( 'gender-msg', 'Alice', 'female' ) , 'Alice reverted her last edit', 'Gender feminine' ); |
29 | 34 | equal( parser( 'gender-msg', 'User' ) , 'User reverted their last edit', 'Gender neutral' ); |
30 | 35 | equal( parser( 'gender-msg', 'User', 'unknown' ) , 'User reverted their last edit', 'Gender neutral' ); |
Index: trunk/phase3/resources/mediawiki/mediawiki.jqueryMsg.js |
— | — | @@ -635,11 +635,17 @@ |
636 | 636 | |
637 | 637 | /** |
638 | 638 | * Transform parsed structure into gender |
639 | | - * @param {Array} of nodes, [ {String}, {String}, {String} ... ] |
| 639 | + * Usage {{gender:[gender| mw.user object ] | masculine|feminine|neutral}}. |
| 640 | + * @param {Array} of nodes, [ {String|mw.User}, {String}, {String} , {String} ] |
640 | 641 | * @return {String} selected gender form according to current language |
641 | 642 | */ |
642 | 643 | gender: function( nodes ) { |
643 | | - var gender = nodes[0]; |
| 644 | + var gender; |
| 645 | + if ( nodes[0] && nodes[0].options instanceof mw.Map ){ |
| 646 | + gender = nodes[0].options.get( 'gender' ) |
| 647 | + } else { |
| 648 | + gender = nodes[0]; |
| 649 | + } |
644 | 650 | var forms = nodes.slice(1); |
645 | 651 | return this.language.gender( gender, forms ); |
646 | 652 | } |
Index: trunk/phase3/resources/mediawiki.language/mediawiki.language.js |
— | — | @@ -98,12 +98,12 @@ |
99 | 99 | }, |
100 | 100 | /** |
101 | 101 | * Provides an alternative text depending on specified gender. |
102 | | - * Usage {{gender:username|masculine|feminine|neutral}}. |
| 102 | + * Usage {{gender:[gender|user object]|masculine|feminine|neutral}}. |
103 | 103 | * If second or third parameter are not specified, masculine is used. |
104 | 104 | * |
105 | 105 | * These details may be overriden per language. |
106 | 106 | * |
107 | | - * @param gender string |
| 107 | + * @param gender string male, female, or anything else for neutral. |
108 | 108 | * @param forms array List of gender forms |
109 | 109 | * |
110 | 110 | * @return string |