Forum: Ruby on Rails Anyone got Globalize working???

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Joshua M. (Guest)
on 2006-01-18 16:22
Hi all

In another thread I complain about an error I get after trying to get
Globalize working.

http://www.ruby-forum.com/topic/51988#new

Now I want to ask you, if anybody of you has ever got Globalize working?
I have done exactly what's written in the (absolutely much too short)
tutorial of its wiki...

http://globalize.diluvia.net/wiki

...and I'm very frustrated that no even the most simple stuff is working
as promised... I have created a model Product, added the translates()
declaration, and tried to create some translated products...
After the following lines, written into the console...

  Locale.set_base_language('en-US')
  Locale.set('en-US')
  Product.create!(:name => 'Meatballs')

...I get a new row in my products table with name=0 (zero)! This can't
be valid, can it?

And after...

  Locale.set('es-ES')
  prod = Product.find(1)
  prod.name = 'Albóndigas'
  prod.save

...I get an error in the console:

>> p.save
ActiveRecord::StatementInvalid: Mysql::Error: You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near 'WHERE id = 1' at line 1:
UPDATE products SET  WHERE id = 1
        from
/Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract_adapter.rb:88:in
`log'
        from
/Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:180:in
`execute'
        from
/Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:195:in
`update'
        from
/Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:1436:in
`update_without_lock'
        from
/Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/locking.rb:45:in
`update_without_callbacks'
        from
/Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/callbacks.rb:274:in
`update_without_timestamps'
        from
/Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/timestamp.rb:39:in
`update'
        from
/Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:1431:in
`create_or_update_without_callbacks'
        from
/Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/callbacks.rb:249:in
`globalize_old_create_or_update'
        from
./script/../config/../config/../vendor/plugins/globalize/lib/globalize/localization/db_translate.rb:204:in
`create_or_update'
        from
/Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:1226:in
`save_without_validation'
        from
/Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/validations.rb:698:in
`save_without_transactions'
        from
/Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/transactions.rb:126:in
`save'
        from
/Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/transactions.rb:126:in
`transaction'
        from
/Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/transactions.rb:91:in
`transaction'
        from
/Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/transactions.rb:118:in
`transaction'
        from
/Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/transactions.rb:126:in
`save'

This ain't fun... Anyone can help me? I'd really like to get this stuff
to work... :-(

Thanks a lot,
Josh
Michael S. (Guest)
on 2006-01-18 16:35
(Received via mailing list)
Hi,

I believe you need to use "_" instead of "-" in the locale.

That would be: "en_US" or "ja_JP" which is the way they are normally
specified.

Hope that works, I haven't gotten to Rails locales yet, but will no
doubt be running into the at some point.

Cheers,
Mike

--
Mobile: +81-80-3202-2599
Office: +81-3-3395-6055

"Any sufficiently advanced technology is indistinguishable from
magic..."
                                   - A. C. Clarke
Joshua M. (Guest)
on 2006-01-18 16:37
Sadly, this isn't the case...

>> Locale.set 'en_US'
ArgumentError: bad format for en_US, not rfc-3066 compliant
        from
./script/../config/../config/../vendor/plugins/globalize/lib/globalize/localization/rfc_3066.rb:6:in
`parse'
        from
./script/../config/../config/../vendor/plugins/globalize/lib/globalize/localization/locale.rb:91:in
`initialize'
        from
./script/../config/../config/../vendor/plugins/globalize/lib/globalize/localization/locale.rb:36:in
`new'
        from
