discourse/app/serializers/site_text_serializer.rb
Ted Johansson 341acacba8
DEV: Add endpoint for dismissing outdated translations (#22509)
Recently we started giving admins a notice in the advice panel when their translations have become outdated due to changes in core. However, we didn't include any additional information.

This PR adds more information about the outdated translation inside the site text edit page, together with an option to dismiss the warning.
2023-07-19 23:06:13 +08:00

62 lines
1.1 KiB
Ruby

# frozen_string_literal: true
class SiteTextSerializer < ApplicationSerializer
attributes :id,
:value,
:status,
:old_default,
:new_default,
:interpolation_keys,
:has_interpolation_keys?,
:overridden?,
:can_revert?
def id
object[:id]
end
def value
object[:value]
end
def status
if override.present?
override.status
else
"up_to_date"
end
end
def old_default
override.original_translation if override.present?
end
def new_default
override.current_default if override.present?
end
def interpolation_keys
object[:interpolation_keys]
end
def has_interpolation_keys?
object[:interpolation_keys].present?
end
def overridden?
if options[:overridden_keys]
options[:overridden_keys].include?(object[:id])
else
override.present?
end
end
alias_method :can_revert?, :overridden?
private
def override
TranslationOverride.find_by(locale: object[:locale], translation_key: object[:id])
end
end