Project

globalize2

0.16
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
Rails I18n: de-facto standard library for ActiveRecord data translation
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Globalize2

Globalize2 is the successor of Globalize for Rails.

It is compatible with and builds on the new I18n api in Ruby on Rails. and adds model translations to ActiveRecord.

Globalize2 is much more lightweight and compatible than its predecessor was. Model translations in Globalize2 use default ActiveRecord features and do not limit any ActiveRecord functionality any more.

Requirements

ActiveRecord
I18n

(or Rails > 2.2)

Installation

To install Globalize2 with its default setup just use:


script/plugin install git://github.com/joshmh/globalize2.git

Model translations

Model translations allow you to translate your models’ attribute values. E.g.


class Post < ActiveRecord::Base
  translates :title, :text
end

Allows you to values for the attributes :title and :text per locale:


I18n.locale = :en
post.title # => Globalize2 rocks!

I18n.locale = :he
post.title # => גלובאלייז2 שולט!

In order to make this work, you’ll need to add the appropriate translation tables. Globalize2 comes with a handy helper method to help you do this. It’s called create_translation_table!. Here’s an example:


class CreatePosts < ActiveRecord::Migration
  def self.up
    create_table :posts do |t|
      t.timestamps
    end
    Post.create_translation_table! :title => :string, :text => :text
  end
  def self.down
    drop_table :posts
    Post.drop_translation_table!
  end
end

Note that the ActiveRecord model Post must already exist and have a translates directive listing the translated fields.

Migration from Globalize

See this script by Tomasz Stachewicz: http://gist.github.com/120867

Changes since Globalize2 v0.1.0

  • The association globalize_translations has been renamed to translations.

Alternative Solutions

  • Veger’s fork – uses default AR schema for the default locale, delegates to the translations table for other locales only
  • TranslatableColumns – have multiple languages of the same attribute in a model (Iain Hecker)
  • localized_record – allows records to have localized attributes without any modifications to the database (Glenn Powell)
  • model_translations – Minimal implementation of Globalize2 style model translations (Jan Andersson)

Related solutions