FIX: Use correct locale when translating without cache

FIX: Use correct locale when translating without cache

follow-up to 6d8eb9c1

diff --git a/lib/freedom_patches/translate_accelerator.rb b/lib/freedom_patches/translate_accelerator.rb
index 7a8969d..7c08da4 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 ea3427f..fc12655 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 c583d4b..8b1e015 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 dd2bee4..f80233d 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:

GitHub sha: a77d8bee

3 Likes

Thanks!!! :hugs: :raised_hands: nice catch

3 Likes