views:

32

answers:

1

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 queries 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.

A: 

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.

duncan
Ok, seems good enough, though I asked about how to design the database for it. Will use the model_translations plugin, and changed it so that I can have separate locales for the whole app and models (in case someone wants to edit the model data, then it wouldn't be good if the whole site and edit form language would change if editing the object in another language)
Tõnis M