Building jsDojo Localization Scripts
Define a module:
dojo.provide("happy.BirthdayWidget");
dojo.requireLocalization("happy", "birthday");
dojo.declare("happy.BirthdayWidget", null, {
constructor: function () {
// do something with HappyBirthday
var nls = dojo.i18n.getLocalization("happy", "birthday");
this._text = nls.HappyBirthday;
alert(this._text);
}
});
Create a profile referencing this module:
dependencies = {
layers: [
{
name: "dojolab.js",
dependencies: ["dijit.Dialog"]
},
{
name: "happy.js",
dependencies: ["happy.BirthdayWidget"],
layerDependencies: ["dojolab.js"]
}
],
prefixes:
[
["dijit", "../dijit"],
["happy", "C:/Users/calix/Documents/Visual Studio 2010/Projects/DojoLab/DojoLab/happy"]
]
};
Build the layers in this profile:
build profile=dojolab action=release
Move the product files from dojo\release\dojo\dojo\ and dojo\release\dojo\dojo\nls into a "scripts" folder:
<script src="scripts/dojolab.js.uncompressed.js" type="text/javascript"></script>
<script src="scripts/happy.js.uncompressed.js" type="text/javascript"></script>
Tell dojo where to find the localization files:
<script type="text/javascript">
var djConfig = {
useXDomain: false,
baseUrl: "http://localhost:52987",
modulePaths: {
"happy": "/happy",
"dojo.nls.happy_en-us": "/scripts/happy_en-us",
"dojo.nls.dojolab_en-us": "/scripts/dojolab_en-us"
}
};
</script>
The former development code which invoked requireLocalization and require is now essentially ignored because the modules are already loaded:
<script type="text/javascript">
dojo.require("dojo.i18n");
dojo.requireLocalization("happy", "birthday");
dojo.require("dijit.Dialog");
dojo.require("happy.BirthdayWidget");
dojo.addOnLoad(function () {
var nls = dojo.i18n.getLocalization("happy", "birthday");
var text = nls.HappyBirthday;
var dialog = new dijit.Dialog({ content: text });
dialog.show();
var w = new happy.BirthdayWidget();
dialog.setContent("w: " + w._text);
});
</script>
No comments:
Post a Comment