A platform for community discussion. Free, open, simple.
DEV: Refactor translation overrides a bit (#28125)
Loïc Guitaut1f5cbb9a44e7
diff --git a/app/models/translation_override.rb b/app/models/translation_override.rbindex e2d74796429..3ded31ce20d 100644--- a/app/models/translation_override.rb+++ b/app/models/translation_override.rb@@ -50,13 +50,11 @@ class TranslationOverride < ActiveRecord::Baseenum status: { up_to_date: 0, outdated: 1, invalid_interpolation_keys: 2, deprecated: 3 }scope :mf_locales,- ->(locale) do- where(locale: locale).where.not(status: "deprecated").where("translation_key LIKE '%_MF'")- end+ ->(locale) { not_deprecated.where(locale: locale).where("translation_key LIKE '%_MF'") }scope :client_locales,->(locale) do- where(locale: locale)- .where.not(status: "deprecated")+ not_deprecated+ .where(locale: locale).where("translation_key LIKE 'js.%' OR translation_key LIKE 'admin_js.%'").where.not("translation_key LIKE '%_MF'")enddiff --git a/lib/i18n/i18n_interpolation_keys_finder.rb b/lib/i18n/i18n_interpolation_keys_finder.rbindex 325df214950..fbcad88a15e 100644--- a/lib/i18n/i18n_interpolation_keys_finder.rb+++ b/lib/i18n/i18n_interpolation_keys_finder.rb@@ -2,7 +2,7 @@class I18nInterpolationKeysFinderdef self.find(text)- return [] unless text.is_a? String+ return [] unless text.is_a?(String)pattern = Regexp.union([*I18n.config.interpolation_patterns, /\{\{(\w+)\}\}/])keys = text.scan(pattern)keys.flatten!diff --git a/spec/lib/js_locale_helper_spec.rb b/spec/lib/js_locale_helper_spec.rbindex 7a4a22f6808..7ba797febc9 100644--- a/spec/lib/js_locale_helper_spec.rb+++ b/spec/lib/js_locale_helper_spec.rb@@ -262,7 +262,9 @@ RSpec.describe JsLocaleHelper doenddescribe ".output_client_overrides" do- it "should not output deprecated translation overrides" do+ subject(:client_overrides) { described_class.output_client_overrides("en") }++ before doFabricate(:translation_override,locale: "en",@@ -276,9 +278,11 @@ RSpec.describe JsLocaleHelper dovalue: "SHOULD_NOT_SHOW",status: "deprecated",)+ end- expect(described_class.output_client_overrides("en").include? "SHOULD_SHOW").to eq(true)- expect(described_class.output_client_overrides("en").include? "SHOULD_NOT_SHOW").to eq(false)+ it "does not output deprecated translation overrides" do+ expect(client_overrides).to include("SHOULD_SHOW")+ expect(client_overrides).not_to include("SHOULD_NOT_SHOW")endendend