FIX: Return properly interpolated translations for flag types
Currently, descriptions for flag types aren’t interpolated, returning `%{base_path}` in their string, for example. This breaks the navigation on the sites. The behavior changed probably because of an upgrade of Ruby, as two hashes were passed to `I18n.t` (`vars` and `default`) without using the splat operator.
This commit is contained in:
parent
a3d61ba1c4
commit
335ab115b3
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue