Git Product home page Git Product logo

globalize's Introduction

Globalize

Build Status Code Climate Open Source Helpers

You can chat with us using Gitter:

Gitter chat

Globalize builds on the I18n API in Ruby on Rails to add model translations to ActiveRecord models.

In other words, a way to translate actual user-generated content, for example; a single blog post with multiple translations.

Current state of the gem

Globalize is not very actively maintained. Pull Requests are welcome, especially for compatibility with new versions of Rails, but none of the maintainers actively use Globalize anymore. If you need a more actively maintained model translation gem, we recommend checking out Mobility, a natural successor of Globalize created by Chris Salzberg (one of Globalize maintainers) and inspired by the ideas discussed around Globalize. For a more up-to-date discussion of the current situation, see issue #753.

Requirements

  • ActiveRecord >= 4.2.0 (see below for installation with ActiveRecord 3.x)
  • I18n

Installation

To install the ActiveRecord 4.2.x compatible version of Globalize with its default setup, just use:

gem install globalize

When using bundler put this in your Gemfile:

gem 'globalize', '~> 5.3.0'

Please help us by letting us know what works, and what doesn't, when using pre-release code.

Put in your Gemfile

gem 'globalize', git: 'https://github.com/globalize/globalize'
gem 'activemodel-serializers-xml'

To use the version of globalize for ActiveRecord 4.0 or 4.1, specify:

gem 'globalize', '~> 4.0.3'

To use the version of globalize for ActiveRecord 3.1 or 3.2, specify:

gem 'globalize', '~> 3.1.0'

(If you are using ActiveRecord 3.0, use version 3.0: gem 'globalize', '3.0.4'.)

The 3-1-stable branch of this repository corresponds to the latest ActiveRecord 3 version of globalize. Note that globalize3 has been deprecated and you are encouraged to update your Gemfile accordingly.

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 translate the attributes :title and :text per locale:

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

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

You can also set translations with mass-assignment by specifying the locale:

post.attributes = { title: 'גלובאלייז2 שולט!', locale: :he }

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

Note that your migrations can use create_translation_table! and drop_translation_table! only inside the up and down instance methods, respectively. You cannot use create_translation_table! and drop_translation_table! inside the change instance method.

Creating translation tables

Also note that before you can create a translation table, you have to define the translated attributes via translates in your model as shown above.

class CreatePosts < ActiveRecord::Migration
  def change
    create_table :posts do |t|
      t.timestamps
    end

    reversible do |dir|
      dir.up do
        Post.create_translation_table! :title => :string, :text => :text
      end

      dir.down do
        Post.drop_translation_table!
      end
    end
  end
end

Also, you can pass options for specific columns. Here’s an example:

class CreatePosts < ActiveRecord::Migration
  def change
    create_table :posts do |t|
      t.timestamps
    end

    reversible do |dir|
      dir.up do
        Post.create_translation_table! :title => :string,
          :text => {:type => :text, :null => false, :default => 'abc'}
      end

      dir.down do
        Post.drop_translation_table!
      end
    end
  end
end

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

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_attributes 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):

class TranslatePosts < ActiveRecord::Migration
  def change
    reversible do |dir|
      dir.up do
        Post.create_translation_table!({
          :title => :string,
          :text => :text
        }, {
          :migrate_data => true
        })
      end

      dir.down do
        Post.drop_translation_table! :migrate_data => true
      end
    end
  end
end

NOTE: Make sure you drop the translated columns from the parent table after all your data is safely migrated.

To automatically remove the translated columns from the parent table after the data migration, please use option remove_source_columns.

class TranslatePosts < ActiveRecord::Migration
  def self.up
    Post.create_translation_table!({
      :title => :string,
      :text => :text
    }, {
      :migrate_data => true,
      :remove_source_columns => true
    })
  end

  def self.down
    Post.drop_translation_table! :migrate_data => true
  end
end

In order to use a specific locale for migrated data, you can use I18n.with_locale:

    I18n.with_locale(:bo) do
      Post.create_translation_table!({
        :title => :string,
        :text => :text
      }, {
        :migrate_data => true
      })
    end

Adding additional fields to the translation table

In order to add a new field to an existing translation table, you can use add_translation_fields!:

class AddAuthorToPost < ActiveRecord::Migration
  def change
    reversible do |dir|
      dir.up do
        Post.add_translation_fields! author: :text
      end

      dir.down do
        remove_column :post_translations, :author
      end
    end
  end
end

NOTE: Remember to add the new field to the model:

translates :title, :author

Gotchas

Because globalize uses the :locale key to specify the locale during mass-assignment, you should avoid having a locale attribute on the parent model.

If you like your translated model to update if a translation changes, use the touch: true option together with translates:

  translates :name, touch: true

Known Issues

If you're getting the ActiveRecord::StatementInvalid: PG::NotNullViolation: ERROR: null value in column "column_name" violates not-null constraint error, the only known way to deal with it as of now is to remove not-null constraint for the globalized columns:

class RemoveNullConstraintsFromResourceTranslations < ActiveRecord::Migration
  def change
    change_column_null :resource_translations, :column_name, true
  end
end

Versioning with Globalize

See the globalize-versioning gem.

I18n fallbacks for empty translations

It is possible to enable fallbacks for empty translations. It will depend on the configuration setting you have set for I18n translations in your Rails config.

You can enable them by adding the next line to config/application.rb (or only config/environments/production.rb if you only want them in production)

# For version 1.1.0 and above of the `i18n` gem:
config.i18n.fallbacks = [I18n.default_locale]
# Below version 1.1.0 of the `i18n` gem:
config.i18n.fallbacks = true

