From caa2dbbba4e56f83d7ca3b851f0d17c206536a39 Mon Sep 17 00:00:00 2001 From: CIC4DA Date: Fri, 5 Jan 2024 19:55:14 +0530 Subject: [PATCH] filter: Use Intl.ListFormat rather than .join(", "). --- web/src/filter.ts | 6 +----- web/tests/filter.test.js | 8 ++++++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/web/src/filter.ts b/web/src/filter.ts index 832ea313e2..96bc742954 100644 --- a/web/src/filter.ts +++ b/web/src/filter.ts @@ -976,11 +976,7 @@ export class Filter { } return person.full_name; }); - - // We use join to handle the addition of a comma and space after every name - // and also to ensure that we return a string and not an array so that we - // can have the same return type as other cases. - return names.join(", "); + return util.format_array_as_list(names, "long", "conjunction"); } if (term_types.length === 1 && _.isEqual(term_types, ["sender"])) { const email = this.operands("sender")[0]; diff --git a/web/tests/filter.test.js b/web/tests/filter.test.js index 4f65917852..7b8462a44f 100644 --- a/web/tests/filter.test.js +++ b/web/tests/filter.test.js @@ -1495,7 +1495,11 @@ test("navbar_helpers", () => { // make sure title has names separated with correct delimiters function properly_separated_names(names) { - return names.join(", "); + const names_internationalized = new Intl.ListFormat("en", { + style: "long", + type: "conjunction", + }).format(names); + return names_internationalized; } function test_redirect_url_with_search(test_case) { @@ -1709,7 +1713,7 @@ test("navbar_helpers", () => { terms: dm_group_including_guest, is_common_narrow: true, icon: "envelope", - title: "translated: alice (guest), joe", + title: "translated: alice (guest) and joe", redirect_url_with_search: "/#narrow/dm/" + joe.user_id + "," + alice.user_id + "-group", }, {