开发者

How to translate the fields of a database model?

I have some tables/models in a web app that will have multilingual content. For example a university, with it's description in a default language(english) and the user wants he can see the same information in another language( if the object has it's fields translated). If there were only a few languages then I would just add fields like name_en and name_de and so on, but the number of languages isn't fixed, so that' would create a mess. I could also just create a new object with the translated data but then foreign keys wouldn't work, and only some of the fields can be translated so that would create duplicate data. Storing the translations in a file and using gettext or something similar is also not an option since the objects fields can be translated by the website user, not only developers/admins.

What would be the best way to design/architect such a database? Searching from the translated data should also be not too complex - as it should not require creating complex joins which would make the queri开发者_如何学Ces slower

I'm using PostgreSQL and Ruby of Rails but I'm not looking for a technical solution but for a general idea how to design it.


Don't reinvent the wheel. Install the globalize2 plugin and there you go. Of course if you want you can also study how it works (using a translation table, and yes, with joins). There is a fork which uses the main table for the default language though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