discourse/app/serializers/wizard_field_choice_serializer.rb
Ted Johansson 059a8a0ff5
DEV: Generate correct i18n keys for wizard radio choices (#28370)
If you wizard step has a dash in it, e.g. foo-bar, the wrong i18n key will be inferred for selects. This PR ensures the key is underscored.
2024-08-14 14:39:18 +02:00

57 lines
952 B
Ruby

# frozen_string_literal: true
class WizardFieldChoiceSerializer < ApplicationSerializer
attributes :id, :label, :extra_label, :description, :icon, :data
def id
object.id
end
def i18nkey
field = object.field
step = field.step
"wizard.step.#{step.id}.fields.#{field.id}.choices.#{id}".underscore
end
def label
return object.label if object.label.present?
# Try getting one from a translation
I18n.t("#{i18nkey}.label", default: id)
end
def extra_label
object.extra_label
end
def include_extra_label?
object.extra_label.present?
end
def description
I18n.t("#{i18nkey}.description", default: "")
end
def include_description?
description.present?
end
def icon
object.icon
end
def include_icon?
object.icon.present?
end
def data
result = object.data.dup
result.delete(:id)
result
end
def include_data?
object.data.present?
end
end