Skip to content

Commit

Permalink
FIX: Use correct locale when translating without cache
Browse files Browse the repository at this point in the history
follow-up to 6d8eb9c
  • Loading branch information
gschlager committed Jun 5, 2019
1 parent 4d1204b commit a77d8be
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/freedom_patches/translate_accelerator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def translate_no_override(key, options)

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
Expand Down
13 changes: 13 additions & 0 deletions spec/components/freedom_patches/translate_accelerator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ def override_translation(locale, key, value)
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'
Expand Down
6 changes: 3 additions & 3 deletions spec/fixtures/i18n/translate_accelerator.de.yml
Original file line number Diff line number Diff line change
@@ -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}"
4 changes: 2 additions & 2 deletions spec/fixtures/i18n/translate_accelerator.en.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

1 comment on commit a77d8be

@discoursereviewbot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SamSaffron posted:

Thanks!!! 🤗 🙌 nice catch

Please sign in to comment.