From 3a718d786f40e9f320413c7f23064ce1365cecd5 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 3 Nov 2022 12:14:03 -0700 Subject: [PATCH] js: Fix type issue with FormatJS rich text elements. Signed-off-by: Anders Kaseorg --- docs/translating/internationalization.md | 2 +- frontend_tests/node_tests/i18n.js | 2 +- frontend_tests/zjsunit/i18n.js | 4 +-- static/js/compose_validate.js | 3 +- static/js/i18n.ts | 2 +- static/js/info_overlay.js | 8 +++-- static/js/narrow_banner.js | 37 +++++++++++++++++------- static/js/read_receipts.js | 4 ++- static/js/settings_account.js | 4 ++- static/js/settings_display.js | 10 +++++-- 10 files changed, 54 insertions(+), 22 deletions(-) diff --git a/docs/translating/internationalization.md b/docs/translating/internationalization.md index 3ba55e73b2..f647e6d827 100644 --- a/docs/translating/internationalization.md +++ b/docs/translating/internationalization.md @@ -247,7 +247,7 @@ locally to the translation: ```js $t_html( {defaultMessage: "HTML linking to the login page"}, - {"z-link": (content_html) => `${content_html}`}, + {"z-link": (content_html) => `${content_html.join("")}`}, ) ``` diff --git a/frontend_tests/node_tests/i18n.js b/frontend_tests/node_tests/i18n.js index 11a48fed4f..5f046b9395 100644 --- a/frontend_tests/node_tests/i18n.js +++ b/frontend_tests/node_tests/i18n.js @@ -60,7 +60,7 @@ run_test("$tr", () => { }, { stream_name: "l'abonnement", - "z-link": (content_html) => `${content_html}`, + "z-link": (content_html) => `${content_html.join("")}`, }, ), "

Le canal l'abonnement n'existe pas.

GĂ©rez vos abonnements sur votre page canaux.

