mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 05:33:47 +08:00
7a53fb65da
We recently introduced this advice to admins when some translation overrides are outdated or using unknown interpolation keys: However we missed the case where the original translation key has been renamed or altogether removed. When this happens they are no longer visible in the admin interface, leading to the confusing situation where we say there are outdated translations, but none are shown. Because we don't explicitly handle this case, some deleted translations were incorrectly marked as having unknown interpolation keys. (This is because I18n.t will return a string like "Translation missing: foo", which obviously has no interpolation keys inside.) This change adds an additional status, deprecated for TranslationOverride, and the job that checks them will check for this status first, taking precedence over invalid_interpolation_keys. Since the advice only checks for the outdated and invalid_interpolation_keys statuses, this fixes the problem.
28 lines
842 B
Ruby
28 lines
842 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class CheckTranslationOverrides < ::Jobs::Scheduled
|
|
every 1.day
|
|
|
|
def execute(args)
|
|
deprecated_ids = []
|
|
invalid_ids = []
|
|
outdated_ids = []
|
|
|
|
TranslationOverride.find_each do |override|
|
|
if override.original_translation_deleted?
|
|
deprecated_ids << override.id
|
|
elsif override.invalid_interpolation_keys.present?
|
|
invalid_ids << override.id
|
|
elsif override.original_translation_updated?
|
|
outdated_ids << override.id
|
|
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")
|
|
end
|
|
end
|
|
end
|