Struts2 internationalization using a database(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 国际化使用数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Struts2 国际化使用数据库


基础教程推荐
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 修改 void 函数的输入参数,然后读取 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01