define(["./_base/kernel", "require", "./has", "./_base/array", "./_base/lang", "./_base/xhr"], function(dojo, require, has, array, lang) { // module: // dojo/i18n // summary: // This module implements the !dojo/i18n plugin and the v1.6- i18n API // description: // We choose to include our own plugin to leverage functionality already contained in dojo // and thereby reduce the size of the plugin compared to various loader implementations. Also, this // allows foreign AMD loaders to be used without their plugins. var thisModule= dojo.i18n= // the dojo.i18n module {}, nlsRe= // regexp for reconstructing the master bundle name from parts of the regexp match // nlsRe.exec("foo/bar/baz/nls/en-ca/foo") gives: // ["foo/bar/baz/nls/en-ca/foo", "foo/bar/baz/nls/", "/", "/", "en-ca", "foo"] // nlsRe.exec("foo/bar/baz/nls/foo") gives: // ["foo/bar/baz/nls/foo", "foo/bar/baz/nls/", "/", "/", "foo", ""] // so, if match[5] is blank, it means this is the top bundle definition. // courtesy of http://requirejs.org /(^.*(^|\/)nls)(\/|$)([^\/]*)\/?([^\/]*)/, getAvailableLocales= function( root, locale, bundlePath, bundleName ){ // return a vector of module ids containing all available locales with respect to the target locale // For example, assuming: // * the root bundle indicates specific bundles for "fr" and "fr-ca", // * bundlePath is "myPackage/nls" // * bundleName is "myBundle" // Then a locale argument of "fr-ca" would return // ["myPackage/nls/myBundle", "myPackage/nls/fr/myBundle", "myPackage/nls/fr-ca/myBundle"] // Notice that bundles are returned least-specific to most-specific, starting with the root. // // If root===false indicates we're working with a pre-AMD i18n bundle that doesn't tell about the available locales; // therefore, assume everything is available and get 404 errors that indicate a particular localization is not available // for(var result= [bundlePath + bundleName], localeParts= locale.split("-"), current= "", i= 0; i/ indicates not the root. return preAmdResult ? (/nls\/[^\/]+\/[^\/]+$/.test(url) ? preAmdResult : {root:preAmdResult, _v1x:1}) : amdResult; }, syncRequire= function(deps, callback){ var results= []; dojo.forEach(deps, function(mid){ var url= require.toUrl(mid + ".js"); if(cache[url]){ results.push(cache[url]); }else{ try { var bundle= require(mid); if(bundle){ results.push(bundle); return; } }catch(e){} dojo.xhrGet({ url:url, sync:true, load:function(text){ var result = evalBundle(text); results.push(cache[url]= fixup(url, result[0], result[1])); }, error:function(){ results.push(cache[url]= {}); } }); } }); callback.apply(null, results); }; thisModule.getLocalization= function(moduleName, bundleName, locale){ var result, l10nName= getL10nName(moduleName, bundleName, locale).substring(10); load(l10nName, (has("dojo-sync-loader") && !require.isXdUrl(require.toUrl(l10nName + ".js")) ? syncRequire : require), function(result_){ result= result_; }); return result; }; thisModule.normalizeLocale= function(locale){ var result = locale ? locale.toLowerCase() : dojo.locale; if(result == "root"){ result = "ROOT"; } return result; }; } return lang.mixin(thisModule, { dynamic:true, normalize:normalize, load:load, cache:function(mid, value){ cache[mid] = value; } }); });