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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 0 deletions

View File

@ -23,6 +23,7 @@ module I18n
def init_accelerator!(overrides_enabled: true)
@overrides_enabled = overrides_enabled
reserve_key(:overrides)
execute_reload
end

View File

@ -2,3 +2,4 @@ de:
foo: "Foo in :de"
bar: "Bar in :de"
wat: "Hello %{count}"
foo_with_variable: "Foo in :de with %{variable}"

View File

@ -2,6 +2,7 @@ en:
got: "winter"
foo: "Foo in :en"
bar: "Bar in :en"
foo_with_variable: "Foo in :en with %{variable}"
wat: "Hello %{count}"
world: "Hello %{world}"
items:

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