2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-25 02:45:35 +08:00
|
|
|
class SiteTextSerializer < ApplicationSerializer
|
2023-07-19 23:06:13 +08:00
|
|
|
attributes :id,
|
|
|
|
:value,
|
|
|
|
:status,
|
|
|
|
:old_default,
|
|
|
|
:new_default,
|
|
|
|
:interpolation_keys,
|
|
|
|
:has_interpolation_keys?,
|
|
|
|
:overridden?,
|
|
|
|
:can_revert?
|
2014-09-25 02:45:35 +08:00
|
|
|
|
2015-08-08 02:05:08 +08:00
|
|
|
def id
|
2015-11-24 05:45:05 +08:00
|
|
|
object[:id]
|
2014-09-25 02:45:35 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def value
|
2015-11-24 05:45:05 +08:00
|
|
|
object[:value]
|
2014-09-25 02:45:35 +08:00
|
|
|
end
|
|
|
|
|
2023-07-19 23:06:13 +08:00
|
|
|
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
|
|
|
|
|
2023-06-28 19:03:04 +08:00
|
|
|
def interpolation_keys
|
|
|
|
object[:interpolation_keys]
|
|
|
|
end
|
|
|
|
|
|
|
|
def has_interpolation_keys?
|
|
|
|
object[:interpolation_keys].present?
|
|
|
|
end
|
|
|
|
|
2015-12-01 04:22:58 +08:00
|
|
|
def overridden?
|
2019-07-02 09:53:16 +08:00
|
|
|
if options[:overridden_keys]
|
|
|
|
options[:overridden_keys].include?(object[:id])
|
2019-05-11 07:52:27 +08:00
|
|
|
else
|
2023-07-19 23:06:13 +08:00
|
|
|
override.present?
|
2015-11-24 05:45:05 +08:00
|
|
|
end
|
2014-09-25 02:45:35 +08:00
|
|
|
end
|
2015-12-01 04:22:58 +08:00
|
|
|
|
|
|
|
alias_method :can_revert?, :overridden?
|
2023-07-19 23:06:13 +08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def override
|
|
|
|
TranslationOverride.find_by(locale: object[:locale], translation_key: object[:id])
|
|
|
|
end
|
2014-09-25 02:45:35 +08:00
|
|
|
end
|