多语言数据库设计模式
我目前正在开发博客软件,该软件应该提供对多种语言内容的支持。
我正在考虑一种设计数据库(MySQL)的方法。我的第一个想法是:
- 每个条目都存储在一个表中(我们称之为
entries
)。这张表 保存不会改变的信息(比如唯一的 ID,如果它是 发表与否以及帖子类型)。 - 另一个表(我们称之为
content
)包含字符串 (例如特定内容的内容、标题、日期和作者 语言)。 - 然后它们由唯一的条目 ID 连接起来。
这样做的想法是一篇文章可以翻译成多种其他语言,但这不是必须的。如果没有用户的母语翻译(由他的 IP 或其他内容决定),他会看到标准语言(可能是英语)。
对我来说,这听起来像是一个简单的多语言数据库,我确信有一个设计模式。遗憾的是,我没有找到。
如果没有模式,你将如何实现这一点?任何意见都将受到高度赞赏。
I'm currently working on Blog-Software which should offer support for content in multiple languages.
I'm thinking of a way to design my database (MySQL). My first thought was the following:
- Every entry is stored in a table (lets call it
entries
). This table
holds information which doesn't change (like the unique ID, if it's
published or not and the post-type). - Another table (let's call it
content
) contains the strings
(like the content, the headline, the date, and author of the specific
language). - They are then joined by the unique entry-id.
The idea of this is that one article can be translated into multiple other languages, but it doesn't need to be. If there is no translation in the native language of the user (determined by his IP or something), he sees the standard language (which would be English).
For me this sounds like a simple multilingual database and I'm sure there is a design pattern for this. Sadly, I didn't find any.
If there is no pattern, how would you go about realizing this? Any input is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在大多数具有这种功能的应用程序中看到了您的方法。唯一的变化是,有些地方会将“默认”值放入基表 (
Entry
) 中,而其他地方则将其视为另一个Content
行。Your approach is what I've seen in most applications with this kind of capability. The only changing piece is that some places will put the "default" values into the base table (
Entry
) while others will treat it as just anotherContent
row.该设计还使您能够轻松地以所有语言进行搜索(或限制搜索)。从数据库设计的角度来看,恕我直言,它是您可以使用的最佳设计。
That design will also give you the ability to search (or restrict search) in all languages easily. From a db design perspective, its imho the best design you can use.
对于少量的文本和简单的应用程序来说,这是可行的。总的来说,您可能会被所需的额外连接所困扰,尤其是当您的数据库大于内存时。以正确的顺序(排序)呈现事物也可能需要解决
With small amounts of text and a simple application this would work. In the large, you might be bitten by the extra joins needed, especially when your database is larger than ram. Presenting things in the right order (sorting) also might need solving