diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-04-19 00:36:04 +0200 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-04-19 00:36:04 +0200 |
commit | 6732bc18905b751fdabdfce58aba70d09de0cb27 (patch) | |
tree | 81401a5a682bf21a68a48d89cd77a86bc3b5bd03 | |
parent | 630c454db63c7af990592e20e7a550bf5bf2b265 (diff) | |
download | nextcloud-server-fix/files-summary.tar.gz nextcloud-server-fix/files-summary.zip |
fix(files): make sure to always have proper plural formsfix/files-summary
counted words should always be translated using `n`.
We can still simply concat the segments with punctation, this always
works regardless of the language used (even with RTL / LTR languages).
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r-- | apps/files/src/utils/fileUtils.ts | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/apps/files/src/utils/fileUtils.ts b/apps/files/src/utils/fileUtils.ts index 421b7d02376..f0b974be21d 100644 --- a/apps/files/src/utils/fileUtils.ts +++ b/apps/files/src/utils/fileUtils.ts @@ -3,15 +3,15 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ import { FileType, type Node } from '@nextcloud/files' -import { translate as t, translatePlural as n } from '@nextcloud/l10n' +import { n } from '@nextcloud/l10n' /** * Extract dir and name from file path * - * @param {string} path the full path - * @return {string[]} [dirPath, fileName] + * @param path - The full path + * @return [dirPath, fileName] */ -export const extractFilePaths = function(path) { +export function extractFilePaths(path: string): [string, string] { const pathSections = path.split('/') const fileName = pathSections[pathSections.length - 1] const dirPath = pathSections.slice(0, pathSections.length - 1).join('/') @@ -20,32 +20,28 @@ export const extractFilePaths = function(path) { /** * Generate a translated summary of an array of nodes - * @param {Node[]} nodes the nodes to summarize - * @param {number} hidden the number of hidden nodes - * @return {string} + * + * @param nodes - The nodes to summarize + * @param hidden - The number of hidden nodes */ -export const getSummaryFor = (nodes: Node[], hidden = 0): string => { +export function getSummaryFor(nodes: Node[], hidden = 0): string { const fileCount = nodes.filter(node => node.type === FileType.File).length const folderCount = nodes.filter(node => node.type === FileType.Folder).length - let summary = '' - - if (fileCount === 0) { - summary = n('files', '{folderCount} folder', '{folderCount} folders', folderCount, { folderCount }) - } else if (folderCount === 0) { - summary = n('files', '{fileCount} file', '{fileCount} files', fileCount, { fileCount }) - } else if (fileCount === 1) { - summary = n('files', '1 file and {folderCount} folder', '1 file and {folderCount} folders', folderCount, { folderCount }) - } else if (folderCount === 1) { - summary = n('files', '{fileCount} file and 1 folder', '{fileCount} files and 1 folder', fileCount, { fileCount }) - } else { - summary = t('files', '{fileCount} files and {folderCount} folders', { fileCount, folderCount }) + const summary: string[] = [] + if (fileCount > 0 || folderCount === 0) { + const fileSummary = n('files', '%n file', '%n files', fileCount) + summary.push(fileSummary) + } + if (folderCount > 0) { + const folderSummary = n('files', '%n folder', '%n folders', folderCount) + summary.push(folderSummary) } - if (hidden > 0) { - // TRANSLATORS: This is a summary of files and folders, where {hiddenFilesAndFolders} is the number of hidden files and folders - summary += ' ' + n('files', '(%n hidden)', ' (%n hidden)', hidden) + // TRANSLATORS: This is the number of hidden files or folders + const hiddenSummary = n('files', '%n hidden', '%n hidden', hidden) + summary.push(hiddenSummary) } - return summary + return summary.join(' ยท ') } |