indi
indi

Reputation: 21

multiple languages models

I've been asked to design a multiple language application and I need advice with which is the best approach with Rails.

Basically all the tables have some common fields that doesn't need to be translated and some others that need translation.

thank you

Upvotes: 2

Views: 2467

Answers (1)

railscard
railscard

Reputation: 1848

For this purpose, will approach gem globalize3. Easy to use.

In your gemfile:

gem 'globalize'

Model:

class Article < ActiveRecord::Base
  translates :title, :text
end

And migration:

class CreateArticles < ActiveRecord::Migration
  def up
    create_table :articles do |t|
      t.timestamps
    end
    Article.create_translation_table! :title => :string, :text => :text
  end

  def down
    drop_table :articles
    Article.drop_translation_table!
  end
end

And run

rake db:migrate

Upvotes: 5

Related Questions