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

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

问题描述

我想使用数据库来存储 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 字符吗?在 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"是英文键(即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 标记的信息,我明白了一点……我自己从来没有这样做过……但我在 服务器端...

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

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

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