Internationalization and JavaScript

In: Java| Web

17 Apr 2008

Lately the amount of JavaScript in web applications has grown a lot. JavaScript has always been there but with the need of AJAX and more and more dynamical features modern web developers can not avoid it.

Luckily there are a lot of good concepts arising and libraries available (e.g. prototype, yui, …) that show how to control the JavaScript monster. Something that always bothered me was that I was not able to find a good editor for JavaScript. Since about six months I am using JSEclipse from Adobe which is a free Eclipse plugin that provides a lot support for writing JavaScript (code-completion, syntac check, …).

The JSEclipse editor allows me to edit standalone JS files and script code included in JSPs but many times I ran into the problem that I needed to mix JavaScript and Java code. For example to define an URL for an AJAX request or to get a message from a resource bundle that has to be displayed in a JavaScript dialog. The JSEclipse editor does not understand this “mixed” code parts. Additionally it is not possible to externalize the JavaScript code into external files and the code looks ugly.

Yesterday I found this article about how to do I18N in JavaScript. I like the approach with the externalized constants very much because

  • it allows me to create a central include containing all the information from Java needed for the JavaScript code -> only one place to change
  • the main JavaScript code is “JavaScript only” -> editable by the JSEclipse editor
  • the JavaScript only code may be externalized into separate files
  • the appearance of the constants instantly makes their purpose clear and the JS code looks clean

5 Responses to Internationalization and JavaScript

Avatar

Avi Deitcher

May 13th, 2008 at 7:01 am

I actually found your article from the trackback from the other one. I had the same issues, so I wrote a library (lots of effort, as you can imagine) to handle these issues. It deals with localized strings, calendar implementations, currencies and others. The really nice piece is that the ResourceBundle syntax from Java is utilized by the i18n library, so you can share across Java and JavaScript.

Take a look at http://jsorm.com, download, enjoy. Released under GPL. There is a pretty good wiki on the site, too.

Avatar

tompson

May 13th, 2008 at 6:31 pm

Thanks Avi, I will have a look into it … I already invested quite some effort into handling calendar values and the way you chose seems quite good!

Avatar

Avi Deitcher

February 16th, 2009 at 3:27 am

@tompson
Thomas, did you have any feedback? I would like to hear it.

A few other libraries have been published there, and I have extended i18n to include some other calendars.

Avi

Avatar

Rich

September 1st, 2009 at 6:48 pm

jsorm can’t be used for commercial product development without purchasing a license. While the price isn’t too high, it can be more of a hassle than it’s worth if you work for a large company. If all you need is string translation capability, take a look at the article at http://www.jspwiki.org/wiki/JavascriptLocalization.

Cheers,
Rich

Avatar

Jane Bronsik

September 11th, 2009 at 2:29 pm

Exactly what I needed, thanks!

Comment Form

Follow Me!

Photostream

    Weihnachten 2009Saalfelden Weihnachten 2009Dodothree brothersThe Bolds 004troii Weihnachtsfeier 2009 006

RSStOMPSON's tweets