Why So Little i18n Support?
The flipside of this architectural decision is that you the developer must write code with i18n in mind, so that scripts don't behave in unexpected ways. While all of the points raised in the Internationalizing a Locale-specific Application in Java article apply, perhaps the most troublesome and obvious sticking point is that of message translation. As described in the
.js file and load the appropriate one at runtime. The following example sets the
src property of the
<SCRIPT> tag to a matching labels script, depending on the value of the language portion of the local identifier (IE: the en in
By default, the
dynaScript src points to the
englishLabels.js script, but this value is overwritten should the locale language match one of the cases in the
switch statement. The
showLanguageScript() method confirms which script is loaded.
That is better than no i18n support at all, but in some ways, providing multiple language versions of a script is the opposite of how internationalization and localization of software are generally done. Unlike the application-level code of true i18n applications, which separate all localizable content from the source code and load display text from separate resource bundles or data stores, you still wind up with programming code that stores hard-coded display text. The inflexible nature of this approach becomes evident when you try to create a compound message, as in the following code:
Printing a properly formatted and grammatically correct string is simple enough: just call a few helper methods:
However, in other languages, the idea quickly falls apart. For instance, in French, the "large" adjective comes after the "widgets" subject. That's why compound messages are strongly discouraged in the realm of i18n programming!
A Better Way
After spending weeks discussing Java's excellent i18n support, perhaps our search for more effective alternatives should start there.
Harnessing the Power of Sever-Side Languages
The rendered page source will contain the following translated text, in English:
...and in French:
The limitation to this technique is that it does not allow for any dynamic text retrieval because all of the values must be set before serving the page to the client. However, one of the perks of Ajax is that it permits seamless interaction between the browser and server. We'll be taking a look at implementing i18n using Ajax in the next article.
Have a suggestion for an article topic? Do you have a product or service that you'd like reviewed? Email it to Rob .
Rob Gravelle combined his love of programming and music to become a software guru and accomplished guitar player. He created systems that are used by Canada Border Services, CSIS and other Intelligence-related organizations. As a software consultant, Rob has developed Web applications for many businesses and recently created a MooTools version of PHPFreechat for ViziMetrics. Musically, Rob recently embarked on a solo music career, after playing with Ivory Knight since 2000. That band was rated as one Canada's top bands by Brave Words magazine (issue #92) and released two CDs. Rob's latest release is called "The Rabbit of Seville". Loosely based on Rossini's The Barber of Seville overture, Rob's amazing rendition includes a full orchestra and numerous guitar tracks. It is sold on his site as a high bitrate MP3 for only $0.99 cents! Rob is available for short-term software projects and recording session work. to inquire, but note that, due to the volume of emails received, he cannot respond to every email. Potential jobs and praise receive highest priority!
Original: August 4, 2010