1 | define(function() { |
---|
2 | var nlsRe= |
---|
3 | // regexp for reconstructing the master bundle name from parts of the regexp match |
---|
4 | // nlsRe.exec("foo/bar/baz/nls/en-ca/foo") gives: |
---|
5 | // ["foo/bar/baz/nls/en-ca/foo", "foo/bar/baz/nls/", "/", "/", "en-ca", "foo"] |
---|
6 | // nlsRe.exec("foo/bar/baz/nls/foo") gives: |
---|
7 | // ["foo/bar/baz/nls/foo", "foo/bar/baz/nls/", "/", "/", "foo", ""] |
---|
8 | // so, if match[5] is blank, it means this is the top bundle definition. |
---|
9 | // courtesy of http://requirejs.org |
---|
10 | /(^.*(^|\/)nls(\/|$))([^\/]*)\/?([^\/]*)/; |
---|
11 | |
---|
12 | return { |
---|
13 | start:function( |
---|
14 | mid, |
---|
15 | referenceModule, |
---|
16 | bc |
---|
17 | ){ |
---|
18 | var i18nPlugin = bc.amdResources["dojo/i18n"], |
---|
19 | match = nlsRe.exec(mid), |
---|
20 | bundleName = match[5] || match[4], |
---|
21 | bundlePath = bc.getSrcModuleInfo(match[1] + bundleName, referenceModule).mid.match(/(.+\/)[^\/]+/)[1], |
---|
22 | locale = (match[5] && match[4]), |
---|
23 | i18nResourceMid = bundlePath + (locale ? locale + "/" : "") + bundleName, |
---|
24 | i18nResource = bc.amdResources[i18nResourceMid]; |
---|
25 | |
---|
26 | if(!i18nPlugin){ |
---|
27 | throw new Error("i18n! plugin missing"); |
---|
28 | } |
---|
29 | if(!i18nResource){ |
---|
30 | throw new Error("i18n resource (" + i18nResourceMid + ") missing"); |
---|
31 | } |
---|
32 | return [i18nPlugin, i18nResource]; |
---|
33 | } |
---|
34 | }; |
---|
35 | }); |
---|