Forcing I18n locale in a block
If you work in a project with i18n maybe you found useful this small trick for forcing the locale in a block:
module I18n class << self def in_locale(new_locale, &block) old_locale = I18n.locale I18n.locale = new_locale yield I18n.locale = old_locale end end end
This is very useful, for example, when you have to send a notification to a user in his locale, not in the current locale, so you have to do it in this way:
I18n.in_locale(@user) { UserMailer.deliver_new_comment(...) }
Hope it helps.
