DEV: Refactor translation overrides a bit (#28125)

This is a small followup of
https://github.com/discourse/discourse/pull/28037.
This commit is contained in:
Loïc Guitaut 2024-07-30 03:56:46 +02:00 committed by GitHub
parent e9aa2c96e1
commit 1f5cbb9a44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 9 deletions

View File

@ -50,13 +50,11 @@ class TranslationOverride < ActiveRecord::Base
enum status: { up_to_date: 0, outdated: 1, invalid_interpolation_keys: 2, deprecated: 3 } enum status: { up_to_date: 0, outdated: 1, invalid_interpolation_keys: 2, deprecated: 3 }
scope :mf_locales, scope :mf_locales,
->(locale) do ->(locale) { not_deprecated.where(locale: locale).where("translation_key LIKE '%_MF'") }
where(locale: locale).where.not(status: "deprecated").where("translation_key LIKE '%_MF'")
end
scope :client_locales, scope :client_locales,
->(locale) do ->(locale) do
where(locale: locale) not_deprecated
.where.not(status: "deprecated") .where(locale: locale)
.where("translation_key LIKE 'js.%' OR translation_key LIKE 'admin_js.%'") .where("translation_key LIKE 'js.%' OR translation_key LIKE 'admin_js.%'")
.where.not("translation_key LIKE '%_MF'") .where.not("translation_key LIKE '%_MF'")
end end

View File

@ -2,7 +2,7 @@
class I18nInterpolationKeysFinder class I18nInterpolationKeysFinder
def self.find(text) def self.find(text)
return [] unless text.is_a? String return [] unless text.is_a?(String)
pattern = Regexp.union([*I18n.config.interpolation_patterns, /\{\{(\w+)\}\}/]) pattern = Regexp.union([*I18n.config.interpolation_patterns, /\{\{(\w+)\}\}/])
keys = text.scan(pattern) keys = text.scan(pattern)
keys.flatten! keys.flatten!

View File

@ -262,7 +262,9 @@ RSpec.describe JsLocaleHelper do
end end
describe ".output_client_overrides" do describe ".output_client_overrides" do
it "should not output deprecated translation overrides" do subject(:client_overrides) { described_class.output_client_overrides("en") }
before do
Fabricate( Fabricate(
:translation_override, :translation_override,
locale: "en", locale: "en",
@ -276,9 +278,11 @@ RSpec.describe JsLocaleHelper do
value: "SHOULD_NOT_SHOW", value: "SHOULD_NOT_SHOW",
status: "deprecated", status: "deprecated",
) )
end
expect(described_class.output_client_overrides("en").include? "SHOULD_SHOW").to eq(true) it "does not output deprecated translation overrides" do
expect(described_class.output_client_overrides("en").include? "SHOULD_NOT_SHOW").to eq(false) expect(client_overrides).to include("SHOULD_SHOW")
expect(client_overrides).not_to include("SHOULD_NOT_SHOW")
end end
end end
end end