No commit activity in last 3 years
No release in over 3 years
Set ActiveRecord field values or retrieve them based on the I18n current locale or by manually specifying
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Acts As Localizable

Acts As Localizable is an alternative to the globalize series of plugins. It enables the ability to localize fields in an ActiveRecord model.

It has the ability to be used with I18n or independently of it and is compatible with Rails 3.

Requirements

ActiveRecord
I18n
Rails( > 3.0.0beta4)

To install Acts As Localizable you can install it as a gem.

gem install acts_as_localizable

Once the gem is installed you need to create the LocalizedField table in your project. To do this run:


	rails generate localized_fields
	rake db:migrate

Translating Fields

In order for Acts As Localizable to work you must first notify the plugin which models you would like to localize. You can do this by simply adding a line to the top of your model:

	class Post < ActiveRecord::Base
	  acts_as_localizable
	end

This allows you to look at fields or set fields by using a localized property:

	post.localized.title # => "Love"
	post.localized(:es).title # => "Amor"
	
	I18n.locale = :es
	post.localized.title # => "Amor"

As can be seen above, you can specify which language you are requesting as an argument to the localized method, or if none is specified, it will use the locale set in the I18n gem.

To set a local title:

	post.localized(:es).title = "Amor"
	post.save