Index: trunk/phase3/js2/mwEmbed/tests/testLang.html |
— | — | @@ -8,11 +8,14 @@ |
9 | 9 | } |
10 | 10 | </style> |
11 | 11 | <script type="text/javascript" > |
| 12 | +//for just setting one or two to test at a time for debug |
| 13 | +var langKeyDebug = ['en']; |
| 14 | + |
12 | 15 | //shortLangKey is an array of at least one language from every group in cldrConverter.php |
13 | | -var shortLangKey = ['en','az', 'da', 'pt']; |
| 16 | +var langKeyGroups = ['en','az', 'da', 'pt', 'fr', 'lv', 'ga','hr','cy','mk','mt','pl','sl']; |
14 | 17 | |
15 | 18 | //longlangKey is every language we have a much more verbose test |
16 | | -var longLangKey = [ |
| 19 | +var langKeyAll = [ |
17 | 20 | //no plurals, there are no rules |
18 | 21 | 'az','fa','hu','ja','ko','my to','tr','vi','yo','zh', |
19 | 22 | 'bo','dz','id','jv ka','km','kn','ms','th', |
— | — | @@ -173,103 +176,116 @@ |
174 | 177 | |
175 | 178 | js2AddOnloadHook( function(){ |
176 | 179 | //do mauall script loaders calls to test multiple languages: |
177 | | - |
| 180 | + function doLangTable(langSet){ |
178 | 181 | //build table output: |
179 | | - var o = '<table>'; |
180 | | - var msgTestSet = { |
181 | | - |
182 | | - 'test_plural_msg':[ 0, 1, 2, 5, 21, 30 ], |
183 | | - |
184 | | - 'undelete_short': [ 0, 1, 2, 5, 21, 30 ], |
185 | | - |
| 182 | + var msgTestSet = { |
| 183 | + 'undelete_short': [ 0, 1, 2, 5, 21, 30 ], |
186 | 184 | //category-subcat-count' has two params: |
187 | 185 | 'category-subcat-count' : [ |
188 | 186 | [0,10], |
189 | 187 | [1,2], |
190 | | - [3,30] ] |
191 | | - |
192 | | - }; |
| 188 | + [3,30] |
| 189 | + ] |
| 190 | + }; |
193 | 191 | |
194 | 192 | var passTest=0; |
195 | 193 | var failTest=0; |
196 | 194 | var testCount=0; |
197 | | - //now for each langage msg: |
198 | | - $j.each(msgTestSet, function(mKey, mTestSet){ |
199 | | - //output table names: |
200 | | - o+='<tr>'+ |
201 | | - '<td>$1:</td>'+ |
202 | | - '<td width="14%">Msg key</td>'+ |
203 | | - '<td width="34%">Msg text</td>'+ |
204 | | - '<td width="24%">Msg Transform JS</td>'+ |
205 | | - '<td width="24%">Msg Transform Mw</td>'+ |
206 | | - '</tr>'; |
207 | | - |
208 | | - //for each number value |
209 | | - for(var i in mTestSet){ |
210 | | - var numVal = mTestSet[i]; |
211 | | - var numKey = (typeof numVal== 'object')? numVal.join( '_' ).replace('/ /', '_') : numVal; |
212 | | - o+='<tr>'+ |
213 | | - '<td>' + numVal + '</td>' + |
214 | | - '<td>' + mKey + '</td>' + |
215 | | - '<td>' + $mw.lang.gMsgNoTrans( mKey ) + '</td>' + |
216 | | - '<td id="' + mKey + '_' + numKey + '_js">' + $mw.lang.gM( mKey, numVal ) + '</td>'; |
217 | | - //show mw col: |
218 | | - if( mKey.substr(0, 5) == 'test_' ){ |
219 | | - o+='<td> (test msg) </td>'; |
220 | | - }else{ |
221 | | - o+='<td id="' + mKey + '_' + numKey + '">loading...</td>'; |
222 | | - |
223 | | - //get transform from mw (& compare and highlight) |
224 | | - function doPopWmMsg(mKey, numVal, numKey){ |
225 | | - testCount++; |
226 | | - $j('#score_card').html('Running Tests <span id="perc_done">0</sapn>% done'); |
227 | | - do_api_req({ |
228 | | - 'data': { |
229 | | - 'action':'parse', |
230 | | - 'text': $mw.lang.gMsgSwap( mKey, numVal) |
231 | | - }, |
232 | | - 'url' : '../../../api.php' |
233 | | - }, function( data ) { |
234 | | - var t = '#'+ mKey + '_'+ numKey; |
235 | | - if(data.parse && data.parse.text && data.parse.text['*']){ |
236 | | - $j(t).html( data.parse.text['*'] ); |
237 | | - //just get the part in the <p> to compare with js version |
238 | | - if( $j.trim( $j(t + ' p').html() ) != $j.trim( $j(t + '_js').html() ) ){ |
239 | | - $j(t).css('color', 'red'); |
240 | | - failTest++; |
241 | | - }else{ |
242 | | - $j(t).css('color', 'green'); |
243 | | - passTest++; |
244 | | - } |
245 | | - var perc = ( failTest + passTest ) / testCount |
246 | | - if( perc != 1){ |
247 | | - $j('#perc_done').html( Math.round(perc*1000)/1000 + '%'); |
248 | | - }else{ |
249 | | - $j('#score_card').html( "Passed: " + passTest + ' Failed:' +failTest); |
250 | | - } |
251 | | - }else{ |
252 | | - $t.html(' error '); |
253 | | - } |
254 | | - }); |
255 | | - }; |
256 | | - //pop off an anonymous function call: |
257 | | - doPopWmMsg(mKey, numVal, numKey); |
258 | | - } |
259 | | - o+='</tr>'; |
260 | | - } |
261 | | - //output a spacer: |
262 | | - o+='<tr><td colspan="6" height="20"> </td></tr>'; |
263 | | - }); |
264 | | - o+='</table>'; |
265 | | - //put the output into the page: |
266 | | - $j('#table_out').html( o ); |
| 195 | + $j.each(langSet, function(na, langKey){ |
| 196 | + js_log('load language key: ' + langKey); |
| 197 | + //do a manual call to the script-lodaer: |
| 198 | + js_log('do load: ' + '../../../mwScriptLoader.php?class=$mw.testLang&urid=5&lang='+langKey ); |
| 199 | + $j.getScript('../../../mwScriptLoader.php?class=$mw.testLang&urid=8&lang='+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; |
| 218 | + o+='<tr>'+ |
| 219 | + '<td>' + numVal + '</td>' + |
| 220 | + '<td>' + mKey + '</td>' + |
| 221 | + '<td>' + $mw.lang.gMsgNoTrans( mKey ) + '</td>' + |
| 222 | + '<td id="' + tkey + '_js">' + $mw.lang.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 | + do_api_req({ |
| 237 | + 'data': { |
| 238 | + 'action' : 'parse', |
| 239 | + 'text' : '{{int:' + mKey + '|' + msgparam + '}}' |
| 240 | + }, |
| 241 | + 'url' : '../../../api.php' |
| 242 | + }, function( data ) { |
| 243 | + var t = '#'+ tkey ; |
| 244 | + if(data.parse && data.parse.text && data.parse.text['*']){ |
| 245 | + $j(t).html( data.parse.text['*'] ); |
| 246 | + //just get the part in the <p> to compare with js version |
| 247 | + if( $j.trim( $j(t + ' p').html() ) != $j.trim( $j(t + '_js').html() ) ){ |
| 248 | + $j(t).css('color', 'red'); |
| 249 | + failTest++; |
| 250 | + }else{ |
| 251 | + $j(t).css('color', 'green'); |
| 252 | + passTest++; |
| 253 | + } |
| 254 | + var perc = ( failTest + passTest ) / testCount |
| 255 | + if( perc != 1){ |
| 256 | + $j('#perc_done').html( Math.round(perc*1000)/1000 + '%'); |
| 257 | + }else{ |
| 258 | + var failHtlm = (failTest == 0)?failTest: '<span style="color:red">'+ failTest+'</span>'; |
| 259 | + $j('#score_card').html( |
| 260 | + 'Passed: <span style="color:green">' + passTest + '</span> Failed:' + failHtlm ); |
| 261 | + } |
| 262 | + }else{ |
| 263 | + $t.html(' error '); |
| 264 | + } |
| 265 | + }); |
| 266 | + }; |
| 267 | + //pop off an anonymous function call |
| 268 | + doPopWmMsg(mKey, numVal, numKey); |
| 269 | + } |
| 270 | + o+='</tr>'; |
| 271 | + } |
| 272 | + //output a spacer: |
| 273 | + o+='<tr><td colspan="6" height="20"> </td></tr>'; |
| 274 | + }); |
| 275 | + //put the output into the page: |
| 276 | + $j('#table_out').append( o ); |
| 277 | + }); |
| 278 | + });// each lang key |
| 279 | + } |
| 280 | + //by default run the "debug" set: |
| 281 | + doLangTable( langKeyDebug ); |
267 | 282 | }); |
| 283 | + |
268 | 284 | </script> |
269 | 285 | </head> |
270 | 286 | <body> |
271 | 287 | <h3>Test Javascript plural msg transformations</h3> |
272 | 288 | <div id="score_card" style="font-size:large"></div> |
273 | | -<div id="table_out"></div> |
| 289 | +<table id="table_out"></table> |
274 | 290 | |
275 | 291 | |
276 | 292 | </body> |
Index: trunk/phase3/js2/mwEmbed/tests/testLang.js |
— | — | @@ -1,12 +1,9 @@ |
2 | 2 | /* a simple language tester replacements |
3 | 3 | */ |
4 | 4 | |
5 | | -loadGM({ |
6 | | - //test msg with English words to see whats going on |
7 | | - 'test_plural_msg' : '{{PLURAL:$1|one|other}}', |
8 | | - //sample real world msgs: |
9 | | - 'undelete_short' : 'Undelete {{PLURAL:$1|one edit|$1 edits}}', |
10 | | - 'category-subcat-count' : "fish {{PLURAL:$2|This {{PLURAL:$1|fistsub|$1 secondsub}} category has only the following subcategory.|This category has the following {{PLURAL:$1|subcategory|$1 subcategories}}, out of $2 total.}}" |
| 5 | +loadGM({ |
| 6 | + "undelete_short" : "Undelete {{PLURAL:$1|one edit|$1 edits}}", |
| 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.}}" |
11 | 8 | }); |
12 | 9 | |
13 | 10 | $mw.lang.loadRS({ |
Index: trunk/phase3/js2/mwEmbed/php/script-cache/README |
— | — | @@ -1,11 +1,6 @@ |
2 | | -This folder holds cached versions of grouped script requests (if running mwEmbed in stand-alone-mode. |
3 | | -(otherwise $wgFileCacheDirectory from mediaWiki is used) |
| 2 | +This folder holds cached versions of grouped script requests |
4 | 3 | |
5 | 4 | Be sure to enable write access by your web-server to this directory. |
6 | | - |
7 | | -You can specify a different directory by updating the $wgFileCacheDirectory variable in noMediaWikiConfig.php |
8 | 5 | |
9 | 6 | You can empty this directory at any time and should not be a problem. |
10 | 7 | |
11 | | -You may want to update your include call since the script server sends long expire headers since it ment to work in conjunction with mediaWiki dynamic pages that output fresh request ids as scripts update. |
12 | | - |
Property changes on: trunk/phase3/js2/mwEmbed/php/script-cache |
___________________________________________________________________ |
Name: svn:ignore |
13 | 8 | - 0 |
1 |
2 |
3 |
4 |
5 |
6 |
8 |
9 |
a |
c |
d |
e |
f |
14 | 9 | + 0 |
1 |
2 |
3 |
4 |
5 |
6 |
8 |
9 |
a |
c |
d |
e |
f |
b |
7 |
Index: trunk/phase3/js2/mwEmbed/jsScriptLoader.php |
— | — | @@ -173,19 +173,19 @@ |
174 | 174 | echo $this->jsout; |
175 | 175 | } |
176 | 176 | } |
177 | | - |
178 | | - function clientAcceptsGzip() { |
| 177 | + |
| 178 | + function clientAcceptsGzip() { |
179 | 179 | $m = array(); |
180 | 180 | if( preg_match( |
181 | 181 | '/\bgzip(?:;(q)=([0-9]+(?:\.[0-9]+)))?\b/', |
182 | 182 | $_SERVER['HTTP_ACCEPT_ENCODING'], |
183 | 183 | $m ) ) { |
184 | | - if( isset( $m[2] ) && ( $m[1] == 'q' ) && ( $m[2] == 0 ) ) |
185 | | - return false; |
| 184 | + if( isset( $m[2] ) && ( $m[1] == 'q' ) && ( $m[2] == 0 ) ) |
| 185 | + return false; |
186 | 186 | //no gzip support found |
187 | | - return true; |
188 | | - } |
189 | | - return false; |
| 187 | + return true; |
| 188 | + } |
| 189 | + return false; |
190 | 190 | } |
191 | 191 | /* |
192 | 192 | * postProcRequestVars uses globals, configuration and mediaWiki to test wiki-titles and files exist etc. |
— | — | @@ -208,6 +208,15 @@ |
209 | 209 | $this->urid = $wgStyleVersion; |
210 | 210 | } |
211 | 211 | |
| 212 | + //get the language code (if not provided use the "default" language |
| 213 | + if ( isset( $_GET['lang'] ) && $_GET['lang'] != '' ) { |
| 214 | + //make sure its a valid lang code: |
| 215 | + $this->langCode = preg_replace( "/[^A-Za-z]/", '', $_GET['lang']); |
| 216 | + }else{ |
| 217 | + //set english as default |
| 218 | + $this->langCode = 'en'; |
| 219 | + } |
| 220 | + |
212 | 221 | $reqClassList = false; |
213 | 222 | if ( isset( $_GET['class'] ) && $_GET['class'] != '' ) { |
214 | 223 | $reqClassList = explode( ',', $_GET['class'] ); |