Index: trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.js |
— | — | @@ -185,12 +185,12 @@ |
186 | 186 | expect( parser.parse( 'en_undelete_empty_param', [ 1 ] ).html() ).toEqual( 'Undelete' ); |
187 | 187 | expect( parser.parse( 'en_undelete_empty_param', [ 3 ] ).html() ).toEqual( 'Undelete multiple edits' ); |
188 | 188 | |
189 | | - } ) |
190 | | - } ) |
| 189 | + } ); |
| 190 | + } ); |
191 | 191 | |
192 | 192 | describe( "easy message interface functions", function() { |
193 | 193 | it( "should allow a global that returns strings", function() { |
194 | | - var gM = mediaWiki.language.parser.getMessageFunction(); |
| 194 | + var gM = mediaWiki.language.getMessageFunction(); |
195 | 195 | // passing this through jQuery and back to string, because browsers may have subtle differences, like the case of tag names. |
196 | 196 | // a surrounding <SPAN> is needed for html() to work right |
197 | 197 | var expectedHtml = $j( '<span>Complex <a href="http://example.com/foo">linking</a> behaviour.</span>' ).html(); |
— | — | @@ -200,7 +200,7 @@ |
201 | 201 | } ); |
202 | 202 | |
203 | 203 | it( "should allow a jQuery plugin that appends to nodes", function() { |
204 | | - $j.fn.msg = mediaWiki.language.parser.getJqueryPlugin(); |
| 204 | + $j.fn.msg = mediaWiki.language.getJqueryMessagePlugin(); |
205 | 205 | var $div = $j( '<div>' ).append( $j( '<p>' ).addClass( 'foo' ) ); |
206 | 206 | var clicked = false; |
207 | 207 | var $button = $j( '<button>' ).click( function() { clicked = true; } ); |
— | — | @@ -221,239 +221,83 @@ |
222 | 222 | delete $j.fn.msg; |
223 | 223 | } ); |
224 | 224 | |
225 | | - |
226 | 225 | } ); |
227 | 226 | |
228 | 227 | describe( "test plurals and other language-specific functions", function() { |
| 228 | + /* copying some language definitions in here -- it's hard to make this test fast and reliable |
| 229 | + otherwise, and we don't want to have to know the mediawiki URL from this kind of test either. |
| 230 | + We also can't preload the langs for the test since they clobber the same namespace. |
| 231 | + In principle Roan said it was okay to change how languages worked so that didn't happen... maybe |
| 232 | + someday. We'd have to the same kind of importing of the default rules for most rules, or maybe |
| 233 | + come up with some kind of subclassing scheme for languages */ |
| 234 | + var languageClasses = { |
| 235 | + ar: { |
| 236 | + /** |
| 237 | + * Arabic (العربية) language functions |
| 238 | + */ |
229 | 239 | |
230 | | - /** |
231 | | - * Get a language transform key |
232 | | - * returns default "en" fallback if none found |
233 | | - * @FIXME the resource loader should do this anyway, should not be necessary to know this client side |
234 | | - * @param String langKey The language key to be checked |
235 | | - */ |
236 | | - mediaWiki.language.getLangTransformKey = function( langKey ) { |
237 | | - if( mediaWiki.language.fallbackTransformMap[ langKey ] ) { |
238 | | - langKey = mediaWiki.language.fallbackTransformMap[ langKey ]; |
239 | | - } |
240 | | - // Make sure the langKey has a transformClass: |
241 | | - for( var i = 0; i < mediaWiki.language.transformClass.length ; i++ ) { |
242 | | - if( langKey == mediaWiki.language.transformClass[i] ){ |
243 | | - return langKey; |
| 240 | + convertPlural: function( count, forms ) { |
| 241 | + forms = mediaWiki.language.preConvertPlural( forms, 6 ); |
| 242 | + if ( count === 0 ) { |
| 243 | + return forms[0]; |
| 244 | + } |
| 245 | + if ( count == 1 ) { |
| 246 | + return forms[1]; |
| 247 | + } |
| 248 | + if ( count == 2 ) { |
| 249 | + return forms[2]; |
| 250 | + } |
| 251 | + if ( count % 100 >= 3 && count % 100 <= 10 ) { |
| 252 | + return forms[3]; |
| 253 | + } |
| 254 | + if ( count % 100 >= 11 && count % 100 <= 99 ) { |
| 255 | + return forms[4]; |
| 256 | + } |
| 257 | + return forms[5]; |
| 258 | + }, |
| 259 | + |
| 260 | + digitTransformTable: { |
| 261 | + '0': '٠', // ٠ |
| 262 | + '1': '١', // ١ |
| 263 | + '2': '٢', // ٢ |
| 264 | + '3': '٣', // ٣ |
| 265 | + '4': '٤', // ٤ |
| 266 | + '5': '٥', // ٥ |
| 267 | + '6': '٦', // ٦ |
| 268 | + '7': '٧', // ٧ |
| 269 | + '8': '٨', // ٨ |
| 270 | + '9': '٩', // ٩ |
| 271 | + '.': '٫', // ٫ wrong table ? |
| 272 | + ',': '٬' // ٬ |
244 | 273 | } |
245 | | - } |
246 | | - // By default return the base 'en' class |
247 | | - return 'en'; |
248 | | - }; |
249 | 274 | |
250 | | - /** |
251 | | - * @@FIXME this should be handled dynamically handled in the resource loader |
252 | | - * so it keeps up-to-date with php maping. |
253 | | - * ( not explicitly listed here ) |
254 | | - */ |
255 | | - mediaWiki.language.fallbackTransformMap = { |
256 | | - 'mwl' : 'pt', |
257 | | - 'ace' : 'id', |
258 | | - 'hsb' : 'de', |
259 | | - 'frr' : 'de', |
260 | | - 'pms' : 'it', |
261 | | - 'dsb' : 'de', |
262 | | - 'gan' : 'gan-hant', |
263 | | - 'lzz' : 'tr', |
264 | | - 'ksh' : 'de', |
265 | | - 'kl' : 'da', |
266 | | - 'fur' : 'it', |
267 | | - 'zh-hk' : 'zh-hant', |
268 | | - 'kk' : 'kk-cyrl', |
269 | | - 'zh-my' : 'zh-sg', |
270 | | - 'nah' : 'es', |
271 | | - 'sr' : 'sr-ec', |
272 | | - 'ckb-latn' : 'ckb-arab', |
273 | | - 'mo' : 'ro', |
274 | | - 'ay' : 'es', |
275 | | - 'gl' : 'pt', |
276 | | - 'gag' : 'tr', |
277 | | - 'mzn' : 'fa', |
278 | | - 'ruq-cyrl' : 'mk', |
279 | | - 'kk-arab' : 'kk-cyrl', |
280 | | - 'pfl' : 'de', |
281 | | - 'zh-yue' : 'yue', |
282 | | - 'ug' : 'ug-latn', |
283 | | - 'ltg' : 'lv', |
284 | | - 'nds' : 'de', |
285 | | - 'sli' : 'de', |
286 | | - 'mhr' : 'ru', |
287 | | - 'sah' : 'ru', |
288 | | - 'ff' : 'fr', |
289 | | - 'ab' : 'ru', |
290 | | - 'ko-kp' : 'ko', |
291 | | - 'sg' : 'fr', |
292 | | - 'zh-tw' : 'zh-hant', |
293 | | - 'map-bms' : 'jv', |
294 | | - 'av' : 'ru', |
295 | | - 'nds-nl' : 'nl', |
296 | | - 'pt-br' : 'pt', |
297 | | - 'ce' : 'ru', |
298 | | - 'vep' : 'et', |
299 | | - 'wuu' : 'zh-hans', |
300 | | - 'pdt' : 'de', |
301 | | - 'krc' : 'ru', |
302 | | - 'gan-hant' : 'zh-hant', |
303 | | - 'bqi' : 'fa', |
304 | | - 'as' : 'bn', |
305 | | - 'bm' : 'fr', |
306 | | - 'gn' : 'es', |
307 | | - 'tt' : 'ru', |
308 | | - 'zh-hant' : 'zh-hans', |
309 | | - 'hif' : 'hif-latn', |
310 | | - 'zh' : 'zh-hans', |
311 | | - 'kaa' : 'kk-latn', |
312 | | - 'lij' : 'it', |
313 | | - 'vot' : 'fi', |
314 | | - 'ii' : 'zh-cn', |
315 | | - 'ku-arab' : 'ckb-arab', |
316 | | - 'xmf' : 'ka', |
317 | | - 'vmf' : 'de', |
318 | | - 'zh-min-nan' : 'nan', |
319 | | - 'bcc' : 'fa', |
320 | | - 'an' : 'es', |
321 | | - 'rgn' : 'it', |
322 | | - 'qu' : 'es', |
323 | | - 'nb' : 'no', |
324 | | - 'bar' : 'de', |
325 | | - 'lbe' : 'ru', |
326 | | - 'su' : 'id', |
327 | | - 'pcd' : 'fr', |
328 | | - 'glk' : 'fa', |
329 | | - 'lb' : 'de', |
330 | | - 'kk-kz' : 'kk-cyrl', |
331 | | - 'kk-tr' : 'kk-latn', |
332 | | - 'inh' : 'ru', |
333 | | - 'mai' : 'hi', |
334 | | - 'tp' : 'tokipona', |
335 | | - 'kk-latn' : 'kk-cyrl', |
336 | | - 'ba' : 'ru', |
337 | | - 'nap' : 'it', |
338 | | - 'ruq' : 'ruq-latn', |
339 | | - 'tt-cyrl' : 'ru', |
340 | | - 'lad' : 'es', |
341 | | - 'dk' : 'da', |
342 | | - 'de-ch' : 'de', |
343 | | - 'be-x-old' : 'be-tarask', |
344 | | - 'za' : 'zh-hans', |
345 | | - 'kk-cn' : 'kk-arab', |
346 | | - 'shi' : 'ar', |
347 | | - 'crh' : 'crh-latn', |
348 | | - 'yi' : 'he', |
349 | | - 'pdc' : 'de', |
350 | | - 'eml' : 'it', |
351 | | - 'uk' : 'ru', |
352 | | - 'kv' : 'ru', |
353 | | - 'koi' : 'ru', |
354 | | - 'cv' : 'ru', |
355 | | - 'zh-cn' : 'zh-hans', |
356 | | - 'de-at' : 'de', |
357 | | - 'jut' : 'da', |
358 | | - 'vec' : 'it', |
359 | | - 'zh-mo' : 'zh-hk', |
360 | | - 'fiu-vro' : 'vro', |
361 | | - 'frp' : 'fr', |
362 | | - 'mg' : 'fr', |
363 | | - 'ruq-latn' : 'ro', |
364 | | - 'sa' : 'hi', |
365 | | - 'lmo' : 'it', |
366 | | - 'kiu' : 'tr', |
367 | | - 'tcy' : 'kn', |
368 | | - 'srn' : 'nl', |
369 | | - 'jv' : 'id', |
370 | | - 'vls' : 'nl', |
371 | | - 'zea' : 'nl', |
372 | | - 'ty' : 'fr', |
373 | | - 'szl' : 'pl', |
374 | | - 'rmy' : 'ro', |
375 | | - 'wo' : 'fr', |
376 | | - 'vro' : 'et', |
377 | | - 'udm' : 'ru', |
378 | | - 'bpy' : 'bn', |
379 | | - 'mrj' : 'ru', |
380 | | - 'ckb' : 'ckb-arab', |
381 | | - 'xal' : 'ru', |
382 | | - 'de-formal' : 'de', |
383 | | - 'myv' : 'ru', |
384 | | - 'ku' : 'ku-latn', |
385 | | - 'crh-cyrl' : 'ru', |
386 | | - 'gsw' : 'de', |
387 | | - 'rue' : 'uk', |
388 | | - 'iu' : 'ike-cans', |
389 | | - 'stq' : 'de', |
390 | | - 'gan-hans' : 'zh-hans', |
391 | | - 'scn' : 'it', |
392 | | - 'arn' : 'es', |
393 | | - 'ht' : 'fr', |
394 | | - 'zh-sg' : 'zh-hans', |
395 | | - 'bat-smg' : 'lt', |
396 | | - 'aln' : 'sq', |
397 | | - 'tg' : 'tg-cyrl', |
398 | | - 'li' : 'nl', |
399 | | - 'simple' : 'en', |
400 | | - 'os' : 'ru', |
401 | | - 'ln' : 'fr', |
402 | | - 'als' : 'gsw', |
403 | | - 'zh-classical' : 'lzh', |
404 | | - 'arz' : 'ar', |
405 | | - 'wa' : 'fr' |
406 | | - }; |
407 | | - |
408 | | - /** |
409 | | - * Language classes ( which have a file in /languages/classes/Language{code}.js ) |
410 | | - * ( for languages that override default transforms ) |
411 | | - * |
412 | | - * @@FIXME again not needed if the resource loader manages this mapping and gives |
413 | | - * us the "right" transform class regardless of what language key we request. |
414 | | - */ |
415 | | - mediaWiki.language.transformClass = ['am', 'ar', 'bat_smg', 'be_tarak', 'be', 'bh', |
416 | | - 'bs', 'cs', 'cu', 'cy', 'dsb', 'fr', 'ga', 'gd', 'gv', 'he', 'hi', |
417 | | - 'hr', 'hsb', 'hy', 'ksh', 'ln', 'lt', 'lv', 'mg', 'mk', 'mo', 'mt', |
418 | | - 'nso', 'pl', 'pt_br', 'ro', 'ru', 'se', 'sh', 'sk', 'sl', 'sma', |
419 | | - 'sr_ec', 'sr_el', 'sr', 'ti', 'tl', 'uk', 'wa' ]; |
420 | | - |
421 | | - // wgLang?? |
422 | | - var wgLanguageCode = 'en'; |
423 | | - // Set-up base convert plural and gender (to restore for non-transform languages ) |
424 | | - var cachedConvertPlural = { 'en' : mediaWiki.language.convertPlural }; |
425 | | - |
426 | | - // XXX THIS ONLY WORKS FOR NEIL |
427 | | - var wgScriptPath = 'http://wiki.ivy.local/w'; |
428 | | - /** |
429 | | - * Clear out digit transform table, load new pluralization rules, for a new language. |
430 | | - * Typically we don't need to do this in MediaWiki, it's one interface language per page. |
431 | | - * @param {String} languageCode |
432 | | - * @param {Function} to be executed when related scripts have loaded |
433 | | - */ |
434 | | - mediaWiki.language.resetForLang = function( langRequested, fn ) { |
435 | | - mediaWiki.language.digitTransformTable = null; |
436 | | - // Load the current language js file if it has a langKey |
437 | | - var lang = mediaWiki.language.getLangTransformKey( langRequested ); |
438 | | - if( cachedConvertPlural[lang] ) { |
439 | | - mediaWiki.language.convertPlural = cachedConvertPlural[lang]; |
440 | | - fn(); |
441 | | - } else { |
442 | | - mw.log( lang + " load msg transform" ); |
443 | | - $j.getScript( wgScriptPath + '/resources/mediaWiki.language/languages/' + lang.toLowerCase() + '.js' , function(){ |
444 | | - cachedConvertPlural[lang] = mediaWiki.language.convertPlural; |
445 | | - fn(); |
446 | | - }); |
447 | | - } |
| 275 | + }, |
| 276 | + en: { }, |
| 277 | + fr: { |
| 278 | + convertPlural: function( count, forms ) { |
| 279 | + forms = mediaWiki.language.preConvertPlural( forms, 2 ); |
| 280 | + return ( count <= 1 ) ? forms[0] : forms[1]; |
| 281 | + } |
| 282 | + }, |
| 283 | + jp: { }, |
| 284 | + zh: { } |
448 | 285 | }; |
449 | 286 | |
| 287 | + /* simulate how the language classes override, or don't, the standard functions in mediaWiki.language */ |
| 288 | + $j.each( languageClasses, function( langCode, rules ) { |
| 289 | + $j.each( [ 'convertPlural', 'convertNumber' ], function( i, propertyName ) { |
| 290 | + if ( typeof rules[ propertyName ] === 'undefined' ) { |
| 291 | + rules[ propertyName ] = mediaWiki.language[ propertyName ]; |
| 292 | + } |
| 293 | + } ); |
| 294 | + } ); |
450 | 295 | |
451 | 296 | $j.each( jasmineMsgSpec, function( i, test ) { |
452 | | - var parser = new mediaWiki.language.parser(); |
453 | 297 | it( "should parse " + test.name, function() { |
454 | | - mediaWiki.language.resetForLang( test.lang, function() { |
455 | | - var parsedHtml = parser.parse( test.key, test.args ).html(); |
456 | | - expect( parsedHtml ).toEqual( test.result ); |
457 | | - } ); |
| 298 | + // using language override so we don't have to muck with global namespace |
| 299 | + var parser = new mediaWiki.language.parser( { language: languageClasses[ test.lang ] } ); |
| 300 | + var parsedHtml = parser.parse( test.key, test.args ).html(); |
| 301 | + expect( parsedHtml ).toEqual( test.result ); |
458 | 302 | } ); |
459 | 303 | } ); |
460 | 304 | |