A platform for community discussion. Free, open, simple.
FIX: Return properly interpolated translations for flag types
Loïc Guitaut335ab115b327
diff --git a/app/serializers/post_action_type_serializer.rb b/app/serializers/post_action_type_serializer.rbindex 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 < ApplicationSerializerdef descriptioni18n("description",- vars: {- tos_url:,- base_path: Discourse.base_path,- },+ tos_url:,+ base_path: Discourse.base_path,default: object.class.descriptions[object.id],)enddef 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: "")enddef name_key@@ -60,10 +58,14 @@ class PostActionTypeSerializer < ApplicationSerializerReviewableScore.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"endenddiff --git a/app/serializers/topic_flag_type_serializer.rb b/app/serializers/topic_flag_type_serializer.rbindex 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: trueclass 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"endenddiff --git a/spec/serializers/post_action_type_serializer_spec.rb b/spec/serializers/post_action_type_serializer_spec.rbnew file mode 100644index 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