Workaround for Rails i18n bug

Workaround for Rails i18n bug

Currently, there is a very annoying bug in Rails (at least in 3, dunno about 2) which completely messes up your nice i18n setup in production environments. If you have set cache_classes set to true, all i18n strings in your model classes will fall back to the default locale (EN that is) because the i18n subsystem is not yet initialized when classes are loaded eagerly.

See this bug for reference. Although it is already fixed, it seems like it did not make its way into the recent Rails 3.0.4. release. Luckily, I can present you a workaround here :)

Simply put the following in your application.rb or the respective environment configuration:

# THIS IS A WORKAROUND FOR A I18N BUG IN RAILS!
# Only required when cache_classes is set to true
# See https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6353
config.before_eager_load do
 I18n.locale = :de
 I18n.load_path += Dir[Rails.root.join('config', 'locales', 'de.yml').to_s]
 I18n.reload!
end


Über den Autor

Bewertet mit durchschnittlich
4.5
Sternen von
51
Lesern.

fortytools by zvoove für Ihre Branche

No items found.

Jetzt 30 Tage kostenlos und unverbindlich testen

Alle Funktionen stehen uneingeschränkt zur Verfügung. Keine Software-Installation, keine Probleme mit Updates. Einfach via Browser Einloggen und fertig. Von jedem internetfähigen Gerät.
Heute kostenlos testen!
Nutzerbewertung: 4,8 von 5 Sternen