From 6184f1cfa51d3f16495adc7c05f038e5e3263753 Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 17 Jan 2021 11:46:19 -0400 Subject: [PATCH] Add utils.commaAndJoin() for "a, b and c" strings --- src/gui/Pages/Chat/TypingMembersBar.qml | 5 +---- src/gui/Utils.qml | 10 ++++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/gui/Pages/Chat/TypingMembersBar.qml b/src/gui/Pages/Chat/TypingMembersBar.qml index f50ce43e..1639aa56 100644 --- a/src/gui/Pages/Chat/TypingMembersBar.qml +++ b/src/gui/Pages/Chat/TypingMembersBar.qml @@ -13,11 +13,8 @@ InfoBar { label.textFormat: Text.StyledText label.text: { const tm = typingMembers - if (tm.length === 0) return "" if (tm.length === 1) return qsTr("%1 is typing...").arg(tm[0]) - - return qsTr("%1 and %2 are typing...") - .arg(tm.slice(0, -1).join(", ")).arg(tm.slice(-1)[0]) + return qsTr("%1 are typing...").arg(utils.commaAndJoin(tm)) } } diff --git a/src/gui/Utils.qml b/src/gui/Utils.qml index 6050883a..e2b68440 100644 --- a/src/gui/Utils.qml +++ b/src/gui/Utils.qml @@ -411,6 +411,16 @@ QtObject { } + function commaAndJoin(array) { + if (array.length === 0) return "" + if (array.length === 1) return array[0] + + return qsTr("%1 and %2") + .arg(array.slice(0, -1).join(qsTr(", "))) + .arg(array.slice(-1)[0]) + } + + function flickPages(flickable, pages, horizontal=false, multiplier=8) { // Adapt velocity and deceleration for the number of pages to flick. // If this is a repeated flicking, flick faster than a single flick.