./script/../config/../config/../vendor/plugins/globalize/lib/globalize/localization/locale.rb:36:in
`set'
        from (irb):49
Keith L. (Guest)
on 2006-01-18 16:47
Michael S. wrote:
> Hi,
>
> I believe you need to use "_" instead of "-" in the locale.
>
> That would be: "en_US" or "ja_JP" which is the way they are normally
> specified.
>

Actually, the syntax that is on the wiki is to use dashes (-) and its
working for me.
I have not tried localizing variables as you describe above, but I have
successfully gotten string translation to work. The redirection to
lanquage specific files works as well. I will look at translating
variables next, and if I have any luck, post what I find.

BTW, you are right: the documentation is pretty sparse. I had to play
quite a bit and dig into the plugin code to figure out what to do. In
the end, it turned out that the documentation was correct - just not
detailed enough. For example, the web page redirection based on language
is an almost offhand comment in the docs, with no further explanation,
but as it turned out, it was correct.

Keith
Joshua M. (Guest)
on 2006-01-18 16:52
Keith L. wrote:
> BTW, you are right: the documentation is pretty sparse. I had to play
> quite a bit and dig into the plugin code to figure out what to do.

I'd be very thankful if you could give me more hints, what to do... Or
maybe you have a complete Rails test app you could send to me?
Alexandre Miguel de Andrade Souza (Guest)
on 2006-01-18 17:44
(Received via mailing list)
you can easily implement you own solution that store the translations in
a
database:

create a table with 3 fields

string
local
translation


create a function (i a php developer, so it can have others options)
that
get a string, search the table e return the value. if not found, make
the
function return the original string.
You can also make the function add the string not found to another
table,
where you register the string and the locate not translated. So you can
implement a page where you can edit the string not translated to that
language. This is specially usefull for dinamic sites, where it grows or
changes fast, and you need to use various languages, and/or if you want
you
users help to translate.


Alexandre Miguel







2006/1/18, Joshua M. <removed_email_address@domain.invalid>:
> tutorial of its wiki...
>   Product.create!(:name => 'Meatballs')
>
> /lib/active_record/connection_adapters/abstract_adapter.rb:88:in
> `update'
>         from
> /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle
> 
./script/../config/../config/../vendor/plugins/globalize/lib/globalize/localization/db_translate.rb:204:in
> `save_without_transactions'
>         from
> /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>



--
=========================
Alexandre Miguel de Andrade Souza
Visite meu blog http://alexandremas.blogspot.com/
Sobre php, linux e afins
Joshua M. (Guest)
on 2006-01-18 17:48
Thanks for this hint, Alexandre, but why should I re-implement the whole
stuff again when somebody has already done it?

Anyway, I'm really disappointed of Rails in this point... It's
discriminating for non-english website developers not to implement a
i18n into Rails...
Joshua M. (Guest)
on 2006-01-18 17:55
Btw, I tried the following expansion of Thomas F.' i18n plugin:

http://defrang.com/articles/2005/12/02/playing-wit...

Sadly, this doesn't work, either... I get the following error:

-------
SyntaxError in Products#list

(eval):11:in `class_eval': compile error
(eval):11: syntax error

      ^
-------

The error must be somewhere in the following code. Can anybody locate
it??

-------
class ActiveRecord::Base
  def self.localize(*attribute_names)
    attribute_names.each { |attribute_name|
      class_eval %{
        def _#{attribute_name}
          unless Localization.lang == :default
            localized_method =
              "#{attribute_name}_\#{Localization.lang.to_s}"
            return send(localized_method.to_sym)
              if respond_to?(localized_method)
          end
          #{attribute_name}
        end
      }
    }
  end
end
-------
Alexandre Miguel de Andrade Souza (Guest)
on 2006-01-18 17:59
(Received via mailing list)
I agree with you. I'm disappointed too, but I think its not too evil,
altough I always had to implement by my self on php. And, at least for
words, it is too simple to implement. So if you think afterall it you be
more fast to develop than using another language, make it.

Another kinds of localizations, like time, currency or metrics should be
more difficult, so it will be insteresting if they implement i18n at
core of
ruby.



Alexandre Miguel


2006/1/18, Joshua M. <removed_email_address@domain.invalid>:
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>



--
=========================
Alexandre Miguel de Andrade Souza
Visite meu blog http://alexandremas.blogspot.com/
Sobre php, linux e afins
Alex Y. (Guest)
on 2006-01-18 18:39
(Received via mailing list)
Joshua M. wrote:
> It's
> discriminating for non-english website developers not to implement a
> i18n into Rails...
Self-serving, maybe.  Discriminating?  I think not.
Rob B. (Guest)
on 2006-01-18 19:03
(Received via mailing list)
Well, in my PickAxe2 (p.547) it says that class_eval is a synonym for
Module.module_eval

