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

查看:30
本文介绍了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)的本地化功能.关键可能是提供您自己的 com.opensymphony 实现.xwork2.TextProvider(并通过在 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天全站免登陆