mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 14:38:17 +08:00
FIX: Ensure JsLocaleHelper to not output deprecated translations (#28037)
* FIX: Ensure JsLocaleHelper to obly outputs up-to-date translations The old implementation forgot to filter out deprecated translations, causing these translations to incorrectly override the new locale in the frontend. This commit fills in the forgotten where clause, filtering only the up-to-date part. Related meta topic: https://meta.discourse.org/t/outdated-translation-replacement-causing-missing-translation/314352
This commit is contained in:
parent
3126c50baa
commit
319075e4dd
|
@ -19,9 +19,9 @@ module Jobs
|
|||
end
|
||||
end
|
||||
|
||||
TranslationOverride.where(id: deprecated_ids).update_all(status: "deprecated")
|
||||
TranslationOverride.where(id: outdated_ids).update_all(status: "outdated")
|
||||
TranslationOverride.where(id: invalid_ids).update_all(status: "invalid_interpolation_keys")
|
||||
TranslationOverride.where(id: deprecated_ids).update_all(status: "deprecated")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -49,10 +49,14 @@ class TranslationOverride < ActiveRecord::Base
|
|||
attribute :status, :integer
|
||||
enum status: { up_to_date: 0, outdated: 1, invalid_interpolation_keys: 2, deprecated: 3 }
|
||||
|
||||
scope :mf_locales, ->(locale) { where(locale: locale).where("translation_key LIKE '%_MF'") }
|
||||
scope :mf_locales,
|
||||
->(locale) do
|
||||
where(locale: locale).where.not(status: "deprecated").where("translation_key LIKE '%_MF'")
|
||||
end
|
||||
scope :client_locales,
|
||||
->(locale) do
|
||||
where(locale: locale)
|
||||
.where.not(status: "deprecated")
|
||||
.where("translation_key LIKE 'js.%' OR translation_key LIKE 'admin_js.%'")
|
||||
.where.not("translation_key LIKE '%_MF'")
|
||||
end
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
class I18nInterpolationKeysFinder
|
||||
def self.find(text)
|
||||
return [] unless text.is_a? String
|
||||
pattern = Regexp.union([*I18n.config.interpolation_patterns, /\{\{(\w+)\}\}/])
|
||||
keys = text.scan(pattern)
|
||||
keys.flatten!
|
||||
|
|
|
@ -260,4 +260,25 @@ RSpec.describe JsLocaleHelper do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".output_client_overrides" do
|
||||
it "should not output deprecated translation overrides" do
|
||||
Fabricate(
|
||||
:translation_override,
|
||||
locale: "en",
|
||||
translation_key: "js.user.preferences.title",
|
||||
value: "SHOULD_SHOW",
|
||||
)
|
||||
Fabricate(
|
||||
:translation_override,
|
||||
locale: "en",
|
||||
translation_key: "js.user.preferences",
|
||||
value: "SHOULD_NOT_SHOW",
|
||||
status: "deprecated",
|
||||
)
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user