From 1354d17270961fff662d40f90521223f8fd0d73b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 14 Aug 2012 18:59:10 +0400 Subject: update dojo to 1.7.3 --- lib/dojo/i18n.js | 258 +------------------------------------------------------ 1 file changed, 2 insertions(+), 256 deletions(-) (limited to 'lib/dojo/i18n.js') diff --git a/lib/dojo/i18n.js b/lib/dojo/i18n.js index 893490fe0..b79ec6c5b 100644 --- a/lib/dojo/i18n.js +++ b/lib/dojo/i18n.js @@ -4,259 +4,5 @@ see: http://dojotoolkit.org/license for details */ - -if(!dojo._hasResource["dojo.i18n"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. -dojo._hasResource["dojo.i18n"] = true; -dojo.provide("dojo.i18n"); - -dojo.getObject("i18n", true, dojo); - -/*===== -dojo.i18n = { - // summary: Utility classes to enable loading of resources for internationalization (i18n) -}; -=====*/ - -// when using a real AMD loader, dojo.i18n.getLocalization is already defined by dojo/lib/backCompat -dojo.i18n.getLocalization = dojo.i18n.getLocalization || function(/*String*/packageName, /*String*/bundleName, /*String?*/locale){ - // summary: - // Returns an Object containing the localization for a given resource - // bundle in a package, matching the specified locale. - // description: - // Returns a hash containing name/value pairs in its prototypesuch - // that values can be easily overridden. Throws an exception if the - // bundle is not found. Bundle must have already been loaded by - // `dojo.requireLocalization()` or by a build optimization step. NOTE: - // try not to call this method as part of an object property - // definition (`var foo = { bar: dojo.i18n.getLocalization() }`). In - // some loading situations, the bundle may not be available in time - // for the object definition. Instead, call this method inside a - // function that is run after all modules load or the page loads (like - // in `dojo.addOnLoad()`), or in a widget lifecycle method. - // packageName: - // package which is associated with this resource - // bundleName: - // the base filename of the resource bundle (without the ".js" suffix) - // locale: - // the variant to load (optional). By default, the locale defined by - // the host environment: dojo.locale - - locale = dojo.i18n.normalizeLocale(locale); - - // look for nearest locale match - var elements = locale.split('-'); - var module = [packageName,"nls",bundleName].join('.'); - var bundle = dojo._loadedModules[module]; - if(bundle){ - var localization; - for(var i = elements.length; i > 0; i--){ - var loc = elements.slice(0, i).join('_'); - if(bundle[loc]){ - localization = bundle[loc]; - break; - } - } - if(!localization){ - localization = bundle.ROOT; - } - - // make a singleton prototype so that the caller won't accidentally change the values globally - if(localization){ - var clazz = function(){}; - clazz.prototype = localization; - return new clazz(); // Object - } - } - - throw new Error("Bundle not found: " + bundleName + " in " + packageName+" , locale=" + locale); -}; - -dojo.i18n.normalizeLocale = function(/*String?*/locale){ - // summary: - // Returns canonical form of locale, as used by Dojo. - // - // description: - // All variants are case-insensitive and are separated by '-' as specified in [RFC 3066](http://www.ietf.org/rfc/rfc3066.txt). - // If no locale is specified, the dojo.locale is returned. dojo.locale is defined by - // the user agent's locale unless overridden by djConfig. - - var result = locale ? locale.toLowerCase() : dojo.locale; - if(result == "root"){ - result = "ROOT"; - } - return result; // String -}; - -dojo.i18n._requireLocalization = function(/*String*/moduleName, /*String*/bundleName, /*String?*/locale, /*String?*/availableFlatLocales){ - // summary: - // See dojo.requireLocalization() - // description: - // Called by the bootstrap, but factored out so that it is only - // included in the build when needed. - - var targetLocale = dojo.i18n.normalizeLocale(locale); - var bundlePackage = [moduleName, "nls", bundleName].join("."); - // NOTE: - // When loading these resources, the packaging does not match what is - // on disk. This is an implementation detail, as this is just a - // private data structure to hold the loaded resources. e.g. - // `tests/hello/nls/en-us/salutations.js` is loaded as the object - // `tests.hello.nls.salutations.en_us={...}` The structure on disk is - // intended to be most convenient for developers and translators, but - // in memory it is more logical and efficient to store in a different - // order. Locales cannot use dashes, since the resulting path will - // not evaluate as valid JS, so we translate them to underscores. - - //Find the best-match locale to load if we have available flat locales. - var bestLocale = ""; - if(availableFlatLocales){ - var flatLocales = availableFlatLocales.split(","); - for(var i = 0; i < flatLocales.length; i++){ - //Locale must match from start of string. - //Using ["indexOf"] so customBase builds do not see - //this as a dojo._base.array dependency. - if(targetLocale["indexOf"](flatLocales[i]) == 0){ - if(flatLocales[i].length > bestLocale.length){ - bestLocale = flatLocales[i]; - } - } - } - if(!bestLocale){ - bestLocale = "ROOT"; - } - } - - //See if the desired locale is already loaded. - var tempLocale = availableFlatLocales ? bestLocale : targetLocale; - var bundle = dojo._loadedModules[bundlePackage]; - var localizedBundle = null; - if(bundle){ - if(dojo.config.localizationComplete && bundle._built){return;} - var jsLoc = tempLocale.replace(/-/g, '_'); - var translationPackage = bundlePackage+"."+jsLoc; - localizedBundle = dojo._loadedModules[translationPackage]; - } - - if(!localizedBundle){ - bundle = dojo["provide"](bundlePackage); - var syms = dojo._getModuleSymbols(moduleName); - var modpath = syms.concat("nls").join("/"); - var parent; - - dojo.i18n._searchLocalePath(tempLocale, availableFlatLocales, function(loc){ - var jsLoc = loc.replace(/-/g, '_'); - var translationPackage = bundlePackage + "." + jsLoc; - var loaded = false; - if(!dojo._loadedModules[translationPackage]){ - // Mark loaded whether it's found or not, so that further load attempts will not be made - dojo["provide"](translationPackage); - var module = [modpath]; - if(loc != "ROOT"){module.push(loc);} - module.push(bundleName); - var filespec = module.join("/") + '.js'; - loaded = dojo._loadPath(filespec, null, function(hash){ - hash = hash.root || hash; - // Use singleton with prototype to point to parent bundle, then mix-in result from loadPath - var clazz = function(){}; - clazz.prototype = parent; - bundle[jsLoc] = new clazz(); - for(var j in hash){ bundle[jsLoc][j] = hash[j]; } - }); - }else{ - loaded = true; - } - if(loaded && bundle[jsLoc]){ - parent = bundle[jsLoc]; - }else{ - bundle[jsLoc] = parent; - } - - if(availableFlatLocales){ - //Stop the locale path searching if we know the availableFlatLocales, since - //the first call to this function will load the only bundle that is needed. - return true; - } - }); - } - - //Save the best locale bundle as the target locale bundle when we know the - //the available bundles. - if(availableFlatLocales && targetLocale != bestLocale){ - bundle[targetLocale.replace(/-/g, '_')] = bundle[bestLocale.replace(/-/g, '_')]; - } -}; - -(function(){ - // If other locales are used, dojo.requireLocalization should load them as - // well, by default. - // - // Override dojo.requireLocalization to do load the default bundle, then - // iterate through the extraLocale list and load those translations as - // well, unless a particular locale was requested. - - var extra = dojo.config.extraLocale; - if(extra){ - if(!extra instanceof Array){ - extra = [extra]; - } - - var req = dojo.i18n._requireLocalization; - dojo.i18n._requireLocalization = function(m, b, locale, availableFlatLocales){ - req(m,b,locale, availableFlatLocales); - if(locale){return;} - for(var i=0; i 0; i--){ - searchlist.push(elements.slice(0, i).join('-')); - } - searchlist.push(false); - if(down){searchlist.reverse();} - - for(var j = searchlist.length - 1; j >= 0; j--){ - var loc = searchlist[j] || "ROOT"; - var stop = searchFunc(loc); - if(stop){ break; } - } -}; - -dojo.i18n._preloadLocalizations = function(/*String*/bundlePrefix, /*Array*/localesGenerated){ - // summary: - // Load built, flattened resource bundles, if available for all - // locales used in the page. Only called by built layer files. - - function preload(locale){ - locale = dojo.i18n.normalizeLocale(locale); - dojo.i18n._searchLocalePath(locale, true, function(loc){ - for(var i=0; i>built +define("dojo/i18n",["./_base/kernel","require","./has","./_base/array","./_base/config","./_base/lang","./_base/xhr","./json"],function(_1,_2,_3,_4,_5,_6,_7,_8){_3.add("dojo-preload-i18n-Api",1);true||_3.add("dojo-v1x-i18n-Api",1);var _9=_1.i18n={},_a=/(^.*(^|\/)nls)(\/|$)([^\/]*)\/?([^\/]*)/,_b=function(_c,_d,_e,_f){for(var _10=[_e+_f],_11=_d.split("-"),_12="",i=0;i<_11.length;i++){_12+=(_12?"-":"")+_11[i];if(!_c||_c[_12]){_10.push(_e+_12+"/"+_f);}}return _10;},_13={},_14=_1.getL10nName=function(_15,_16,_17){_17=_17?_17.toLowerCase():_1.locale;_15="dojo/i18n!"+_15.replace(/\./g,"/");_16=_16.replace(/\./g,"/");return (/root/i.test(_17))?(_15+"/nls/"+_16):(_15+"/nls/"+_17+"/"+_16);},_18=function(_19,_1a,_1b,_1c,_1d,_1e){_19([_1a],function(_1f){var _20=_6.clone(_1f.root),_21=_b(!_1f._v1x&&_1f,_1d,_1b,_1c);_19(_21,function(){for(var i=1;i<_21.length;i++){_20=_6.mixin(_6.clone(_20),arguments[i]);}var _22=_1a+"/"+_1d;_13[_22]=_20;_1e();});});},_23=function(id,_24){return /^\./.test(id)?_24(id):id;},_25=function(_26){var _27=_5.extraLocale||[];_27=_6.isArray(_27)?_27:[_27];_27.push(_26);return _27;},_28=function(id,_29,_2a){if(_3("dojo-preload-i18n-Api")){var _2b=id.split("*"),_2c=_2b[1]=="preload";if(_2c){if(!_13[id]){_13[id]=1;_2d(_2b[2],_8.parse(_2b[3]),1);}_2a(1);}if(_2c||_2e(id,_29,_2a)){return;}}var _2f=_a.exec(id),_30=_2f[1]+"/",_31=_2f[5]||_2f[4],_32=_30+_31,_33=(_2f[5]&&_2f[4]),_34=_33||_1.locale,_35=_32+"/"+_34,_36=_33?[_34]:_25(_34),_37=_36.length,_38=function(){if(!--_37){_2a(_6.delegate(_13[_35]));}};_4.forEach(_36,function(_39){var _3a=_32+"/"+_39;if(_3("dojo-preload-i18n-Api")){_3b(_3a);}if(!_13[_3a]){_18(_29,_32,_30,_31,_39,_38);}else{_38();}});};if(_3("dojo-unit-tests")){var _3c=_9.unitTests=[];}if(_3("dojo-preload-i18n-Api")||1){var _3d=_9.normalizeLocale=function(_3e){var _3f=_3e?_3e.toLowerCase():_1.locale;return _3f=="root"?"ROOT":_3f;},_40=function(mid){return (1&&1)?_2.isXdUrl(_2.toUrl(mid+".js")):true;},_41=0,_42=[],_2d=_9._preloadLocalizations=function(_43,_44,_45){function _46(_47,_48){var _49=_47.split("-");while(_49.length){if(_48(_49.join("-"))){return true;}_49.pop();}return _48("ROOT");};function _4a(_4b){_4b=_3d(_4b);_46(_4b,function(loc){if(_4.indexOf(_44,loc)>=0){var mid=_43.replace(/\./g,"/")+"_"+loc;_41++;(_40(mid)||_45?_2:_50)([mid],function(_4c){for(var p in _4c){_13[p+"/"+_4b]=_4c[p];}--_41;while(!_41&&_42.length){_28.apply(null,_42.shift());}});return true;}return false;});};_4a();_4.forEach(_1.config.extraLocale,_4a);},_2e=function(id,_4d,_4e){if(_41){_42.push([id,_4d,_4e]);}return _41;};}if(1){var _4f=new Function("__bundle","__checkForLegacyModules","__mid","var define = function(){define.called = 1;},"+" require = function(){define.called = 1;};"+"try{"+"define.called = 0;"+"eval(__bundle);"+"if(define.called==1)"+"return 1;"+"if((__checkForLegacyModules = __checkForLegacyModules(__mid)))"+"return __checkForLegacyModules;"+"}catch(e){}"+"try{"+"return eval('('+__bundle+')');"+"}catch(e){"+"return e;"+"}"),_50=function(_51,_52){var _53=[];_4.forEach(_51,function(mid){var url=_2.toUrl(mid+".js");function _28(_54){var _55=_4f(_54,_3b,mid);if(_55===1){_2([mid],function(_56){_53.push(_13[url]=_56);});}else{if(_55 instanceof Error){console.error("failed to evaluate i18n bundle; url="+url,_55);_55={};}_53.push(_13[url]=(/nls\/[^\/]+\/[^\/]+$/.test(url)?_55:{root:_55,_v1x:1}));}};if(_13[url]){_53.push(_13[url]);}else{var _57=_2.syncLoadNls(mid);if(_57){_53.push(_57);}else{if(!_7){try{_2.getText(url,true,_28);}catch(e){_53.push(_13[url]={});}}else{_7.get({url:url,sync:true,load:_28,error:function(){_53.push(_13[url]={});}});}}}});_52&&_52.apply(null,_53);},_3b=function(_58){for(var _59,_5a=_58.split("/"),_5b=_1.global[_5a[0]],i=1;_5b&&i<_5a.length-1;_5b=_5b[_5a[i++]]){}if(_5b){_59=_5b[_5a[i]];if(!_59){_59=_5b[_5a[i].replace(/-/g,"_")];}if(_59){_13[_58]=_59;}}return _59;};_9.getLocalization=function(_5c,_5d,_5e){var _5f,_60=_14(_5c,_5d,_5e).substring(10);_28(_60,(!_40(_60)?_50:_2),function(_61){_5f=_61;});return _5f;};if(_3("dojo-unit-tests")){_3c.push(function(doh){doh.register("tests.i18n.unit",function(t){var _62;_62=_4f("{prop:1}");t.is({prop:1},_62);t.is(undefined,_62[1]);_62=_4f("({prop:1})");t.is({prop:1},_62);t.is(undefined,_62[1]);_62=_4f("{'prop-x':1}");t.is({"prop-x":1},_62);t.is(undefined,_62[1]);_62=_4f("({'prop-x':1})");t.is({"prop-x":1},_62);t.is(undefined,_62[1]);_62=_4f("define({'prop-x':1})");t.is(1,_62);_62=_4f("this is total nonsense and should throw an error");t.is(_62 instanceof Error,true);});});}}return _6.mixin(_9,{dynamic:true,normalize:_23,load:_28,cache:_13});}); \ No newline at end of file -- cgit v1.2.3