-
Notifications
You must be signed in to change notification settings - Fork 5
/
processNls.js
40 lines (35 loc) · 977 Bytes
/
processNls.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
define([
"dojo/node!fs",
"dojo/node!path"
], function (fs, pathUtil) {
return function (code, path, config) {
var dirname = pathUtil.dirname(path);
// root bundle
if (pathUtil.basename(dirname) === "nls") {
var availableLocales = {},
hasLocales = false,
basename = pathUtil.basename(path);
fs.readdirSync(pathUtil.join(config.srcDir, dirname)).sort().forEach(function (filename) {
var stats;
try {
stats = fs.statSync(pathUtil.join(config.srcDir, dirname, filename, basename));
}
catch (e) {
stats = null;
}
if (stats) {
availableLocales[filename] = true;
hasLocales = true;
}
});
return "define({\n\troot: " +
code.replace(/\n/g, "\n\t\t").replace(/\n\t\t\}\)\s*$/, "\n\t})") +
(hasLocales ? ",\n" + JSON.stringify(availableLocales, null, "\t").slice(1, -1) : "") +
"});";
}
// language bundle
else {
return "define(\n\t" + code.replace(/\n/g, "\n\t") + "\n);";
}
};
});