Gem Version Code Climate Build Status Dependency 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 :models, :attr

Update your db:

rake db:migrate

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 mmontossi.

License

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