views:

1796

answers:

4

I've searched a bit on the web but haven't really found a concrete solution to internationalize an application running ExtJS & Spring MVC. Currently (for testing), I define global javascript variables in the JSP's & assign the string literals using JSTL tags.

Has anyone had any success in coming up w/ a clear/clean/flexible solution on this?

Any thoughts are really appreciated. TIA.

A: 

This is how it is done in my application, which is using Pylons, Ext JS and a template engine called Mako.

I'm treating JavaScript files as templates. I keep each class in a separate file and use a defined by me function require() to handle dependencies. My server processes these templates, handles dependencies, joins them together and compresses. Those templates contain calls to gettext-like function "_" e.g.:

window.setTitle("${_('My title')}");

These templates are regular Mako templates and can be preprocessed by a gettext-like utility to create .po files. The .po generator I'm using (Babel) puts positions of found strings as comments inside a .po file, which is convenient for me, because I know where the string appeared.

Adam Dziendziel
A: 

http://www.extjs.com/forum/showthread.php?t=32456 See this. I've created an ExtJS extension to load Resource Bundles.

Max
A: 

Take a look at the Spring MVC Ajax example frpm Spring. if you use JSP views, you can use fmt tag library and resource bundles. If you use Velocity views, use #springMessage('my.key') as explained in Spring documentation.

Gaël Marziou
A: 

There are 3 types of strings that you should translate in an application

  1. Static strings on you page -> as Adam said using a template is a good idea. MVC can solve the problem. So you keep all your strings in a db or a properties file.

  2. Error messages strings that are send to Ext J.S -> Here you have two solutions, either you allow Ext J.S to handle them , so this means that you have js files with the translations loaded OR on the MVC before you send the reply you add the translation on your response

  3. Values from a db table that must be translated, e.g car parts. In this case you keep the key in you car_parts table and the translations in a properties file or on a translation table in db.

On my current app I perform the translation on the MVC level and I keep the translations on the db. The advantage are 1. The translation logic is one place the MVC and not split. 2. Your translations are in one place and whenever you make an error on a translation you do not have to make a new release, you just update the db OR you provide a form on the application admins to do it on their own. Backup of the translation table is required!!!

Michael