Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

I18n load path needs to be setup before eager loading

#6353

While running some cucumber features I came across a failing cuke that at first glance seemed to be a simple case of a missing translation. In fact, the translation was not missing at all and was rendered properly when viewing the same page in development.

I traced the issue to the fact that in certain cases, when config.cache_classes is true (e.g. in cucumber environments), eager loading of various initializers triggers loading of app models (e.g. via observers). The I18n load path is setup (e.g. config/locales/*.{rb,yml} added to it) via an after_initialize hook but in this particular case, active record models that have been loaded via eagerly loaded initializers (e.g.) and use I18n (.e.g validation messages) don't see the fully loaded load path and thus we get the missing translation issue.

In my opinion, the I18n load path setup should happen before any eager loading is done so that it's completely setup if any AR models are eagerly loaded.

Please see my pull request (https://github.com/rails/rails/pull/179) which contains both a fix and a test that fails without the fix but passes with it.

Reported by Saimon Moore · February 1st, 2011 @ 03:21 PM

State: resolved
Milestone: none
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Repository
    Repository
    • State changed from new to resolved

    (from [c2aca3ddd78b514d099ddef5afc4cee0dd7d75f2]) Ensure I18n setup is only executed once if triggered on eager loading [#6353 I18n load path needs to be setup before eager loading state:resolved]

    Signed-off-by: Santiago Pastorino santiago@wyeworks.com
    https://github.com/rails/rails/commit/c2aca3ddd78b514d099ddef5afc4c...

    February 1st, 2011 @ 05:42 PM

  2. Repository
    Repository

    (from [b1ca339b53559a71958c02644e329c714037f616]) Additionally trigger i18n configuration setup before any eager loading [#6353 I18n load path needs to be setup before eager loading state:resolved]

    This handles the case where config.cache_classes is true and classes
    are loaded before the I18n load path has had a chance to be populated.

    Signed-off-by: Santiago Pastorino santiago@wyeworks.com
    https://github.com/rails/rails/commit/b1ca339b53559a71958c02644e329...

    February 1st, 2011 @ 05:42 PM

  3. Repository
    Repository

    (from [979f38a4ff20f388bf75da2d1a3c7e76f1c82fc6]) Additionally trigger i18n configuration setup before any eager loading [#6353 I18n load path needs to be setup before eager loading state:resolved]

    This handles the case where config.cache_classes is true and classes
    are loaded before the I18n load path has had a chance to be populated.

    Signed-off-by: Santiago Pastorino santiago@wyeworks.com
    https://github.com/rails/rails/commit/979f38a4ff20f388bf75da2d1a3c7...

    February 1st, 2011 @ 05:43 PM

  4. Repository
  5. Sven Fuchs
    Sven Fuchs
    • Importance changed from to Low

    Wow, that was quick!

    I just wanted to +1 on this, but it's already applied.

    Thanks Saimon for looking into this! And thanks Santiago for acting so quickly :)

    February 2nd, 2011 @ 02:57 PM

  6. tbh
  7. Robert Pankowecki
    Robert Pankowecki

    Thank you for fixing this bug and backporting it to 3-0-stable :-)

    February 7th, 2011 @ 10:07 PM

  8. tbh
    tbh

    Has this fix made its way into 3.0.4? I just upgraded and still have problems with mixed translations due to eagerly loaded models when using cache_classes = true.

    February 16th, 2011 @ 09:51 AM