A platform for community discussion. Free, open, simple.
FIX: Missing translation when translation override contained a `%{key}` (#16625)
Gerhard Schlager28e8ae553d11
diff --git a/lib/freedom_patches/translate_accelerator.rb b/lib/freedom_patches/translate_accelerator.rbindex d776670064b..9fc7bf77493 100644--- a/lib/freedom_patches/translate_accelerator.rb+++ b/lib/freedom_patches/translate_accelerator.rb@@ -23,6 +23,7 @@ module I18ndef init_accelerator!(overrides_enabled: true)@overrides_enabled = overrides_enabled+ reserve_key(:overrides)execute_reloadenddiff --git a/spec/fixtures/i18n/translate_accelerator.de.yml b/spec/fixtures/i18n/translate_accelerator.de.ymlindex 8b1e01530f5..e33cdc96b11 100644--- a/spec/fixtures/i18n/translate_accelerator.de.yml+++ b/spec/fixtures/i18n/translate_accelerator.de.yml@@ -2,3 +2,4 @@ de:foo: "Foo in :de"bar: "Bar in :de"wat: "Hello %{count}"+ foo_with_variable: "Foo in :de with %{variable}"diff --git a/spec/fixtures/i18n/translate_accelerator.en.yml b/spec/fixtures/i18n/translate_accelerator.en.ymlindex f80233dc69d..ebffeb50b30 100644--- a/spec/fixtures/i18n/translate_accelerator.en.yml+++ b/spec/fixtures/i18n/translate_accelerator.en.yml@@ -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:diff --git a/spec/lib/freedom_patches/translate_accelerator_spec.rb b/spec/lib/freedom_patches/translate_accelerator_spec.rbindex c85f0ae5ff7..f6c67c7878f 100644--- a/spec/lib/freedom_patches/translate_accelerator_spec.rb+++ b/spec/lib/freedom_patches/translate_accelerator_spec.rb@@ -221,6 +221,19 @@ describe "translate accelerator" dooverride_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}") }+ endendcontext "translation precedence" do