【问题标题】:Using Views for Multilingual Database为多语言数据库使用视图
【发布时间】:2015-04-09 10:07:35
【问题描述】:

这是一个已经讨论过多次的话题,而且总是视情况而定,但我喜欢分享我的想法。

我正在构建一个新的 CMS,它必须支持多语言应用程序并且可以安装在现有应用程序之后。

我知道并找到的解决方案是:

[Product]
id
price
name_en
name_de
name_fr

only getting the fields you need in your language.

或使用多个表,例如:

[product]
id
price

[languages]
id
tag

[product_translation]
product_id
language_id
name

 Joining the correct language

这两种情况都有效,各有利弊。根据您的选择,您必须重写您的查询。

我的想法:

[product]
id
price
name

[product_translations]
product_id
language_id
name

[product_es_view]
id -- references the product table
price -- references the product table 
name -- references the translation table

现在的想法是为每种语言创建一个视图,但该视图与产品表相同。

为什么? 有了这个设置,我可以制作非多语言网站,多语言而不编辑现有的模型/表格。现在我在我的代码中唯一要做的就是使用另一个表,我得到了我的模型的翻译版本(在 php 中,可以通过向模型添加一个简单的特征来完成)。使用 SQL Server 和 Mysql,您可以使用可更新的视图,将值保存在引用的表中。

我很想听听你们对这个想法的看法,最重要的是,使用视图解决这个问题的最大缺点是什么?

【问题讨论】:

    标签: php mysql sql-server laravel multilingual


    【解决方案1】:

    我更喜欢第二种选择,即每个实体都在自己的表中。如果您使用 product_es_view 那么它可能更容易但不太干净的代码。

    添加新语言通常不应包括添加新数据库表。向语言表中添加新行会更好。

    【讨论】:

      猜你喜欢
      • 2012-08-11
      • 1970-01-01
      • 1970-01-01
      • 2013-10-06
      • 1970-01-01
      • 2019-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多