Index: trunk/extensions/UploadWizard/test/jasmine/spec/mw.Language.spec.js |
— | — | @@ -1,13 +0,0 @@ |
2 | | -describe( "mw.Language", function() { |
3 | | - |
4 | | - mw.addMessages( { |
5 | | - 'simple-message' => 'simple message' |
6 | | - |
7 | | - } ); |
8 | | - |
9 | | - it( "should return identity for simple string", function() { |
10 | | - expect( gM( 'simple-message' ).toEqual( 'simple message' ); |
11 | | - } ); |
12 | | - |
13 | | - |
14 | | -} ); |
Index: trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.js |
— | — | @@ -0,0 +1,268 @@ |
| 2 | +/* spec for language & message behaviour in MediaWiki */ |
| 3 | + |
| 4 | +// boilerplate crap, can we eliminate this? |
| 5 | + |
| 6 | +jQuery( document ).ready( function() { |
| 7 | + // add "magic" to Language template parser for keywords |
| 8 | + mw.addTemplateTransform( { 'SITENAME' : function() { return wgSitename; } } ); |
| 9 | + |
| 10 | + // sets up plural "magic" and so on. Seems like a bad design to have to do this, though. |
| 11 | + mw.Language.magicSetup(); |
| 12 | + |
| 13 | +} ); |
| 14 | + |
| 15 | + |
| 16 | +/** |
| 17 | + * Tests |
| 18 | + */ |
| 19 | +describe( "mw.Language", function() { |
| 20 | + |
| 21 | + |
| 22 | + describe( "basic message functionality", function() { |
| 23 | + mw.addMessages( { |
| 24 | + 'simple-message': 'simple message' |
| 25 | + } ); |
| 26 | + |
| 27 | + it( "should return identity for simple string", function() { |
| 28 | + expect( gM( 'simple-message' ) ).toEqual( 'simple message' ); |
| 29 | + } ); |
| 30 | + |
| 31 | + } ); |
| 32 | + |
| 33 | + describe( "test for matching functionality with PHP", function() { |
| 34 | + |
| 35 | + /** |
| 36 | + * Get a language transform key |
| 37 | + * returns default "en" fallback if none found |
| 38 | + * @param String langKey The language key to be checked |
| 39 | + */ |
| 40 | + mw.Language.getLangTransformKey = function( langKey ) { |
| 41 | + if( mw.Language.fallbackTransformMap[ langKey ] ) { |
| 42 | + langKey = mw.Language.fallbackTransformMap[ langKey ]; |
| 43 | + } |
| 44 | + // Make sure the langKey has a transformClass: |
| 45 | + for( var i = 0; i < mw.Language.transformClass.length ; i++ ) { |
| 46 | + if( langKey == mw.Language.transformClass[i] ){ |
| 47 | + return langKey |
| 48 | + } |
| 49 | + } |
| 50 | + // By default return the base 'en' class |
| 51 | + return 'en'; |
| 52 | + }; |
| 53 | + |
| 54 | + /** |
| 55 | + * @@FIXME this should be handled dynamically handled in the resource loader |
| 56 | + * so it keeps up-to-date with php maping. |
| 57 | + * ( not explicitly listed here ) |
| 58 | + */ |
| 59 | + mw.Language.fallbackTransformMap = { |
| 60 | + 'mwl' : 'pt', |
| 61 | + 'ace' : 'id', |
| 62 | + 'hsb' : 'de', |
| 63 | + 'frr' : 'de', |
| 64 | + 'pms' : 'it', |
| 65 | + 'dsb' : 'de', |
| 66 | + 'gan' : 'gan-hant', |
| 67 | + 'lzz' : 'tr', |
| 68 | + 'ksh' : 'de', |
| 69 | + 'kl' : 'da', |
| 70 | + 'fur' : 'it', |
| 71 | + 'zh-hk' : 'zh-hant', |
| 72 | + 'kk' : 'kk-cyrl', |
| 73 | + 'zh-my' : 'zh-sg', |
| 74 | + 'nah' : 'es', |
| 75 | + 'sr' : 'sr-ec', |
| 76 | + 'ckb-latn' : 'ckb-arab', |
| 77 | + 'mo' : 'ro', |
| 78 | + 'ay' : 'es', |
| 79 | + 'gl' : 'pt', |
| 80 | + 'gag' : 'tr', |
| 81 | + 'mzn' : 'fa', |
| 82 | + 'ruq-cyrl' : 'mk', |
| 83 | + 'kk-arab' : 'kk-cyrl', |
| 84 | + 'pfl' : 'de', |
| 85 | + 'zh-yue' : 'yue', |
| 86 | + 'ug' : 'ug-latn', |
| 87 | + 'ltg' : 'lv', |
| 88 | + 'nds' : 'de', |
| 89 | + 'sli' : 'de', |
| 90 | + 'mhr' : 'ru', |
| 91 | + 'sah' : 'ru', |
| 92 | + 'ff' : 'fr', |
| 93 | + 'ab' : 'ru', |
| 94 | + 'ko-kp' : 'ko', |
| 95 | + 'sg' : 'fr', |
| 96 | + 'zh-tw' : 'zh-hant', |
| 97 | + 'map-bms' : 'jv', |
| 98 | + 'av' : 'ru', |
| 99 | + 'nds-nl' : 'nl', |
| 100 | + 'pt-br' : 'pt', |
| 101 | + 'ce' : 'ru', |
| 102 | + 'vep' : 'et', |
| 103 | + 'wuu' : 'zh-hans', |
| 104 | + 'pdt' : 'de', |
| 105 | + 'krc' : 'ru', |
| 106 | + 'gan-hant' : 'zh-hant', |
| 107 | + 'bqi' : 'fa', |
| 108 | + 'as' : 'bn', |
| 109 | + 'bm' : 'fr', |
| 110 | + 'gn' : 'es', |
| 111 | + 'tt' : 'ru', |
| 112 | + 'zh-hant' : 'zh-hans', |
| 113 | + 'hif' : 'hif-latn', |
| 114 | + 'zh' : 'zh-hans', |
| 115 | + 'kaa' : 'kk-latn', |
| 116 | + 'lij' : 'it', |
| 117 | + 'vot' : 'fi', |
| 118 | + 'ii' : 'zh-cn', |
| 119 | + 'ku-arab' : 'ckb-arab', |
| 120 | + 'xmf' : 'ka', |
| 121 | + 'vmf' : 'de', |
| 122 | + 'zh-min-nan' : 'nan', |
| 123 | + 'bcc' : 'fa', |
| 124 | + 'an' : 'es', |
| 125 | + 'rgn' : 'it', |
| 126 | + 'qu' : 'es', |
| 127 | + 'nb' : 'no', |
| 128 | + 'bar' : 'de', |
| 129 | + 'lbe' : 'ru', |
| 130 | + 'su' : 'id', |
| 131 | + 'pcd' : 'fr', |
| 132 | + 'glk' : 'fa', |
| 133 | + 'lb' : 'de', |
| 134 | + 'kk-kz' : 'kk-cyrl', |
| 135 | + 'kk-tr' : 'kk-latn', |
| 136 | + 'inh' : 'ru', |
| 137 | + 'mai' : 'hi', |
| 138 | + 'tp' : 'tokipona', |
| 139 | + 'kk-latn' : 'kk-cyrl', |
| 140 | + 'ba' : 'ru', |
| 141 | + 'nap' : 'it', |
| 142 | + 'ruq' : 'ruq-latn', |
| 143 | + 'tt-cyrl' : 'ru', |
| 144 | + 'lad' : 'es', |
| 145 | + 'dk' : 'da', |
| 146 | + 'de-ch' : 'de', |
| 147 | + 'be-x-old' : 'be-tarask', |
| 148 | + 'za' : 'zh-hans', |
| 149 | + 'kk-cn' : 'kk-arab', |
| 150 | + 'shi' : 'ar', |
| 151 | + 'crh' : 'crh-latn', |
| 152 | + 'yi' : 'he', |
| 153 | + 'pdc' : 'de', |
| 154 | + 'eml' : 'it', |
| 155 | + 'uk' : 'ru', |
| 156 | + 'kv' : 'ru', |
| 157 | + 'koi' : 'ru', |
| 158 | + 'cv' : 'ru', |
| 159 | + 'zh-cn' : 'zh-hans', |
| 160 | + 'de-at' : 'de', |
| 161 | + 'jut' : 'da', |
| 162 | + 'vec' : 'it', |
| 163 | + 'zh-mo' : 'zh-hk', |
| 164 | + 'fiu-vro' : 'vro', |
| 165 | + 'frp' : 'fr', |
| 166 | + 'mg' : 'fr', |
| 167 | + 'ruq-latn' : 'ro', |
| 168 | + 'sa' : 'hi', |
| 169 | + 'lmo' : 'it', |
| 170 | + 'kiu' : 'tr', |
| 171 | + 'tcy' : 'kn', |
| 172 | + 'srn' : 'nl', |
| 173 | + 'jv' : 'id', |
| 174 | + 'vls' : 'nl', |
| 175 | + 'zea' : 'nl', |
| 176 | + 'ty' : 'fr', |
| 177 | + 'szl' : 'pl', |
| 178 | + 'rmy' : 'ro', |
| 179 | + 'wo' : 'fr', |
| 180 | + 'vro' : 'et', |
| 181 | + 'udm' : 'ru', |
| 182 | + 'bpy' : 'bn', |
| 183 | + 'mrj' : 'ru', |
| 184 | + 'ckb' : 'ckb-arab', |
| 185 | + 'xal' : 'ru', |
| 186 | + 'de-formal' : 'de', |
| 187 | + 'myv' : 'ru', |
| 188 | + 'ku' : 'ku-latn', |
| 189 | + 'crh-cyrl' : 'ru', |
| 190 | + 'gsw' : 'de', |
| 191 | + 'rue' : 'uk', |
| 192 | + 'iu' : 'ike-cans', |
| 193 | + 'stq' : 'de', |
| 194 | + 'gan-hans' : 'zh-hans', |
| 195 | + 'scn' : 'it', |
| 196 | + 'arn' : 'es', |
| 197 | + 'ht' : 'fr', |
| 198 | + 'zh-sg' : 'zh-hans', |
| 199 | + 'bat-smg' : 'lt', |
| 200 | + 'aln' : 'sq', |
| 201 | + 'tg' : 'tg-cyrl', |
| 202 | + 'li' : 'nl', |
| 203 | + 'simple' : 'en', |
| 204 | + 'os' : 'ru', |
| 205 | + 'ln' : 'fr', |
| 206 | + 'als' : 'gsw', |
| 207 | + 'zh-classical' : 'lzh', |
| 208 | + 'arz' : 'ar', |
| 209 | + 'wa' : 'fr' |
| 210 | + }; |
| 211 | + |
| 212 | + /** |
| 213 | + * Language classes ( which have a file in /languages/classes/Language{code}.js ) |
| 214 | + * ( for languages that override default transforms ) |
| 215 | + * |
| 216 | + * @@FIXME again not needed if the resource loader manages this mapping and gives |
| 217 | + * us the "right" transform class regardless of what language key we request. |
| 218 | + */ |
| 219 | + mw.Language.transformClass = ['am', 'ar', 'bat_smg', 'be_tarak', 'be', 'bh', |
| 220 | + 'bs', 'cs', 'cu', 'cy', 'dsb', 'fr', 'ga', 'gd', 'gv', 'he', 'hi', |
| 221 | + 'hr', 'hsb', 'hy', 'ksh', 'ln', 'lt', 'lv', 'mg', 'mk', 'mo', 'mt', |
| 222 | + 'nso', 'pl', 'pt_br', 'ro', 'ru', 'se', 'sh', 'sk', 'sl', 'sma', |
| 223 | + 'sr_ec', 'sr_el', 'sr', 'ti', 'tl', 'uk', 'wa' ]; |
| 224 | + |
| 225 | + // wgLang?? |
| 226 | + var wgLanguageCode = 'en'; |
| 227 | + // Set-up base convert plural and gender (to restore for non-transform languages ) |
| 228 | + var cachedConvertPlural = { 'en' : mw.Language.convertPlural }; |
| 229 | + |
| 230 | + // XXX THIS ONLY WORKS FOR NEIL |
| 231 | + var wgScriptPath = 'http://wiki.ivy.local/w'; |
| 232 | + /** |
| 233 | + * Clear out digit transform table, load new pluralization rules, for a new language. |
| 234 | + * Typically we don't need to do this in MediaWiki, it's one interface language per page. |
| 235 | + * @param {String} languageCode |
| 236 | + * @param {Function} to be executed when related scripts have loaded |
| 237 | + */ |
| 238 | + mw.Language.resetForLang = function( lang, fn ) { |
| 239 | + mw.Language.digitTransformTable = null; |
| 240 | + // Load the current language js file if it has a langKey |
| 241 | + var lang = mw.Language.getLangTransformKey( lang ); |
| 242 | + if( cachedConvertPlural[lang] ) { |
| 243 | + mw.Language.convertPlural = cachedConvertPlural[lang]; |
| 244 | + fn(); |
| 245 | + } else { |
| 246 | + mw.log( lang + " load msg transform" ); |
| 247 | + $j.getScript( wgScriptPath + '/resources/mediawiki.language/languages/' + lang.toLowerCase() + '.js' , function(){ |
| 248 | + cachedConvertPlural[lang] = mw.Language.convertPlural; |
| 249 | + fn(); |
| 250 | + }); |
| 251 | + } |
| 252 | + } |
| 253 | + |
| 254 | + |
| 255 | + $j.each( jasmineMsgSpec, function( i, test ) { |
| 256 | + it( "should parse " + test.name, function() { |
| 257 | + mw.Language.resetForLang( test.lang, function() { |
| 258 | + var argArray = [ test.key ].concat( test.args ); |
| 259 | + result = gM.apply( this, argArray ); |
| 260 | + //if ( test.name == 'jp undelete_short 0' ) { |
| 261 | + // debugger; |
| 262 | + //} |
| 263 | + expect( result ).toEqual( test.result ); |
| 264 | + } ); |
| 265 | + } ); |
| 266 | + } ); |
| 267 | + } ); |
| 268 | + |
| 269 | +} ); |
Property changes on: trunk/extensions/UploadWizard/test/jasmine/spec/mediawiki.language.parser.spec.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 270 | + native |