load_translations gone?

100 views
Skip to first unread message

Geoffroy Gomet

unread,
Oct 2, 2008, 2:59:05 PM10/2/08
to rails-i18n
Hey,

I had a (testing) Rails application working perfectly with I18n, but
since a day or two, I updated rails to the latest edge (rake
rails:freeze:edge) and my app isn't working anymore.

The error I get is "undefined method `load_translations' for
I18n:Module"

I searched a lot, but didn't find anything about load_translations
beeing removed.

Thanks in advance for the help

Geoffroy

iain hecker

unread,
Oct 2, 2008, 3:15:22 PM10/2/08
to rails-i18n
I seem to have missed that too! There hasn't been any announcement
here as far as I know.

Anyway, I did some poking around, and found that it has been replaced
with I18n.load_path, which is an array.

http://github.com/rails/rails/commit/a3b7fa78bfdc33e45e39c095b67e02d50a2c7bea

I also don't update rails very often (especially since I thought that
behavior was frozen, this is rather a big change to have happened so
recently).

Have to change my advice everywhere now.

Iain

Karel Minarik

unread,
Oct 3, 2008, 8:46:09 AM10/3/08
to rails-i18n
Hello Geoffroy,

indeed it has changed, have a look here for inspiration how to fix it:

--> http://github.com/karmi/rails_i18n_demo_app/commit/3b2d44cf52a75ae1c7fdf6feb56823a48c47abd4#diff-1

Karel

On Oct 2, 8:59 pm, Geoffroy Gomet <geoffroy.go...@gmail.com> wrote:

Edgar J. Suárez

unread,
Oct 3, 2008, 4:34:45 PM10/3/08
to rails...@googlegroups.com
It's just me or it doesn't work properly? When I start the server it doesn't loads the translations because it seems to be already initialized so when I change the locale or add a new load_path to the array, it doesn't reloads these changes.

Maybe I'm missing something but as far as I know it should works the same load_translations worked.

So I came out with this "temporary" (hopefully) solution, but I think there should be a reload method or detect whenever a new path is added or the current locale is changed and check if it is available in the load_path array.


# initializer locales.rb
I18n.default_locale = 'es-MX'

LOCALES_DIRECTORY = "#{RAILS_ROOT}/config/locales/"
LOCALES_AVAILABLE = [['English', 'en-US'], ['Español', 'es-MX']].collect { |name, code|
  I18n.load_path << "#{LOCALES_DIRECTORY}#{code}.yml"
  [name, code]
}

# Application Controller
before_filter :set_locale

protected

def available_locales
  I18n.backend.send(:translations).keys
end

def set_locale
  session[:locale] = params[:ln] if params[:ln] && LOCALES_AVAILABLE.find { |name, code|
    code == params[:ln]
  }
  I18n.locale = session[:locale] || I18n.default_locale
  I18n.backend.send(:init_translations) unless available_locales.include?(I18n.locale.to_sym)
end


On Oct 2, 2:15 pm, iain hecker <i...@iain.nl> wrote:
> I seem to have missed that too! There hasn't been any announcement
> here as far as I know.
>
> Anyway, I did some poking around, and found that it has been replaced
> with I18n.load_path, which is an array.
>

>
> I also don't update rails very often (especially since I thought that
> behavior was frozen, this is rather a big change to have happened so
> recently).
>
> Have to change my advice everywhere now.
>
> Iain
>

csbartus

unread,
Oct 24, 2008, 12:00:42 PM10/24/08
to rails-i18n
follow this topic, it solved me out, i've freezed rails today:

http://groups.google.com/group/rails-i18n/browse_thread/thread/de73dbd1309ae640

Karel Minarik

unread,
Oct 25, 2008, 4:58:22 AM10/25/08
to rails-i18n
I don't understand what precisely is the problem, Edgar, could you
elaborate?

You should use `+=` operator probably, see this:
http://github.com/karmi/rails_i18n_demo_app/tree/master/config/initializers/locales.rb#L3

Why do you think reloading locales should be neccessary? When you
restart the app, it's reloaded automatically. I can't see any reason
to add & reload locale definitions "on the fly".

Please, *do not use session for storing the locale!!!*, follow this
discussion:
http://groups.google.com/group/rails-i18n/browse_thread/thread/de73dbd1309ae640/3344e4dbcb226cdf?lnk=gst&q=restful#3344e4dbcb226cdf

[See, Sven? :) It's *unbelievable* how bad practices spread like
bushfire, while good practices freeze in hell :) I probably will set
out to fix the Clemens' demoapp myself.]

Karel

On Oct 24, 6:00 pm, csbartus <bartus.cson...@gmail.com> wrote:
> follow this topic, it solved me out, i've freezed rails today:
>
> http://groups.google.com/group/rails-i18n/browse_thread/thread/de73db...

Sven Fuchs

unread,
Oct 25, 2008, 5:44:27 AM10/25/08
to rails...@googlegroups.com
Hi Iain,

On 02.10.2008, at 21:15, iain hecker wrote:
> I seem to have missed that too! There hasn't been any announcement
> here as far as I know.

I've been pretty sure I've sent a notice to the list, but looking at
the archives I can not find anything either.

Sorry about that :(

This was the outcome of this discussion:

http://groups.google.com/group/rails-i18n/browse_thread/thread/4057b418355121ad

... as well as our work on Globalize.

It was necessary to "lazy-load" translations, i.e. to defer the actual
loading process to the latest possible point. This way you can
exchange the backend or do other interesting stuff in both plugin/init
stage and config/initializer stage ... that was not possible before
without blackmagic tricks.

Sven Fuchs

unread,
Oct 25, 2008, 5:44:30 AM10/25/08
to rails...@googlegroups.com
Hi Karel!

On 25.10.2008, at 10:58, Karel Minarik wrote:
> Why do you think reloading locales should be neccessary? When you
> restart the app, it's reloaded automatically. I can't see any reason
> to add & reload locale definitions "on the fly".

Really?

> Please, *do not use session for storing the locale!!!*, follow this
> discussion:
> http://groups.google.com/group/rails-i18n/browse_thread/thread/de73dbd1309ae640/3344e4dbcb226cdf?lnk=gst&q=restful#3344e4dbcb226cdf
>
> [See, Sven? :) It's *unbelievable* how bad practices spread like
> bushfire, while good practices freeze in hell :) I probably will set
> out to fix the Clemens' demoapp myself.]

LOL :)

I guess Clemens is currently superbusy with his thesis and stuff so he
might appreciate that a lot.

You're right we should do something about it.


Karel Minarik

unread,
Oct 25, 2008, 11:06:00 AM10/25/08
to rails-i18n
> > I can't see any reason
> > to add & reload locale definitions "on the fly".
>
> Really?

I am quite stupid generally, so yes :) What reason comes to your mind
I am not seeing?

> You're right we should do something about it.

Yes. But at this point it means to stick `I18n.locale` to every
`link_to` which isn't very convenient...

Karel
Reply all
Reply to author
Forward
0 new messages