<commit_before>h1. Globalize3

Globalize3 is the successor of Globalize for Rails. Globalize is targeted at ActiveRecord 3. It is compatible with and builds on the new "I18n API in Ruby on Rails":http://guides.rubyonrails.org/i18n.html and adds model translations to ActiveRecord.

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

h2. Requirements

ActiveRecord > 3.0.0.rc
I18n

h2. Installation

To install Globalize3 with its default setup just use:

<pre><code>
$ gem install globalize3
</code></pre>

h2. Model translations

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

<pre><code>
class Post < ActiveRecord::Base
  translates :title, :text
end
</code></pre>

Allows you to translate the attributes :title and :text per locale:

<pre><code>
I18n.locale = :en
post.title # => Globalize3 rocks!

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

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

<pre><code>
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
</code></pre>

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

h2. Versioning with Globalize3

Globalize3 nicely integrates with "vestal_versions":http://github.com/laserlemon/vestal_versions:

<pre><code>
require 'globalize/versioning/vestal_versions'
</code></pre>

As of writing (2010-08-05) the original vestal_versions respository has not been updated to be compatible with Rails 3 though. You can use "this fork":http://github.com/svenfuchs/vestal_versions though. "Globalize3's Gemfile":http://github.com/svenfuchs/globalize3/blob/master/Gemfile#L10 is currently set up accordingly.

