1 | /// |
---|
2 | // \module build/plugins/i18n |
---|
3 | // |
---|
4 | define(["../buildControl"], function(bc) { |
---|
5 | var |
---|
6 | nlsRe= |
---|
7 | // regexp for reconstructing the master bundle name from parts of the regexp match |
---|
8 | // nlsRe.exec("foo/bar/baz/nls/en-ca/foo") gives: |
---|
9 | // ["foo/bar/baz/nls/en-ca/foo", "foo/bar/baz/nls/", "/", "/", "en-ca", "foo"] |
---|
10 | // nlsRe.exec("foo/bar/baz/nls/foo") gives: |
---|
11 | // ["foo/bar/baz/nls/foo", "foo/bar/baz/nls/", "/", "/", "foo", ""] |
---|
12 | // so, if match[5] is blank, it means this is the top bundle definition. |
---|
13 | // courtesy of http://requirejs.org |
---|
14 | /(^.*(^|\/)nls(\/|$))([^\/]*)\/?([^\/]*)/, |
---|
15 | |
---|
16 | getAvailableLocales= function( |
---|
17 | root, |
---|
18 | locale, |
---|
19 | bundlePath, |
---|
20 | bundleName, |
---|
21 | availableLocales |
---|
22 | ) { |
---|
23 | for (var localeParts= locale.split("-"), current= "", i= 0; i<localeParts.length; i++) { |
---|
24 | current+= localeParts[i]; |
---|
25 | if (root[current]) { |
---|
26 | availableLocales[bundlePath + current + "/" + bundleName]= 1; |
---|
27 | } |
---|
28 | } |
---|
29 | }, |
---|
30 | |
---|
31 | start= function( |
---|
32 | mid, |
---|
33 | referenceModule, |
---|
34 | bc |
---|
35 | ) { |
---|
36 | var |
---|
37 | i18nPlugin= bc.amdResources["dojo/i18n"], |
---|
38 | match= nlsRe.exec(mid), |
---|
39 | bundleName= match[5] || match[4], |
---|
40 | bundlePath= bc.getSrcModuleInfo(match[1] + bundleName, referenceModule).mid.match(/(.+\/)[^\/]+/)[1], |
---|
41 | locale= (match[5] && match[4]), |
---|
42 | i18nResourceMid= bundlePath + (locale ? locale + "/" : "") + bundleName, |
---|
43 | i18nResource= bc.amdResources[i18nResourceMid]; |
---|
44 | |
---|
45 | if (!i18nPlugin) { |
---|
46 | throw new Error("i18n! plugin missing"); |
---|
47 | } |
---|
48 | if (!i18nResource) { |
---|
49 | throw new Error("i18n resource (" + i18nResourceMid + ") missing"); |
---|
50 | } |
---|
51 | return [i18nPlugin, i18nResource]; |
---|
52 | }; |
---|
53 | |
---|
54 | return { |
---|
55 | start:start |
---|
56 | }; |
---|
57 | }); |
---|