Skip to content

Commit 095cafb

Browse files
committed
add preload module
1 parent 8b10c0c commit 095cafb

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ This plugin should work with RequireJS and Dojo.
1212
This plugin is based on requirejs i18n.
1313
* see: http://github.com/requirejs/i18n for details
1414

15+
## loadNlsAndLayer.js
16+
17+
This plugin is used to load layer files output by the Dojo 2 build system.
18+
* see: http://github.com/requirejs/i18n for details
19+
1520
## Licensing
1621

1722
This project is distributed by the Dojo Foundation and licensed under the ["New" BSD License](https://github.com/dojo/dojo/blob/master/LICENSE#L13-L41).

plugins/i18n/preload.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ define(["./common"], function (common) {
1010
name = parts[0];
1111
while (locale) {
1212
if (flattenedLocales.indexOf(locale) >= 0) {
13-
require([name + "_" + locale], function (bundle) {
13+
req([name + "_" + locale], function (bundle) {
1414
onLoad(bundle);
1515
return;
1616
});

plugins/loadNlsAndLayer.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
define(["module", "./i18n/common"], function (module, common) {
2+
return {
3+
load: function (name, req, onLoad, config) {
4+
config = config || {};
5+
6+
var moduleLayer = name,
7+
parts = name.split('/'),
8+
bundleName = parts.pop(),
9+
nlsLayer = parts.join('/') + "/nls/" + bundleName,
10+
locale = common.getLocale(config),
11+
flattenedLocales = module.config().locales;
12+
13+
while (locale) {
14+
if (flattenedLocales.indexOf(locale) >= 0) {
15+
req([nlsLayer + "_" + locale], function () {
16+
//need to wait for the nls layer before loading the module layer
17+
req([moduleLayer], function () {
18+
onLoad(1);
19+
});
20+
});
21+
}
22+
locale = common.getParentLocale(locale);
23+
}
24+
}
25+
};
26+
});

0 commit comments

Comments
 (0)