i18n using database

十年热恋 提交于 2019-12-08 04:38:57

问题


I have to design a database which will allow me store data in multiple languages. I came up with something like this.


create table lang ( id primary key, lang_code )
create table data (id primary key)
create table i18n_data (id primary key, i18n_text ,data_id references data, lang_id references lang)

Is creating a table with only one column/primary key is an overkill for my requirement? Is there any better way to do it?

Thanks.


回答1:


I think that your solution is a quite nice one, I am solving such problems the same way. And I wouldn't fear to create a table only with a primary key (although you might find a few attributes which are belonging to this table).




回答2:


On the top of my head I see two similar options:

Having just two tables lang and i18n_data and an indexed field in i18n_data that you use with the language to index the translation.

Another option could be to use a composed primary key on the i18n_data table that has the reference to lang and the data identifier.



来源:https://stackoverflow.com/questions/9960241/i18n-using-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!