Please also note that @update_attribute@ currently hides itself from dirty tracking in ActiveRecord >= 3.0.0.beta (which is considered a "regression":http://github.com/rails/rails/commit/01629d180468049d17a8be6900e27a4f0d2b18c4#commitcomment-123199). That means that you currently need to use attribute writers or @update_attributes@ in order to track changes/versions for your models.

Also, please see the tests in test/globalize3/versioning_test.rb for some current gotchas.

h2. Changes since Globalize2

* `translation_table_name` was renamed to `translations_table_name`
* `available_locales` has been removed. please use `translated_locales`

h2. Migration from Globalize for Rails (version 1)

See this script by <NAME>: http://gist.github.com/120867

h2. Alternative Solutions

* "Veger's fork":http://github.com/veger/globalize2 - uses default AR schema for the default locale, delegates to the translations table for other locales only
* "TranslatableColumns":http://github.com/iain/translatable_columns - have multiple languages of the same attribute in a model (Iain Hecker)
* "localized_record":http://github.com/glennpow/localized_record - allows records to have localized attributes without any modifications to the database (<NAME>)
* "model_translations":http://github.com/janne/model_translations - Minimal implementation of Globalize2 style model translations (<NAME>)

h2. Related solutions

* "globalize2_versioning":http://github.com/joshmh/globalize2_versioning - acts_as_versioned style versioning for globalize2 (<NAME>)
* "i18n_multi_locales_validations":http://github.com/ZenCocoon/i18n_multi_locales_validations - multi-locales attributes validations to validates attributes from globalize2 translations models (<NAME>)
* "globalize2 Demo App":http://github.com/svenfuchs/globalize2-demo - demo application for globalize2 (Sven Fuchs)</li>
* "migrate_from_globalize1":http://gist.github.com/120867 - migrate model translations from Globalize1 to globalize2 (Tomasz Stachewicz)</li>
* "easy_globalize2_accessors":http://github.com/astropanic/easy_globalize2_accessors - easily access (read and write) globalize2-translated fields (astropanic, Tomasz Stachewicz)</li>
* "globalize2-easy-translate":http://github.com/bsamman/globalize2-easy-translate - adds methods to easily access or set translated attributes to your model (bsamman)</li>
* "batch_translations":http://github.com/alvarezrilla/batch_translations - allow saving multiple globalize2 translations in the same request (<NAME>)</li>
<commit_msg>Added documentation for :migrate_data and untranslated_fields.<commit_after>h1. Globalize3

Globalize3 is the successor of Globalize for Rails. Globalize is targeted at ActiveRecord 3. It is compatible with and builds on the new "I18n API in Ruby on Rails":http://guides.rubyonrails.org/i18n.html and adds model translations to ActiveRecord.

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

h2. Requirements

ActiveRecord > 3.0.0.rc
I18n

h2. Installation

To install Globalize3 with its default setup just use:

<pre><code>
$ gem install globalize3
</code></pre>

h2. Model translations

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

<pre><code>
class Post < ActiveRecord::Base
  translates :title, :text
end
</code></pre>

Allows you to translate the attributes :title and :text per locale:

<pre><code>
I18n.locale = :en
post.title # => Globalize3 rocks!

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

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

<pre><code>
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
</code></pre>

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

h2. Migrating existing data to and from the translated version

As well as creating a translation table, you can also use @create_translation_table!@ to migrate across any 
existing data to the default locale. This can also operate in reverse to restore any translations from the default locale 
back to the model when you don't want to use a translation table anymore using @drop_translation_table!@

This feature makes use of @untranslated_fields@ which allows access to the model's attributes as they were before
the translation was applied. Here's an example (which assumes you already have a model called @Post@ and its table exists):

<pre><code>
  class CreatePosts < ActiveRecord::Migration
    def self.up
      Post.create_translation_table!({
        :title => :string,
        :text => :text
      }, {
        :migrate_data => true
      })
    end
    def self.down
      Post.drop_translation_table! :migrate_data => true
    end
  end
</code></pre>

h2. Versioning with Globalize3

Globalize3 nicely integrates with "vestal_versions":http://github.com/laserlemon/vestal_versions:

<pre><code>
require 'globalize/versioning/vestal_versions'
</code></pre>

As of writing (2010-08-05) the original vestal_versions respository has not been updated to be compatible with Rails 3 though. You can use "this fork":http://github.com/svenfuchs/vestal_versions though. "Globalize3's Gemfile":http://github.com/svenfuchs/globalize3/blob/master/Gemfile#L10 is currently set up accordingly.

Please also note that @update_attribute@ currently hides itself from dirty tracking in ActiveRecord >= 3.0.0.beta (which is considered a "regression":http://github.com/rails/rails/commit/01629d180468049d17a8be6900e27a4f0d2b18c4#commitcomment-123199). That means that you currently need to use attribute writers or @update_attributes@ in order to track changes/versions for your models.

Also, please see the tests in test/globalize3/versioning_test.rb for some current gotchas.

h2. Changes since Globalize2

* `translation_table_name` was renamed to `translations_table_name`
* `available_locales` has been removed. please use `translated_locales`

h2. Migration from Globalize for Rails (version 1)

See this script by <NAME>: http://gist.github.com/120867

h2. Alternative Solutions

* "Veger's fork":http://github.com/veger/globalize2 - uses default AR schema for the default locale, delegates to the translations table for other locales only
* "TranslatableColumns":http://github.com/iain/translatable_columns - have multiple languages of the same attribute in a model (Iain Hecker)
* "localized_record":http://github.com/glennpow/localized_record - allows records to have localized attributes without any modifications to the database (Glenn Powell)
* "model_translations":http://github.com/janne/model_translations - Minimal implementation of Globalize2 style model translations (<NAME>)

h2. Related solutions

* "globalize2_versioning":http://github.com/joshmh/globalize2_versioning - acts_as_versioned style versioning for globalize2 (<NAME>)
* "i18n_multi_locales_validations":http://github.com/ZenCocoon/i18n_multi_locales_validations - multi-locales attributes validations to validates attributes from globalize2 translations models (<NAME>)
* "globalize2 Demo App":http://github.com/svenfuchs/globalize2-demo - demo application for globalize2 (Sven Fuchs)</li>
* "migrate_from_globalize1":http://gist.github.com/120867 - migrate model translations from Globalize1 to globalize2 (Tomasz Stachewicz)</li>
* "easy_globalize2_accessors":http://github.com/astropanic/easy_globalize2_accessors - easily access (read and write) globalize2-translated fields (astropanic, Tomasz Stachewicz)</li>
* "globalize2-easy-translate":http://github.com/bsamman/globalize2-easy-translate - adds methods to easily access or set translated attributes to your model (bsamman)</li>
* "batch_translations":http://github.com/alvarezrilla/batch_translations - allow saving multiple globalize2 translations in the same request (<NAME>)</li>

{'fraction_non_alphanumeric': 0.0866887730933207, 'fraction_numerical': 0.023211747986736146, 'mean_word_length': 5.137209302325582, 'pattern_counts': {'":': 32, '<': 73, '<?xml version=': 0, '>': 84, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2430562', 'n_tokens_mistral': 3260, 'n_tokens_neox': 3068, 'n_words': 1069}