动态多语言数据结构的 db 设计模式

发布于 2024-10-03 20:49:42 字数 328 浏览 2 评论 0原文

到目前为止我已经用几种不同的方式做到了这一点。我想知道是否有一个好的模式。

系统具有动态内容。因此,不仅数据量和数据本身是动态的(计数(行)),而且字段的数量也是动态的。因此,博客可能有 10 个需要翻译的字段,但购物车项目有 5 个

。我一直在做的是为保存该字段的语言数据的表​​行插入一个 id。该语言表包含 id、defaultlanguage 以及任意数量的其他语言。这样就只有一个语言表。

这很漂亮,但我无法更新视图,因为当多个联接引用同一张表时,它是不可更新的(MySQL)。那么也许有更好的方法可以做到这一点。

有更好的设计吗?在这种情况下,有哪些常见的设计模式?

I've done this a few different ways by now. I'd like to know if there is a good pattern for this.

A system has dynamic content. So not only is the amount of data and the data itself dynamic (count(rows)), but the number of fields is also dynamic. So a blog may have 10 fields that need to be translated, but a shopping cart item has 5.

What I've been doing is inserting an id for a table row which holds the language data for that field. This language table has id, defaultlanguage, plus any number of additional languages. This way there is only one language table.

This is nifty, but I can't update views because when more than one join references the same table, it's not updatedable(MySQL). Then perhaps there are much better ways of doing this.

Is there a better design? What are some of the common design patterns used in this situation?

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

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

发布评论

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

评论(1

滥情哥ㄟ 2024-10-10 20:49:42
  • 实体字段类型ID名称
  • 实体字段ID名称FieldType
  • 实体FieldValuesIDCollectionID字段 >、
  • 实体内容ID字段数据
  • 实体< strong>i18n(ID字段语言 ID)

示例:

insert into FieldTypes('S', 'string');
insert into FieldTypes('DT', 'date/time');

insert into Fields(1, 'Author', 'S');
insert into Fields(2, 'Created', 'D');

insert into i18n(1, 1, 'en', 'Author');
insert into i18n(2, 1, 'ru', 'Автор');
insert into i18n(3, 2, 'en', 'Created');
insert into i18n(4, 2, 'ru', 'Создано');

insert into Content(1, 2, 'Test data');
insert into FieldValues(3, 2, 1, 'Tester');
insert into FieldValues(4, 2, 2, '2011-03-20T12:20:00');

/* Display content fields in the user language */ 
select c.ID, f.ID, i.Value as FieldName, fv.Value as FieldValue
from Content c, FieldValues fv, Fields f, i18n i
where c.Fields = fv.CollectionID
  and fv.Field = i.Field
  and i.LanguageID = :UserLanguage
  and c.ID = :ContentID
  • Entity FieldTypes (ID, Name)
  • Entity Fields (ID, Name, FieldType)
  • Entity FieldValues (ID, CollectionID, Field, Value)
  • Entity Content (ID, Fields, Data)
  • Entity i18n(ID, Field, LanguageID, Value)

Example:

insert into FieldTypes('S', 'string');
insert into FieldTypes('DT', 'date/time');

insert into Fields(1, 'Author', 'S');
insert into Fields(2, 'Created', 'D');

insert into i18n(1, 1, 'en', 'Author');
insert into i18n(2, 1, 'ru', 'Автор');
insert into i18n(3, 2, 'en', 'Created');
insert into i18n(4, 2, 'ru', 'Создано');

insert into Content(1, 2, 'Test data');
insert into FieldValues(3, 2, 1, 'Tester');
insert into FieldValues(4, 2, 2, '2011-03-20T12:20:00');

/* Display content fields in the user language */ 
select c.ID, f.ID, i.Value as FieldName, fv.Value as FieldValue
from Content c, FieldValues fv, Fields f, i18n i
where c.Fields = fv.CollectionID
  and fv.Field = i.Field
  and i.LanguageID = :UserLanguage
  and c.ID = :ContentID
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文