使用数据库的Struts2国际化 [英] Struts2 internationalization using a database

查看:78
本文介绍了使用数据库的Struts2国际化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个相当大的应用程序,其中包含大量动态内容.无论如何,有没有强迫Struts使用i18n查找数据库而不是属性文件?

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?

如果有人曾经使用动态内容完成过i18n的操作,我也会欢迎其他方式来解决此问题.

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

推荐答案

我不知道有一个简单的即插即用解决方案,因此您可能必须自己实施-计划花相当大的钱只是一点时间来了解如何实现Struts 2(和XWork)的本地化功能.关键可能是提供您自己的(并通过在struts.xml中提供< bean>标记来告诉struts使用它).我可以想到至少两种将其适合于整个体系结构的方法:

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:

  • 让您的TextProvider实现直接访问数据库.本着YAGNI的精神,这可能是最好的开始方式(如有必要,您以后随时可以重构).

  • 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).

或者,您可以将数据库代码放入Java的 ResourceBundle 接口,这是XWork在内部使用的接口.对我来说,这听起来像是一种更加沉重的设计方法,但从正面来看,有一些周围.

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.

这篇关于使用数据库的Struts2国际化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