Index: branches/js2-work/phase3/js/mwEmbed/tests/testLang.html |
— | — | @@ -11,46 +11,69 @@ |
12 | 12 | |
13 | 13 | mw.ready( function(){ |
14 | 14 | //for just setting one or two to test at a time for debug |
15 | | - var langTestSet = [ 'es' ]; //pl |
16 | | - //var langTestSet = mw.getConfig( 'languageCodeList' ); |
| 15 | + //var langTestSet = [ 'es' ]; //pl |
17 | 16 | |
18 | | - //do mauall script loaders calls to test multiple languages: |
| 17 | + // Setup bindings: |
| 18 | + $j('#runLang').click(function(){ |
| 19 | + $j('#table_out,#score_card').empty(); |
| 20 | + if( !mw.Language.names[ $j('#testLangKey').val() ] ){ |
| 21 | + alert( escape( $j('#testLangKey').val() ) + ' does not appear to be a valid language key' ); |
| 22 | + } else { |
| 23 | + doLangTable( new Array( $j('#testLangKey').val() ) ) |
| 24 | + } |
| 25 | + }); |
| 26 | + $j('#runAll').click(function(){ |
| 27 | + $j('#table_out,#score_card').empty(); |
| 28 | + // Build the langTestSet from mw.Language.names |
| 29 | + var langTestSet = [] |
| 30 | + for( var i in mw.Language.names ) { |
| 31 | + langTestSet.push( i ) ; |
| 32 | + } |
| 33 | + doLangTable( langTestSet ); |
| 34 | + }); |
| 35 | + |
| 36 | + // Set-up base convert plural and gender (to restore for non-transofrm languages ) |
| 37 | + var baseConvertPlural = mw.Language.convertPlural; |
| 38 | + var baseGender = mw.Language.gender.prototype; |
| 39 | + |
| 40 | + // Do mauall script loaders calls to test multiple languages: |
19 | 41 | function doLangTable( langSet ){ |
20 | 42 | //build table output: |
21 | 43 | var msgTestSet = { |
22 | | - 'undelete_short' : [ 0, 1, 2, 5, 21, 30 ], |
| 44 | + 'undelete_short' : [ 0, 1, 2, 5, 21, 101 ], |
23 | 45 | //category-subcat-count' has two params: |
24 | 46 | 'category-subcat-count' : [ |
25 | 47 | [0,10], |
26 | | - [1,2], |
| 48 | + [1,2], |
27 | 49 | [3,30] |
28 | | - ], |
29 | | - 'contributions-title' : [0,1,2] |
30 | | - }; |
31 | | - // Set-up base convert plural and gender (to restore if no language class is set) |
32 | | - var baseConvertPlural = mw.Language.convertPlural; |
33 | | - var baseGender = mw.Language.gender; |
| 50 | + ] |
| 51 | + }; |
34 | 52 | |
35 | 53 | var passTest=0; |
36 | 54 | var failTest=0; |
37 | 55 | var testCount=0; |
38 | 56 | |
39 | 57 | /** |
40 | | - * proccess a language key test set |
| 58 | + * Proccess a language key test set |
41 | 59 | */ |
42 | 60 | function doProcLangKey( langKey ){ |
43 | 61 | mw.log(" doProcLangKey: " + langKey ); |
44 | 62 | // Clear out the old digitTransformTable |
45 | 63 | mw.Language.digitTransformTable = null; |
46 | | - // Load the current language js file if it has a langKey |
47 | | - if( mw.hasLangTransform (langKey ) ){ |
| 64 | + // Load the current language js file if it has a langKey |
| 65 | + if( mw.hasLangTransform ( langKey ) ){ |
| 66 | + mw.log( langKey + " load msg transform" ); |
48 | 67 | var langName = 'Language' + langKey.substr(0,1).toUpperCase() + langKey.substr( 1,langKey.length ); |
49 | 68 | $j.getScript( '../languages/classes/' + langName + '.js' , function(){ |
50 | 69 | doLangTest(); |
51 | 70 | }); |
52 | 71 | } else { |
| 72 | + mw.log( langKey + " no msg transform restore base" ); |
| 73 | + //If no transform, restore base plural |
| 74 | + mw.Language.convertPlural = baseConvertPlural; |
53 | 75 | doLangTest(); |
54 | 76 | } |
| 77 | + |
55 | 78 | function doLangTest(){ |
56 | 79 | // Get the current language mw.testLang js |
57 | 80 | $j.getScript( '../../../mwScriptLoader.php?class=mw.testLang&debug=true&uselang='+langKey, function(){ |
— | — | @@ -149,14 +172,15 @@ |
150 | 173 | |
151 | 174 | doProcLangKey( langSet.pop() ); |
152 | 175 | } |
153 | | - //by default run the "debug" set: |
154 | | - doLangTable( langTestSet ); |
155 | 176 | }); |
156 | 177 | |
157 | 178 | </script> |
158 | 179 | </head> |
159 | 180 | <body> |
160 | | -<h3>Test Javascript plural msg transformations</h3> |
| 181 | +<h3>Test Javascript plural msg transformations ( note this is a very resource intensive test )</h3> |
| 182 | +<a id="runAll" href="#">Run Test all<a> ( takes a few minutes ) <br> |
| 183 | +<a id="runLang" href="#">Run Language Key</a>:<input size="5" id="testLangKey" name = "testLangKey" value="en"/> |
| 184 | + |
161 | 185 | <div id="score_card" style="font-size:large"></div> |
162 | 186 | <table id="table_out"></table> |
163 | 187 | |
Index: branches/js2-work/phase3/js/mwEmbed/languages/mw.Language.js |
— | — | @@ -28,23 +28,32 @@ |
29 | 29 | } |
30 | 30 | } |
31 | 31 | |
| 32 | + var messageKeyQueue = []; |
32 | 33 | /** |
33 | 34 | * mw.addMessagesKey function |
34 | 35 | * Adds a msgKey to be pulled in remotely. |
35 | 36 | * |
36 | 37 | * NOTE the script-loader should replace this with localized addMessages calls |
37 | | - * if addMessagesKey is called then we are running in raw file debug mode. |
38 | 38 | * |
| 39 | + * If addMessagesKey is called then we are running in raw file debug mode. |
| 40 | + * it populates the messegeKeyQueue and loads the values in a separate request callback |
| 41 | + * |
39 | 42 | * @param {Array} msgSet The set of msgs to be loaded |
40 | 43 | */ |
41 | | - mw.addMessageKeys = function( msgSet ) { |
42 | | - /*for ( var i in msgSet ) { |
43 | | - messageCache[ i ] = msgSet[i]; |
44 | | - }*/ |
45 | | - // FLAG loader to wait for remote msg keys |
| 44 | + mw.addMessageKeys = function( msgSet ) { |
| 45 | + messageKeyQueue.concat( msgSet ); |
46 | 46 | } |
47 | 47 | |
| 48 | + /** |
| 49 | + * NOTE: this is somewhat of a hack. But its only used in debug mode since |
| 50 | + * normal msg loading happens via script-loader |
| 51 | + */ |
| 52 | + mw.loadQueuedMessages = function( classSet, callback ){ |
| 53 | + // Load the queued msgs ( requires access to the mediaWiki entry point ) |
| 54 | + |
| 55 | + } |
48 | 56 | |
| 57 | + |
49 | 58 | /** |
50 | 59 | * Returns a transformed msg string |
51 | 60 | * |
— | — | @@ -531,8 +540,8 @@ |
532 | 541 | }; |
533 | 542 | |
534 | 543 | // Language classes ( has a file in /languages/classes/Language{code}.js ) |
535 | | - // ( for languages that overide default transforms ) |
536 | | - mw.Language.transformClass = ['en', 'am', 'ar', 'bat_smg', 'be_tarak', 'be', 'bh', |
| 544 | + // ( for languages that override default transforms ) |
| 545 | + mw.Language.transformClass = ['am', 'ar', 'bat_smg', 'be_tarak', 'be', 'bh', |
537 | 546 | 'bs', 'cs', 'cu', 'cy', 'dsb', 'fr', 'ga', 'gd', 'gv', 'he', 'hi', |
538 | 547 | 'hr', 'hsb', 'hy', 'ksh', 'ln', 'lt', 'lv', 'mg', 'mk', 'mo', 'mt', |
539 | 548 | 'nso', 'pl', 'pt_br', 'ro', 'ru', 'se', 'sh', 'sk', 'sl', 'sma', |
— | — | @@ -674,14 +683,14 @@ |
675 | 684 | return ( mw.Language.names[ langKey ] )? true : false; |
676 | 685 | } |
677 | 686 | /** |
678 | | - * Checks if a language key has a transform class file |
| 687 | + * Checks if a language key has a transform class file |
679 | 688 | */ |
680 | 689 | mw.hasLangTransform = function( langKey ) { |
681 | | - for( var i =0; i < mw.Language.transformClass; i++) { |
| 690 | + for( var i =0; i < mw.Language.transformClass.length; i++ ) { |
682 | 691 | if( langKey == mw.Language.transformClass[i] ){ |
683 | 692 | return true; |
684 | 693 | } |
685 | | - } |
| 694 | + } |
686 | 695 | return false; |
687 | 696 | } |
688 | 697 | |
Index: branches/js2-work/phase3/js/mwEmbed/languages/classes/LanguageFr.js |
— | — | @@ -8,7 +8,6 @@ |
9 | 9 | * Use singular form for zero (see bug 7309) |
10 | 10 | */ |
11 | 11 | mw.Language.convertPlural = function( count, forms ) { |
12 | | - |
13 | 12 | forms = mw.Language.preConvertPlural( forms, 2 ); |
14 | 13 | |
15 | 14 | return (count <= 1) ? forms[0] : forms[1]; |
Index: branches/js2-work/phase3/js/mwEmbed/mwEmbed.js |
— | — | @@ -1745,7 +1745,7 @@ |
1746 | 1746 | } |
1747 | 1747 | |
1748 | 1748 | // Get mwEmbed src: |
1749 | | - var src = mw.getMwEmbedSrc(); |
| 1749 | + var src = mw.getMwEmbedSrc(); |
1750 | 1750 | var mwpath = null; |
1751 | 1751 | |
1752 | 1752 | // Check for direct include of the mwEmbed.js |
— | — | @@ -2237,7 +2237,6 @@ |
2238 | 2238 | langCode + '.js' ); |
2239 | 2239 | } |
2240 | 2240 | } |
2241 | | - |
2242 | 2241 | mw.setConfig('loaderContext', '' ); |
2243 | 2242 | mw.load( loaderRequest, function() { |
2244 | 2243 | mw.log( 'Done moduleLoaderCheck request' ); |
Index: branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php |
— | — | @@ -396,14 +396,16 @@ |
397 | 397 | |
398 | 398 | // Check for the two jsScriptLoader entry points: |
399 | 399 | if( strpos( $serverUri, 'mwScriptLoader.php') !== false ){ |
400 | | - $cssOptions[ 'prependRelativePath' ] = |
401 | | - str_replace('mwScriptLoader.php', '', $serverUri) |
402 | | - . dirname( $path ) . '/'; |
| 400 | + // Using the local mediaWiki entry point we should have our $wgScriptPath global |
| 401 | + global $wgScriptPath; |
| 402 | + $cssOptions[ 'prependRelativePath' ] = $wgScriptPath . '/' . dirname( $path ) . '/'; |
403 | 403 | } else if( strpos( $serverUri, 'jsScriptLoader.php') !== false ){ |
| 404 | + // We should use an absolute url to jsScriptLoader.php |
404 | 405 | $cssOptions[ 'prependRelativePath' ] = |
405 | 406 | str_replace('jsScriptLoader.php', '', $serverUri) |
406 | 407 | . dirname( $path ) . '/'; |
407 | 408 | } |
| 409 | + |
408 | 410 | // We always run minify to update css urls |
409 | 411 | $cssString = Minify_CSS::minify( $cssString, $cssOptions); |
410 | 412 | |