Friday, 20 August 2010

i18n in rails 3

Well it's been a long time, but I'm going to make an effort to do more blogging now that rails 3 is almost here - partly to keep track of what I need to remember - but also because it might be useful to others.

I'm upgrading a big app to rails 3 before we go live with it - and of course there are a few glitches. Mostly these are to do with gems and plugins that don't work - more on them when I get to them. But the first big hiccup was internationalization. The app I'm upgrading is fully internationalized - but when I got the front page up i got things like

translation missing: 'en'::character varying, devise, sessions, user, signed_in

instead of the nice translations i was expecting.

The cause seems to lie in the I18n gem - where it gets the configuration object


class << self
# Gets I18n configuration object.
def config
Thread.current[:i18n_config] ||= I18n::Config.new
end


I patched this by dropping a file in the lib directory and requiring it from application.rb

module I18n
class << self
def config
# don't pick up the config object from the current thread -
# it returns 'en'::character varying
I18n::Config.new
end
end
end



My guess is that this might slow things down a touch - creating a new config object instead of using an existing one - but it works for me so far

No comments: