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…
…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…
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…
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:ininitialize’
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:inset’
from (irb):49
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.
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.
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
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
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.
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.
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:inentries’
/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:ininitialize’
/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:increate_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:increate_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:increate_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:insetup’
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:inteardown’
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:inentries’
/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:ininitialize’
/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:increate_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:increate_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:increate_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:insetup’
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:inteardown’
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.