Project

utranslate

0.0
The project is in a healthy, maintained state
A simple model translation gem using postgresql JSONB columns
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Development

Runtime

>= 6.0.0
 Project Readme

Utranslate

A very easy to use and configure gem to add I18n support to Activerecord models using postgresql JSONB columns.

Usage

Installation

Add this line to your application's Gemfile:

gem 'utranslate'

And then execute:

$ bundle

Or install it yourself as:

$ gem install utranslate

Configuration

Include utranslate in all the models that you want to translate:

class Post
  include Utranslate
end

Add translations for every attribute that you want to translate.

translate :title

You can specify to check for presence of all I18n.available_locales

translate :title, null: false

Or you can define what locales you want to check

translate :title, null: false, locales: [:es, :en]

Adding a translation for current locale

To add a translation for current locale you just have to assign as usual

post.title = 'translation'

Adding a translation for a given locale

To add a translation for a given locale you must pass the locale and the translation

post.title(:es, 'traducción')

Mass assigning translations

To mass assign translations you can do it as usual

post = Post.new(title: { es: 'traducción', en: 'translation'})

Retriving a translation for current locale

To retrive a translation for current locale you can do it as usual

post.title

Retriving a translation for given locale

To retrive a translation for current locale you can do it as usual

post.title(:es)

Contributing

Feel free to contribute to this project or to contact me through klatooine@gmail.com

License

The gem is available as open source under the terms of the MIT License.