Skip to content
Branch: master
Go to file
Code

Latest commit

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 

README.rdoc

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

Installation

In your Gemfile:

gem 'acts_as_translatable'

And run 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"

puts Category.first.name     # => "English name"
puts Category.first.name_en  # => "Deutsche Name"
puts Category.first.name_es  # => nil

Category.find_by_name("Programming")
Category.find_by_name_de("Programmierung")

And it supports I18n fallbacks.

Use it in conjunction with the translate_acts_as_translatable_models (lassebunk/translate_acts_as_translatable_models) to automatically translate your acts_as_translatable models.

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

Todo's

  • Add finder methods such as find_by_name and find_by_name_en.

  • Cache translations on application level using Rails.cache so they won't be loaded for each translated record?

Copyright © 2012 Lasse Bunk, released under the MIT license

About

Ruby on Rails plugin for easy translation of Ruby on Rails models and database tables.

Resources

Releases

No releases published

Languages

You can’t perform that action at this time.