From 8d04a13daf4d4809ae755dd2e5f8f00710c53672 Mon Sep 17 00:00:00 2001 From: awesomerobot Date: Mon, 13 Mar 2023 14:16:29 -0400 Subject: [PATCH] refactor for more complete translation strings --- .../initializers/extend-for-assigns.js | 60 ++++++++++--------- config/locales/client.en.yml | 7 ++- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js b/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js index 01cec2e..12e958a 100644 --- a/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js +++ b/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js @@ -16,6 +16,7 @@ import { inject as controller } from "@ember/controller"; import I18n from "I18n"; import { isEmpty } from "@ember/utils"; import { registerTopicFooterDropdown } from "discourse/lib/register-topic-footer-dropdown"; +import RawHtml from "discourse/widgets/raw-html"; const PLUGIN_ID = "discourse-assign"; @@ -701,38 +702,39 @@ function initialize(api) { ]; const assigneeElements = []; + const assignedHtml = (username, path) => { + return `${htmlSafe( + I18n.t("discourse_assign.assigned_topic_to", { + username, + path, + }) + )}`; + }; + if (assignedToUser) { assigneeElements.push( - h("span.assignee", [ - h("span", `${I18n.t("discourse_assign.topic_to")} `), - h( - "a", - { - attributes: { - class: "assigned-to-username", - href: assignedToUserPath(assignedToUser), - }, - }, - assignedToUser.username - ), - ]) + h( + "span.assignee", + new RawHtml({ + html: assignedHtml( + assignedToUser.username, + assignedToUserPath(assignedToUser) + ), + }) + ) ); } if (assignedToGroup) { assigneeElements.push( - h("span.assignee", [ - h("span", `${I18n.t("discourse_assign.topic_to")} `), - h( - "a", - { - attributes: { - class: "assigned-to-group", - href: assignedToGroupPath(assignedToGroup), - }, - }, - assignedToGroup.name - ), - ]) + h( + "span.assignee", + new RawHtml({ + html: assignedHtml( + assignedToGroup.name, + assignedToGroupPath(assignedToGroup) + ), + }) + ) ); } if (indirectlyAssignedTo) { @@ -749,7 +751,7 @@ function initialize(api) { href: `${topic.url}/${postNumber}`, }, }, - I18n.t("discourse_assign.assign_post_to", { + I18n.t("discourse_assign.assign_post_to_multiple", { post_number: postNumber, username: assignee.username || assignee.name, }) @@ -761,7 +763,9 @@ function initialize(api) { if (!isEmpty(assigneeElements)) { return h("p.assigned-to", [ assignedToUser ? iconNode("user-plus") : iconNode("group-plus"), - h("span.assign-text", I18n.t("discourse_assign.assigned")), + assignedToUser || assignedToGroup + ? "" + : h("span.assign-text", I18n.t("discourse_assign.assigned")), assigneeElements, ]); } diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index bbead29..169d78a 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -27,8 +27,11 @@ en: assigned: "Assigned" group_everyone: "Everyone" assigned_to: "Assigned to" - topic_to: "topic to" # Context example: "Assigned [topic to] example_username" - assign_post_to: "#%{post_number} to %{username}" # Context example: "Assigned [#2 to example_username]" + assigned_topic_to: "Assigned topic to %{username}" + assign_post_to: "Assigned #%{post_number} to %{username}" + assign_post_to_multiple: + "#%{post_number} to %{username}" + # assign_post_to_multiple used in list form, example: "Assigned topic to username0, [#2 to username1], [#10 to username2]" assigned_to_w_ellipsis: "Assigned to..." assign_notification: "

%{username} %{description}

" assign_group_notification: "

%{username} %{description}

"