views:

30

answers:

0

I have this in my controller:

class CoursesController < ApplicationController
  add_crumb I18n.t('courses.breadcrumbs.default'), :courses_path

  ...
end

This works fine in my development machine and using WEBrick. However, on the production server, it seems the strings are loaded only once and from the default locale.

I have a small before filter to change locale based on the request parameters. If I change the locale, lets say to "fi", everything in the views will get translated in Finnish. However, the breadcrumb text won't change.

What I'm looking for is some kind of "lazy loading" behaviour for I18n translations. It should load the translation string each time it's accessed, not only when the controller is loaded into memory. In Django, this is called "lazy translation", see: http://docs.djangoproject.com/en/dev/topics/i18n/#lazy-translation

A quick and dirty solution would be to move all calls to I18n.translate inside methods, so those would be called each time the method is being called, and thus with the correct locale. However, as I'm asking here, I'd like to know if there's a better approach to this problem?