*
The moose likes JSP and the fly likes Displaying English language content in other languages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Displaying English language content in other languages" Watch "Displaying English language content in other languages" New topic
Author

Displaying English language content in other languages

Hemanth Pallavajula
Ranch Hand

Joined: Oct 07, 2004
Posts: 38
hi Friends,

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.

Please help me in this regard.


Cheers,<br />Hemanth...<br />(When opportunity doesn't knock, build a door.)
srikanth k
Greenhorn

Joined: Mar 07, 2005
Posts: 4
you have to use resourcebundle class in java.util packlage for that
Hemanth Pallavajula
Ranch Hand

Joined: Oct 07, 2004
Posts: 38
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.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Tarun Chatterjee
Greenhorn

Joined: Mar 07, 2005
Posts: 25
Hello hemanth

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.

I hope i have made it clear.


Take Care

Tarun Chatterjee
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Sounds like a job for a realtime translation engine. Problem is that none exist that are very good, so there's potentially a lot of money if you're the first to create one.
Good luck


42
srikanth k
Greenhorn

Joined: Mar 07, 2005
Posts: 4
sorry for late reply
it's better to maintain a xml file as suggested by our friends.depending on the locale or selectedc language it automatically replaces those keys with corresponding value.



<file name="keyvalues.xml"

<translation key="Sample.sampleapplication">
<comment>
<p>
This is for sample application

</p>
</comment>
<phrase xml:lang="ad">..............</phrase>
<phrase xml:lang="en">Sample Application</phrase>
<phrase xml:lang="af">...............</phrase>
<phrase xml:lang="ag">...........</phrase>
</translation>

<translation key="sample......



</translation>


.
.....
</file>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying English language content in other languages