Is this code in a Module?  If not, should it be?

-Rob
Charles M. Gerungan (Guest)
on 2006-01-18 19:24
(Received via mailing list)
On 18-jan-2006, at 15:52, Joshua M. wrote:

> I'd be very thankful if you could give me more hints, what to do... Or
> maybe you have a complete Rails test app you could send to me?

http://www.globalize-rails.org/wiki/pages/example

You have two wishes left.

--
Regards, Charles.
Joshua M. (Guest)
on 2006-01-18 19:30
Charles M. Gerungan wrote:
> On 18-jan-2006, at 15:52, Joshua M. wrote:
>
>> I'd be very thankful if you could give me more hints, what to do... Or
>> maybe you have a complete Rails test app you could send to me?
>
> http://www.globalize-rails.org/wiki/pages/example
>
> You have two wishes left.
>
> --
> Regards, Charles.

Thanks a lot, I will take a look at it. :-)
Joshua M. (Guest)
on 2006-01-18 20:40
Slowly but surely I think I have to be an idiot... Even this tutorial
does not work for me... I get several errors when running the tests...

chraftbuech-2:/Users/Josh/Webwork/Locomotive/globalize josh$ ruby
test/unit/new
sitem_test.rb
Loaded suite test/unit/newsitem_test
Started
EEEE
Finished in 0.099222 seconds.

  1) Error:
test_add_content_translations(NewsitemTest):
Errno::ENOENT: No such file or directory -
/Users/Josh/Webwork/Locomotive/globalize/config/../test/fixtures/globalize_countries
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:316:in
`open'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:316:in
`entries'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:316:in
`read_fixture_files'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:275:in
`initialize'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:247:in
`new'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:247:in
`create_fixtures'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:246:in
`map'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:246:in
`create_fixtures'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:244:in
`silence'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:244:in
`create_fixtures'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:540:in
`load_fixtures'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:487:in
`setup'

  2) Error:
test_add_content_translations(NewsitemTest):
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.-
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/transactions.rb:112:in
`unlock_mutex'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:509:in
`teardown'

  3) Error:
test_add_string_translations(NewsitemTest):
Errno::ENOENT: No such file or directory -
/Users/Josh/Webwork/Locomotive/globalize/config/../test/fixtures/globalize_countries
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:316:in
`open'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:316:in
`entries'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:316:in
`read_fixture_files'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:275:in
`initialize'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:247:in
`new'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:247:in
`create_fixtures'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:246:in
`map'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:246:in
`create_fixtures'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:244:in
`silence'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:244:in
`create_fixtures'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:540:in
`load_fixtures'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:487:in
`setup'

  4) Error:
test_add_string_translations(NewsitemTest):
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.-
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/transactions.rb:112:in
`unlock_mutex'
    /Applications/Locomotive/Bundles/rails-1.0.0-min.bundle/Contents/Resources/ports/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/fixtures.rb:509:in
`teardown'

2 tests, 0 assertions, 0 failures, 4 errors
Charles M. Gerungan (Guest)
on 2006-01-18 22:19
(Received via mailing list)
On 18-jan-2006, at 19:40, Joshua M. wrote:

> Slowly but surely I think I have to be an idiot... Even this tutorial
> does not work for me... I get several errors when running the tests...
>
> chraftbuech-2:/Users/Josh/Webwork/Locomotive/globalize josh$ ruby
> test/unit/new
> sitem_test.rb
> Loaded suite test/unit/newsitem_test
> Started
> EEEE
> Finished in 0.099222 seconds.

I believe this was the result of creating tables yourself instead of
using the migration and me forgetting to take the fixtures out?
Please let us know if you got it working.

--
Regards, Charles.
Joshua M. (Guest)
on 2006-01-18 22:21
Yes, it was because of the fixtures. Thanks.
This topic is locked and can not be replied to.