对于在多语言网站和电子商店工作过很多经验的人来说,这更像是一个问题。这不是数据库结构问题或类似的问题。这是关于如何存储多语言网站的问题:而不是如何存储翻译。多语种网站不仅可以翻译成多种语言,还可以有特定语言的内容。例如,网站的英文版本可以具有与俄语或任何其他语言的同一网站完全不同的结构。对于这种情况,我想出了 2 种存储模式:
// NUMBER ONE
table contents // to store some HYPOTHETICAL content
id // content id
table contents_loc // to translate the content
content, // ID of content to translate
lang, // language to translate to
value, // translated content
online // availability flag, VERY IMPORTANT
ADVANTAGES:
- Content can be stored in multiple languages. This schema is pretty common, except maybe for the "online" flag in the "_loc" tables. About that below.
- Every content can not only be translated into multiple languages, but also you could mark online=false for a single language and disable the content from appearing in that language. Alternatively, that record could be removed from "_loc" table to achieve the same functionality as online=false, but this time it would be permanent and couldn't be easily undone. For instance we could create some sort of a menu, but we don't want one or more items to appear in english - so we use online=false on those "translations".
DISADVANTAGES:
- Quickly gets pretty ugly with more complex table relations.
- More difficult queries.
// NUMBER 2
table contents // to store some HYPOTHETICAL content
id, // content id
online // content availability (not the same as in first example)
lang, // language of the content
value, // translated content
ADVANTAGES:
1. Less painful to implement
2. Shorter queries
DISADVANTAGES:
2. Every multilingual record would now have 3 different IDs. It would be bad for eg. products in an e-shop, since the first version would allow us to store different languages under the same ID and this one would require 3 separate records to represent the same product.
第一个存储选项似乎是一个很好的解决方案,因为您也可以轻松地使用它而不是第二个,但反过来您就不能轻松地做到这一点。唯一的问题是……第一个结构似乎有点矫枉过正(除了产品存储等情况)
所以我对你的问题是:
实施第一个存储选项是否合乎逻辑?根据您的经验,有人会需要这样的解决方案吗?