Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts2 internationalization using a database

We have a rather large application, with a great deal of dynamic content. Is there anyway to force struts to use a database for the i18n lookups, instead of properties files?

I'd be open for other ways to solve this as well, if anyone has ever done i18n with dynamic content.

like image 356
partkyle Avatar asked Feb 06 '11 04:02

partkyle


2 Answers

I don't know of an easy plug-and-play solution for this, so you will probably have to implement it yourself -- plan on spending quite a bit of time just coming to grips with how the localization features of struts 2 (and XWork) are implemented. The key will probably be to provide your own implementation of com.opensymphony.xwork2.TextProvider (and tell struts to use it by providing a <bean> tag in struts.xml). I can think of at least two ways of fitting this into the overall architecture:

  • Have your TextProvider implementation access the database directly. In the spirit of YAGNI, this is probably the best way to start (you can always refactor later, if necessary).

  • Alternatively, you could place the database code into an implementation of Java's ResourceBundle interface, which is what XWork uses internally. To me this sounds like an even more design-heavy approach, but on the plus side there are some articles around describing how to do this.

like image 139
Todd Owen Avatar answered Sep 25 '22 06:09

Todd Owen


No, there is no built-in way to have Struts2 load localized content from a database. You would need to write that yourself.

What are your requirements? Do you need for users to be able to dynamically change field prompts, error messages, etc.?

like image 44
Steven Benitez Avatar answered Sep 24 '22 06:09

Steven Benitez