FIX: Use correct locale when translating without cache

follow-up to 6d8eb9c1
This commit is contained in:
Gerhard Schlager 2019-06-05 14:19:46 +02:00
parent 4d1204b5e8
commit a77d8bee68
4 changed files with 19 additions and 6 deletions

View File

@ -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

View File

@ -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'

View File

@ -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}"

View File

@ -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: