Index: branches/jsgrammar/resources/mediawiki/mediawiki.jqueryMsg.js |
— | — | @@ -103,7 +103,9 @@ |
104 | 104 | }; |
105 | 105 | |
106 | 106 | var parserDefaults = { |
107 | | - 'magic' : {}, |
| 107 | + 'magic' : { |
| 108 | + 'SITENAME' : mw.config.get( 'wgSiteName' ) |
| 109 | + }, |
108 | 110 | 'messages' : mw.messages, |
109 | 111 | 'language' : mw.language |
110 | 112 | }; |
— | — | @@ -660,8 +662,18 @@ |
661 | 663 | } |
662 | 664 | var forms = nodes.slice(1); |
663 | 665 | return this.language.gender( gender, forms ); |
| 666 | + }, |
| 667 | + /** |
| 668 | + * Transform parsed structure into grammar conversion |
| 669 | + * Invoked by putting {{grammar:form|word}} in a message |
| 670 | + * @param {Array} of noders [{Grammar case eg: genitive}, {String word}] |
| 671 | + * @return {String} selected gender form according to current language |
| 672 | + */ |
| 673 | + grammar: function( nodes ) { |
| 674 | + var form = nodes[0]; |
| 675 | + var word = nodes[1]; |
| 676 | + return this.language.convertGrammar( word , form ); |
664 | 677 | } |
665 | | - |
666 | 678 | }; |
667 | 679 | |
668 | 680 | // TODO figure out a way to make magic work with common globals like wgSiteName, without requiring init from library users... |
Index: branches/jsgrammar/resources/mediawiki.language/mediawiki.language.js |
— | — | @@ -9,6 +9,24 @@ |
10 | 10 | |
11 | 11 | mw.language = { |
12 | 12 | /** |
| 13 | + * @var data {Object} Langauge related data |
| 14 | + * Keyed by language, contains instances of mw.Map |
| 15 | + * @example Set data |
| 16 | + * <code> |
| 17 | + * var langCode = 'nl'; |
| 18 | + * var langData = mw.language.data; |
| 19 | + * if ( langData[langCode] === undefined ) { |
| 20 | + * langData[langCode] = new mw.Map(); |
| 21 | + * } |
| 22 | + * langData[langCode].set( .. ); // Will override, extend or create the data |
| 23 | + * </code> |
| 24 | + * @example Get data |
| 25 | + * <code> |
| 26 | + * var grammerForms = mw.language.data[langCode].get( 'grammerForms' ); |
| 27 | + * </code> |
| 28 | + */ |
| 29 | + data: {}, |
| 30 | + /** |
13 | 31 | * Process the PLURAL template substitution |
14 | 32 | * |
15 | 33 | * @param {object} template Template object |
— | — | @@ -121,7 +139,23 @@ |
122 | 140 | } |
123 | 141 | return ( forms.length === 3 ) ? forms[2] : forms[0]; |
124 | 142 | }, |
125 | | - |
| 143 | + /** |
| 144 | + * Grammatical transformations, needed for inflected languages |
| 145 | + * Invoked by putting {{grammar:form|word}} in a message |
| 146 | + * The rules can be defined in wgGrammarForms global or grammar |
| 147 | + * forms can be dynamically calculated by overriding this per language |
| 148 | + * |
| 149 | + * @param word string |
| 150 | + * @param form string |
| 151 | + * @return string |
| 152 | + */ |
| 153 | + 'convertGrammar': function( word, form ) { |
| 154 | + var grammarForms = mw.language.data[ mw.config.get( 'wgContentLanguage' )].get( 'grammarForms' ); |
| 155 | + if ( grammarForms && grammarForms[form] ) { |
| 156 | + return grammarForms[form][word] || word ; |
| 157 | + } |
| 158 | + return word; |
| 159 | + }, |
126 | 160 | // Digit Transform Table, populated by language classes where applicable |
127 | 161 | 'digitTransformTable': null |
128 | 162 | }; |