By default, globalize will only use fallbacks when your translation model does not exist or the translation value for the item you've requested is nil. However it is possible to also use fallbacks for blank translations by adding :fallbacks_for_empty_translations => true to the translates method.

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

puts post.translations.inspect
# => [#<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize rocks!", name: "Globalize">,
      #<Post::Translation id: 2, post_id: 1, locale: "nl", title: '', name: nil>]

I18n.locale = :en
post.title # => 'Globalize rocks!'
post.name  # => 'Globalize'

I18n.locale = :nl
post.title # => ''
post.name  # => 'Globalize'
class Post < ActiveRecord::Base
  translates :title, :name, :fallbacks_for_empty_translations => true
end

puts post.translations.inspect
# => [#<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize rocks!", name: "Globalize">,
      #<Post::Translation id: 2, post_id: 1, locale: "nl", title: '', name: nil>]

I18n.locale = :en
post.title # => 'Globalize rocks!'
post.name  # => 'Globalize'

I18n.locale = :nl
post.title # => 'Globalize rocks!'
post.name  # => 'Globalize'

Fallback locales to each other

It is possible to setup locales to fallback to each other.

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

Globalize.fallbacks = {:en => [:en, :pl], :pl => [:pl, :en]}

I18n.locale = :en
en_post = Post.create(:title => 'en_title')

I18n.locale = :pl
pl_post = Post.create(:title => 'pl_title')
en_post.title # => 'en_title'

I18n.locale = :en
en_post.title # => 'en_title'
pl_post.title # => 'pl_title'

Scoping objects by those with translations

To only return objects that have a translation for the given locale we can use the with_translations scope. This will only return records that have a translations for the passed in locale.

Post.with_translations('en')
# => [
  #<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize rocks!", name: "Globalize">,
  #<Post::Translation id: 2, post_id: 1, locale: "nl", title: '', name: nil>
]

Post.with_translations(I18n.locale)
# => [
  #<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize rocks!", name: "Globalize">,
  #<Post::Translation id: 2, post_id: 1, locale: "nl", title: '', name: nil>
]

Post.with_translations('de')
# => []

Show different languages

In views, if there is content from different locales that you wish to display, you should use the with_locale option with a block, as below:

<% Globalize.with_locale(:en) do %>
  <%= render "my_translated_partial" %>
<% end %>

Your partial will now be rendered with the :en locale set as the current locale.

Interpolation

Globalize supports interpolation in a similar manner to I18n.

class Post < ActiveRecord::Base
  translates :title
end

I18n.locale = :en
post.title = "Globalize %{superlative}!"

post.title
# #=> "Globalize %{superlative}!"

post.title(:foo => "bar")
# SomeError: missing interpolation argument :superlative

post.title(:superlative => "rocks")
# #=> "Globalize rocks!"

Fragment caching

Don't forget to add globalize locale into the cache_key to separate different localizations of the record. One of the possible ways to implement it:

# inside translated model
def cache_key
  super + '-' + Globalize.locale.to_s
end

Thread-safety

Globalize uses request_store gem to clean up thread-global variable after every request. RequestStore includes a Railtie that will configure everything properly for Rails 3+ apps.

If you're not using Rails, you may need to consult a RequestStore's README to configure it.

Tutorials and articles

Official Globalize extensions

Alternative solutions

  • Traco - use multiple columns in the same model (Barsoom)
  • Mobility - pluggable translation framework supporting many strategies, including translatable columns, translation tables and hstore/jsonb (Chris Salzberg)
  • hstore_translate - use PostgreSQL's hstore datatype to store translations, instead of separate translation tables (Cédric Fabianski)
  • json_translate - use PostgreSQL's json/jsonb datatype to store translations, instead of separate translation tables (Cédric Fabianski)
  • Trasto - store translations directly in the model in a Postgres Hstore column

Related solutions

globalize's People

Contributors

annaswims avatar asnow avatar bramjetten avatar dalpo avatar heathd avatar henare avatar hukl avatar inukshuk avatar joshmh avatar kiliancs avatar krisdigital avatar lancedikson avatar mseppae avatar n-rodriguez avatar nabuchi avatar nobuhikosawai avatar ota42y avatar parndt avatar pixeltrix avatar pranik avatar pwim avatar robotblake avatar sedubois avatar shioyama avatar shir avatar simi avatar tekin avatar tjwallace avatar tomash avatar zencocoon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

globalize's Issues

VestalVersions

I am trying to get globalize3 working with vestal_versions. But I guess it still needs some work / love. I haven't tried to use the quite outdated vestal_version fork by Sven so far, but by looking at the source code, it seems that it requires another database column "locale" in the versions table. Unfortunately, it is nowhere mentioned. As I am working on a patch to get everything going, I just wanted to check back with the team, if my assumptions are correct?!

globalize3 not playing nice with other plugins

Hi,

I'm not quite sure what is going on but as soon as I include this gem in my app and set the migration to create the translation table all of my other plugins stop working with undefined local variable or method <plguin_name>.

class Category < ActiveRecord::Base 
  #has_friendly_id :name, :use_slug => true, :approximate_ascii => true
  acts_as_nested_set
  translates :name
end

class CreateCategories < ActiveRecord::Migration
  def self.up
    create_table :categories do |t|
      t.timestamps
    end       
  end
  def self.down
    drop_table :categories
  end
end

