• Post Reply Bookmark Topic Watch Topic
  • New Topic

I'd like to use a database to store i18n. Has anyone done this?  RSS feed

 
Nagu Spartan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like to use a database to store i18n key/value pairs so we can modify / reload the i18n data at runtime. Has anyone done this?
 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 198
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. you can definitely do that, if you think that is appropriate for your requiement.
 
Nagu Spartan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
Can you explain how to use the database to store i18n key/value pairs(in JSP).
Please give me some sample codes.


Prabhakar Reddy Bokka wrote:Yes. you can definitely do that, if you think that is appropriate for your requiement.
 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 198
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a table and 2 columns to insert your key/value pairs. Changing the data depending on geography is up to you.
Write the code to load this data in your startup servlet. This servlet will call a DAO to load the reference data from database at the startup. Once the data is available you can put it in cache and use it accross the application.
 
Nagu Spartan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
I can understand.
HttpSession session = .. [get hold of the session]
ResourceBundle bundle = new PropertyResourceBundle(toInputStream(myOwnProperties)) [toInputStream just stores the properties into an inputstream]
Locale locale = .. [get hold of the locale]
javax.servlet.jsp.jstl.core.Config.set(session, Config.FMT_LOCALIZATION_CONTEXT, new LocalizationContext(bundle ,locale));



ResourceBundle bundle = ResourceBundle.getBundle("AwesomeBundle", locale, DbResourceBundle.getMyControl());
javax.servlet.jsp.jstl.core.Config.set(actionBeanContext.getRequest(), Config.FMT_LOCALIZATION_CONTEXT, new LocalizationContext(bundle, locale));

Can you please explain the above code and give me some sample working examples.


Prabhakar Reddy Bokka wrote:Create a table and 2 columns to insert your key/value pairs. Changing the data depending on geography is up to you.
Write the code to load this data in your startup servlet. This servlet will call a DAO to load the reference data from database at the startup. Once the data is available you can put it in cache and use it accross the application.
 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 198
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

HttpSession session = .. [get hold of the session]
Map resourceMap = loadProperties();// loads the properties from the database and returns a HashMap with key value pairs.
ServletContext ctx = .....
ctx.put("localeMap",resourceMap);

Now your key/value pairs available accross the application, work same as you worked with ResourceBundle.

If yours is an Enterprise application you need to use some chache service to put the loaded "resourceMap", so that it is available accross the application.
 
Nagu Spartan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
Here how can I implement fmt or bean tag. Can you please explain with some examples in brief.



Prabhakar Reddy Bokka wrote:
HttpSession session = .. [get hold of the session]
Map resourceMap = loadProperties();// loads the properties from the database and returns a HashMap with key value pairs.
ServletContext ctx = .....
ctx.put("localeMap",resourceMap);

Now your key/value pairs available accross the application, work same as you worked with ResourceBundle.

If yours is an Enterprise application you need to use some chache service to put the loaded "resourceMap", so that it is available accross the application.
 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 198
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why can't you implement? Can you please explain with some examples in brief.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!