数据库支持i18n for java web-app [英] Database backed i18n for java web-app

查看:139
本文介绍了数据库支持i18n for java web-app的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用数据库来存储i18n键/值对,这样我们就可以在运行时修改/重新加载i18n数据。有没有人这样做过?或者有人知道如何实现这个?我已经阅读了几个线程,但我还没有看到一个可行的解决方案。

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? Or does anyone have an idea of how to implement this? I've read several threads on this, but I haven't seen a workable solution.

我特别指的是可以使用jstl标签的东西,比如

I'm specifically refering to something that would work with the jstl tags such as

<fmt:setlocale>
<fmt:bundle>
<fmt:setBundle>
<fmt:message>

我认为这将涉及扩展ResourceBundle,但是当我尝试这个时,我遇到了必须要做的问题jstl标签获取资源包的方式。

I think this will involve extending ResourceBundle, but when I tried this I ran into problems that had to do with the way the jstl tags get the resource bundle.

推荐答案

您是否只是询问如何存储UTF-8/16字符一个DB?在mysql中,只需要确保使用UTF8支持构建并将其设置为默认值,或者在列级或表级别指定它。我以前在oracle和mysql中完成了这个。创建一个表格并将一些i18n数据剪切并粘贴到其中,看看会发生什么......你可能已经设置好了..

Are you just asking how to store UTF-8/16 characters in a DB? in mysql it's just a matter of making sure you build with UTF8 support and setting that as the default, or specifying it at the column or table level. I've done this in oracle and mysql before. Create a table and cut and paste some i18n data into it and see what happens... you might be set already..

还是我完全错过了你的观点?

or am I completely missing your point?

编辑:

更明确...我通常实现三列表...语言,key,value ...其中value包含潜在的外语单词或短语......language包含一些语言键,key是英语键(即login.error.password.dup)...语言和键被索引...

to be more explicit... I usually implement a three column table... language, key, value... where "value" contains potentially foreign language words or phrases... "language" contains some language key and "key" is an english key (i.e. login.error.password.dup)... language and key are indexed...

然后我在这样的结构上构建接口,显示每个键及其所有翻译(值)...它可以获得花哨,包括审计线索和脏标记以及使翻译人员和数据输入人员能够使用它所需的所有其他内容..

I've then built interfaces on a structure like this that shows each key with all its translations (values)... it can get fancy and include audit trails and "dirty" markers and all the other stuff you need to enable translators and data entry folk to make use of it..

编辑2:

现在您已经添加了有关JSTL标签的信息,我理解了一点......我自己从未这样做过..但我发现这个旧信息< a href =http://www.theserverside.com/discussions/thread.tss?thread_id=27390 =nofollow noreferrer> theserverside ...

Now that you added the info about the JSTL tags, I understand a bit more... I've never done that myself.. but I found this old info on theserverside...

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));

这篇关于数据库支持i18n for java web-app的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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