设计数据库架构:用于多种不同语言的数据库

发布于 2024-09-12 17:00:19 字数 559 浏览 5 评论 0原文

我有一个网站,应该将相同内容翻译成不同的语言。因此它应该具有相同字符串的不同翻译的数据库条目。 它不只是一个小网站,所以有很多不同的复杂数据结构。

我有一个想法如何实现这一点。但我真的不喜欢它。

我想引入一个额外的翻译表,其中计划存储不同语言的字符串字段。

例如,对于表 Project,包含三个字符串字段(name、shortDescr、fullDescr),我将以下面的方式使用翻译表:

alt text http://a.imageshack.us/img576/7948/2deldbtop.png

我会将 name、shortDescr、fullDecr 字段从字符串更改为整数(包含链接(ID ) 到翻译TxtID)。不同的translationTxtID和lang字段将为每个字符串标记和语言定义唯一的字符串。 所以这个解决方案是可行的,但我正在寻找更优雅的解决方案。你能建议我解决这个问题吗?

I have a web site that should have translation of the same content on different languages. So it should have the databases entries with different translations of same strings.
It is not just a small website, so there is a lot of different complicated data structures.

I have one idea how to realize this. But I don't really like it.

I think to introduce an additional Translation table, where plan to store string fields on different languages.

For example for table Project, that contain three string fields(name, shortDescr, fullDescr) I will use Translation table in the next way:

alt text http://a.imageshack.us/img576/7948/2deldbtop.png

I will change name, shortDescr, fullDescr fields from string to integer(that contain link(ID) to translationTxtID). Different translationTxtID and lang fields will define the unique string for each string token and language.
So this solution will work, but I am looking for more elegant solution. Can you suggest me a solution of this problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

方圜几里 2024-09-19 17:00:19

你能建议我解决这个问题吗?

是的。

不要使用整数键。事实上,这不是你自己发明的。只需使用gettext。您已经可以在几乎所有操作系统上使用它了。它是快速且经过验证的软件,您无需编写。

执行标准 gettext 模块为 i18n 所做的操作。 (参见http://en.wikipedia.org/wiki/GNU_gettext

  1. 使用文本键。

  2. 选择一个区域设置(即“C”区域设置,或您编写软件的区域设置)。

  3. 将所有消息作为默认区域设置中的字符串放入“项目”表中。

  4. 将所有翻译与原始字符串和要翻译的 I18N 语言环境一起放入“翻译”表中。是的,翻译表由一个又大又长的字符串作为键。这在实践中非常有效,因为(1)你没有那么多字符串,(2)你不经常查找它们,(3)你应该使用 gettext,而不是滚动你自己的字符串。

  5. 当您向用户呈现任何数据时,您会尝试执行 SELECT 来获取翻译。如果您找到翻译,那就太好了。

    如果您找不到翻译,那么他们会告诉您您使用的是默认字符串,这总比没有好。将异常记录在某处,并显示原始字符串。

Can you suggest me a solution of this problem?

Yes.

Don't use integer keys. Indeed, don't invent this yourself. Just use gettext. You already have it available on just about every OS there is. It's fast, proven software you don't need to write.

Do what the standard gettext module does for i18n. (see http://en.wikipedia.org/wiki/GNU_gettext)

  1. Use Text Keys.

  2. Pick a Locale (i.e, the "C" locale, or the locale in which you wrote the software).

  3. Put all the messages into your "Project" table as strings in the default locale.

  4. Put all the translations into the "Translation" table with the original string and the I18N locale to translate it to. Yes the Translation table is keyed by a big, long string. This works great in practice because (1) you don't have that many strings, (2) you don't look them up all that often, and (3) you should be using gettext, not rolling your own.

  5. When you present any data to a user, you attempt a SELECT to get the translation. If you find the translation, that's good.

    If you don't find the translation, then they key you're using is the default string, which is better than nothing. Log the exception somewhere, and present the original string.

孤独患者 2024-09-19 17:00:19

为什么表中不包含多个条目,每个语言对应一个条目? PK 可以是 ID 和 LangID 的组合。对于上面的示例:

Project

ID, int
LangId, int
Name, varchar
shortDesc, varchar
Fulldesc, varchar
date, date

然后,您在代码中需要做的就是设置一个语言变量,并在查询中将其作为查询中的一个选项提供(我在这里使用 SQL 作为参考):

SELECT (columns)
FROM Project
WHERE ID = @id
and LangId = @langid

您可以在所有查询中保持 langid查询该特定会话。

Why not have multiple entries in the tables, one for each lang? The PK can be a combo of ID and LangID. For your example above:

Project

ID, int
LangId, int
Name, varchar
shortDesc, varchar
Fulldesc, varchar
date, date

Then all you need to do in your code is set a language variable, and in your queries feed it as one option in the query (I'm using SQL as a reference here):

SELECT (columns)
FROM Project
WHERE ID = @id
and LangId = @langid

You keep langid through all the queries for that particular session.

耶耶耶 2024-09-19 17:00:19

我为每个包含字符串的父表使用本地化表。因此,如果您有一个表“Project”,那么您也会有一个表“Project_Locale”。 Project_Locale 与 Project 具有相同的 PK + 增加了“文化”字段。所有可本地化的字符串字段都放在 Project_Locale 中,其他所有内容都放在 Project 中。

I use a localization table for each parent table that contains strings. So if you have a table "Project", you would also have a table "Project_Locale". Project_Locale has the same PK as Project + the addition of a "Culture" field. All the localizable string fields go in Project_Locale and everything else goes in Project.

白色秋天 2024-09-19 17:00:19

我的选择是

Project
-------
ProjectID (PK)
Date

ProjectLoc
----------
ProjectID (FK)
Lang
Name
ShortDesc
FullDesc

然后您可以运行一个简单的查询,例如

SELECT Project.ProjectID, Date, Name, ShortDesc, FullDesc
FROM Project
LEFT JOIN ProjectLoc ON Project.ProjectID = ProjectLoc.ProjectID
WHERE ProjectLoc.Lang = %CurrentLang%

优点:优雅而简单
缺点:大量表格

My choice is

Project
-------
ProjectID (PK)
Date

ProjectLoc
----------
ProjectID (FK)
Lang
Name
ShortDesc
FullDesc

Then you can run a simple query like

SELECT Project.ProjectID, Date, Name, ShortDesc, FullDesc
FROM Project
LEFT JOIN ProjectLoc ON Project.ProjectID = ProjectLoc.ProjectID
WHERE ProjectLoc.Lang = %CurrentLang%

Pros: Elegant and simple
Cons: Large number of tables

妞丶爷亲个 2024-09-19 17:00:19

在.net中,我们使用由rick strahl设计的sql本地化数据库。


数据驱动的 ASP.NET 本地化资源提供程序和编辑器

In .net we are using sql Localization database that is designed by rick strahl.

See
Data Driven ASP.NET Localization Resource Provider and Editor

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文