Skip to content

Instantly share code, notes, and snippets.

@remi
Created August 22, 2012 17:27
Show Gist options
  • Save remi/3427752 to your computer and use it in GitHub Desktop.
Save remi/3427752 to your computer and use it in GitHub Desktop.
Change I18n.locale just for the time of a block
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
@ph
Copy link

ph commented Aug 23, 2012

Pourquoi tu changes kernel?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment