Login Register

Dojo XDomain Build + I18N

Hello Everyone,

I have created a custom xdomain build of dojo ( results in dojo.xd.js and custom.xd.js )

I am including it in the following way




dojo.require("dojo.i18n"); dojo.require("dijit.form.DateTextBox"); dojo.registerModulePath("i18n","/js/i18n"); dojo.requireLocalization("i18n.messages","salutations"); var NLS = dojo.i18n.getLocalization("i18n.messages", "salutations"); console.log(NLS.hello);

In the above code

-> The date control works perfectly ( i.e shows in korean language/locale)

-> But, the custom message bundle ( for my project's js related messages ) code does not work. I see these errors
_9d has no properties
toString("i18n.messages", "salutations", undefined, undefined)dojo.xd.js (line 20)
toString("i18n.messages", "salutations", undefined, undefined)dojo.xd.js (line 20)
toString("i18n.messages", "salutations", undefined, undefined)

The location of the message bundle ( /js/i18n ) contains "nls" folder which internally contains salutations.js file.

So I would like to know if there are any issues in using custom message bundles ( for my project's js files ) along with dojo bundle in a xdomain build ?

Thanks,
Rakesh

In xdomain builds,

In xdomain builds, dojo.require and dojo.requireLocalization are asynchronous operations, so instead of calling dojo.i18n.getLocalization() directly after the dojo.requireLocalization call, wrap it in a dojo.addOnLoad() call:

dojo.requireLocalization("i18n.messages","salutations");
dojo.addOnLoad(function(){
    var NLS = dojo.i18n.getLocalization("i18n.messages", "salutations");
    console.log(NLS.hello);
});

I tried that, but I still

I tried that, but I still get the error on

dojo.requireLocalization("i18n.messages","salutations");

The error is still the same

_9d has no properties
toString("i18n.messages", "salutations", undefined, undefined)dojo.xd.js (line 20)
toString("i18n.messages", "salutations", undefined, undefined)dojo.xd.js (line 20)
toString("i18n.messages", "salutations", undefined, undefined)

Further observation,

Further observation,

Instead of

dojo.requireLocalization("i18n.messages","salutations");

if I use

dojo.requireLocalization("i18n.messages","salutations","myapp","en-gb,en-us,de-de,es-es,fr-fr,it-it,pt-br,ko-kr,zh-tw,zh-cn,ja-jp");

I don't see "_9d has no properties" error any more.(where myapp is a folder within nls folder). But I get an error on salutations.xd.js file not found ( I just have salutations.js ).

-Rakesh

I'm assuming that the i18n

I'm assuming that the i18n modules are in a directory on the same host as the page, and you did not include those modules as part of the xdomain build.

Is the page served from the http://static0.localhost/dojo/ domain? If not, then baseUrl should point to a path
relative to the page, and then the registerModulePath call should be a relative path to that djConfig.baseUrl setting. I think the problem is that the loader thinks the i18n.messages module is an xdomain module when it is not, because of the baseUrl configuration. What about something like this:

<script type="text/javascript" src="http://static0.localhost/dojo/dojo.xd.js"
  djConfig="isDebug:false,
      preventBackButtonFix: false,
      parseOnLoad: true,
      locale: 'ko-kr',
      baseUrl: './' "
>

</script>
<!-- baseUrl above assumes you want all path resolutions to happen relative to this page. You can also use a path that starts with a / to specify a full path on this page's domain. You should also be able to use a full domain path, but the domain should match the domain of the page. -->

<script type="text/javascript" src="http://localhost/dojo/custom.xd.js"></script>

<div dojoType="dijit.form.DateTextBox"  constraints={formatLength:'full'}></div>
<script type="text/javascript">
  dojo.require("dojo.i18n");
  dojo.require("dijit.form.DateTextBox");
  dojo.registerModulePath("i18n","js/i18n"); //Notice I removed the leading slash
  dojo.requireLocalization("i18n.messages","salutations");

  dojo.addOnLoad(function(){
    var NLS = dojo.i18n.getLocalization("i18n.messages", "salutations");
    console.log(NLS.hello);
  });
</script>

Thanks! it worked like a

Thanks! it worked like a charm :)

The problem was the I had used the baseURL as "http://static0.localhost/dojo" instead of "./". So it would have assumed the i18n module to be an xdomain module.

Supposing I have around 10 custom locales for UI related messages, are there any optimizations ( in terms of build etc ) that I can perform ?

Thanks,
Rakesh

Yes, if you do a build that

Yes, if you do a build that includes your i18n folder, the build process "flattens" the locales, so that it only needs to ask for one locale file after a build (instead of possibly up to three files: the locale, language and then ROOT file). That benefit is available for regular and xdomain builds.

I checked the build doc and

I checked the build doc and found about the parameter "localeList"

localeList The set of locales to use when flattening i18n bundles Default: "en-gb,en-us,de-de,es-es,fr-fr,it-it,pt-br,ko-kr,zh-tw,zh-cn,ja-jp",

But my understanding is that this is for Dojo/Dijit related I18N bundles. How can I specify/include my custom I18N bundles also ? ( my custom bundles are just for app specific UI related messages, so this is in addition with Dojo/Dijit's I18N bundles)

As long as your bundles are

As long as your bundles are in a directory that is registered in the "prefixes" area of the build profile, they should be flattened. So, say you had your bundles in a mymodules/nls/mybundle.js configuration. Specifying this in your build's prefixes config should do it:

prefixes: [
		[ "dijit", "../dijit" ],
		[ "dojox", "../dojox" ]
		[ "mymodules", "../mymodules" ] //If mymodules is a sibling dir to dojo
	]