0

I use the helper method time_ago_in_words extensively, and it works as expected with I18n.

But in some parts of the application, I just want the default english.

Is there anyway to escape translation on selected methods/areas of an application?

Fellow Stranger
  • 32,129
  • 35
  • 168
  • 232

1 Answers1

1

You can use the I18n.with_locale method to force a block of code under a specific locale regardless the global configuration.

I18n.with_locale(:en) do
  time_ago_in_words(...)
end

If you find yourself using this pattern frequently, you can create a specific helper.

def english_time_ago_in_words(*args)
  I18n.with_locale(:en) do
    time_ago_in_words(*args)
  end
end

You can also use I18n.default_locale instead of referencing :en directly.

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364