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:
parent
9b6eea2023
commit
28e8ae553d
|
@ -23,6 +23,7 @@ module I18n
|
|||
|
||||
def init_accelerator!(overrides_enabled: true)
|
||||
@overrides_enabled = overrides_enabled
|
||||
reserve_key(:overrides)
|
||||
execute_reload
|
||||
end
|
||||
|
||||
|
|
|
@ -2,3 +2,4 @@ de:
|
|||
foo: "Foo in :de"
|
||||
bar: "Bar in :de"
|
||||
wat: "Hello %{count}"
|
||||
foo_with_variable: "Foo in :de with %{variable}"
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue