Displaying English language content in other languages

I have a requirement in which the text of the message will be present in english language in the database. During the display of these messages, depending upon the language associate with an user, the messages need to be displayed. That is, the message can be displayed in French, Spanish or other languages.

If the user has multiple languages associated with him/her, he/she can dynamically select from a dropdown in which language he/she wants to see the message, and the message needs to be displayed in that language.

Srikanth, I think with this ResourceBundle approach, we need to have property files in which we will be having one-to-one mapping for all the words. As we are not sure of the content of the message, having so many words in the properties file will require maintenance to be done.

Originally posted by Hemanth Pallavajula: Srikanth, I think with this ResourceBundle approach, we need to have property files in which we will be having one-to-one mapping for all the words. As we are not sure of the content of the message, having so many words in the properties file will require maintenance to be done.

Can I get any other solution.

You don't need a one-to-one mapping for all the words, rather something like:

Of course this doesn't work if your messages are dynamically created. You could look at the java.text.MessageFormat class for more dynamic messages. With that you can match and replace certain patterns at run time. For example your message becomes something like:

{1} and {2} get replaced at run time, and could even be replaced by other properties in your translation properties files.

Of course this still means you have to have data stored in both the database and in properties files, which isn't great. If you wanted to keep these messages in the DB you could create seperate message tables for each supported locale, which you can add as the requirements necessitate. ResourceBundles are not the best fit though if you do this. There is a lot of work done in ResourceBundles to cache already requested properties, none of which can be used unless your properies are stored files or classes. You might consider your own Translation cache implementation.

Your Translation Logic depends on whether you would want to support multiple languages at one time or multiple times.

Create an XML, which would tell you how many languages you would like the English Message to convert to. IN that XML , u might put a flag to access the same content in other languages from DB, or you can put the language content in XML, and while rendering the page pick the Language and display it on the screen.

so the flow would be like this.

For a Given Customer Profile, get the language which the customer will understand. IN ur XML put all valid foreign language. check from the user /Customer Profile the language and compare it from the Data in XML. Once compared get the Language content either from XML or DB depending upon your Project Requirement.