多语言数据库设计的最佳实践是什么? [英] What are best practices for multi-language database design?

查看:248
本文介绍了多语言数据库设计的最佳实践是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建多语言数据库的最佳方法是什么?为每个表创建本地化表是使设计和查询复杂,在其他情况下为每种语言添加列是简单但不动态,请帮助我了解什么是最好的选择企业应用程序

What is the best way to create multi-language database? To create localized table for every table is making design and querying complex, in other case to add column for each language is simple but not dynamic, please help me to understand what is the best choose for enterprise applications

推荐答案

我们做的是为每个多语言对象创建两个表。

What we do, is to create two tables for each multilingual object.

第一个表只包含语言中性数据(主键等),第二个表每个语言包含一个记录,包含本地化数据和语言的ISO代码。

E.g. the first table contains only language-neutral data (primary key, etc.) and the second table contains one record per language, containing the localized data plus the ISO code of the language.

在某些情况下,我们添加一个DefaultLanguage字段,以便如果没有可用于指定语言的本地化数据,我们可以回退到该语言。

In some cases we add a DefaultLanguage field, so that we can fall-back to that language if no localized data is available for a specified language.

示例:

Table "Product":
----------------
ID                 : int
<any other language-neutral fields>


Table "ProductTranslations"
---------------------------
ID                 : int      (foreign key referencing the Product)
Language           : varchar  (e.g. "en-US", "de-CH")
IsDefault          : bit
ProductDescription : nvarchar
<any other localized data>

使用这种方法,您可以处理尽可能多的语言新语言)。

With this approach, you can handle as many languages as needed (without having to add additional fields for each new language).

更新(2014-12-14):请查看此答案,了解有关用于将多语言数据加载到应用程序中的实现的一些其他信息。

Update (2014-12-14): please have a look at this answer, for some additional information about the implementation used to load multilingual data into an application.

这篇关于多语言数据库设计的最佳实践是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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