Friday, April 18, 2008

Internationalization in Struts

Def: Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. Localization is the process of adapting software for a specific region or language by adding locale-specific components and translating text.

How do we achieve this in Struts.. very simple. Struts comes with built in support for interanationalization.

by default you have applicationResources.properties file, which supports the default locale english. Now for every additional language you wish to support, create a new applicationResources_{Locale u r adding}.properties.

example: For Hindi create a file called,

ApplicationResources_hi.properties file and put all ur messages in a key, value format.

Ex: in ApplicationResources.properties (default for english) you define messages like
page.title=Thank you for visiting!

now for Hindi.. you'll have a file like
ApplicationResources_hi.properties
page.title=Dhanyawaad!


And define both files in ur struts-config.xml file, in message resources section

{message-resources
parameter="com.sunny.app.ApplicationResources" /}

{message-resources
parameter="com.sunny.app.ApplicationResources_hi" /}


Calling From JSP:

{h2}{bean:message key="page.title"/}{/h2}

Thats it depending on ur locale.. apt file will be invoked and apt msg in ur language is shown on screen.

Testing: To change locale of ur browser.. goto

tools-->internet options-->languages --> add-->

choose hindi add and move it to the top.

Now when you run your application, message is displayed in Hindi...:D


This is too cool and exciting..!!!

1 comment:

Unknown said...

Hi,

This is only to the texts that are been added in the Property files. But now i need to display the datas that are been stored in the database. In that scenario what procedure do you take with Locale.

regards,
K. Navin.