A platform for community discussion. Free, open, simple.
FIX: incorrect flag message when en_GB language (#32191)
Krzysztof Kotlarek14a42bdafebb
diff --git a/app/assets/javascripts/discourse/app/lib/transform-post.js b/app/assets/javascripts/discourse/app/lib/transform-post.jsindex dbc58c3487f..53ac7d15fdc 100644--- a/app/assets/javascripts/discourse/app/lib/transform-post.js+++ b/app/assets/javascripts/discourse/app/lib/transform-post.js@@ -2,7 +2,6 @@ import { isEmpty } from "@ember/utils";import getURL from "discourse/lib/get-url";import { userPath } from "discourse/lib/url";import Badge from "discourse/models/badge";-import { i18n } from "discourse-i18n";const _additionalAttributes = new Set();@@ -197,18 +196,12 @@ export default function transformPost(return a.actionType.name_key !== "like" && a.acted;}).map((a) => {- const action = a.actionType.name_key;-return {id: a.id,postId: post.id,- action,+ action: a.actionType.name_key,canUndo: a.can_undo,- description: i18n(`post.actions.by_you.${action}`, {- defaultValue: i18n(`post.actions.by_you.custom`, {- custom: a.actionType.name,- }),- }),+ description: a.actionType.translatedDescription,};});}diff --git a/app/assets/javascripts/discourse/app/models/post-action-type.js b/app/assets/javascripts/discourse/app/models/post-action-type.jsindex 4ce015d1696..26955f9d027 100644--- a/app/assets/javascripts/discourse/app/models/post-action-type.js+++ b/app/assets/javascripts/discourse/app/models/post-action-type.js@@ -1,8 +1,20 @@import { equal } from "@ember/object/computed";+import discourseComputed from "discourse/lib/decorators";import RestModel from "discourse/models/rest";+import { i18n } from "discourse-i18n";export const MAX_MESSAGE_LENGTH = 500;export default class PostActionType extends RestModel {@equal("name_key", "illegal") isIllegal;++ @discourseComputed()+ translatedDescription() {+ if (this.system) {+ return i18n(`post.actions.by_you.${this.name_key}`);+ }+ return i18n(`post.actions.by_you.custom`, {+ custom: this.name,+ });+ }}diff --git a/app/assets/javascripts/discourse/app/models/post.js b/app/assets/javascripts/discourse/app/models/post.jsindex 386bca0465b..de5f984762f 100644--- a/app/assets/javascripts/discourse/app/models/post.js+++ b/app/assets/javascripts/discourse/app/models/post.js@@ -744,18 +744,12 @@ export default class Post extends RestModel {return postAction.actionType.name_key !== "like" && postAction.acted;})?.map((postAction) => {- const action = postAction.actionType.name_key;-return {id: postAction.id,postId: this.id,- action,+ action: postAction.actionType.name_key,canUndo: postAction.can_undo,- description: i18n(`post.actions.by_you.${action}`, {- defaultValue: i18n(`post.actions.by_you.custom`, {- custom: postAction.actionType.name,- }),- }),+ description: postAction.translatedDescription,};});}diff --git a/app/serializers/flag_serializer.rb b/app/serializers/flag_serializer.rbindex bc072927c3b..b70dbbdfbb4 100644--- a/app/serializers/flag_serializer.rb+++ b/app/serializers/flag_serializer.rb@@ -13,7 +13,8 @@ class FlagSerializer < ApplicationSerializer:is_flag,:applies_to,:is_used,- :auto_action_type+ :auto_action_type,+ :systemdef i18n_prefix"#{@options[:target] || "post_action"}_types.#{object.name_key}"@@ -47,4 +48,8 @@ class FlagSerializer < ApplicationSerializerdef applies_toArray.wrap(object.applies_to)end++ def system+ object.system?+ endenddiff --git a/spec/requests/api/schemas/json/site_response.json b/spec/requests/api/schemas/json/site_response.jsonindex f4cfb00927a..c33f0734255 100644--- a/spec/requests/api/schemas/json/site_response.json+++ b/spec/requests/api/schemas/json/site_response.json@@ -377,6 +377,9 @@},"auto_action_type": {"type": "boolean"+ },+ "system": {+ "type": "boolean"}},"required": [@@ -436,6 +439,9 @@},"auto_action_type": {"type": "boolean"+ },+ "system": {+ "type": "boolean"}},"required": [diff --git a/spec/system/flagging_post_spec.rb b/spec/system/flagging_post_spec.rbindex 0954957ef00..1c8c94eb032 100644--- a/spec/system/flagging_post_spec.rb+++ b/spec/system/flagging_post_spec.rb@@ -56,6 +56,27 @@ describe "Flagging post", type: :system doendend+ describe "As send a message to user" do+ before do+ SiteSetting.allow_user_locale = true+ current_user.update!(locale: "en_GB")+ sign_in(current_user)+ end++ it do+ topic_page.visit_topic(topic)+ topic_page.expand_post_actions(post_to_flag)+ topic_page.click_post_action_button(post_to_flag, :flag)+ flag_modal.choose_type(:notify_user)++ flag_modal.fill_message("This looks totally illegal to me.")++ flag_modal.confirm_flag++ expect(page).to have_content(I18n.t("js.post.actions.by_you.notify_user"))+ end+ end+context "when tl0" dofab!(:tl0_user) { Fabricate(:user, trust_level: TrustLevel[0]) }before { sign_in(tl0_user) }