In my project, there are embedded and non-embedded javascript codes. And i did localization of the embedded codes like below and it works.
CN.DEFAULT_CONFIG = {
strings : {
year: '<%=GetGlobalResourceObject("Resource", "YEAR") %>'
…
..
.
But, this method does not work for non-embedded javascript codes. How can i do localization for them?
There’s several ways to accomplish the goal (embedded resources, handlers, and ajax methods exist with various pros/cons) but if you need to do this on a native file basis, you can use the ajax scriptmanagers as described here.
In a nutshell you create a base localised script containing whatever functions, objects, strings, foo you need:
…then add whatever localised variations you like using the resource naming pattern:
…then add a reference in script manager thus:
(I’m not 100% sure about the CSV list of cultures there, but I think that’s correct)
Edit: Usage
So you could populate base.js with
…base.fr.js with:
..base.en-US.js with:
…and then simply use
translations.helloin your invariant code and get whatever the culture comes up with.You could add whole methods in these files (for date calcs, formatting or whatever) or anything. The key is to realise they’ve exclusive to each other and that it’s therefore important that they have the same… Interface for lack of a better word so they can be orthogonal to whatever consumes them.