No commit activity in last 3 years
No release in over 3 years
Ruby on Rails plugin for easy translation of database fields.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

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