33 * SPDX-License-Identifier: AGPL-3.0-or-later
44 */
55import { FileType , type Node } from '@nextcloud/files'
6- import { translate as t , translatePlural as n } from '@nextcloud/l10n'
6+ import { n } from '@nextcloud/l10n'
77
88/**
99 * Extract dir and name from file path
1010 *
11- * @param { string } path the full path
12- * @return { string[] } [dirPath, fileName]
11+ * @param path - The full path
12+ * @return [dirPath, fileName]
1313 */
14- export const extractFilePaths = function ( path ) {
14+ export function extractFilePaths ( path : string ) : [ string , string ] {
1515 const pathSections = path . split ( '/' )
1616 const fileName = pathSections [ pathSections . length - 1 ]
1717 const dirPath = pathSections . slice ( 0 , pathSections . length - 1 ) . join ( '/' )
@@ -20,32 +20,28 @@ export const extractFilePaths = function(path) {
2020
2121/**
2222 * Generate a translated summary of an array of nodes
23- * @param { Node[] } nodes the nodes to summarize
24- * @param { number } hidden the number of hidden nodes
25- * @return { string }
23+ *
24+ * @param nodes - The nodes to summarize
25+ * @param hidden - The number of hidden nodes
2626 */
27- export const getSummaryFor = ( nodes : Node [ ] , hidden = 0 ) : string => {
27+ export function getSummaryFor ( nodes : Node [ ] , hidden = 0 ) : string {
2828 const fileCount = nodes . filter ( node => node . type === FileType . File ) . length
2929 const folderCount = nodes . filter ( node => node . type === FileType . Folder ) . length
3030
31- let summary = ''
32-
33- if ( fileCount === 0 ) {
34- summary = n ( 'files' , '{folderCount} folder' , '{folderCount} folders' , folderCount , { folderCount } )
35- } else if ( folderCount === 0 ) {
36- summary = n ( 'files' , '{fileCount} file' , '{fileCount} files' , fileCount , { fileCount } )
37- } else if ( fileCount === 1 ) {
38- summary = n ( 'files' , '1 file and {folderCount} folder' , '1 file and {folderCount} folders' , folderCount , { folderCount } )
39- } else if ( folderCount === 1 ) {
40- summary = n ( 'files' , '{fileCount} file and 1 folder' , '{fileCount} files and 1 folder' , fileCount , { fileCount } )
41- } else {
42- summary = t ( 'files' , '{fileCount} files and {folderCount} folders' , { fileCount, folderCount } )
31+ const summary : string [ ] = [ ]
32+ if ( fileCount > 0 || folderCount === 0 ) {
33+ const fileSummary = n ( 'files' , '%n file' , '%n files' , fileCount )
34+ summary . push ( fileSummary )
35+ }
36+ if ( folderCount > 0 ) {
37+ const folderSummary = n ( 'files' , '%n folder' , '%n folders' , folderCount )
38+ summary . push ( folderSummary )
4339 }
44-
4540 if ( hidden > 0 ) {
46- // TRANSLATORS: This is a summary of files and folders, where {hiddenFilesAndFolders} is the number of hidden files and folders
47- summary += ' ' + n ( 'files' , '(%n hidden)' , ' (%n hidden)' , hidden )
41+ // TRANSLATORS: This is the number of hidden files or folders
42+ const hiddenSummary = n ( 'files' , '%n hidden' , '%n hidden' , hidden )
43+ summary . push ( hiddenSummary )
4844 }
4945
50- return summary
46+ return summary . join ( ' · ' )
5147}
0 commit comments