Gem Version Code Climate Build Status Dependency Status

Translatable Records

Fully customizable record translations for rails.

Why

I did this gem to:

  • Have the freedom to customize the translation model.
  • Avoid duplication by delegate translatable attributes directly to translation model.
  • Use translations other than I18n.available_locales.

Install

Put this line in your Gemfile:

gem 'translatable_records'

Then bundle:

$ bundle

Configuration

Define wich attributes will be translated in the model:

class Product < ActiveRecord::Base
  translate :name
end

Generate the translation and migration:

$ bundle exec rails g translation product

Update your db:

$ bundle exec rake db:migrate

Usage

Accessors

By default will use I18n.locale but you can change it:

product.locale = :en

Accessor continue working the same:

product.name = 'Phone'

Views

If you want to save multiple translations:

<%= f.fields_for :translations do |ff| %>
  <%= ff.hidden_field :locale %>
  <%= ff.label :name %>
  <%= ff.text_field :name %>
<% 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.