以下是我设计数据库的方法:
Visualization by 100
i18n
表只包含一个PK,因此任何表只需引用此PK即可国际化字段.然后,表translation
负责将这个通用ID与正确的翻译列表链接起来.
locale.id_locale
是管理en
和en_US
ISO syntaxes的VARCHAR(5)
.
currency.id_currency
是管理ISO 4217 syntax的CHAR(3)
.
你可以找到两个例子:page
和newsletter
.这admin-managed个实体都需要国际化他们的领域,分别是title/description
和subject/content
.
下面是一个查询示例:
select
t_subject.tx_translation as subject,
t_content.tx_translation as content
from newsletter n
-- join for subject
inner join translation t_subject
on t_subject.id_i18n = n.i18n_subject
-- join for content
inner join translation t_content
on t_content.id_i18n = n.i18n_content
inner join locale l
-- condition for subject
on l.id_locale = t_subject.id_locale
-- condition for content
and l.id_locale = t_content.id_locale
-- locale condition
where l.id_locale = 'en_GB'
-- other conditions
and n.id_newsletter = 1
请注意,这是一个规范化的数据模型.如果你有一个巨大的数据集,也许你可以考虑denormalizing it个来优化你的查询.您还可以使用索引来提高查询性能(在某些数据库中,外键会自动索引,例如MySQL/InnoDB).