From a77d8bee68219c8710bbe81e3860012c1a0e4b64 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Wed, 5 Jun 2019 14:19:46 +0200 Subject: [PATCH] FIX: Use correct locale when translating without cache follow-up to 6d8eb9c1 --- lib/freedom_patches/translate_accelerator.rb | 2 +- .../freedom_patches/translate_accelerator_spec.rb | 13 +++++++++++++ spec/fixtures/i18n/translate_accelerator.de.yml | 6 +++--- spec/fixtures/i18n/translate_accelerator.en.yml | 4 ++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/freedom_patches/translate_accelerator.rb b/lib/freedom_patches/translate_accelerator.rb index 7a8969d388b..7c08da42382 100644 --- a/lib/freedom_patches/translate_accelerator.rb +++ b/lib/freedom_patches/translate_accelerator.rb @@ -120,7 +120,7 @@ module I18n val = @cache.getset(k) do begin - translate_no_cache(key, raise: true).freeze + translate_no_cache(key, locale: locale, raise: true).freeze rescue I18n::MissingTranslationData MissingTranslation end diff --git a/spec/components/freedom_patches/translate_accelerator_spec.rb b/spec/components/freedom_patches/translate_accelerator_spec.rb index ea3427fb076..fc12655881d 100644 --- a/spec/components/freedom_patches/translate_accelerator_spec.rb +++ b/spec/components/freedom_patches/translate_accelerator_spec.rb @@ -33,6 +33,19 @@ describe "translate accelerator" do expect(I18n.t('i_am_an_unknown_key99')).to eq("translation missing: en_US.i_am_an_unknown_key99") end + it "returns the correct language" do + expect(I18n.t('foo', locale: :en)).to eq('Foo in :en') + expect(I18n.t('foo', locale: :de)).to eq('Foo in :de') + + I18n.with_locale(:en) do + expect(I18n.t('foo')).to eq('Foo in :en') + end + + I18n.with_locale(:de) do + expect(I18n.t('foo')).to eq('Foo in :de') + end + end + it "overrides for both string and symbol keys" do key = 'user.email.not_allowed' text_overriden = 'foobar' diff --git a/spec/fixtures/i18n/translate_accelerator.de.yml b/spec/fixtures/i18n/translate_accelerator.de.yml index c583d4b3407..8b1e01530f5 100644 --- a/spec/fixtures/i18n/translate_accelerator.de.yml +++ b/spec/fixtures/i18n/translate_accelerator.de.yml @@ -1,4 +1,4 @@ -en: - foo: 'Foo in :de' - bar: 'Bar in :de' +de: + foo: "Foo in :de" + bar: "Bar in :de" wat: "Hello %{count}" diff --git a/spec/fixtures/i18n/translate_accelerator.en.yml b/spec/fixtures/i18n/translate_accelerator.en.yml index dd2bee491f5..f80233dc69d 100644 --- a/spec/fixtures/i18n/translate_accelerator.en.yml +++ b/spec/fixtures/i18n/translate_accelerator.en.yml @@ -1,7 +1,7 @@ en: got: "winter" - foo: 'Foo in :en' - bar: 'Bar in :en' + foo: "Foo in :en" + bar: "Bar in :en" wat: "Hello %{count}" world: "Hello %{world}" items: