<img src=“” alt=“Gem Version” /> <img src=“” /> <img src=“secure.travis-ci.org/museways/translatable_records.png?branch=master” alt=“Build Status” />

Translatable Records

Minimalistic toolkit to work with translatable records in rails.

Install

Put this line in your Gemfile:

gem 'translatable_records'

Then bundle:

$ bundle

Configuration

Define wich attributes will be translatable with the attr_translatable in your models:

attr_translatable :attr

Generate the translation model and migration for them:

rails g translation model

Complete the migrations adding the columns for each field in the translatations tables:

add_column :model_translations, :attr, :string

Remove the original column from models table:

remove_column :model, :attr

Update your db:

rake db:migrate

NOTE: If you are using rails 3 you should add attr_accessible :attr to pass the atrr to create, update, etc.

Usage

If you want to change the locale to something different than I18n.locale:

record.with_locale :es

If you want to build a translation for each available locale:

record.build_translations

If you want to save multiple translations:

<%= f.fields_for :translations do |ff| %>
  <%= ff.hidden_field :locale %>
  <%= ff.label :attr %>
  <%= ff.text_field :attr %>
<% end %>

Credits

This gem is maintained and funded by museways.

License

It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.