Add utils.commaAndJoin() for "a, b and c" strings

This commit is contained in:
miruka 2021-01-17 11:46:19 -04:00
parent 661ca47430
commit 6184f1cfa5
2 changed files with 11 additions and 4 deletions

View File

@ -13,11 +13,8 @@ InfoBar {
label.textFormat: Text.StyledText label.textFormat: Text.StyledText
label.text: { label.text: {
const tm = typingMembers const tm = typingMembers
if (tm.length === 0) return "" if (tm.length === 0) return ""
if (tm.length === 1) return qsTr("%1 is typing...").arg(tm[0]) if (tm.length === 1) return qsTr("%1 is typing...").arg(tm[0])
return qsTr("%1 are typing...").arg(utils.commaAndJoin(tm))
return qsTr("%1 and %2 are typing...")
.arg(tm.slice(0, -1).join(", ")).arg(tm.slice(-1)[0])
} }
} }

View File

@ -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) { function flickPages(flickable, pages, horizontal=false, multiplier=8) {
// Adapt velocity and deceleration for the number of pages to flick. // Adapt velocity and deceleration for the number of pages to flick.
// If this is a repeated flicking, flick faster than a single flick. // If this is a repeated flicking, flick faster than a single flick.