FIX: Missing translation when translation override contained a %{key} (#16625)

This happened only for languages other than "en" and when `I18n.t` was called without any interpolation keys. The lib still tried to interpolate keys because it interpreted the `overrides` option as interpolation key.
This commit is contained in:
Gerhard Schlager
2022-05-04 17:35:22 +02:00
committed by GitHub
parent 9b6eea2023
commit 28e8ae553d
4 changed files with 16 additions and 0 deletions

View File

@ -221,6 +221,19 @@ describe "translate accelerator" do
override_translation('en', 'fish', 'fake fish')
expect(Fish.model_name.human).to eq('Fish')
end
it "works when the override contains an interpolation key" do
expect(I18n.t("foo_with_variable")).to eq("Foo in :en with %{variable}")
I18n.with_locale(:de) { expect(I18n.t("foo_with_variable")).to eq("Foo in :de with %{variable}") }
override_translation("en", "foo_with_variable", "Override in :en with %{variable}")
expect(I18n.t("foo_with_variable")).to eq("Override in :en with %{variable}")
I18n.with_locale(:de) { expect(I18n.t("foo_with_variable")).to eq("Foo in :de with %{variable}") }
override_translation("de", "foo_with_variable", "Override in :de with %{variable}")
expect(I18n.t("foo_with_variable")).to eq("Override in :en with %{variable}")
I18n.with_locale(:de) { expect(I18n.t("foo_with_variable")).to eq("Override in :de with %{variable}") }
end
end
context "translation precedence" do