class AddTranslationsToCategories < ActiveRecord::Migration
  def self.up
    Category.create_translation_table!({:name => :string})
  end
  def self.down
    Category.drop_translation_table!
  end
end

If I comment out both has_friendly_id + acts_as_nested_set then it runs fine. Or if I comment out Category.create_translation_table! then this also allow my migrations run.

I had a hunt around the code, but could not see anything that might explain a clash.

Thanks in advance

"validates :column_name, :uniqueness => true" breaks in Rails 3

I use Rails 3.0.0 and Globalize3 (0.07)

Given the following class:

class Page < ActiveRecord::Base
  translates :full_path

  validates :full_path, :uniqueness => true
end

Run the following code:
page = Page.new(:full_path => "anything", :name => 'a page')
page.save => throws an exception => "NoMethodError (undefined method `text?' for nil:NilClass)"

valid? ignores new attribute values for existing record

Let's say you have this model:
class Product < ActiveRecord::Base translates :title validates :title, :presence => :true end

The attribute "title" does not actually exist in the "products" table, but exists in the "product_translations" table (I'm not sure if that matters). I am just starting out with globalize3 and don't know if this is trivial or not.

Now look at the following excerpt from rails console:
Loading development environment (Rails 3.0.9) ruby-1.9.2-p180 :001 > product = Product.first => #<Product id: 1, image_url: "/images/ruby.jpg", price: #<BigDecimal:3369a18,'0.495E2',18(18)>, created_at: "2011-03-16 10:00:03", updated_at: "2011-07-07 13:04:49"> ruby-1.9.2-p180 :002 > product.title => "Eloquency" ruby-1.9.2-p180 :003 > product.title = nil => nil ruby-1.9.2-p180 :004 > product.valid? => true ruby-1.9.2-p180 :005 > product.save => true ruby-1.9.2-p180 :006 > product.valid? => false ruby-1.9.2-p180 :007 > product.errors => {:title=>["can't be blank"]} ruby-1.9.2-p180 :008 >

The product was saved with an invalid, blank title (which should fail if you look at the validator in the model). It's as if the validator doesn't see the new title before saving it once.

When I remove globalize3 support (then I'd need to add a column called "title" to the products table as well), everything works as expected: the first product.valid? will yield false

Failing fallbacks_tests

At present, fallbacks_test never runs. If it did there would be an error that two tests have the same name. Beyond fixing that, I'm a little lost as to what needs to be updated to have the other tests pass. To get the fallbacks_test running, I put this near the top:

I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)

The reason I'm trying to get these tests passing, and understand what's going on with fallbacks, is so I can make some tweaks to better support easy_globalize_accessors (with no fallbacks, even though fallbacks are used normally).

test_resolves_a_complex_fallback_without_reloading
<"foo"> expected but was <nil>.

test_resolves_a_simple_fallback_without_reloading
<"bar"> expected but was <nil>.

Blank (nil) translations created for fallbacks

With fallbacks enabled, blank translations are created and saved to the database (despite validations).

With a Page model that translates :title,

> Globalize.locale
 => :en 

> ::I18n.fallbacks[:en] = [:en, :ru]

> p = Page.new
> p.translations
 => []

> p.title = 'test'

> p.translations
 => [#<Page::Translation id: nil, page_id: nil, locale: "en", title: nil, created_at: nil, updated_at: nil>, #<Page::Translation id: nil, page_id: nil, locale: "ru", title: nil, created_at: nil, updated_at: nil>] 

> p.save

> p.translations
[#<Page::Translation id: 31, page_id: 15, locale: "en", title: nil, created_at: "2011-09-12 10:38:20", updated_at: "2011-09-12 10:38:20">, #<Page::Translation id: 32, page_id: 15, locale: "ru", title: nil, created_at: "2011-09-12 10:38:20", updated_at: "2011-09-12 10:38:20">]

> p.translations.length
 => 2

globalize3 translates original table fields

How do we not translate the original table but only the translation table? The translation works nicely but however it updates the original table as well which I do not want to happen.

SOLVED Quering on a model with translated attributes

Hi!

How can I query a model where an attribute is translated with globalize3. I have for example this line, and the attribute name is in the country_translations table:

I18n.locale = :de
@countries = Country.scoped
@countries.where(:name => '[Some country name]')

This gives me an error: ActiveRecord::StatementInvalid (No attribute named name exists for table countries): ...

Thx

destroy raises error (undefined method to_ary) on ActiveRecord 3.0.0.rc and ruby 1.9.2

I got this error using my own branch of globalize2, but it is also present on your branch (i don't consider mine to be serious, so i believe it will have more visibility here :D)

The problem is that ruby 1.9.2 changes the behavior of method_missing, and for some reason it raises the undefined method error to_ary when trying to destroy a record that has a translation.

Steps to reproduce are:
switch to ruby 1.9.2.rc2 (haven't tested in other 1.9.2 versions, but i believe the error will persist)
rails new ary_error
edit Gemfile, add gem 'globalize3', and change sqlite3 to some other database (the problem also occurs in sqlite3, but it is less verbosive, it just states 'SQLite3::SQLException: cannot rollback - no transaction is active')
rails g model Post title:string
edit app/models/post.rb and add 'translates :body'
edit db/migrate/xxxxxxx_create_posts.rb and add 'Post.create_translation_table! :body=>:text'
rake db:migrate
rails c
Post.create title: 'Destroy doesnt works', body: 'When there is a translation it raises error on destroy'
Post.first.destroy #=> NameError: undefined local variable or method `to_ary' for #<Post...>

I belive this error is related to what Yehuda Kats wrote in http://yehudakatz.com/2010/01/02/the-craziest-fing-bug-ive-ever-seen/.

One very stupid way to get rid of this error is to define the method to_ary on ActiveRecord, but i believe that something related to method_missing would be a better solution. I don't have much time right now to fix this the right way so i probably will be doing the stupid fix on my branch for now :p

find_or_create_by doesn't work

Got "find_or_create_by_" method not working after adding globalize3 in my app. Tried it in console, and noticed, that it just creates SELECT query, but dont insert anything.

Rails 3.0.5 deprecated '&' method for merging relation's.

DEPRECATION WARNING: Using & to merge relations has been deprecated and will be removed in Rails 3.1. Please use the relation's merge method, instead. (called from with_locales at /home/rupert/.rvm/gems/ruby-1.9.2-p136/bundler/gems/globalize3-30c19227ddc8/lib/globalize/active_record/class_methods.rb:7)

Remote => true causing some problems with globalize3

Here's a strange problem!

When i use remote => true on a form, the update to my model is done first and then the rendering of the view starts before the translations are copied over to the translation database...

The final effect is that i only see the latest values after a page refresh (defeats the purpose of a ajax call).

Any idea on how to resolve that? Thanks!

Example:

 View:
   form_for @example, :remote => true
   value_changed = something_new   

 Controller:
  @example.update_attributes(params[:example])
   render :js => "alert(#{@example.value_changed})

 Ouput:
   value_changed = old_value

Sorting the results by the data in translation table...

I am not even sure, if this functionality was even ment to be implemented, but the lack of it really hurts... I want to fetch the result from the table ordered by the data contained in the table, which is translated by Globalize3. The problem is, that the .where clause is translated directly into SQL, so if the original field is present, the results are simply unsorted. If the translated field is not present in the model, then the query throws the error.

Is there any resonable solution to this problem?

Why is original table's column set to current locale's translation?

When I set a translated column of a model, its original column is also set.
This seems not neccessary to me. Is there any reason why it is done?

Example:

ruby-1.9.2-p290 > I18n.locale = :'de-CH'
=> :"de-CH" 

ruby-1.9.2-p290 > j = Job.find 1138
=> #<Job id: 1138, name: "Job Name", ...

ruby-1.9.2-p290 > j.name = 'Test de-ch'
 => "Test de-ch" 

ruby-1.9.2-p290 > j.save!
   (0.2ms)  BEGIN
   (0.6ms)  UPDATE "jobs" SET "name" = 'Test de-ch', "updated_at" = '2011-10-27 06:14:25.613120' WHERE "jobs"."id" = 1138
  Job::Translation Load (0.5ms)  SELECT "job_translations".* FROM "job_translations" WHERE "job_translations"."job_id" = 1138 AND "job_translations"."locale" = 'de-CH' LIMIT 1
   (0.7ms)  UPDATE "job_translations" SET "name" = 'Test de-ch', "updated_at" = '2011-10-27 06:14:25.621191' WHERE "job_translations"."id" = 137
  Job::Translation Load (0.4ms)  SELECT "job_translations".* FROM "job_translations" WHERE "job_translations"."id" = $1 LIMIT 1  [["id", 1625]]
  Job::Translation Load (0.2ms)  SELECT "job_translations".* FROM "job_translations" WHERE "job_translations"."id" = $1 LIMIT 1  [["id", 1624]]
  Job::Translation Load (0.2ms)  SELECT "job_translations".* FROM "job_translations" WHERE "job_translations"."id" = $1 LIMIT 1  [["id", 137]]
   (1.1ms)  COMMIT
 => true 

Database level unique constraint on "translated" column

I just integrated Globalize3 in my application after first trying to write my own multi-language active record implementation and I have to say that I am very impressed and pleased with the ease of use and the results.

I am however, running into a single problem with this: What if I have a column that I want both to be translated, and want to use in a database unique constraint?

For example, I want this index:

add_index :pages, [:name, :website_id, :parent_id], unique: true

I had this working in an older version of my app, but now I am stuck with the fact that I wanted to make name localized, and thus added it to the Globalize3 translates method, but now this column no longer exists in the table and I can't force the uniqueness on this.

Any workaround for this? I can obviously still use the Rails validates method (although there are some issues with that, see #7), but it's always best to enforce uniqueness on a database level as well, just in case something slips through the rails code.

Any thoughts on this?

New rails migration does not have self.up and self.down

Not user if this is a issue, feel free to ignore/close if not the right place.

New version of rails (not sure before, but 3.1.0.rc5 does) generate the migrations this way:

class CreatePosts < ActiveRecord::Migration
  def change
    create_table :posts do |t|
      t.timestamps
    end
  end
end

I cannot understand how to use globalize3 in

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

Is it enough (and right) to add self.up and self.down after the change?

0.2.0.beta4 inserts translation with null values before updating

Whereas 0.1.0 inserts a translation with the correct values, the newer version first inserts a translation with null values and then updates that translation with its proper values.

This stops me from disallowing null values for a translation field that shouldn't have null values.

Is this the intended behaviour?

Example below:

class Thing < ActiveRecord::Base
  translates :name
end

config.i18n.fallbacks = { :fr => :en }

Thing.create! :name => 'cat'

Rails 3.0.10
Globalize3 0.2.0.beta4

SQL (0.1ms)  BEGIN
SQL (0.2ms)  SHOW TABLES
SQL (0.6ms)  describe `things`
AREL (0.1ms)  INSERT INTO `things` (`updated_at`, `created_at`) VALUES ('2011-10-21 00:11:13', '2011-10-21 00:11:13')
SQL (0.6ms)  describe `thing_translations`
AREL (0.2ms)  INSERT INTO `thing_translations` (`updated_at`, `text`, `locale`, `thing_id`, `created_at`, `name`) VALUES ('2011-10-21 00:11:13', NULL, 'en', 1, '2011-10-21 00:11:13', NULL)
Thing::Translation Load (0.2ms)  SELECT `thing_translations`.* FROM `thing_translations` WHERE `thing_translations`.`locale` = 'en' AND (`thing_translations`.thing_id = 1) LIMIT 1
AREL (0.1ms)  UPDATE `thing_translations` SET `updated_at` = '2011-10-21 00:11:13', `name` = 'cat' WHERE `thing_translations`.`id` = 1
Thing::Translation Load (0.1ms)  SELECT `thing_translations`.* FROM `thing_translations` WHERE `thing_translations`.`id` = 1 LIMIT 1
Thing::Translation Load (0.1ms)  SELECT `thing_translations`.* FROM `thing_translations` WHERE (`thing_translations`.thing_id = 1)
SQL (0.3ms)  COMMIT

Rails 3.0.10
Globalize3 0.1.0

SQL (0.1ms)  BEGIN
  AREL (0.2ms)  INSERT INTO `things` (`updated_at`, `created_at`) VALUES ('2011-10-21 00:13:41', '2011-10-21 00:13:41')
  Thing::Translation Load (0.2ms)  SELECT `thing_translations`.* FROM `thing_translations` WHERE `thing_translations`.`locale` = 'en' AND (`thing_translations`.thing_id = 3) LIMIT 1
  AREL (0.1ms)  INSERT INTO `thing_translations` (`text`, `locale`, `created_at`, `updated_at`, `name`, `thing_id`) VALUES (NULL, 'en', '2011-10-21 00:13:41', '2011-10-21 00:13:41', 'cat', 3)
  Thing::Translation Load (0.2ms)  SELECT `thing_translations`.* FROM `thing_translations` WHERE (`thing_translations`.thing_id = 3)
  SQL (0.3ms)  COMMIT

Add locale index to translation tables

Looks like translation tables miss index on "locale" field. This causes a big slow-down on large translation tables (have over 1 second query on DB with 30k records) in Globalize::ActiveRecord::Translation.translated_locales function call (SELECT DISTINCT locale). MySQL EXPLAIN command says "Using temporary" on this query, what is definitely bad. Adding index to "locale" fixes this issue. This should be added to migration.rb.

migrate data with table name different from the model

Greetings. I've got some legacy code. Now I try to migrate existed data from model to translations table.
I have following model:

class NewsItem < ActiveRecord::Base
  translates :title, :content
  set_table_name "news"
end

How I write migration:

  NewsItem.create_translation_table!({}, { :migrate_data => true })

Then I running migration I've get following error:

==  CreateGlobalize3Tables: migrating ====================================
rake aborted!
An error has occurred, all later migrations canceled:

Mysql2::Error: Unknown column 'news_item_translations.news_item_id' in 'where clause': SELECT `news_item_translations`.* FROM `news_item_translations` WHERE (`news_item_translations`.news_item_id = 2)

The table was created with name news_item_translations

mysql> describe news_item_translations;
+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int(11)      | NO   | PRI | NULL    | auto_increment |
| news_id    | int(11)      | YES  |     | NULL    |                |
| locale     | varchar(255) | YES  |     | NULL    |                |

with field news_id

serialized attribute

Hi,

I was trying to translate with globalize3 serialized attribute. After small research I realized it is impossible. My proposition is to consider to add this functionality to globalize3.

Thanks!

Loading model's record (and using puts on it) loads associated translation record 3-4 times

So I'm trying to figure out scaling aspects of our application when I stumbled across this:

> Page.where(:id => 1)
=> [#<Page id: 1, ...>]

Seems normal.... but then I looked in the log:

Page Load (0.3ms)  SELECT `pages`.* FROM `pages` WHERE `pages`.`id` = 1
  Page::Translation Load (0.3ms)  SELECT `page_translations`.* FROM `page_translations` WHERE `page_translations`.`locale` IN ('en') AND (`page_translations`.page_id = 1)
  Page::Translation Load (0.4ms)  SELECT `page_translations`.* FROM `page_translations` WHERE `page_translations`.`locale` IN ('en') AND (`page_translations`.page_id = 1)
  Page::Translation Load (0.3ms)  SELECT `page_translations`.* FROM `page_translations` WHERE `page_translations`.`locale` IN ('en') AND (`page_translations`.page_id = 1)
  Page::Translation Load (0.3ms)  SELECT `page_translations`.* FROM `page_translations` WHERE `page_translations`.`locale` IN ('en') AND (`page_translations`.page_id = 1)

So it seems it's loading the translations 4 times for that one simple query (and I gutted the model to ensure it was really globalize3)

The relevant line in globalize3 seems to be in read_attribute here: https://github.com/svenfuchs/globalize3/blob/master/lib/globalize/active_record/instance_methods.rb#L52

If I change this line to super(name) then the issue goes away (but of course, no translated data anymore).

find_by_(translated attribute) returns array

the find_by_* dynamic finder for standard active_record attributes returns a single object, so should find_by_* for translated attributes, or did i miss something?

i realize that changing this behavior now will probably break a lot of apps, but its worth pointing out.

use of Faker to populate data doesn't add anything to _translations

I'm trying to get Globalize3 working for first time.

I've specified the attributes I want translated in my model and also added the necessary stuff to my create table migration

https://gist.github.com/924892

However, when I run my Faker script to "rake db:populate", nothing gets inserted into products_translations. Instead all the records are inserted into products table. What am I missing here?

FWIW, I'm using 0.1.0.beta.

Your help is greatly appreciated

private method `gsub' called for nil:NilClass

HI, I have just installed the gem and tried to add translation table for one of my existing tables, I just followed the instructions in the gem description, so to migrate data I added :migrate_data => true

class CreateContentTranslationTable < ActiveRecord::Migration
def self.up
Content.create_translation_table!({:title => :string, :description => :text, :text => :text}, {:migrate_data => true})
end

def self.down
Content.drop_translation_table! :migrate_data => true
end
end

and when I try 'rake db:migrate' I get error
private method `gsub' called for nil:NilClass

I tried to add some kind of workaround and added to migration

Content.all.each do |c|
c.connection.execute("insert into content_translations (locale, title, text) values ('en', '#{c.title}', '#{c.text}')")
end

but then realized that c.title and c.text in this case returns translated value which is nil, thus I have table with blank values
And I could not find how to get value of translated field from origin table, is it possible?

Thanks for any help

Cannot fetch model after translating it via create_translation_table! migrate_data: true

I just translated a model called "Content". When I do Content.first I get a stack level too deep error as globalize seems to try to fetch the same translated instance over and over again:

Content.first
  Content Load (0.8ms)  SELECT "contents".* FROM "contents" LIMIT 1
  Content::Translation Load (0.6ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.6ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.5ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.6ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.7ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.5ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.7ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.5ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.5ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.5ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.5ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.5ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.5ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.9ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.6ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.5ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.5ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.8ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.6ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.5ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.5ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.5ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.5ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.5ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.5ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.5ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.5ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.5ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.5ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.5ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.6ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.7ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.6ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.6ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.5ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.5ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.5ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.5ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.5ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.5ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.9ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.6ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.6ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.5ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
  Content::Translation Load (0.5ms)  SELECT "content_translations".* FROM "content_translations" WHERE "content_translations"."content_id" = 3
  Content Load (0.5ms)  SELECT "contents".* FROM "contents" WHERE "contents"."id" = 3 LIMIT 1
....
many more of the above
....
SystemStackError: stack level too deep
    from /Users/nico/.rvm/gems/ruby-1.9.2-p290/gems/arel-2.2.1/lib/arel/visitors/to_sql.rb:100

Im using Rails 3.1.0 with Ruby 1.9.2-p290 and the latest globalize3 gem from github.

data migration to translation table slow for complex models

I noticed when using the migrate_data option, my migrations became horribly slow (speaking about hours for a couple of hundred records ;-). I found out that the cause was the data migration that caused reassignment of all model attributes, triggering some complex overwritten setters and getters.

I refactored the move_data_to_translation_table method to hopefully be much faster now:

def move_data_to_translation_table
  model.find_each do |record|
    translation = record.translations.build(:locale => I18n.default_locale)
    translated_attribute_names.each do |attribute|
      translation[attribute] = record[attribute]
    end
    translation.save!
  end
end

Any issues with this? Otherwise I could supply a pull request, just need to figure out, why I can't get the globalize3 tests running so far - I get 33 errors. Do I have anything else todo besides running bundle?

Multiple calls to translates method

I gather that translates is only meant to be called once. Just wondering what your thoughts are on allowing it to be called multiple times so that more translatable attributes can be added in mixins.

Model's reload method doesn't work properly anymore with globalize

Since using globalize, the reload method of a model seems to not work properly anymore.
I discovered this in a failing functional test:

# new_forum.name is 'test'
put :update, :id => new_forum.id, :forum => { :name => 'updated', :description => 'test' }

new_forum.reload
assert_equal 'updated', new_forum.name
Failure:
<"updated">("US-ASCII") expected but was
<"test">("UTF-8").

Now I have to do

put :update, :id => new_forum.id, :forum => { :name => 'updated', :description => 'test' }

new_forum = Forum.find new_forum.id 
assert_equal 'updated', new_forum.name

to get the test passing.

Model.create_translation_table! with migrate_data is not working

I create a migration like:

Category.create_translation_table!({:name => :string}, :migrate_data => true)

But when running rake db:migrate, it only creates the category_translations table, without any data, and the original categories table still has the name field populated.

Also, when fetching a Category, the name attribute is nil

What can this be related to?

I'm using Rails 3.0.3, Ruby 1.9.2-p0 on Ubuntu 10.10

globalize3 conflicting with i18n database backend

the problem seems to come from globalize3 defining Translation model (and #translations association proxy for globalize3-translated classes), while we have this model already for I18n AR backend (according to guide)

here's some gist:
https://gist.github.com/706344

proposed solutions:

  1. instead of Translation/translations use Globalize/globalizations (Localization/localizations) by globalize3
  2. change I18n guides to advise AGAINST naming i18n translations model "Translation"

Travis-ci all tests red?

I noticed a commit adding this gem to the Travis-ci, so I went there looking at the current status (there isn't a Travis-ci badge in the readme yet). I noticed all tests shown as red, with quite a few errors. Is there anything wrong with Travis, or is the beta3 build extremely broken?

edit actually it seems the tests refer to sprockets as being broken. Not sure how this is related to globalize3, and I am not really familiar yet with Travis and how their system works, but I think it's safe to assume this is not related to globalize3 after all.

edit 2 never mind. Not sure what happened, but I clicked the globalize3 item in the list and it sent me to the sprockets page, after realizing this I tried again and I now see the globalize3 gem shown as green. My bad.

undefined method `translates` for with rails 3

Hi ! I have installed the globalize3 gem and added the translates method in my model and when I run rake db:migrate , here what I get :

undefined method translates' for #<Class:0xa988b90> /home/dupereg/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.5/lib/active_record/base.rb:1008:inmethod_missing'
/home/dupereg/rails_projects/antiquaire/app/models/product.rb:2:in <class:Product>' /home/dupereg/rails_projects/antiquaire/app/models/product.rb:1:in<top (required)>'

Model file :
class Product < ActiveRecord::Base
translates :title, :text
attr_accessor :description , :category , :country , :material, :style

  validates :description, :presence => true      

end

Migration file :

class AddNameToProducts < ActiveRecord::Migration
def self.up
Product.create_translation_table! :title => :string, :text => :text
end
def self.down
Product.drop_translation_table!
end

end

thanks

Here's the gems I have :

*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.5, 3.0.3, 3.0.1)
actionpack (3.0.5, 3.0.3, 3.0.1)
activemodel (3.0.5, 3.0.3, 3.0.1)
activerecord (3.0.5, 3.0.3, 3.0.1)
activeresource (3.0.5, 3.0.3, 3.0.1)
activesupport (3.0.5, 3.0.3, 3.0.1)
annotate-models (1.0.4)
arel (2.0.9, 2.0.4, 2.0.3, 1.0.1)
builder (2.1.2)
bundler (1.0.7, 1.0.6)
cucumber (0.10.0)
diff-lcs (1.1.2)
erubis (2.6.6)
gherkin (2.3.2)
globalize3 (0.0.11)
i18n (0.5.0, 0.4.2)
json (1.4.6)
mail (2.2.15, 2.2.10)
mime-types (1.16)
mysql (2.8.1)
mysql2 (0.2.6)
nokogiri (1.4.4)
polyglot (0.3.1)
rack (1.2.2, 1.2.1)
rack-mount (0.6.14, 0.6.13)
rack-test (0.5.7, 0.5.6)
rails (3.0.5, 3.0.3, 3.0.1)
railties (3.0.5, 3.0.3, 3.0.1)
rake (0.8.7)
rspec (2.5.0, 2.0.1)
rspec-core (2.5.1, 2.0.1)
rspec-expectations (2.5.0, 2.0.1)
rspec-mocks (2.5.0, 2.0.1)
rspec-rails (2.5.0, 2.0.1)
sqlite3 (1.3.3)
sqlite3-ruby (1.3.2, 1.2.5)
term-ansicolor (1.0.5)
thor (0.14.6, 0.14.4)
treetop (1.4.9)
tzinfo (0.3.25, 0.3.23)
webrat (0.7.1)

Update specific translation

Hi
For now it seems that to update specific translation I have to switch to that locale first but it doesn't make a lot of sense to me, I would prefer having some drop down where I could select a language and type some text and that would save translation with correct locale without being switched to that locale. I found some plugin but in some cases it doesn't work for me. So I'm wandering is there any ability to manually update translations or set locale for particular object while creating new record?

something like this

product = Product.new(some_params)
product.locale = :ua
product.save

and that would create new Product with data with :ua locale.

Thanks for any help!

undefined method `create_translation_table!' on migration

Hi!

I use rails 3.0.3 and globalize3 as plugin. If I start rake:db:migrate:reset RAILS_ENV="production" on the production environment then a migration with code:

class AddTranslationToUser < ActiveRecord::Migration
  def self.up
    User.create_translation_table!({
      :name => :string
    }, {
      :migrate_data => true
    })
    remove_column :users, :name
  end
  ...
end

gives me this error "undefined method `create_translation_table!' for ..." Why? The plugin is present in the vendor/plugins dir! On the development environment all works fine!

How to acces localized attributes directly?

Not really a bug mor a configuration problem probably. But I'm totally lost and would very much appreciate any help.
I must have read somewhere that I can access the localized versions of attributes directly by calling f.e. name_en, name_de etc.
I used this in a view where I would put the different translations for each language.

Now I have the problem that it works on my dev system but not on my production system (heroku) where it says, "undefined method name_de".
Trying around with my dev system I found that I can't set name_fr, _es there either. But _en and _de works (on dev). Any idea how that happened. I guess I must have screwed the configuration somehow, but I can't find anything for I18n or globalie where to set which languages are "allowed"?
If there's another way to access localized attributes directly like say name.locale[:de] it would solve my problem too I guess.

find_first_by_translated_attribute doesn't work

I use rails 3.0.0 and globalize3 0.0.7.

Given the following ActiveRecord class:
class Page < ActiveRecord::Base
translates :full_path
end

Page.with_locales(:de).find_by_full_path 'deutsch_1/deutsch_1_2' 

=> works

Page.with_locales(:de).find_first_by_full_path 'deutsch_1/deutsch_1_2'

=> throws an error:
=> NoMethodError: undefined method `find_first_by_full_path' for #ActiveRecord::Relation:0x0000000361bf68

The issue:
module Globalize
module ActiveRecord
module ClassMethods
def respond_to?(method, *args, &block)
method.to_s =~ /^find_by_(\w+)$/ && translated?($1.to_sym) || super
# should be same code like in method_missing
method.to_s =~ /^find_(first_|)by_(\w+)$/ && translated?($2.to_sym) || super
end

      def method_missing(method, *args)
        if method.to_s =~ /^find_(first_|)by_(\w+)$/ && translated?($2.to_sym)
          result = with_translated_attribute($2, args.first)
          $1 == 'first_' ? result.first : result.all
        else
          super
        end
      end
    end
  end
end

globalize3 breaks permalink_fu

Hi,

i'm using rails3, globalize3 & permalink_fu.

When using globalize3 with permalink_fu, i've a problem :

If I create a first entry named "Test", it takes "test" as a permalink

But then, when i create a second entry named "Test", it stills takes the "test" permalink while it should be "test-2"

I know that's maybe a permalink_fu related issue but as it only occurs when I put "translates :name" in my model, i'm posting it here.

I you have any idea about this issue, it would be really great !

No queries in default_locale (strings) anymore?

Hey,

I've been using globalize2 which supoorted e.g.
Attribute.find_by_name("Experience")
even though the current language was Spanish, German or whatever but not English (default_locale was :en though)

But now I can only use
Attribute.find_by_name("Experience")
when English is the active language and it doesn't find anything in any other language, which would make me use
Attribute.find_by_name("Erfahrung") for German
or
Attribute.find_by_name("Experiencia") for Spanish
which sucks. I can't really use id's because I don't know them so my question is if it's possible to still use one single language for queries with no effect for the actual output in a different language?

Select only translated rows

Hello. I need to select only news, that are translated into current locale. But I don't know how to do that. I read some code and found with_locales method. But it is not working :(

https://gist.github.com/886918

Is now possible to select only translated rows from DB ?

using where on a translated attribute

I was wondering if the solution provided in issue #34 is still the best way to query a table on a translated attribute.

For example, I wanted to do this:

Page.where(name: "homepage")

But it results in:

1.9.3 (main):0 > Page.where(name: "homepage")
  Page Load (0.6ms)  SELECT "pages".* FROM "pages" WHERE "pages"."name" = 'homepage'
=> []

So the query doesn't error out, as was said in issue #34, but it also doesn't return any records.

Using the solution in that thread worked, but I am starting to wonder what else could go wrong in my code, if all the where queries will go wrong when not using includes, especially for gems and other plugins that query on translated attributes...

1.9.3 (main):0 > Page.includes(:translations).where("page_translations.name" => "vixia")

  SQL (0.7ms)  SELECT "pages"."id" AS t0_r0, "pages"."published" AS t0_r1, "pages"."position" AS t0_r2, "pages"."ancestry" AS t0_r3, "pages"."ancestry_depth" AS t0_r4, "pages"."user_style_id" AS t0_r5, "pages"."theme_id" AS t0_r6, "pages"."website_id" AS t0_r7, "pages"."created_at" AS t0_r8, "pages"."updated_at" AS t0_r9,
"page_translations"."id" AS t1_r0, "page_translations"."page_id" AS t1_r1, "page_translations"."locale" AS t1_r2, "page_translations"."name" AS t1_r3, "page_translations"."cached_slug" AS t1_r4, "page_translations"."created_at" AS t1_r5, "page_translations"."updated_at" AS t1_r6 FROM "pages" LEFT OUTER JOIN "page_translations" ON "page_translations"."page_id" = "pages"."id" WHERE "page_translations"."name" = 'vixia'
+----+-----------+----------+----------+----------------+---------------+----------+------------+-------------------------+-------------------------+-------+-------------+
| id | published | position | ancestry | ancestry_depth | user_style_id | theme_id | website_id | created_at              | updated_at              | name  | cached_slug |
+----+-----------+----------+----------+----------------+---------------+----------+------------+-------------------------+-------------------------+-------+-------------+
| 3  | true      | 7340032  | 2        | 1              |               | 3        | 1          | 2011-09-27 10:22:58 UTC | 2011-09-27 12:14:34 UTC | vixia | vixia       |
+----+-----------+----------+----------+----------------+---------------+----------+------------+-------------------------+-------------------------+-------+-------------+
1 row in set

The funny thing is, that the find_by accessors do work with the translated attributes, just not the where queries (but I am sure there is a perfectly good reason for this).

:migrate_data => true does not work ?

Using rails: 3.05 and globalize3 0.0.11 ( also tried 0.1.0.beta, and some older versions just in case)

I never get any migrated data in the new table.. e.g
Post.create_translation_table!({
:name => :string
}, {
:migrate_data => true
})

E.g all the previous :name entries in Post do not migrate over. HOWEVER, the reverse does work (e.g when I run:
Post.drop_translation_table! :migrate_data => true

new data migrates back.

I even installed a fresh app to test this, as I thought I may have some settings issue, but the same issue with a clean new rails app.

With globalize3 0.0.11 - the migration succeeds, just no data copies over.
With 0.1.0.beta - migration fails with "Validation failed: Name can't be blank" ... It actually attempts to migrate the data at least, but then doesn't copy the action migrated field ?

Any help appreciates.

Fallbacks + multiple languages on form

Problem starts while using nested hashes to create new translations. In my project I'm using batch_translate plugin to have multiple forms for different languages.This creates this kind of hash on submit

"params"=>{"translations_attributes"=>{"1"=>{"id"=>"", "locale"=>"pl", "name"=>"asdas", "description"=>"sth"}, "2"=> {"id"=>"", "locale"=>"en", "name"=>"", "description"=>""}} }

After submiting this form I have an AR error that my name and description cant be blank. I assume its the nested hash fault.

failed to migrate

I've just installed globalize3 gem (rails v3.0.9), added translation helper method to my model and modified migration. But when I try to migrate database it fails to to that with notice:

rake aborted!
An error has occurred, this and all later migrations canceld:

undifined method 'translates' for #Class:0x12345

Just dont get it why

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.