Index: branches/js2-work/phase3/js/mwEmbed/tests/Playlist_Player.html |
— | — | @@ -10,7 +10,7 @@ |
11 | 11 | <table> |
12 | 12 | <tr> |
13 | 13 | <td> |
14 | | -<playlist id="playlist_player" src="media/sample_smil.xml" width="320" height="240"> |
| 14 | +<playlist id="playlist_player" src="media/sequence_transition_smil.xml" width="320" height="240"> |
15 | 15 | </playlist> |
16 | 16 | </td> |
17 | 17 | <td valign="top"> |
Index: branches/js2-work/phase3/js/mwEmbed/tests/testLang.html |
— | — | @@ -8,172 +8,13 @@ |
9 | 9 | } |
10 | 10 | </style> |
11 | 11 | <script type="text/javascript" > |
12 | | -var scriptLoaderURID = 't16'; |
| 12 | +var scriptLoaderURID = 't17'; |
13 | 13 | //for just setting one or two to test at a time for debug |
14 | | -var langKeyDebug = ['en']; //pl |
| 14 | +//var langKeyDebug = [ 'en', 'ar' ]; //pl |
15 | 15 | //var langKeyDebug = [ 'az', 'da', 'pt', 'fr', 'lv', 'en']; |
16 | 16 | //var langKeyDebug = ['en','az', 'da', 'pt', 'fr', 'lv', 'ga','hr','cy','mk','mt','pl','sl']; |
| 17 | +var langKeyDebug = mw.getConfig( 'languageCodeList' ); |
17 | 18 | |
18 | | -//longlangKey is every language we have a much more verbose test |
19 | | -var langKeyAll = [ |
20 | | - //no plurals, there are no rules |
21 | | - 'az','fa','hu','ja','ko','my to','tr','vi','yo','zh', |
22 | | - 'bo','dz','id','jv ka','km','kn','ms','th', |
23 | | - |
24 | | - /* |
25 | | - 'zero' => 0, |
26 | | - 'one' => 1, |
27 | | - 'two' => 2, |
28 | | - //n mod 100 in 3..10 |
29 | | - 'few' => array( 'mod' => 100, 'is'=>'3-10' ), |
30 | | - //n mod 100 in 11..99 |
31 | | - 'many' => array( 'mod' => 100, 'is'=>'11-99') |
32 | | - */ |
33 | | - 'ar', |
34 | | - |
35 | | - /* |
36 | | - 'one' => 1 |
37 | | - */ |
38 | | - 'da','de','el','en','eo','es','et','fi','fo','gl', |
39 | | - 'he','iw','it','nb','nl','nn','no','pt_PT','sv', |
40 | | - 'af','bg','bn','ca','eu','fur','fy','gu','ha', |
41 | | - 'is','ku','lb','ml','mr','nah','ne','om','or', |
42 | | - 'pa','pap','ps','so','sq','sw','ta','te','tk', |
43 | | - 'ur','zu','mn','gsw', |
44 | | - |
45 | | - /* |
46 | | - 'one'=> '0-1' |
47 | | - */ |
48 | | - 'pt','am','bh','fil','tl','guw','hi','ln','mg','nso','ti','wa', |
49 | | - |
50 | | - /* |
51 | | - 'one' => array( 'is'=>'0-2', 'not' => 2) |
52 | | - */ |
53 | | - 'fr', |
54 | | - |
55 | | - /* |
56 | | - 'zero' => 0, |
57 | | - //n mod 10 is 1 and n mod 100 is not 11 |
58 | | - 'one'=>array( |
59 | | - array( 'mod' => 10, 'is' => 1 ), |
60 | | - //AND |
61 | | - array( 'mod' => 100, 'not' => 11) |
62 | | - ) |
63 | | - */ |
64 | | - 'lv', |
65 | | - |
66 | | - /* |
67 | | - 'one' => 1, |
68 | | - 'two' => 2 |
69 | | - */ |
70 | | - 'ga','se','sma','smi','smj','smn','sms', |
71 | | - |
72 | | - |
73 | | - /* |
74 | | - 'one' => 1, |
75 | | - //n is 0 OR n is not 1 AND n mod 100 in 1..19 |
76 | | - 'few' => array( |
77 | | - 'or'=> array( |
78 | | - array( 'is' => 0), |
79 | | - array( |
80 | | - array( 'not' => 1), |
81 | | - //and |
82 | | - array( 'mod' => 100, 'is'=>'1-19') |
83 | | - ) |
84 | | - ) |
85 | | - ) |
86 | | - */ |
87 | | - 'ro','mo', |
88 | | - |
89 | | - |
90 | | - /* |
91 | | - //n mod 10 is 1 and n mod 100 not in 11..19 |
92 | | - 'one' => array( |
93 | | - array( 'mod'=>10, 'is'=> 1 ), |
94 | | - array( 'mod'=> 100, 'not'=> '11-19') |
95 | | - ), |
96 | | - //n mod 10 in 2..9 and n mod 100 not in 11..19 |
97 | | - 'few' => array( |
98 | | - array( 'mod'=> 10, 'is'=> '2-9' ), |
99 | | - array( 'mod'=> 100, 'not' => '11-19') |
100 | | - ), |
101 | | - */ |
102 | | - 'lt', |
103 | | - |
104 | | - |
105 | | - /* |
106 | | - //n mod 10 is 1 and n mod 100 is not 11 |
107 | | - 'one' => array( |
108 | | - array( 'mod' => 10, 'is' => 1), |
109 | | - array( 'mod' => 100, 'not' => 11) |
110 | | - ), |
111 | | - //n mod 10 in 2..4 and n mod 100 not in 12..14 |
112 | | - 'few' => array( |
113 | | - array( 'mod' => 10, 'is' => '2-4'), |
114 | | - array( 'mod' => 100, 'not' => '12-14') |
115 | | - ), |
116 | | - //n mod 10 is 0 or n mod 10 in 5..9 or n mod 100 in 11..14 |
117 | | - 'many' => array( |
118 | | - 'or'=>array( |
119 | | - array( 'mod'=> 10, 'is' => 0), |
120 | | - array( 'mod'=> 10, 'is' => '5-9'), |
121 | | - array( 'mod'=> 100, 'is' => '11-14') |
122 | | - ) |
123 | | - ), |
124 | | - */ |
125 | | - 'hr','ru','sr','uk','be','bs','sh', |
126 | | - |
127 | | - |
128 | | - /* |
129 | | - 'one' => 1, |
130 | | - 'few' => array( |
131 | | - //n mod 10 in 2..4 |
132 | | - array( 'mod' => 10, 'is' => '2-4'), |
133 | | - //and n mod 100 not in 12..14 |
134 | | - array( 'mod' => 100, 'not'=> '12-14'), |
135 | | - //and n mod 100 not in 22..24 |
136 | | - array( 'mod' => 100, 'in' => '22-24') |
137 | | - ) |
138 | | - */ |
139 | | - 'pl', |
140 | | - |
141 | | - /* |
142 | | - 'one' => array( 'mod'=>100, 'is' => 1 ), |
143 | | - 'two' => array( 'mod'=>100, 'is' => 2 ), |
144 | | - 'few' => array( 'mod'=>100, 'is' => '3-4') |
145 | | - */ |
146 | | - 'sl', |
147 | | - |
148 | | - |
149 | | - /* |
150 | | - 'one' => 1, |
151 | | - //n is 0 or n mod 100 in 2..10 |
152 | | - 'few' => array( |
153 | | - array( 'is' => 0 ), |
154 | | - 'or', |
155 | | - array( 'mod' => 100, 'is' => '2-10') |
156 | | - ), |
157 | | - //n mod 100 in 11..19 |
158 | | - 'many' => array( 'mod'=>100, 'is' => '11-19') |
159 | | - */ |
160 | | - 'mt', |
161 | | - |
162 | | - /* |
163 | | - 'one' => array('mod' => 10, 'is' => '1') |
164 | | - */ |
165 | | - 'mk', |
166 | | - |
167 | | - /* |
168 | | - 'one' => 1, |
169 | | - 'two' => 2, |
170 | | - //n is 8 or n is 11 |
171 | | - 'many' => array( |
172 | | - array( 'is' => 8 ), |
173 | | - array( 'is' => 11 ) |
174 | | - )*/ |
175 | | - 'cy' |
176 | | -]; |
177 | | - |
178 | 19 | mw.ready( function(){ |
179 | 20 | //do mauall script loaders calls to test multiple languages: |
180 | 21 | function doLangTable( langSet ){ |
— | — | @@ -191,94 +32,102 @@ |
192 | 33 | var passTest=0; |
193 | 34 | var failTest=0; |
194 | 35 | var testCount=0; |
195 | | - |
196 | | - |
197 | | - //do a manual call to the script-lodaer: |
198 | | - function doProcLangKey(langKey){ |
199 | | - $j.getScript('../../../mwScriptLoader.php?class=mw.testLang&debug=true&urid='+ scriptLoaderURID +'&uselang='+langKey, function(){ |
200 | | - var o=''; |
201 | | - o+='<tr><td colspan="6" height="20" style="font-size:large"><b>Lang:' + langKey + '</b></td></tr>'; |
202 | | - //now for each langage msg: |
203 | | - $j.each(msgTestSet, function(mKey, mTestSet){ |
204 | | - //output table names: |
205 | | - o+='<tr>'+ |
206 | | - '<td>$1[,$2]</td>'+ |
207 | | - '<td width="14%">Msg key</td>'+ |
208 | | - '<td width="34%">Msg text</td>'+ |
209 | | - '<td width="24%">Msg Transform JS</td>'+ |
210 | | - '<td width="24%">Msg Transform Mw</td>'+ |
211 | | - '</tr>'; |
212 | | - |
213 | | - //for each number value |
214 | | - for(var i in mTestSet){ |
215 | | - var numVal = mTestSet[i]; |
216 | | - var numKey = (typeof numVal== 'object')? numVal.join( '_' ).replace('/ /', '_') : numVal; |
217 | | - var tkey = mKey + '_' + numKey + '_' + langKey; |
| 36 | + |
| 37 | + /** |
| 38 | + * proccess a language key test set |
| 39 | + */ |
| 40 | + function doProcLangKey( langKey ){ |
| 41 | + // Clear out the old digitTransformTable |
| 42 | + mw.lang.digitTransformTable = null; |
| 43 | + //Load the current language js file |
| 44 | + var langName = 'Language' + langKey.substr(0,1).toUpperCase() + langKey.substr( 1,langKey.length ); |
| 45 | + $j.getScript( '../includes/languages/classes/' + langName + '.js' , function(){ |
| 46 | + // Get the current language mw.testLang js |
| 47 | + $j.getScript( '../../../mwScriptLoader.php?class=mw.testLang&debug=true&urid='+ scriptLoaderURID +'&uselang='+langKey, function(){ |
| 48 | + var o=''; |
| 49 | + o+='<tr><td colspan="6" height="20" style="font-size:large"><b>Lang:' + langKey + '</b></td></tr>'; |
| 50 | + //now for each langage msg: |
| 51 | + $j.each(msgTestSet, function(mKey, mTestSet){ |
| 52 | + //output table names: |
218 | 53 | o+='<tr>'+ |
219 | | - '<td>' + numVal + '</td>' + |
220 | | - '<td>' + mKey + '</td>' + |
221 | | - '<td>' + mw.lang.msgNoTrans( mKey ) + '</td>' + |
222 | | - '<td id="' + tkey + '_js">' + gM( mKey, numVal ) + '</td>'; |
223 | | - //show mw col: |
224 | | - if( mKey.substr(0, 5) == 'test_' ){ |
225 | | - o+='<td> (test msg) </td>'; |
226 | | - }else{ |
227 | | - o+='<td id="' + tkey + '">loading...</td>'; |
228 | | - |
229 | | - //get transform from mw (& compare and highlight) |
230 | | - function doPopWmMsg(mKey, numVal, numKey){ |
231 | | - //set the local tkey: |
232 | | - var tkey = mKey + '_' + numKey + '_' + langKey; |
233 | | - testCount++; |
234 | | - $j('#score_card').html('Running Tests <span id="perc_done">0</sapn>% done'); |
235 | | - var msgparam = (typeof numVal== 'object')? numVal.join( '|' ) : numVal; |
236 | | - var request = { |
237 | | - 'action' : 'parse', |
238 | | - 'uselang' : langKey, |
239 | | - 'text' : '{{int:' + mKey + '|' + msgparam + '}}' |
240 | | - }; |
241 | | - mw.getJSON('../../../api.php', request, function( data ) { |
242 | | - var t = '#'+ tkey ; |
243 | | - if(data.parse && data.parse.text && data.parse.text['*']){ |
244 | | - $j(t).html( data.parse.text['*'] ); |
245 | | - var js_txt = $j.trim( $j(t + '_js').text().replace('\n', '') ); |
246 | | - var php_txt = $j.trim( $j(t + ' p').text()) |
247 | | - //just get the part in the <p> to compare with js version |
248 | | - if( js_txt != php_txt ){ |
249 | | - $j(t).css('color', 'red'); |
250 | | - failTest++; |
| 54 | + '<td>$1[,$2]</td>'+ |
| 55 | + '<td width="14%">Msg key</td>'+ |
| 56 | + '<td width="34%">Msg text</td>'+ |
| 57 | + '<td width="24%">Msg Transform JS</td>'+ |
| 58 | + '<td width="24%">Msg Transform Mw</td>'+ |
| 59 | + '</tr>'; |
| 60 | + |
| 61 | + //for each number value |
| 62 | + for(var i in mTestSet){ |
| 63 | + var numVal = mTestSet[i]; |
| 64 | + var numKey = (typeof numVal== 'object')? numVal.join( '_' ).replace('/ /', '_') : numVal; |
| 65 | + var tkey = mKey + '_' + numKey + '_' + langKey; |
| 66 | + o+='<tr>'+ |
| 67 | + '<td>' + numVal + '</td>' + |
| 68 | + '<td>' + mKey + '</td>' + |
| 69 | + '<td>' + mw.lang.msgNoTrans( mKey ) + '</td>' + |
| 70 | + '<td id="' + tkey + '_js">' + gM( mKey, numVal ) + '</td>'; |
| 71 | + //show mw col: |
| 72 | + if( mKey.substr(0, 5) == 'test_' ){ |
| 73 | + o+='<td> (test msg) </td>'; |
| 74 | + }else{ |
| 75 | + o+='<td id="' + tkey + '">loading...</td>'; |
| 76 | + |
| 77 | + //get transform from mw (& compare and highlight) |
| 78 | + function doPopWmMsg(mKey, numVal, numKey){ |
| 79 | + //set the local tkey: |
| 80 | + var tkey = mKey + '_' + numKey + '_' + langKey; |
| 81 | + testCount++; |
| 82 | + $j('#score_card').html('Running Tests <span id="perc_done">0</sapn>% done'); |
| 83 | + var msgparam = (typeof numVal== 'object')? numVal.join( '|' ) : numVal; |
| 84 | + var request = { |
| 85 | + 'action' : 'parse', |
| 86 | + 'uselang' : langKey, |
| 87 | + 'text' : '{{int:' + mKey + '|' + msgparam + '}}' |
| 88 | + }; |
| 89 | + mw.getJSON('../../../api.php', request, function( data ) { |
| 90 | + var t = '#'+ tkey ; |
| 91 | + if(data.parse && data.parse.text && data.parse.text['*']){ |
| 92 | + $j(t).html( data.parse.text['*'] ); |
| 93 | + var js_txt = $j.trim( $j(t + '_js').text().replace('\n', '') ); |
| 94 | + var php_txt = $j.trim( $j(t + ' p').text()) |
| 95 | + //just get the part in the <p> to compare with js version |
| 96 | + if( js_txt != php_txt ){ |
| 97 | + $j(t).css('color', 'red'); |
| 98 | + failTest++; |
| 99 | + }else{ |
| 100 | + $j(t).css('color', 'green'); |
| 101 | + passTest++; |
| 102 | + } |
| 103 | + var perc = ( failTest + passTest ) / testCount |
| 104 | + if( perc != 1){ |
| 105 | + $j('#perc_done').html( Math.round(perc*1000)/1000 + '%'); |
| 106 | + }else{ |
| 107 | + var failHtlm = (failTest == 0)?failTest: '<span style="color:red">'+ failTest+'</span>'; |
| 108 | + $j('#score_card').html( |
| 109 | + 'Passed: <span style="color:green">' + passTest + '</span> Failed:' + failHtlm ); |
| 110 | + |
| 111 | + //done with this lang... call outer function if we have lang keys left to proccess: |
| 112 | + if(langSet.length!=0) |
| 113 | + doProcLangKey( langSet.pop() ); |
| 114 | + } |
251 | 115 | }else{ |
252 | | - $j(t).css('color', 'green'); |
253 | | - passTest++; |
| 116 | + $t.html(' error '); |
254 | 117 | } |
255 | | - var perc = ( failTest + passTest ) / testCount |
256 | | - if( perc != 1){ |
257 | | - $j('#perc_done').html( Math.round(perc*1000)/1000 + '%'); |
258 | | - }else{ |
259 | | - var failHtlm = (failTest == 0)?failTest: '<span style="color:red">'+ failTest+'</span>'; |
260 | | - $j('#score_card').html( |
261 | | - 'Passed: <span style="color:green">' + passTest + '</span> Failed:' + failHtlm ); |
262 | | - |
263 | | - //done with this lang... call outer function if we have lang keys left to proccess: |
264 | | - if(langSet.length!=0) |
265 | | - doProcLangKey( langSet.pop() ); |
266 | | - } |
267 | | - }else{ |
268 | | - $t.html(' error '); |
269 | | - } |
270 | | - }); |
271 | | - }; |
272 | | - //pop off an anonymous function call |
273 | | - doPopWmMsg(mKey, numVal, numKey); |
274 | | - } |
275 | | - o+='</tr>'; |
276 | | - } |
277 | | - //output a spacer: |
278 | | - o+='<tr><td colspan="6" height="20"> </td></tr>'; |
279 | | - }); |
280 | | - //put the output into the page: |
281 | | - $j('#table_out').append( o ); |
282 | | - }); |
| 118 | + }); |
| 119 | + }; |
| 120 | + //pop off an anonymous function call |
| 121 | + doPopWmMsg(mKey, numVal, numKey); |
| 122 | + } |
| 123 | + o+='</tr>'; |
| 124 | + } |
| 125 | + //output a spacer: |
| 126 | + o+='<tr><td colspan="6" height="20"> </td></tr>'; |
| 127 | + }); |
| 128 | + //put the output into the page: |
| 129 | + $j('#table_out').append( o ); |
| 130 | + }); |
| 131 | + }); |
283 | 132 | }//procc lang key: |
284 | 133 | doProcLangKey( langSet.pop() ); |
285 | 134 | } |
Index: branches/js2-work/phase3/js/mwEmbed/tests/testLang.js |
— | — | @@ -6,10 +6,5 @@ |
7 | 7 | "category-subcat-count" : "{{PLURAL:$2|This category has only the following subcategory.|This category has the following {{PLURAL:$1|subcategory|$1 subcategories}}, out of $2 total.}}", |
8 | 8 | "mwe-upload-multi" : "Upload {{PLURAL:$1|file|files}}" |
9 | 9 | } ); |
10 | | - |
11 | | -mw.lang.loadRS( { |
12 | | - 'PLURAL' : { "one" : 1 } |
13 | | -} ); |
14 | | - |
15 | 10 | // define a class by the name of this file: |
16 | 11 | mw.testLang = { }; |
\ No newline at end of file |
Index: branches/js2-work/phase3/js/mwEmbed/tests/testApiProxy.html |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | $j('#helloTarget').html( mw.loading_spinner() ); |
25 | 25 | //first get the user name: |
26 | 26 | getUserName(function( user_name ){ |
27 | | - $j('#helloTarget').hide().text( user_name ).fadeIn('slow'); |
| 27 | + $j('#helloTarget').addClass('UserNameFound').hide().text( user_name ).fadeIn('slow'); |
28 | 28 | }); |
29 | 29 | return false; |
30 | 30 | } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/maintenance/mergeJavascriptMsg.php |
— | — | @@ -92,7 +92,9 @@ |
93 | 93 | |
94 | 94 | $objects = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $path ), RecursiveIteratorIterator::SELF_FIRST ); |
95 | 95 | foreach ( $objects as $fname => $object ) { |
96 | | - if ( substr( $fname, - 3 ) == '.js' && strpos( $fname, '/cache/' ) === false ) { |
| 96 | + if ( substr( $fname, - 3 ) == '.js' |
| 97 | + && strpos( $fname, '/cache/' ) === false |
| 98 | + && strpos( $fname, '/tests/' ) === false ) { |
97 | 99 | $jsFileText = file_get_contents( $fname ); |
98 | 100 | $mwPos = strpos( $fname, 'mwEmbed' ) + 7; |
99 | 101 | $curFileName = substr( $fname, $mwPos ); |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/cldrConverter.php |
— | — | @@ -1,5 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /* |
| 4 | + * |
4 | 5 | * cldr format tries to build a structured representation of |
5 | 6 | * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html |
6 | 7 | * |
— | — | @@ -77,7 +78,7 @@ |
78 | 79 | //n is 0 OR n is not 1 AND n mod 100 in 1..19 |
79 | 80 | 'few' => array( |
80 | 81 | 'or'=> array( |
81 | | - array( 'is' => 0), |
| 82 | + array( 'is' => 0), |
82 | 83 | array( |
83 | 84 | array( 'not' => 1), |
84 | 85 | //and |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/mwEmbed.i18n.php |
— | — | @@ -467,12 +467,6 @@ |
468 | 468 | 'mwe-credit-title' => 'Title: $1', |
469 | 469 | 'mwe-kaltura-platform-title' => 'Kaltura open source video platform', |
470 | 470 | |
471 | | - /* |
472 | | - * js file: /tests/testLang.js |
473 | | - */ |
474 | | - 'undelete_short' => 'Undelete {{PLURAL:$1|one edit|$1 edits}}', |
475 | | - 'category-subcat-count' => '{{PLURAL:$2|This category has only the following subcategory.|This category has the following {{PLURAL:$1|subcategory|$1 subcategories}}, out of $2 total.}}', |
476 | | - 'mwe-upload-multi' => 'Upload {{PLURAL:$1|file|files}}', |
477 | 471 | ); |
478 | 472 | |
479 | 473 | /** Message documentation (Message documentation) |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageHi.js |
— | — | @@ -0,0 +1,14 @@ |
| 2 | + |
| 3 | +/** |
| 4 | + * |
| 5 | + * @ingroup Language |
| 6 | + */ |
| 7 | + /** |
| 8 | + * Use singular form for zero |
| 9 | + */ |
| 10 | + mw.lang.convertPlural = function( count, forms ) { |
| 11 | + |
| 12 | + forms = mw.lang.preConvertPlural( forms, 2 ); |
| 13 | + |
| 14 | + return (count <= 1) ? forms[0] : forms[1]; |
| 15 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageMg.js |
— | — | @@ -0,0 +1,14 @@ |
| 2 | + |
| 3 | +/** |
| 4 | + * |
| 5 | + * @ingroup Language |
| 6 | + */ |
| 7 | + /** |
| 8 | + * Use singular form for zero |
| 9 | + */ |
| 10 | + mw.lang.convertPlural = function( count, forms ) { |
| 11 | + |
| 12 | + forms = mw.lang.preConvertPlural( forms, 2 ); |
| 13 | + |
| 14 | + return (count <= 1) ? forms[0] : forms[1]; |
| 15 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageBs.js |
— | — | @@ -0,0 +1,23 @@ |
| 2 | +/** Bosnian (bosanski) |
| 3 | + * |
| 4 | + * @ingroup Language |
| 5 | + */ |
| 6 | + |
| 7 | +mw.lang.convertPlural = function( count, forms ) { |
| 8 | + |
| 9 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 10 | + |
| 11 | + // FIXME: CLDR defines 4 plural forms instead of 3. Plural for decimals is missing. |
| 12 | + // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html |
| 13 | + if (count > 10 && Math.floor((count % 100) / 10) == 1) { |
| 14 | + return forms[2]; |
| 15 | + } else { |
| 16 | + switch (count % 10) { |
| 17 | + case 1: return forms[0]; |
| 18 | + case 2: |
| 19 | + case 3: |
| 20 | + case 4: return forms[1]; |
| 21 | + default: return forms[2]; |
| 22 | + } |
| 23 | + } |
| 24 | +} |
\ No newline at end of file |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageCs.js |
— | — | @@ -0,0 +1,27 @@ |
| 2 | + |
| 3 | + |
| 4 | +/** Czech (čeština [subst.], český [adj.], česky [adv.]) |
| 5 | + * |
| 6 | + * @ingroup Language |
| 7 | + */ |
| 8 | + |
| 9 | +// Plural transformations |
| 10 | +// Invoked by putting |
| 11 | +// {{plural:count|form1|form2-4|form0,5+}} for two forms plurals |
| 12 | +// {{plural:count|form1|form0,2+}} for single form plurals |
| 13 | +// in a message |
| 14 | +mw.lang.convertPlural = function( count, forms ) { |
| 15 | + |
| 16 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 17 | + |
| 18 | + switch ( count ) { |
| 19 | + case 1: |
| 20 | + return forms[0]; |
| 21 | + case 2: |
| 22 | + case 3: |
| 23 | + case 4: |
| 24 | + return forms[1]; |
| 25 | + default: |
| 26 | + return forms[2]; |
| 27 | + } |
| 28 | +} |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguagePt_br.js |
— | — | @@ -0,0 +1,15 @@ |
| 2 | + |
| 3 | + |
| 4 | +/** Brazilian Portugese (Portuguêsi do Brasil) |
| 5 | + * |
| 6 | + * @ingroup Language |
| 7 | + */ |
| 8 | + /** |
| 9 | + * Use singular form for zero (see bug 7309) |
| 10 | + */ |
| 11 | + mw.lang.convertPlural = function( count, forms ) { |
| 12 | + |
| 13 | + forms = mw.lang.preConvertPlural( forms, 2 ); |
| 14 | + |
| 15 | + return (count <= 1) ? forms[0] : forms[1]; |
| 16 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageMk.js |
— | — | @@ -0,0 +1,19 @@ |
| 2 | + |
| 3 | +/** |
| 4 | + * |
| 5 | + * @ingroup Language |
| 6 | + */ |
| 7 | + /** |
| 8 | + * Plural forms per |
| 9 | + * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#mk |
| 10 | + */ |
| 11 | + mw.lang.convertPlural = function( count, forms ) { |
| 12 | + |
| 13 | + forms = mw.lang.preConvertPlural( forms, 2 ); |
| 14 | + |
| 15 | + if ( count % 10 === 1 ) { |
| 16 | + return forms[0]; |
| 17 | + } else { |
| 18 | + return forms[1]; |
| 19 | + } |
| 20 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageCu.js |
— | — | @@ -0,0 +1,20 @@ |
| 2 | + |
| 3 | + |
| 4 | +/** Old Church Slavonic (Ѩзыкъ словѣньскъ) |
| 5 | + * |
| 6 | + * @ingroup Language |
| 7 | + */ |
| 8 | + |
| 9 | +mw.lang.convertPlural = function( count, forms ) { |
| 10 | + |
| 11 | + forms = mw.lang.preConvertPlural( forms, 4 ); |
| 12 | + |
| 13 | + switch (count % 10) { |
| 14 | + case 1: return forms[0]; |
| 15 | + case 2: return forms[1]; |
| 16 | + case 3: |
| 17 | + case 4: return forms[2]; |
| 18 | + default: return forms[3]; |
| 19 | + } |
| 20 | +} |
| 21 | + |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageSe.js |
— | — | @@ -0,0 +1,20 @@ |
| 2 | + |
| 3 | +/** |
| 4 | + * |
| 5 | + * @ingroup Language |
| 6 | + */ |
| 7 | + mw.lang.convertPlural = function( count, forms ) { |
| 8 | + |
| 9 | + |
| 10 | + // plural forms per http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#se |
| 11 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 12 | + |
| 13 | + if ( count == 1 ) { |
| 14 | + $index = 1; |
| 15 | + } else if( count == 2 ) { |
| 16 | + $index = 2; |
| 17 | + } else { |
| 18 | + $index = 3; |
| 19 | + } |
| 20 | + return forms[$index]; |
| 21 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageWa.js |
— | — | @@ -0,0 +1,16 @@ |
| 2 | + |
| 3 | +/** |
| 4 | + * Walloon (Walon) |
| 5 | + * |
| 6 | + * @ingroup Language |
| 7 | + */ |
| 8 | + |
| 9 | + /** |
| 10 | + * Use singular form for zero |
| 11 | + */ |
| 12 | + mw.lang.convertPlural = function( count, forms ) { |
| 13 | + |
| 14 | + forms = mw.lang.preConvertPlural( forms, 2 ); |
| 15 | + |
| 16 | + return (count <= 1) ? forms[0] : forms[1]; |
| 17 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageDsb.js |
— | — | @@ -0,0 +1,20 @@ |
| 2 | + |
| 3 | + |
| 4 | +/** Lower Sorbian (Dolnoserbski) |
| 5 | + * |
| 6 | + * @ingroup Language |
| 7 | + */ |
| 8 | + |
| 9 | + |
| 10 | + mw.lang.convertPlural = function( count, forms ) { |
| 11 | + |
| 12 | + forms = mw.lang.preConvertPlural( forms, 4 ); |
| 13 | + |
| 14 | + switch ( Math.abs( count ) % 100 ) { |
| 15 | + case 1: return forms[0]; // singular |
| 16 | + case 2: return forms[1]; // dual |
| 17 | + case 3: |
| 18 | + case 4: return forms[2]; // plural |
| 19 | + default: return forms[3]; // pluralgen |
| 20 | + } |
| 21 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageMo.js |
— | — | @@ -0,0 +1,21 @@ |
| 2 | + |
| 3 | +/** |
| 4 | + * |
| 5 | + * @ingroup Language |
| 6 | + */ |
| 7 | + mw.lang.convertPlural = function( count, forms ) { |
| 8 | + // Plural rules per |
| 9 | + // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#mo |
| 10 | + |
| 11 | + |
| 12 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 13 | + |
| 14 | + if ( count == 1 ) { |
| 15 | + $index = 0; |
| 16 | + } else if ( count == 0 || count % 100 < 20 ) { |
| 17 | + $index = 1; |
| 18 | + } else { |
| 19 | + $index = 2; |
| 20 | + } |
| 21 | + return forms[$index]; |
| 22 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageCy.js |
— | — | @@ -0,0 +1,22 @@ |
| 2 | + |
| 3 | +/** Welsh (Cymraeg) |
| 4 | + * |
| 5 | + * @ingroup Language |
| 6 | + * |
| 7 | + * @author Niklas Laxström |
| 8 | + */ |
| 9 | + mw.lang.convertPlural = function( count, forms ) { |
| 10 | + |
| 11 | + |
| 12 | + // FIXME: CLDR defines 4 plural forms; very different, actually. |
| 13 | + // See http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#cy |
| 14 | + forms = mw.lang.preConvertPlural( forms, 6 ); |
| 15 | + count = Math.abs( count ); |
| 16 | + if ( count >= 0 && count <= 3 ) { |
| 17 | + return forms[count]; |
| 18 | + } else if ( count == 6 ) { |
| 19 | + return forms[4]; |
| 20 | + } else { |
| 21 | + return forms[5]; |
| 22 | + } |
| 23 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageHsb.js |
— | — | @@ -0,0 +1,18 @@ |
| 2 | + |
| 3 | +/** Upper Sorbian (Hornjoserbsce) |
| 4 | + * |
| 5 | + * @ingroup Language |
| 6 | + */ |
| 7 | + |
| 8 | + mw.lang.convertPlural = function( count, forms ) { |
| 9 | + |
| 10 | + forms = mw.lang.preConvertPlural( forms, 4 ); |
| 11 | + |
| 12 | + switch ( Math.abs( count ) % 100 ) { |
| 13 | + case 1: return forms[0]; // singular |
| 14 | + case 2: return forms[1]; // dual |
| 15 | + case 3: |
| 16 | + case 4: return forms[2]; // plural |
| 17 | + default: return forms[3]; // pluralgen |
| 18 | + } |
| 19 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageTi.js |
— | — | @@ -0,0 +1,14 @@ |
| 2 | + |
| 3 | +/** |
| 4 | + * |
| 5 | + * @ingroup Language |
| 6 | + */ |
| 7 | + /** |
| 8 | + * Use singular form for zero |
| 9 | + */ |
| 10 | + mw.lang.convertPlural = function( count, forms ) { |
| 11 | + |
| 12 | + forms = mw.lang.preConvertPlural( forms, 2 ); |
| 13 | + |
| 14 | + return (count <= 1) ? forms[0] : forms[1]; |
| 15 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageSk.js |
— | — | @@ -0,0 +1,19 @@ |
| 2 | + |
| 3 | +/** |
| 4 | + * Slovak (Slovenčina) |
| 5 | + * |
| 6 | + * @ingroup Language |
| 7 | + */ |
| 8 | + mw.lang.convertPlural = function( count, forms ) { |
| 9 | + |
| 10 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 11 | + |
| 12 | + if ( count == 1 ) { |
| 13 | + $index = 0; |
| 14 | + } else if ( count == 2 || count == 3 || count == 4 ) { |
| 15 | + $index = 1; |
| 16 | + } else { |
| 17 | + $index = 2; |
| 18 | + } |
| 19 | + return forms[$index]; |
| 20 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageUk.js |
— | — | @@ -0,0 +1,29 @@ |
| 2 | + |
| 3 | + |
| 4 | +/** Ukrainian (українська мова) |
| 5 | + * |
| 6 | + * @ingroup Language |
| 7 | + */ |
| 8 | + |
| 9 | + mw.lang.convertPlural = function( count, forms ) { |
| 10 | + |
| 11 | + |
| 12 | + //if no number with word, then use $form[0] for singular and $form[1] for plural or zero |
| 13 | + if( forms.length === 2 ) return count == 1 ? forms[0] : forms[1]; |
| 14 | + |
| 15 | + // FIXME: CLDR defines 4 plural forms. Form for decimals is missing/ |
| 16 | + // See http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#uk |
| 17 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 18 | + |
| 19 | + if (count > 10 && Math.floor((count % 100) / 10) == 1) { |
| 20 | + return forms[2]; |
| 21 | + } else { |
| 22 | + switch (count % 10) { |
| 23 | + case 1: return forms[0]; |
| 24 | + case 2: |
| 25 | + case 3: |
| 26 | + case 4: return forms[1]; |
| 27 | + default: return forms[2]; |
| 28 | + } |
| 29 | + } |
| 30 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageSma.js |
— | — | @@ -0,0 +1,20 @@ |
| 2 | + |
| 3 | +/** |
| 4 | + * |
| 5 | + * @ingroup Language |
| 6 | + */ |
| 7 | + mw.lang.convertPlural = function( count, forms ) { |
| 8 | + |
| 9 | + |
| 10 | + // plural forms per http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#sma |
| 11 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 12 | + |
| 13 | + if ( count == 1 ) { |
| 14 | + $index = 1; |
| 15 | + } else if( count == 2 ) { |
| 16 | + $index = 2; |
| 17 | + } else { |
| 18 | + $index = 3; |
| 19 | + } |
| 20 | + return forms[$index]; |
| 21 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageRo.js |
— | — | @@ -0,0 +1,21 @@ |
| 2 | + |
| 3 | +/** |
| 4 | + * |
| 5 | + * @ingroup Language |
| 6 | + */ |
| 7 | + mw.lang.convertPlural = function( count, forms ) { |
| 8 | + // Plural rules per |
| 9 | + // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#ro |
| 10 | + |
| 11 | + |
| 12 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 13 | + |
| 14 | + if ( count == 1 ) { |
| 15 | + $index = 0; |
| 16 | + } else if ( count == 0 || count % 100 < 20 ) { |
| 17 | + $index = 1; |
| 18 | + } else { |
| 19 | + $index = 2; |
| 20 | + } |
| 21 | + return forms[$index]; |
| 22 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageHy.js |
— | — | @@ -0,0 +1,15 @@ |
| 2 | + |
| 3 | + |
| 4 | +/** Armenian (Հայերեն) |
| 5 | + * |
| 6 | + * @ingroup Language |
| 7 | + * @author Ruben Vardanyan (Me@RubenVardanyan.com) |
| 8 | + */ |
| 9 | + |
| 10 | + mw.lang.convertPlural = function( count, forms ) { |
| 11 | + |
| 12 | + forms = mw.lang.preConvertPlural( forms, 2 ); |
| 13 | + |
| 14 | + return (Math.abs(count) <= 1) ? forms[0] : forms[1]; |
| 15 | + } |
| 16 | + |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageRu.js |
— | — | @@ -0,0 +1,48 @@ |
| 2 | + |
| 3 | + |
| 4 | +/** Russian (русский язык) |
| 5 | + * |
| 6 | + * You can contact Alexander Sigachov (alexander.sigachov at Googgle Mail) |
| 7 | + * |
| 8 | + * @ingroup Language |
| 9 | + */ |
| 10 | + |
| 11 | + /** |
| 12 | + * Plural form transformations |
| 13 | + * |
| 14 | + * forms[0] - singular form (for 1, 21, 31, 41...) |
| 15 | + * forms[1] - paucal form (for 2, 3, 4, 22, 23, 24, 32, 33, 34...) |
| 16 | + * forms[2] - plural form (for 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 26...) |
| 17 | + * |
| 18 | + * Examples: |
| 19 | + * message with number |
| 20 | + * "Сделано $1 {{PLURAL:$1|изменение|изменения|изменений}}" |
| 21 | + * message without number |
| 22 | + * "Действие не может быть выполнено по {{PLURAL:$1|следующей причине|следующим причинам}}:" |
| 23 | + * |
| 24 | + */ |
| 25 | + |
| 26 | + mw.lang.convertPlural = function( count, forms ) { |
| 27 | + |
| 28 | + |
| 29 | + //if no number with word, then use $form[0] for singular and $form[1] for plural or zero |
| 30 | + if( forms.length === 2 ) return count == 1 ? forms[0] : forms[1]; |
| 31 | + |
| 32 | + // FIXME: CLDR defines 4 plural forms. Form with decimals missing. |
| 33 | + // See http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#ru |
| 34 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 35 | + |
| 36 | + if (count > 10 && Math.floor((count % 100) / 10) == 1) { |
| 37 | + return forms[2]; |
| 38 | + } else { |
| 39 | + switch (count % 10) { |
| 40 | + case 1: return forms[0]; |
| 41 | + case 2: |
| 42 | + case 3: |
| 43 | + case 4: return forms[1]; |
| 44 | + default: return forms[2]; |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + |
\ No newline at end of file |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageBh.js |
— | — | @@ -0,0 +1,14 @@ |
| 2 | + |
| 3 | +/** |
| 4 | + * |
| 5 | + * @ingroup Language |
| 6 | + */ |
| 7 | +/** |
| 8 | + * Use singular form for zero |
| 9 | + */ |
| 10 | +mw.lang.convertPlural = function( count, forms ) { |
| 11 | + |
| 12 | + forms = mw.lang.preConvertPlural( forms, 2 ); |
| 13 | + |
| 14 | + return (count <= 1) ? forms[0] : forms[1]; |
| 15 | +} |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageGd.js |
— | — | @@ -0,0 +1,33 @@ |
| 2 | + |
| 3 | +/** Scots Gaelic (Gàidhlig) |
| 4 | + * |
| 5 | + * @ingroup Language |
| 6 | + * |
| 7 | + * @author Raimond Spekking |
| 8 | + */ |
| 9 | + |
| 10 | + /** |
| 11 | + * Plural form transformations |
| 12 | + * Based on this discussion: http://translatewiki.net/w/i.php?title=Portal_talk:Gd&oldid=1094065#%C3%80ireamhan |
| 13 | + * |
| 14 | + * forms[0] - singular form (for 1) |
| 15 | + * forms[1] - dual form (for 2) |
| 16 | + * forms[2] - plural form 1 (for 3-10) |
| 17 | + * forms[3] - plural form 2 (for >= 11) |
| 18 | + * |
| 19 | + */ |
| 20 | + mw.lang.convertPlural = function( count, forms ) { |
| 21 | + |
| 22 | + forms = mw.lang.preConvertPlural( forms, 4 ); |
| 23 | + |
| 24 | + count = Math.abs( count ); |
| 25 | + if ( count === 1 ) { |
| 26 | + return forms[0]; |
| 27 | + } else if ( count === 2 ) { |
| 28 | + return forms[1]; |
| 29 | + } else if ( count >= 3 && count <= 10 ) { |
| 30 | + return forms[2]; |
| 31 | + } else { |
| 32 | + return forms[3]; |
| 33 | + } |
| 34 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageEn.js |
— | — | @@ -0,0 +1,34 @@ |
| 2 | +/** |
| 3 | +* MediaWiki javascript language transformations |
| 4 | +* |
| 5 | +* port of php language converters. |
| 6 | +* |
| 7 | +* Conversions are packaged into script-loader requests per |
| 8 | +* the requested language. |
| 9 | +* |
| 10 | +* The structure of mediaWiki language/classes is preserved |
| 11 | +* as much as possible |
| 12 | +*/ |
| 13 | + |
| 14 | +/** |
| 15 | + * Plural form transformations, needed for some languages. |
| 16 | + * For example, there are 3 form of plural in Russian and Polish, |
| 17 | + * depending on "count mod 10". See [[w:Plural]] |
| 18 | + * For English it is pretty simple. |
| 19 | + * |
| 20 | + * Invoked by putting {{plural:count|wordform1|wordform2}} |
| 21 | + * or {{plural:count|wordform1|wordform2|wordform3}} |
| 22 | + * |
| 23 | + * Example: {{plural:{{NUMBEROFARTICLES}}|article|articles}} |
| 24 | + * |
| 25 | + * @param count Integer: non-localized number |
| 26 | + * @param forms Array: different plural forms |
| 27 | + * @return string Correct form of plural for count in this language |
| 28 | + */ |
| 29 | + |
| 30 | +mw.lang.convertPlural = function( count, forms ){ |
| 31 | + if ( forms.length == 0 ) { |
| 32 | + return ''; |
| 33 | + } |
| 34 | + return ( parseInt( count ) == 1 ) ? forms[0] : forms[1]; |
| 35 | +} |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageAr.js |
— | — | @@ -0,0 +1,40 @@ |
| 2 | +/** Arabic (العربية) |
| 3 | + * |
| 4 | + * @ingroup Language |
| 5 | + * |
| 6 | + */ |
| 7 | +mw.lang.convertPlural = function( count, forms ){ |
| 8 | + forms = mw.lang.preConvertPlural( forms, 6 ); |
| 9 | + |
| 10 | + if ( count == 0 ) { |
| 11 | + index = 0; |
| 12 | + } else if ( count == 1 ) { |
| 13 | + index = 1; |
| 14 | + } else if( count == 2 ) { |
| 15 | + index = 2; |
| 16 | + } else if( count % 100 >= 3 && count % 100 <= 10 ) { |
| 17 | + index = 3; |
| 18 | + } else if( count % 100 >= 11 && count % 100 <= 99 ) { |
| 19 | + index = 4; |
| 20 | + } else { |
| 21 | + index = 5; |
| 22 | + } |
| 23 | + |
| 24 | + return forms[ index ]; |
| 25 | +} |
| 26 | + |
| 27 | +// Update the digitTransformTable for ar language key |
| 28 | +mw.lang.digitTransformTable = { |
| 29 | + '0' : '٠', // ٠ |
| 30 | + '1' : '١', // ١ |
| 31 | + '2' : '٢', // ٢ |
| 32 | + '3' : '٣', // ٣ |
| 33 | + '4' : '٤', // ٤ |
| 34 | + '5' : '٥', // ٥ |
| 35 | + '6' : '٦', // ٦ |
| 36 | + '7' : '٧', // ٧ |
| 37 | + '8' : '٨', // ٨ |
| 38 | + '9' : '٩', // ٩ |
| 39 | + '.' : '٫', // ٫ wrong table ? |
| 40 | + ',' : '٬' // ٬ |
| 41 | +}; |
\ No newline at end of file |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageSr_el.js |
— | — | @@ -0,0 +1,21 @@ |
| 2 | + |
| 3 | + |
| 4 | +/** |
| 5 | + * @ingroup Language |
| 6 | + */ |
| 7 | + mw.lang.convertPlural = function( count, forms ) { |
| 8 | + |
| 9 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 10 | + |
| 11 | + if (count > 10 && Math.floor((count % 100) / 10) == 1) { |
| 12 | + return forms[2]; |
| 13 | + } else { |
| 14 | + switch (count % 10) { |
| 15 | + case 1: return forms[0]; |
| 16 | + case 2: |
| 17 | + case 3: |
| 18 | + case 4: return forms[1]; |
| 19 | + default: return forms[2]; |
| 20 | + } |
| 21 | + } |
| 22 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageFr.js |
— | — | @@ -0,0 +1,15 @@ |
| 2 | + |
| 3 | + |
| 4 | +/** French (Français) |
| 5 | + * |
| 6 | + * @ingroup Language |
| 7 | + */ |
| 8 | + /** |
| 9 | + * Use singular form for zero (see bug 7309) |
| 10 | + */ |
| 11 | + mw.lang.convertPlural = function( count, forms ) { |
| 12 | + |
| 13 | + forms = mw.lang.preConvertPlural( forms, 2 ); |
| 14 | + |
| 15 | + return (count <= 1) ? forms[0] : forms[1]; |
| 16 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageHr.js |
— | — | @@ -0,0 +1,25 @@ |
| 2 | + |
| 3 | +/** Croatian (hrvatski) |
| 4 | + * |
| 5 | + * @ingroup Language |
| 6 | + */ |
| 7 | + |
| 8 | + |
| 9 | + mw.lang.convertPlural = function( count, forms ) { |
| 10 | + |
| 11 | + // FIXME: CLDR defines 4 plural forms instead of 3. Plural for for decimals is missing. |
| 12 | + // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html |
| 13 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 14 | + |
| 15 | + if (count > 10 && Math.floor((count % 100) / 10) == 1) { |
| 16 | + return forms[2]; |
| 17 | + } else { |
| 18 | + switch (count % 10) { |
| 19 | + case 1: return forms[0]; |
| 20 | + case 2: |
| 21 | + case 3: |
| 22 | + case 4: return forms[1]; |
| 23 | + default: return forms[2]; |
| 24 | + } |
| 25 | + } |
| 26 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageLn.js |
— | — | @@ -0,0 +1,16 @@ |
| 2 | + |
| 3 | +/** |
| 4 | + * |
| 5 | + * @ingroup Language |
| 6 | + */ |
| 7 | + /** |
| 8 | + * Use singular form for zero |
| 9 | + * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#ln |
| 10 | + |
| 11 | + */ |
| 12 | + mw.lang.convertPlural = function( count, forms ) { |
| 13 | + |
| 14 | + forms = mw.lang.preConvertPlural( forms, 2 ); |
| 15 | + |
| 16 | + return (count <= 1) ? forms[0] : forms[1]; |
| 17 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageSh.js |
— | — | @@ -0,0 +1,27 @@ |
| 2 | + |
| 3 | +/** |
| 4 | + * |
| 5 | + * @ingroup Language |
| 6 | + */ |
| 7 | + mw.lang.convertPlural = function( count, forms ) { |
| 8 | + |
| 9 | + |
| 10 | + //if no number with word, then use $form[0] for singular and $form[1] for plural or zero |
| 11 | + if( forms.length === 2 ) return count == 1 ? forms[0] : forms[1]; |
| 12 | + |
| 13 | + // FIXME: CLDR defines 4 plural forms. Form with decimals missing. |
| 14 | + // See http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#sh |
| 15 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 16 | + |
| 17 | + if (count > 10 && Math.floor((count % 100) / 10) == 1) { |
| 18 | + return forms[2]; |
| 19 | + } else { |
| 20 | + switch (count % 10) { |
| 21 | + case 1: return forms[0]; |
| 22 | + case 2: |
| 23 | + case 3: |
| 24 | + case 4: return forms[1]; |
| 25 | + default: return forms[2]; |
| 26 | + } |
| 27 | + } |
| 28 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguagePl.js |
— | — | @@ -0,0 +1,22 @@ |
| 2 | + |
| 3 | + |
| 4 | +/** Polish (polski) |
| 5 | + * |
| 6 | + * @ingroup Language |
| 7 | + */ |
| 8 | + mw.lang.convertPlural = function( count, forms ) { |
| 9 | + |
| 10 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 11 | + count = Math.abs( count ); |
| 12 | + if ( count == 1 ) |
| 13 | + return forms[0]; // singular |
| 14 | + switch ( count % 10 ) { |
| 15 | + case 2: |
| 16 | + case 3: |
| 17 | + case 4: |
| 18 | + if ( count / 10 % 10 != 1 ) |
| 19 | + return forms[1]; // plural |
| 20 | + default: |
| 21 | + return forms[2]; // plural genitive |
| 22 | + } |
| 23 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageGv.js |
— | — | @@ -0,0 +1,25 @@ |
| 2 | + |
| 3 | + |
| 4 | +/** Manx (Gaelg) |
| 5 | + * |
| 6 | + * @ingroup Language |
| 7 | + * |
| 8 | + * @author Niklas Laxström |
| 9 | + */ |
| 10 | + |
| 11 | + mw.lang.convertPlural = function( count, forms ) { |
| 12 | + |
| 13 | + |
| 14 | + forms = mw.lang.preConvertPlural( forms, 4 ); |
| 15 | + |
| 16 | + if (count > 0 && (count % 20) === 0 ) { |
| 17 | + return forms[0]; |
| 18 | + } else { |
| 19 | + switch (count % 10) { |
| 20 | + case 1: return forms[1]; |
| 21 | + case 2: return forms[2]; |
| 22 | + default: return forms[3]; |
| 23 | + } |
| 24 | + } |
| 25 | + } |
| 26 | + |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageBat_smg.js |
— | — | @@ -0,0 +1,22 @@ |
| 2 | +/** Samogitian (Žemaitėška) |
| 3 | + * |
| 4 | + * @ingroup Language |
| 5 | + * |
| 6 | + * @author Niklas Laxström |
| 7 | + * ported to js by mdale |
| 8 | + */ |
| 9 | +mw.lang.convertPlural = function( count, forms ) { |
| 10 | + |
| 11 | + forms = mw.lang.preConvertPlural( forms, 4 ); |
| 12 | + |
| 13 | + count = Math.abs( count ); |
| 14 | + if ( count === 0 || (count % 100 === 0 || (count % 100 >= 10 && count % 100 < 20)) ) { |
| 15 | + return forms[2]; |
| 16 | + } else if ( count % 10 === 1 ) { |
| 17 | + return forms[0]; |
| 18 | + } else if ( count % 10 === 2 ) { |
| 19 | + return forms[1]; |
| 20 | + } else { |
| 21 | + return forms[3]; |
| 22 | + } |
| 23 | +} |
\ No newline at end of file |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageSl.js |
— | — | @@ -0,0 +1,24 @@ |
| 2 | + |
| 3 | + |
| 4 | +/** Slovenian (Slovenščina) |
| 5 | + * |
| 6 | + * @ingroup Language |
| 7 | + */ |
| 8 | + |
| 9 | + mw.lang.convertPlural = function( count, forms ) { |
| 10 | + |
| 11 | + forms = mw.lang.preConvertPlural( forms, 5 ); |
| 12 | + |
| 13 | + if ( count % 100 == 1 ) { |
| 14 | + $index = 0; |
| 15 | + } else if ( count % 100 == 2 ) { |
| 16 | + $index = 1; |
| 17 | + } else if ( count % 100 == 3 || count % 100 == 4 ) { |
| 18 | + $index = 2; |
| 19 | + } else if ( count != 0 ) { |
| 20 | + $index = 3; |
| 21 | + } else { |
| 22 | + $index = 4; |
| 23 | + } |
| 24 | + return forms[$index]; |
| 25 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageLt.js |
— | — | @@ -0,0 +1,23 @@ |
| 2 | + |
| 3 | + |
| 4 | +/** Lithuanian (Lietuvių) |
| 5 | + * |
| 6 | + * @ingroup Language |
| 7 | + */ |
| 8 | + /* Word forms (with examples): |
| 9 | + 1 - vienas (1) lapas, dvidešimt vienas (21) lapas |
| 10 | + 2 - trys (3) lapai |
| 11 | + 3 - penkiolika (15) lapų |
| 12 | + */ |
| 13 | + mw.lang.convertPlural = function( count, forms ) { |
| 14 | + |
| 15 | + |
| 16 | + //if no number with word, then use $form[0] for singular and $form[1] for plural or zero |
| 17 | + if( forms.length === 2 ) return count == 1 ? forms[0] : forms[1]; |
| 18 | + |
| 19 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 20 | + |
| 21 | + if (count%10==1 && count%100!=11) return forms[0]; |
| 22 | + if (count%10>=2 && (count%100<10 || count%100>=20)) return forms[1]; |
| 23 | + return forms[2]; |
| 24 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageTl.js |
— | — | @@ -0,0 +1,14 @@ |
| 2 | + |
| 3 | +/** |
| 4 | + * |
| 5 | + * @ingroup Language |
| 6 | + */ |
| 7 | + /** |
| 8 | + * Use singular form for zero |
| 9 | + */ |
| 10 | + mw.lang.convertPlural = function( count, forms ) { |
| 11 | + |
| 12 | + forms = mw.lang.preConvertPlural( forms, 2 ); |
| 13 | + |
| 14 | + return (count <= 1) ? forms[0] : forms[1]; |
| 15 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageMt.js |
— | — | @@ -0,0 +1,20 @@ |
| 2 | + |
| 3 | + |
| 4 | +/** Maltese (Malti) |
| 5 | + * |
| 6 | + * @ingroup Language |
| 7 | + * |
| 8 | + * @author Niklas Laxström |
| 9 | + */ |
| 10 | + |
| 11 | + mw.lang.convertPlural = function( count, forms ) { |
| 12 | + |
| 13 | + |
| 14 | + forms = mw.lang.preConvertPlural( forms, 4 ); |
| 15 | + |
| 16 | + if ( count === 1 ) $index = 0; |
| 17 | + else if ( count === 0 || ( count%100>1 && count%100<11) ) $index = 1; |
| 18 | + else if ( count%100>10 && count%100<20 ) $index = 2; |
| 19 | + else $index = 3; |
| 20 | + return forms[$index]; |
| 21 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageLv.js |
— | — | @@ -0,0 +1,31 @@ |
| 2 | + |
| 3 | + |
| 4 | +/** Latvian (Latviešu) |
| 5 | + * |
| 6 | + * @ingroup Language |
| 7 | + * |
| 8 | + * @author Niklas Laxström |
| 9 | + * |
| 10 | + * @copyright Copyright © 2006, Niklas Laxström |
| 11 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 12 | + */ |
| 13 | + /** |
| 14 | + * Plural form transformations. Using the first form for words with the last digit 1, but not for words with the last digits 11, and the second form for all the others. |
| 15 | + * |
| 16 | + * Example: {{plural:{{NUMBEROFARTICLES}}|article|articles}} |
| 17 | + * |
| 18 | + * @param integer count |
| 19 | + * @param string $wordform1 |
| 20 | + * @param string $wordform2 |
| 21 | + * @param string $wordform3 (not used) |
| 22 | + * @return string |
| 23 | + */ |
| 24 | + mw.lang.convertPlural = function( count, forms ) { |
| 25 | + |
| 26 | + |
| 27 | + // FIXME: CLDR defines 3 plural forms instead of 2. Form for 0 is missing. |
| 28 | + // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#lv |
| 29 | + forms = mw.lang.preConvertPlural( forms, 2 ); |
| 30 | + |
| 31 | + return ( ( count % 10 == 1 ) && ( count % 100 != 11 ) ) ? forms[0] : forms[1]; |
| 32 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageSr.js |
— | — | @@ -0,0 +1,24 @@ |
| 2 | + |
| 3 | + |
| 4 | + mw.lang.convertPlural = function( count, forms ) { |
| 5 | + |
| 6 | + |
| 7 | + //if no number with word, then use $form[0] for singular and $form[1] for plural or zero |
| 8 | + if( forms.length === 2 ) return ( count == 1 ) ? forms[0] : forms[1]; |
| 9 | + |
| 10 | + // FIXME: CLDR defines 4 plural forms. Form with decimals missing. |
| 11 | + // See http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#ru |
| 12 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 13 | + |
| 14 | + if (count > 10 && Math.floor((count % 100) / 10) == 1) { |
| 15 | + return forms[2]; |
| 16 | + } else { |
| 17 | + switch (count % 10) { |
| 18 | + case 1: return forms[0]; |
| 19 | + case 2: |
| 20 | + case 3: |
| 21 | + case 4: return forms[1]; |
| 22 | + default: return forms[2]; |
| 23 | + } |
| 24 | + } |
| 25 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageKsh.js |
— | — | @@ -0,0 +1,24 @@ |
| 2 | + |
| 3 | + |
| 4 | +/** Ripuarian (Ripoarėsh) |
| 5 | + * |
| 6 | + * @ingroup Language |
| 7 | + * |
| 8 | + * @author Purodha Blissenbach |
| 9 | + */ |
| 10 | + |
| 11 | + /** |
| 12 | + * Handle cases of (1, other, 0) or (1, other) |
| 13 | + */ |
| 14 | + mw.lang.convertPlural = function( count, forms ) { |
| 15 | + |
| 16 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 17 | + |
| 18 | + if ( count == 1 ) { |
| 19 | + return forms[0]; |
| 20 | + } else if ( count == 0 ) { |
| 21 | + return forms[2]; |
| 22 | + } else { |
| 23 | + return forms[1]; |
| 24 | + } |
| 25 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageBe.js |
— | — | @@ -0,0 +1,33 @@ |
| 2 | +/** Belarusian normative (Беларуская мова) |
| 3 | + * |
| 4 | + * This is still the version from Be-x-old, only duplicated for consistency of |
| 5 | + * plural and grammar functions. If there are errors please send a patch. |
| 6 | + * |
| 7 | + * @ingroup Language |
| 8 | + * |
| 9 | + * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com> |
| 10 | + * @bug 1638, 2135 |
| 11 | + * @link http://be.wikipedia.org/wiki/Talk:LanguageBe.php |
| 12 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License |
| 13 | + * @license http://www.gnu.org/copyleft/fdl.html GNU Free Documentation License |
| 14 | + * |
| 15 | + * ported to js by mdale |
| 16 | + */ |
| 17 | + |
| 18 | + mw.lang.convertPlural = function convertPlural( count, forms ) { |
| 19 | + // FIXME: CLDR defines 4 plural forms instead of 3 |
| 20 | + // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html |
| 21 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 22 | + |
| 23 | + if (count > 10 && floor((count % 100) / 10) == 1) { |
| 24 | + return forms[2]; |
| 25 | + } else { |
| 26 | + switch (count % 10) { |
| 27 | + case 1: return forms[0]; |
| 28 | + case 2: |
| 29 | + case 3: |
| 30 | + case 4: return forms[1]; |
| 31 | + default: return forms[2]; |
| 32 | + } |
| 33 | + } |
| 34 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageGa.js |
— | — | @@ -0,0 +1,22 @@ |
| 2 | + |
| 3 | + |
| 4 | +/** Irish (Gaeilge) |
| 5 | + * |
| 6 | + * @ingroup Language |
| 7 | + */ |
| 8 | + |
| 9 | + mw.lang.convertPlural = function( count, forms ) { |
| 10 | + |
| 11 | + |
| 12 | + // plural forms per http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#ga |
| 13 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 14 | + |
| 15 | + if ( count == 1 ) { |
| 16 | + $index = 0; |
| 17 | + } else if( count == 2 ) { |
| 18 | + $index = 1; |
| 19 | + } else { |
| 20 | + $index = 2; |
| 21 | + } |
| 22 | + return forms[$index]; |
| 23 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageBe_tarask.js |
— | — | @@ -0,0 +1,40 @@ |
| 2 | +/** Belarusian in Taraškievica orthography (Беларуская тарашкевіца) |
| 3 | + * |
| 4 | + * @ingroup Language |
| 5 | + * |
| 6 | + * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com> |
| 7 | + * @bug 1638, 2135 |
| 8 | + * @link http://be.wikipedia.org/wiki/Talk:LanguageBe.php |
| 9 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License |
| 10 | + * @license http://www.gnu.org/copyleft/fdl.html GNU Free Documentation License |
| 11 | + * |
| 12 | + * ported to js by mdale |
| 13 | + */ |
| 14 | +/** |
| 15 | +* Plural form transformations |
| 16 | +* |
| 17 | +* $wordform1 - singular form (for 1, 21, 31, 41...) |
| 18 | +* $wordform2 - plural form (for 2, 3, 4, 22, 23, 24, 32, 33, 34...) |
| 19 | +* $wordform3 - plural form (for 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 26...) |
| 20 | +*/ |
| 21 | +mw.lang.convertPlural = function( count, forms ) { |
| 22 | + |
| 23 | + // If no number with word, then use $form[0] for singular and $form[1] for plural or zero |
| 24 | + if( forms.length === 2 ) return count == 1 ? forms[0] : forms[1]; |
| 25 | + |
| 26 | + // FIXME: CLDR defines 4 plural forms instead of 3 |
| 27 | + // http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html |
| 28 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 29 | + |
| 30 | + if (count > 10 && Math.floor((count % 100) / 10) == 1) { |
| 31 | + return forms[2]; |
| 32 | + } else { |
| 33 | + switch (count % 10) { |
| 34 | + case 1: return forms[0]; |
| 35 | + case 2: |
| 36 | + case 3: |
| 37 | + case 4: return forms[1]; |
| 38 | + default: return forms[2]; |
| 39 | + } |
| 40 | + } |
| 41 | +} |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageSr_ec.js |
— | — | @@ -0,0 +1,18 @@ |
| 2 | +/** |
| 3 | + * @ingroup Language |
| 4 | + */ |
| 5 | + mw.lang.convertPlural = function( count, forms ) { |
| 6 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 7 | + |
| 8 | + if (count > 10 && Math.floor((count % 100) / 10) == 1) { |
| 9 | + return forms[2]; |
| 10 | + } else { |
| 11 | + switch (count % 10) { |
| 12 | + case 1: return forms[0]; |
| 13 | + case 2: |
| 14 | + case 3: |
| 15 | + case 4: return forms[1]; |
| 16 | + default: return forms[2]; |
| 17 | + } |
| 18 | + } |
| 19 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageHe.js |
— | — | @@ -0,0 +1,34 @@ |
| 2 | + |
| 3 | + |
| 4 | +/** |
| 5 | + * Hebrew (עברית) |
| 6 | + * |
| 7 | + * @ingroup Language |
| 8 | + * |
| 9 | + * @author Rotem Liss |
| 10 | + */ |
| 11 | + |
| 12 | + /** |
| 13 | + * Gets a number and uses the suited form of the word. |
| 14 | + * |
| 15 | + * @param integer the number of items |
| 16 | + * @param string the first form (singular) |
| 17 | + * @param string the second form (plural) |
| 18 | + * @param string the third form (2 items, plural is used if not applicable and not specified |
| 19 | + * @param not used (for compatibility with ancestor) |
| 20 | + * @param not used (for compatibility with ancestor) |
| 21 | + * |
| 22 | + * @return string of the suited form of word |
| 23 | + */ |
| 24 | + mw.lang.convertPlural = function( count, forms ) { |
| 25 | + |
| 26 | + forms = mw.lang.preConvertPlural( forms, 3 ); |
| 27 | + |
| 28 | + if ( count == '1' ) { |
| 29 | + return forms[0]; |
| 30 | + } else if ( count == '2' && forms[2] ) { |
| 31 | + return forms[2]; |
| 32 | + } else { |
| 33 | + return forms[1]; |
| 34 | + } |
| 35 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageAm.js |
— | — | @@ -0,0 +1,10 @@ |
| 2 | + |
| 3 | +/** |
| 4 | + * Use singular form for zero |
| 5 | + */ |
| 6 | +mw.lang.convertPlural = function( count, forms ){ |
| 7 | + |
| 8 | + forms = mw.lang.preConvertPlural( forms, 2 ); |
| 9 | + |
| 10 | + return ( count <= 1 ) ? forms[0] : forms[1]; |
| 11 | +} |
Index: branches/js2-work/phase3/js/mwEmbed/includes/languages/classes/LanguageNso.js |
— | — | @@ -0,0 +1,14 @@ |
| 2 | + |
| 3 | +/** |
| 4 | + * |
| 5 | + * @ingroup Language |
| 6 | + */ |
| 7 | + /** |
| 8 | + * Use singular form for zero |
| 9 | + */ |
| 10 | + mw.lang.convertPlural = function( count, forms ) { |
| 11 | + |
| 12 | + forms = mw.lang.preConvertPlural( forms, 2 ); |
| 13 | + |
| 14 | + return (count <= 1) ? forms[0] : forms[1]; |
| 15 | + } |
Index: branches/js2-work/phase3/js/mwEmbed/modules/Sequencer/mw.PlayList.js |
— | — | @@ -301,26 +301,27 @@ |
302 | 302 | // playlist does not really support time request atm |
303 | 303 | return '0:0:0/' + mw.seconds2npt( this.getDuration() ); |
304 | 304 | }, |
305 | | - getDataSource: function() { |
| 305 | + getDataSource: function() { |
306 | 306 | mw.log( "f:getDataSource " + this.src ); |
307 | 307 | // determine the type / first is it m3u or xml? |
308 | | - var pl_parent = this; |
| 308 | + var _this = this; |
309 | 309 | this.src = mw.absoluteUrl( this.src ); |
310 | | - if ( this.src != null ) { |
311 | | - if ( mw.isLocalDomain( roe_url ) ){ |
312 | | - $j.get( roe_url, callback ); |
313 | | - } else { |
314 | | - roe_url = mw.replaceUrlParams(roe_url, { |
315 | | - 'feed_format':'json_roe', |
316 | | - 'cb':'?', |
317 | | - 'cb_inx': '1' |
318 | | - }) |
319 | | - $j.getJSON( roe_url, function( data ) { |
320 | | - pl_parent.data = data; |
321 | | - pl_parent.getSourceType(); |
322 | | - }); |
323 | | - } |
324 | | - } |
| 310 | + if ( mw.isLocalDomain( this.src ) ){ |
| 311 | + $j.get( this.src, function( data ) { |
| 312 | + _this.data = data; |
| 313 | + _this.getSourceType(); |
| 314 | + }); |
| 315 | + } else { |
| 316 | + roe_url = mw.replaceUrlParams( this.src, { |
| 317 | + 'feed_format':'json_roe', |
| 318 | + 'cb':'?', |
| 319 | + 'cb_inx': '1' |
| 320 | + }) |
| 321 | + $j.getJSON( roe_url, function( data ) { |
| 322 | + _this.data = data; |
| 323 | + _this.getSourceType(); |
| 324 | + }); |
| 325 | + } |
325 | 326 | }, |
326 | 327 | getSrc: function(){ |
327 | 328 | return this.src; |
Index: branches/js2-work/phase3/js/mwEmbed/mwEmbed.js |
— | — | @@ -75,6 +75,19 @@ |
76 | 76 | //If we are in debug mode ( results in fresh debugg javascript includes ) |
77 | 77 | 'debug' : false, |
78 | 78 | |
| 79 | + // Valid language codes ( has a file in /includes/languages/classes/Language{code}.js ) |
| 80 | + 'languageCodeList': ['en', 'am', 'ar', 'bat_smg', 'be_tarak', 'be', 'bh', |
| 81 | + 'bs', 'cs', 'cu', 'cy', 'dsb', 'fr', 'ga', 'gd', 'gv', 'he', 'hi', |
| 82 | + 'hr', 'hsb', 'hy', 'ksh', 'ln', 'lt', 'lv', 'mg', 'mk', 'mo', 'mt', |
| 83 | + 'nso', 'pl', 'pt_br', 'ro', 'ru', 'se', 'sh', 'sk', 'sl', 'sma', |
| 84 | + 'sr_ec', 'sr_el', 'sr', 'ti', 'tl', 'uk', 'wa' |
| 85 | + ], |
| 86 | + |
| 87 | + // Default user language is "en" Can be overwiteen by: |
| 88 | + // "uselang" url param |
| 89 | + // wgUserLang global |
| 90 | + 'userLanguage' : 'en', |
| 91 | + |
79 | 92 | // Set the default providers ( you can add more provider via {provider_id}_apiurl = $api_url |
80 | 93 | 'commons_apiurl' : 'http://commons.wikimedia.org/w/api.php' |
81 | 94 | }; |
— | — | @@ -232,20 +245,8 @@ |
233 | 246 | messageCache[ i ] = msgSet[i]; |
234 | 247 | } |
235 | 248 | } |
236 | | - |
| 249 | + |
237 | 250 | /** |
238 | | - * loadRS function |
239 | | - * Loads a ruleset by given template key ie PLURAL : { //ruleSetObj } |
240 | | - * |
241 | | - * @param json ruleSet The ruleset object ( extends gRuleSet ) |
242 | | - */ |
243 | | - mw.lang.loadRS = function( ruleSet ) { |
244 | | - for ( var i in ruleSet ) { |
245 | | - gRuleSet[ i ] = ruleSet[ i ]; |
246 | | - } |
247 | | - } |
248 | | - |
249 | | - /** |
250 | 251 | * Returns a transformed msg string |
251 | 252 | * |
252 | 253 | * it take a msg key and array of replacement values of form |
— | — | @@ -260,15 +261,12 @@ |
261 | 262 | |
262 | 263 | // Check for missing message key |
263 | 264 | if ( ! messageCache[ msgKey ] ) |
264 | | - return '<' + msgKey + '>'; |
265 | | - |
266 | | - // swap in the arg values |
267 | | - var ms = mw.lang.msgReplaceArgs( messageCache[ msgKey ], args ); |
268 | | - |
269 | | - // a quick check to see if we need to send the msg to the 'parser' |
270 | | - // (we can add more detailed check once we support more wiki syntax) |
271 | | - if ( ms.indexOf( '{{' ) === -1 && ms.indexOf( '[' ) === -1 ) { |
272 | | - return ms; |
| 265 | + return '<' + msgKey + '>'; |
| 266 | + |
| 267 | + var ms = mw.lang.msgReplaceArgs( messageCache[ msgKey ], args ); |
| 268 | + // A quick check to see if we need to send the msg to the 'parser' |
| 269 | + if ( ms.indexOf( '{{' ) === -1 && ms.indexOf( '[' ) === -1 ) { |
| 270 | + return ms; |
273 | 271 | } |
274 | 272 | |
275 | 273 | // Send the msg key through the parser |
— | — | @@ -287,22 +285,32 @@ |
288 | 286 | mw.lang.msgReplaceArgs = function( message , args ) { |
289 | 287 | // replace values |
290 | 288 | if ( typeof args == 'object' || typeof args == 'array' ) { |
291 | | - for ( var v =0; v < args.length; v++ ) { |
| 289 | + for ( var v =0; v < args.length; v++ ) { |
292 | 290 | if( typeof args[v] == 'undefined' ){ |
293 | 291 | continue; |
| 292 | + } |
| 293 | + var replaceValue = args[ v ]; |
| 294 | + // Convert number if applicable |
| 295 | + if( parseInt( replaceValue ) == replaceValue ){ |
| 296 | + replaceValue = mw.lang.convertNumber( replaceValue ); |
294 | 297 | } |
| 298 | + |
295 | 299 | // Message test replace arguments start at 1 instead of zero: |
296 | 300 | var rep = new RegExp( '\\$' + ( parseInt( v ) + 1 ), 'g' ); |
297 | 301 | |
298 | 302 | // Check if we got passed in a jQuery object: |
299 | 303 | if( typeof args[v]['html'] == 'function' ){ |
300 | | - message = message.replace( rep, $j('<div />').append( args[v] ).html() ); |
| 304 | + message = message.replace( rep, $j('<div />').append( replaceValue ).html() ); |
301 | 305 | }else{ |
302 | | - // Assume args[v] string |
303 | | - message = message.replace( rep, args[v] ); |
| 306 | + // Assume replaceValue string |
| 307 | + message = message.replace( rep, replaceValue ); |
304 | 308 | } |
305 | 309 | } |
306 | 310 | } else if ( typeof args == 'string' || typeof args == 'number' ) { |
| 311 | + // Convert number if applicable |
| 312 | + if( parseInt( args ) == args ){ |
| 313 | + args = mw.lang.convertNumber( args ); |
| 314 | + } |
307 | 315 | message = message.replace( /\$1/g, args ); |
308 | 316 | } |
309 | 317 | return message; |
— | — | @@ -338,99 +346,101 @@ |
339 | 347 | } |
340 | 348 | |
341 | 349 | /** |
342 | | - * Process the PLURAL special language template key: |
| 350 | + * Process the PLURAL template substitution |
| 351 | + * @param {Object} template Template object |
| 352 | + * |
| 353 | + * {{Template:argument|params}} |
| 354 | + * |
| 355 | + * Template object should include: |
| 356 | + * [arg] The argument sent to the template |
| 357 | + * [params] The template parameters |
343 | 358 | */ |
344 | 359 | mw.lang.procPLURAL = function( tObj ) { |
345 | | - // setup shortcuts |
346 | | - // (gRuleSet is loaded from script-loader to contains local ruleset) |
347 | | - var rs = gRuleSet['PLURAL']; |
348 | | - |
349 | | - /* |
350 | | - * Plural matchRuleTest |
351 | | - */ |
352 | | - function matchRuleTest( cRule, val ) { |
353 | | - mw.log("matchRuleTest:: " + typeof cRule + ' ' + cRule + ' == ' + val ); |
354 | | - function checkValue( compare, val ) { |
355 | | - if ( typeof compare == 'string' ) { |
356 | | - range = compare.split( '-' ); |
357 | | - if ( range.length >= 1 ) { |
358 | | - if ( val >= range[0] && val <= range[1] ) |
359 | | - return true; |
360 | | - } |
361 | | - } |
362 | | - // else do a direct compare |
363 | | - if ( compare == val ) { |
364 | | - return true; |
365 | | - } |
366 | | - return false; |
| 360 | + // Setup shortcuts |
| 361 | + // ( gRuleSet is loaded from script-loader to contains local ruleset ) |
| 362 | + var rs = gRuleSet[ 'PLURAL' ]; |
| 363 | + if( tObj.arg && tObj.param && mw.lang.convertPlural){ |
| 364 | + // Check if we have forms to replace |
| 365 | + if ( tObj.param.length == 0 ) { |
| 366 | + return ''; |
367 | 367 | } |
368 | | - // check for simple cRule type: |
369 | | - if ( typeof cRule == 'number' ) { |
370 | | - return ( parseInt( val ) == parseInt( cRule ) ); |
371 | | - } else if ( typeof cRule == 'object' ) { |
372 | | - var cmatch = { }; |
373 | | - // if a list we need to match all for rule match |
374 | | - for ( var i in cRule ) { |
375 | | - var cr = cRule[i]; |
376 | | - // set cr type |
377 | | - var crType = ''; |
378 | | - for ( var j in cr ) { |
379 | | - if ( j == 'mod' ) |
380 | | - crType = 'mod' |
381 | | - } |
382 | | - switch( crType ) { |
383 | | - case 'mod': |
384 | | - if ( cr ['is'] ) { |
385 | | - if ( checkValue( val % cr['mod'], cr ['is'] ) ) |
386 | | - cmatch[i] = true; |
387 | | - } else if ( cr['not'] ) { |
388 | | - if ( ! checkValue( val % cr['mod'], cr ['not'] ) ) |
389 | | - cmatch[i] = true; |
390 | | - } |
391 | | - break; |
392 | | - } |
393 | | - } |
394 | | - // Check all the matches (taking into consideration "or" order) |
395 | | - for ( var i in cRule ) { |
396 | | - if ( ! cmatch[i] ) |
397 | | - return false; |
398 | | - } |
399 | | - return true; |
400 | | - |
401 | | - } |
| 368 | + // Restore the count ( if it got converted earlier ) |
| 369 | + var count = mw.lang.convertNumber( tObj.arg, true ); |
| 370 | + |
| 371 | + // Do convertPlural call |
| 372 | + return mw.lang.convertPlural( count, tObj.param ); |
402 | 373 | } |
403 | | - /** |
404 | | - * Maps a given rule Index to template params: |
405 | | - * |
406 | | - * if index is out of range return last param |
407 | | - * @param {Object} tObj Template Object |
408 | | - * @param {Object} ruleInx Index of rule to be applied |
409 | | - */ |
410 | | - function getTempParamFromRuleInx( tObj, ruleInx ) { |
411 | | - // mw.log('getTempParamFromRuleInx: ruleInx: ' + ruleInx + ' tempParamLength ' + tObj.param.length ); |
412 | | - if ( ruleInx >= tObj.param.length ) |
413 | | - return tObj.param[ tObj.param.length - 1 ]; |
414 | | - // else return the requested index: |
415 | | - return tObj.param[ ruleInx ]; |
| 374 | + // Could not proccess plural return first form or nothing |
| 375 | + if( tObj.param[0] ){ |
| 376 | + return tObj.param[0]; |
416 | 377 | } |
| 378 | + return ''; |
| 379 | + }; |
| 380 | + |
| 381 | + /** |
| 382 | + * Checks that convertPlural was given an array and pads it to requested |
| 383 | + * amound of forms by copying the last one. |
| 384 | + * |
| 385 | + * @param {Array} forms Forms given to convertPlural |
| 386 | + * @param {Integer} count How many forms should there be at least |
| 387 | + * @return {Array} Padded array of forms or an exception if not an array |
| 388 | + */ |
| 389 | + mw.lang.preConvertPlural = function( forms, count ) { |
| 390 | + while ( forms.length < count ) { |
| 391 | + forms.push( forms[ forms.length-1 ] ); |
| 392 | + } |
| 393 | + return forms; |
| 394 | + }; |
| 395 | + |
| 396 | + /** |
| 397 | + * Init the digitTransformTable ( populated by language classes where applicable ) |
| 398 | + */ |
| 399 | + mw.lang.digitTransformTable = null; |
| 400 | + |
| 401 | + /** |
| 402 | + * Convert a number using the digitTransformTable |
| 403 | + * @param Number number to be converted |
| 404 | + * @param Bollean latin if we should return the latin type 0-10 |
| 405 | + */ |
| 406 | + mw.lang.convertNumber = function( number, latin ) { |
| 407 | + if( !mw.lang.digitTransformTable ) |
| 408 | + return number; |
417 | 409 | |
418 | | - var rCount = 0 |
419 | | - // run the actual rule lookup: |
420 | | - for ( var ruleInx in rs ) { |
421 | | - cRule = rs[ruleInx]; |
422 | | - if ( matchRuleTest( cRule, tObj.arg ) ) { |
423 | | - mw.log("matched rule: " + ruleInx ); |
424 | | - return getTempParamFromRuleInx( tObj, rCount ); |
| 410 | + // Set the target Transform table: |
| 411 | + var transformTable = mw.lang.digitTransformTable; |
| 412 | + |
| 413 | + // Check if the "restore" to latin number flag is set: |
| 414 | + if( latin ){ |
| 415 | + if( parseInt( number ) == number ) |
| 416 | + return number; |
| 417 | + var tmp = []; |
| 418 | + for( var i in transformTable ){ |
| 419 | + tmp[ transformTable[i] ] = i; |
425 | 420 | } |
426 | | - rCount ++; |
| 421 | + transformTable = tmp; |
427 | 422 | } |
428 | | - mw.log('no match found for: ' + tObj.arg + ' using last/other : ' + tObj.param [ tObj.param.length -1 ] ); |
429 | | - //debugger; |
430 | | - // return the last /"other" template param |
431 | | - return tObj.param [ tObj.param.length - 1 ]; |
| 423 | + |
| 424 | + var numberString = '' + number; |
| 425 | + var convertedNumber = ''; |
| 426 | + for( var i =0; i < numberString.length; i++){ |
| 427 | + if( transformTable[ numberString[i] ] ){ |
| 428 | + convertedNumber += transformTable[ numberString[i] ]; |
| 429 | + }else{ |
| 430 | + convertedNumber += numberString[i]; |
| 431 | + } |
| 432 | + } |
| 433 | + return ( latin )? parseInt( convertedNumber) : convertedNumber; |
432 | 434 | } |
433 | | - |
| 435 | + |
434 | 436 | /** |
| 437 | + * Checks if a language key is valid ( is part of languageCodeList ) |
| 438 | + * @param {String} langKey Language key to be checked |
| 439 | + */ |
| 440 | + mw.isValidLang = function( langKey ){ |
| 441 | + return ( $j.inArray(langKey, mw.getConfig( 'languageCodeList') ) == -1 ) |
| 442 | + } |
| 443 | + |
| 444 | + /** |
435 | 445 | * getRemoteMsg loads remote msg strings |
436 | 446 | * |
437 | 447 | * @param {Mixed} msgSet the set of msg to load remotely |
— | — | @@ -551,16 +561,11 @@ |
552 | 562 | // invalidate the output (will force a re-parse ) |
553 | 563 | this.pOut = ''; |
554 | 564 | }, |
| 565 | + /** |
| 566 | + * Quickly recursive / parse out templates: |
| 567 | + * This parser only really only tested against msg templates see tests/testLang.html |
| 568 | + */ |
555 | 569 | parse : function() { |
556 | | - /* |
557 | | - * quickly recursive / parse out templates: |
558 | | - */ |
559 | | - |
560 | | - // ~ probably a better algorithm out there / should mirror php parser flow ~ |
561 | | - // (we are already running white-space issues ie php parse strips whitespace differently) |
562 | | - // or at least expose something similar to: http://www.mediawiki.org/wiki/Extension:Page_Object_Model |
563 | | - |
564 | | - // ... but here is a quick hack that solves my current problem: |
565 | 570 | function rdpp ( txt , cn ) { |
566 | 571 | var node = { }; |
567 | 572 | // inspect each char |
— | — | @@ -683,12 +688,7 @@ |
684 | 689 | |
685 | 690 | // do the recursive magic swap text: |
686 | 691 | this.pOut = recurse_magic_swap( this.pNode ); |
687 | | - }, |
688 | | - |
689 | | - /** |
690 | | - * parsed template api ~loosely based off of ~POM~ |
691 | | - * http://www.mediawiki.org/wiki/Extension:Page_Object_Model |
692 | | - */ |
| 692 | + }, |
693 | 693 | |
694 | 694 | /** |
695 | 695 | * templates |
— | — | @@ -2347,6 +2347,17 @@ |
2348 | 2348 | |
2349 | 2349 | mw.log( 'mw:setupMwEmbed :: ' + mw.getMwEmbedSrc() ); |
2350 | 2350 | |
| 2351 | + // Set the User language |
| 2352 | + if( typeof wgUserLanguage != 'undefined' && mw.isValidLang( wgUserLanguage) ){ |
| 2353 | + mw.setConfig( 'userLanguage', wgUserLanguage ) |
| 2354 | + }else{ |
| 2355 | + // Grab it from the included url |
| 2356 | + var langKey = mw.parseUri( mw.getMwEmbedSrc() ).queryKey['uselang']; |
| 2357 | + if ( langKey && mw.isValidLang( langKey ) ) { |
| 2358 | + mw.setConfig( 'userLanguage', langKey); |
| 2359 | + } |
| 2360 | + } |
| 2361 | + |
2351 | 2362 | // Make sure we have all the module loaders |
2352 | 2363 | mw.moduleLoaderCheck( function(){ |
2353 | 2364 | // Make sure we have jQuery: |
— | — | @@ -2396,10 +2407,10 @@ |
2397 | 2408 | } |
2398 | 2409 | |
2399 | 2410 | /** |
2400 | | - * Check for module loaders |
2401 | | - * loads module loaders. |
| 2411 | + * Check for module loaders, and localization |
2402 | 2412 | * |
2403 | | - * Note if using a scriptLoader all the loaders are included automatically. |
| 2413 | + * Note if using a scriptLoader all the loaders and localization converters |
| 2414 | + * are included automatically. |
2404 | 2415 | */ |
2405 | 2416 | mw.moduleLoaderCheck = function( callback ){ |
2406 | 2417 | mw.log( 'doLoaderCheck::' ); |
— | — | @@ -2409,13 +2420,24 @@ |
2410 | 2421 | return ; |
2411 | 2422 | } |
2412 | 2423 | // Add the Core loader to the request |
2413 | | - mw.load( 'loader.js', function(){ |
| 2424 | + mw.load( 'loader.js', function(){ |
| 2425 | + |
2414 | 2426 | // Load all the "loaders" of the enabled modules: |
2415 | 2427 | var loaderRequest = []; |
2416 | 2428 | var enabledModules = mw.getConfig( 'enabledModules' ); |
2417 | 2429 | for(var i=0; i < enabledModules.length; i++ ){ |
2418 | 2430 | loaderRequest.push( 'modules/' + enabledModules[ i ] + '/loader.js' ); |
2419 | | - }; |
| 2431 | + }; |
| 2432 | + |
| 2433 | + // Add the language ( if set ) |
| 2434 | + if( mw.getConfig( 'userLanguage' ) ){ |
| 2435 | + var langCode = mw.getConfig( 'userLanguage' ); |
| 2436 | + // Upper case the first letter: |
| 2437 | + langCode = langCode.substr(0,1).toUpperCase() + langCode.substr(1,langCode.length); |
| 2438 | + loaderRequest.push( 'includes/languages/classes/Language' + |
| 2439 | + langCode + '.js' ); |
| 2440 | + } |
| 2441 | + |
2420 | 2442 | mw.setConfig('loaderContext', '' ); |
2421 | 2443 | mw.load( loaderRequest, function(){ |
2422 | 2444 | callback(); |
— | — | @@ -2526,7 +2548,8 @@ |
2527 | 2549 | "mwe-cancel" : "Cancel", |
2528 | 2550 | "mwe-enable-gadget" : "Enable mwEmbed gadget for all pages", |
2529 | 2551 | "mwe-enable-gadget-done" : "mwEmbed gadget has been enabled", |
2530 | | - "mwe-must-login-gadget" : "To enable gadget you must <a target=\"_new\" href=\"$1\">login</a>" |
| 2552 | + "mwe-must-login-gadget" : "To enable gadget you must <a target=\"_new\" href=\"$1\">login</a>", |
| 2553 | + "mwe-test-plural" : "I ran {{PLURAL:$1|$1 test|$1 tests}}" |
2531 | 2554 | } ); |
2532 | 2555 | |
2533 | 2556 | |
Index: branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php |
— | — | @@ -723,8 +723,6 @@ |
724 | 724 | // Do the language lookup |
725 | 725 | if ( $jmsg ) { |
726 | 726 | |
727 | | - // See if any msgKey has the PLURAL template tag |
728 | | - //package in PLURAL mapping |
729 | 727 | self::updateMsgKeys( $jmsg, $this->langCode ); |
730 | 728 | |
731 | 729 | // Return the updated JSON with Msgs: |