From 89e3a8b968797569880d3e7ea37c2725eb6c80f8 Mon Sep 17 00:00:00 2001 From: Andrey Novikov Date: Wed, 13 Dec 2017 15:48:37 +0300 Subject: [PATCH] Do not overwrite available locales, append :en if needed I18n was raising an error while trying to return to the original locale in `I18n.with_locale` because that locale was excluded from the list of available locales. --- lib/evil/client/model.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/evil/client/model.rb b/lib/evil/client/model.rb index e8cfbc3..6cb0d05 100644 --- a/lib/evil/client/model.rb +++ b/lib/evil/client/model.rb @@ -113,11 +113,13 @@ def new(op = {}) private def in_english(&block) - available_locales = I18n.available_locales - I18n.available_locales = %i[en] + unless I18n.available_locales.include?(:en) + available_locales = I18n.available_locales + I18n.available_locales += %i[en] + end I18n.with_locale(:en, &block) ensure - I18n.available_locales = available_locales + I18n.available_locales = available_locales if available_locales end end end