views:

87

answers:

1

We have a problem here.

We need to translate a website into multiple language. We already use gettext to translate the static content. But we have to translate some text content in multiple language.

The ui isn't a problem.

We found 2 ways to translate the text. 1. use JSON inside our text input Why this solution is bad. Every text input will need to be bigger because we can't guess the real size of the attribute.

  1. Use the a translating table that keep reference to the original model and translate every field. It will still need big field because we cant define the field size by record.

  2. Finally, the best solution I came with is creating a translating table. The table will keep foreign key of other tables. For each translation, we copy the record that need to be translated. Inside the translation table, there is 4 field, model_name(primary), reference_id(primary), translated_id(primary), locale(primary). This solution make it impossible to have multiple translation for the same model in the same language.

  3. Last but not least, we could use something like someone proposed...a database gettext. We have a table that contain strings and only string (key, text, locale) so we can search for a model, a string that is the same as the one used in the model and then use the we found instead.

My opinion is that all of these solutions are hack, the 4 solution is probably the one that looks better.

As I didn't found any good documentation, I would really like to make this question shine.

+1  A: 

Here is how we dealt with the multiple languages (we had some experts look at this solutions as well!).

  • We have text a table in the database (textid, key, nl, uk, de, fr)
  • We have foreignkeys to the text table (from for instance the productnameid)
  • Static text that needs to be translated in html pages is surrounded with hashes: ##name##
  • right before the html content is send from the server to the client the htmlstream is parsed to translate the content between hashes.
  • the translated texts are stored in the cache which makes this solution flexible and still fast

It works for us, and we build websites that have over 100k pageviews per hour.

Florian