I am posting my question about implementing Internationalization on this forum as after searching all forums, I did not find any better place to ask this. If moderator or anybody has better idea about placing the question in correct forum, I will be thankful.
I am working on a project which needs to be functional for users in several different countries including Asian, American and European countries. We are planning to put the application messages and html/applet widget label texts in properties file and using UTF-8 as the content type char set. Everything works fine.
My question is, as ResourBundle is extensible, how about storing the properties (key value pairs of messages) in database and then extend RresourceBundle to create resource bundle from database. For example, we can have a key and language (optionally country and variants added) as a unique key in two columns and having value in another column. For e.g.
And then, for a key OKKey, and language EN we can get label "OK" from third column?
Did anybody try this? Any pros and cons here? Any performance issues? [ January 05, 2006: Message edited by: Susanta Chatterjee ]
Sounds like a neat idea to me. It will be very cool if you can do it with a new subclass of ListResourceBundle and not change any of the code that uses it. This OO stuff works out really great sometimes.
It may be just me, but I'd build in a JMX interface so I could tell this thing to throw away its current list and reload from the database. That way you could correct spelling in the database without stopping and restarting the server. With thousands of labels in multiple languages you will accidentally put something goofy or offensive in one of them.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ulf, your link is very informative and useful. I see the issue now. After going thru the materials there, I found one of my fear is true - If we go through custom ResourceBundle, we will end up having one class for each locale (and variant) and add more locale will require more coding and deployment. Your link has one hint to use struts messageresource utility to achieve the same. As we will also use Struts for web-tier front controller, I will explore this option.
why do we have to create one class for each locale if we are going to store the resources in database. you pass the country, language and/or variant to the database and get the info.. If the resource not available for the country, lanaguage and/orvariant, search for it with country alone.. Why can't we write code to do this?? Can somebody explain me why we need separate classes?
Abi, If you read the API for java.util.ResourceBundle class, it should be clear to you. Specifically, the class description and method description for method "getBundle" is very helpful, as that provides the algorithm used by ResourceBundle to find a resource.
Hope this helps. If you have more questions, feel free to ask.
Thanks for your reply. I read the API for ResourceBundle Class. My question why cant we fetch the resouce directly from DB without using the ResourceBundle class. You can write the same algorithm used by resoucrebundle to find the resource instead of creating the classes.. Clarify me if I am wrong.
Yes, Abi. We could do that. But most of the existing framework code expect to use resource bundle. If we have to use new classes, then a lot of code rewrite would be necessary to replace resource bundle usage.