• Post Reply Bookmark Topic Watch Topic
  • New Topic

Implementing i18n using Database instead of Properties file  RSS feed

 
Susanta Chatterjee
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is some discussion of this topic here, which indicates that there are class loading issues with this approach.
[ January 06, 2006: Message edited by: Ulf Dittmer ]
 
Susanta Chatterjee
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to Stan and Ulf for reply.

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.

I will keep you posted as things are unfolded.

- Susanta
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting. Looks like they've finally addressed this in 1.6.
 
Susanta Chatterjee
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernst,
Interesting indeed. But we will not be able to leverage this as we are using WebSphere App Server 6.x and that limits our JDK choice.

Regards,
- Susanta
 
Abi Raj
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read the link sent by Ulf.

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?


 
Susanta Chatterjee
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

- Susanta
 
Abi Raj
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Susanta,

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.

Thanks.
 
Susanta Chatterjee
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abi Raj
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Susanta,

Thanks for your Reply

-Abi
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!