", diff --git a/frontend_tests/zjsunit/i18n.js b/frontend_tests/zjsunit/i18n.js index 4746c0622f..a8897762f5 100644 --- a/frontend_tests/zjsunit/i18n.js +++ b/frontend_tests/zjsunit/i18n.js @@ -13,7 +13,7 @@ exports.intl = createIntl( ["b", "code", "em", "i", "kbd", "p", "strong"].map((tag) => [ tag, /* istanbul ignore next */ - (content_html) => `<${tag}>${content_html}`, + (content_html) => `<${tag}>${content_html.join("")}`, ]), ), }, @@ -33,7 +33,7 @@ exports.$t = (descriptor, values) => const default_html_elements = Object.fromEntries( ["b", "code", "em", "i", "kbd", "p", "strong"].map((tag) => [ tag, - (content_html) => `<${tag}>${content_html}`, + (content_html) => `<${tag}>${content_html.join("")}`, ]), ); diff --git a/static/js/compose_validate.js b/static/js/compose_validate.js index 4c2da5b7e5..37c11f6633 100644 --- a/static/js/compose_validate.js +++ b/static/js/compose_validate.js @@ -392,7 +392,8 @@ export function validation_error(error_type, stream_name) { }, { stream_name, - "z-link": (content_html) => `${content_html}`, + "z-link": (content_html) => + `${content_html.join("")}`, }, ); compose_error.show(response, $("#stream_message_recipient_stream")); diff --git a/static/js/i18n.ts b/static/js/i18n.ts index eb2394918b..b4c06b34a2 100644 --- a/static/js/i18n.ts +++ b/static/js/i18n.ts @@ -30,7 +30,7 @@ export const $t = intl.formatMessage.bind(intl); export const default_html_elements = Object.fromEntries( ["b", "code", "em", "i", "kbd", "p", "strong"].map((tag) => [ tag, - (content_html: string) => `<${tag}>${content_html}`, + (content_html: string[]) => `<${tag}>${content_html.join("")}`, ]), ); diff --git a/static/js/info_overlay.js b/static/js/info_overlay.js index 979a973aeb..1c59f25647 100644 --- a/static/js/info_overlay.js +++ b/static/js/info_overlay.js @@ -141,7 +141,9 @@ def zulip(): }, { "z-link": (content_html) => - `${content_html}`, + `${content_html.join( + "", + )}`, }, ), }, @@ -177,7 +179,9 @@ This text won't be visible until the user clicks. }, { "z-link": (content_html) => - `${content_html}`, + `${content_html.join( + "", + )}`, }, ), }, diff --git a/static/js/narrow_banner.js b/static/js/narrow_banner.js index d76e4b8a02..48c2f84819 100644 --- a/static/js/narrow_banner.js +++ b/static/js/narrow_banner.js @@ -15,7 +15,8 @@ const SPECTATOR_STREAM_NARROW_BANNER = { defaultMessage: "This is not a publicly accessible conversation.", }, { - "z-link": (content_html) => `${content_html}`, + "z-link": (content_html) => + `${content_html.join("")}`, }, ), }; @@ -74,7 +75,9 @@ function pick_empty_narrow_banner() { }, { "z-link": (content_html) => - `${content_html}`, + `${content_html.join( + "", + )}`, }, ), }; @@ -162,7 +165,7 @@ function pick_empty_narrow_banner() { }, { "z-link": (content_html) => - `${content_html}`, + `${content_html.join("")}`, }, ), }; @@ -175,7 +178,9 @@ function pick_empty_narrow_banner() { }, { "z-link": (content_html) => - `${content_html}`, + `${content_html.join( + "", + )}`, }, ), }; @@ -191,7 +196,9 @@ function pick_empty_narrow_banner() { // TODO: The href here is a bit weird; we probably want to migrate // this to a button element down the line. "z-link": (content_html) => - `${content_html}`, + `${content_html.join( + "", + )}`, }, ), }; @@ -241,7 +248,9 @@ function pick_empty_narrow_banner() { }, { "z-button": (content_html) => - ``, + ``, }, ), }; @@ -286,7 +295,9 @@ function pick_empty_narrow_banner() { }, { "z-link": (content_html) => - `${content_html}`, + `${content_html.join( + "", + )}`, }, ), }; @@ -301,7 +312,9 @@ function pick_empty_narrow_banner() { }, { "z-link": (content_html) => - `${content_html}`, + `${content_html.join( + "", + )}`, }, ), }; @@ -314,7 +327,9 @@ function pick_empty_narrow_banner() { }, { "z-link": (content_html) => - `${content_html}`, + `${content_html.join( + "", + )}`, }, ), }; @@ -341,7 +356,9 @@ function pick_empty_narrow_banner() { }, { "z-link": (content_html) => - `${content_html}`, + `${content_html.join( + "", + )}`, }, ), }; diff --git a/static/js/read_receipts.js b/static/js/read_receipts.js index 454d5c5486..6a26a36439 100644 --- a/static/js/read_receipts.js +++ b/static/js/read_receipts.js @@ -57,7 +57,9 @@ export function show_user_list(message_id) { { num_of_people: users.length, "z-link": (content_html) => - `${content_html}`, + `${content_html.join( + "", + )}`, }, ), ); diff --git a/static/js/settings_account.js b/static/js/settings_account.js index e83a1dfb3f..89292bc2d3 100644 --- a/static/js/settings_account.js +++ b/static/js/settings_account.js @@ -714,7 +714,9 @@ export function set_up() { }, { "z-link": (content_html) => - `${content_html}`, + `${content_html.join( + "", + )}`, }, ); let rendered_error_msg; diff --git a/static/js/settings_display.js b/static/js/settings_display.js index 37131c7d5f..3c0239f9ca 100644 --- a/static/js/settings_display.js +++ b/static/js/settings_display.js @@ -104,7 +104,10 @@ function user_default_language_modal_post_render() { defaultMessage: "Saved. Please reload for the change to take effect.", }, - {"z-link": (content_html) => `${content_html}`}, + { + "z-link": (content_html) => + `${content_html.join("")}`, + }, ), true, ); @@ -196,7 +199,10 @@ export function set_up(settings_panel) { defaultMessage: "Saved. Please reload for the change to take effect.", }, - {"z-link": (content_html) => `${content_html}`}, + { + "z-link": (content_html) => + `${content_html.join("")}`, + }, ), true, );