Quantcast
Channel: Lasse Bunk's weblog
Viewing all articles
Browse latest Browse all 14

Translate your Ruby on Rails models and database tables using acts_as_translatable

$
0
0

acts_as_translatable is a plugin for easy translation of your Ruby on Rails models and database tables.

Installation

In your Gemfile:

gem 'acts_as_translatable'

Install the new gem:

bundle install

Example

Generate translations for a category model with name and description fields, with default locale set to ‘en’ (English):

$ rails generate acts_as_translatable en category name description

This will create the necessary migration. Then run:

$ rake db:migrate

Then add to app/models/category.rb:

class Category < ActiveRecord::Base
  acts_as_translatable_on :name, :description
  ...
end

And play around with I18n:

I18n.locale = "en"
Category.first.update_attribute :name, "English name"

I18n.locale = "de"
Category.first.update_attribute :name, "Deutsche Name"

Also try in combination with my translate_acts_as_translatable_models plugin to automatically translate your acts_as_translatable enabled models.

Have fun! Please send comments and suggestions to lassebunk@gmail.com, and issues at GitHub, please :)


Viewing all articles
Browse latest Browse all 14

Trending Articles