Created
August 22, 2012 17:27
-
-
Save remi/3427752 to your computer and use it in GitHub Desktop.
Change I18n.locale just for the time of a block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Kernel | |
# I18n.locale = :en | |
# with_locale(:fr) do | |
# I18n.localize(Time.now, :format => :long) # => "mercredi 22 août 2012 13:23" | |
# end | |
# I18n.localize(Time.now, :format => :long) # => "August 22, 2012 13:23" | |
def with_locale(locale) | |
old_locale = I18n.locale | |
I18n.locale = locale | |
capture = yield | |
I18n.locale = old_locale | |
capture | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pourquoi tu changes kernel?