diff --git a/app/serializers/post_action_type_serializer.rb b/app/serializers/post_action_type_serializer.rb index 99fd16fe5aa..2ed5bce2d79 100644 --- a/app/serializers/post_action_type_serializer.rb +++ b/app/serializers/post_action_type_serializer.rb @@ -31,16 +31,14 @@ class PostActionTypeSerializer < ApplicationSerializer def description i18n( "description", - vars: { - tos_url:, - base_path: Discourse.base_path, - }, + tos_url:, + base_path: Discourse.base_path, default: object.class.descriptions[object.id], ) end def short_description - i18n("short_description", vars: { tos_url: tos_url, base_path: Discourse.base_path }) + i18n("short_description", tos_url:, base_path: Discourse.base_path, default: "") end def name_key @@ -60,10 +58,14 @@ class PostActionTypeSerializer < ApplicationSerializer ReviewableScore.exists?(reviewable_score_type: object.id) end - protected + private - def i18n(field, default: nil, vars: nil) - key = "post_action_types.#{name_key}.#{field}" - vars ? I18n.t(key, vars, default: default) : I18n.t(key, default: default) + def i18n(field, **args) + key = "#{i18n_prefix}.#{name_key}.#{field}" + I18n.t(key, **args) + end + + def i18n_prefix + "post_action_types" end end diff --git a/app/serializers/topic_flag_type_serializer.rb b/app/serializers/topic_flag_type_serializer.rb index a53a09356ff..5a0330f1c26 100644 --- a/app/serializers/topic_flag_type_serializer.rb +++ b/app/serializers/topic_flag_type_serializer.rb @@ -1,10 +1,9 @@ # frozen_string_literal: true class TopicFlagTypeSerializer < PostActionTypeSerializer - protected + private - def i18n(field, default: nil, vars: nil) - key = "topic_flag_types.#{name_key}.#{field}" - vars ? I18n.t(key, vars, default: default) : I18n.t(key, default: default) + def i18n_prefix + "topic_flag_types" end end diff --git a/spec/serializers/post_action_type_serializer_spec.rb b/spec/serializers/post_action_type_serializer_spec.rb new file mode 100644 index 00000000000..692eca7c0af --- /dev/null +++ b/spec/serializers/post_action_type_serializer_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +RSpec.describe PostActionTypeSerializer do + subject(:serializer) { described_class.new(post_action_type, scope: Guardian.new, root: false) } + + let(:post_action_type) { PostActionType.find_by(name_key: :inappropriate) } + + describe "#description" do + before { Discourse.stubs(:base_path).returns("discourse.org") } + + it "returns properly interpolated translation" do + expect(serializer.description).to match(%r{discourse\.org/guidelines}) + end + end +end