No commit activity in last 3 years
No release in over 3 years
Translator uses postgres hstore to keep model translations in your database.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.18

Runtime

 Project Readme

Translator¶ ↑

<img src=“https://travis-ci.org/hzamani/translator.png” />

This is a rails plugin to translate models data.

Requirements¶ ↑

This plugin uses postgres hstore, so postgres is a must.

How to Install¶ ↑

Install the gem

gem install rails-translator

add

gem 'activerecord-postgres-hstore'
gem 'rails-translator'

to your Gemfile and run bundler

bundle install

How to Use¶ ↑

First be sure to install postgres hstore extension, by

rails g hstore:setup
rake db:migrate

Generate your models but use hstore for translatable string and text fields.

rails g model Post title:hstore content:hstore published_at:datatime

optionally add hstore_index for hstore columns:

# migration file
add_hstore_index :posts, :title
add_hstore_index :posts, :content

tell which fields do you want to have translations:

class Post < ActiveRecord::Base
  translates :title, :content
  # ...
end

now post has locale based attribute accessors:

I18n.locale = :en
p = Post.create title: 'first post', content: 'This is my first post.'
I18n.locale = :fa
p.title = ''