Search code examples
ruby-on-railslocalegenerator

How to localize existing content in Rails 3?


I have set up a simple Rails app based on Post, Comment example from the default documentation. -> http://edgeguides.rubyonrails.org/getting_started.html

What would be the appropriate way of localizing existing content from these Posts ?

If I assume that Post has a :title and "content, and I would like this content to be entered not only in English, but also in German and Dutch, then how would I achieve this if I want the end result to look similar to this :

http://0.0.0.0:3000/en/posts.json to get all posts in English and respectively, http://0.0.0.0:3000/de/posts.json for German?

I havent found a gem yet, that would support such multilangual content.

I have seen doe, many existing ways to do so, mostly in applications like Wordpress or Drupal, which are not rails based.

I guess the preferred way would be either storing EN and DE posts in seperate tables (but then how to add new languages?), or to place all translations within the same database table, but seperate translations in a different way, but how to get them easily out in json in the right language?

I am really confused and puzzled why such a "common" problem, is not solved in Rails by default, or maybe I am simply looking in the wrong place.


Solution

  • Globalize3 will do what you want to do. It stores all translations for a particular model in a separate table, with a locale column identifying what the language of a particular translation is. This makes it possible to add new languages without having to migrate the database, so the approach is very scalable.

    There are other gems for translating content as well, e.g. Traco is one that I know of, but this one stores the translations in the same table as the model, so when you add new languages you have to migrate each model table. I personally prefer the Globalize3 approach, although it makes the gem itself more complicated internally.