A platform for community discussion. Free, open, simple.
FIX: Use correct locale when translating without cache
Gerhard Schlagera77d8bee6821
diff --git a/lib/freedom_patches/translate_accelerator.rb b/lib/freedom_patches/translate_accelerator.rbindex 7a8969d388b..7c08da42382 100644--- a/lib/freedom_patches/translate_accelerator.rb+++ b/lib/freedom_patches/translate_accelerator.rb@@ -120,7 +120,7 @@ module I18nval = @cache.getset(k) dobegin- translate_no_cache(key, raise: true).freeze+ translate_no_cache(key, locale: locale, raise: true).freezerescue I18n::MissingTranslationDataMissingTranslationenddiff --git a/spec/components/freedom_patches/translate_accelerator_spec.rb b/spec/components/freedom_patches/translate_accelerator_spec.rbindex 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" doexpect(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" dokey = 'user.email.not_allowed'text_overriden = 'foobar'diff --git a/spec/fixtures/i18n/translate_accelerator.de.yml b/spec/fixtures/i18n/translate_accelerator.de.ymlindex 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.ymlindex 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: