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.
ActiveRecord
I18n
(or Rails > 2.2)
To install Globalize2 with its default setup just use:
script/plugin install git://github.com/joshmh/globalize2.git
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.
See this script by Tomasz Stachewicz: http://gist.github.com/120867
- The association globalize_translations has been renamed to translations.
- 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)
- globalize2_versioning โ acts_as_versioned style versioning for Globalize2 (Joshua Harvey)
- i18n_multi_locales_validations โ multi-locales attributes validations to validates attributes from Globalize2 translations models (Sรฉbastien Grosjean)
- Globalize2 Demo App โ demo application for Globalize2 (Sven Fuchs)
- migrate_from_globalize1 โ migrate model translations from Globalize1 to Globalize2 (Tomasz Stachewicz)
- easy_globalize2_accessors โ easily access (read and write) globalize2-translated fields (astropanic, Tomasz Stachewicz)
- globalize2-easy-translate โ adds methods to easily access or set translated attributes to your model (bsamman)
- batch_translations โ allow saving multiple Globalize2 translations in the same request (Jose Alvarez Rilla)