No release in over 3 years
Low commit activity in last 3 years
Simple localization your ActiveRecord fields without magic
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0.0
~> 1.8.4
= 1.4.1
= 3.2.10
~> 2.8.0

Runtime

 Project Readme

Simple Localizer

Simple localization your ActiveRecord fields without magic.

Installation

source 'https://rubygems.org'

gem 'simple_localizer'

Model translations

class Product < ActiveRecord::Base
  translates :name
end

Create migration for translations

bundle exec rails generate simple_localizer:install product name:string

Usage

product = Product.create! :name_en => 'a'
puts product.name_en # => a
product.name_en = 'b'
product.save!
puts product.name_en # => b
product.update_attributes :name_en => 'c'
puts product.name_en # => c

I18n.locale = :en
product = Product.create! :name => 'd'
puts product.name # => d
puts product.name_en # => d

I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
I18n.locale = :ru
I18n.fallbacks[:ru] = [:ru, :en, :fr]
product = Product.create! :name_fr => 'e', :name_ru => nil, :name_en => nil
puts product.name_ru # => nil
puts product.name # => e

Supported locales

You can change supported locales if necessary. Create file config/initializers/simple_localizer.rb:

SimpleLocalizer.supported_locales = %w(ru en fr)

Locales ​​supported by default:

aa ab ae af al am ar as ay az ba be bg bh bi bn bo bp br ca cf ch co cs cy de dr dt dz ef eg ej el en eo ep er es et eu fa fi fj fo fr fy ga gd gl gn gu ha he hi hm hr hu hy ia ie ik in is it iw ja ji jv ka kk kl km kn ko ks ku ky la ln lo lt lv mg mi mk ml mn mo mr ms mt my na ne nl no nt oc of og om or pa pl pn ps pt qu re rm rn ro ru rw sa sd sf sg sh si sk sl sm sn so sq sr ss st su sv sw ta te tg th ti tj tk tl tn to tp tr ts tt tw uk ul ur uz vi vo wo xh yo zh zu

Testing

bundle
rake db:migrate
rake