diff --git a/frontend/src/i18n/index.ts b/frontend/src/i18n/index.ts index 1bfbb866..1f3561c9 100755 --- a/frontend/src/i18n/index.ts +++ b/frontend/src/i18n/index.ts @@ -6,6 +6,7 @@ import koKR from './locales/ko-KR.ts' import jaJP from './locales/ja-JP.ts' import zhTW from './locales/zh-TW.ts' import { BUILT_IN_DEFAULT, resolveDefaultLocale } from './resolveDefaultLocale.ts' +import { pluralRules } from './pluralizationRules.ts' const messages = { 'zh-CN': zhCN, @@ -27,6 +28,7 @@ const i18n = createI18n({ locale: savedLocale, fallbackLocale: BUILT_IN_DEFAULT, globalInjection: true, + pluralRules, // Some translations intentionally embed `` markup (e.g. agent step summaries). // We render them via v-html with our own sanitization, so silence vue-i18n's HTML warning // to avoid flooding the console and slowing renders during history loads. diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 32c483ec..5be33b96 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -654,7 +654,7 @@ export default { }, knowledgeBase: { tagAddAction: 'Add tags', - documentCount: '{count} documents', + documentCount: '{count} document | {count} documents', filters: 'Filters', clearFilters: 'Clear filters', @@ -720,9 +720,11 @@ export default { title: 'Folders', rootRow: 'Root', rootRowTip: 'Knowledge base root; documents not in a subfolder live here', - folderCardCount: '{count} documents', + folderCardCount: '{count} document | {count} documents', searchingSubtree: '(including sub-folders)', emptyFolder: 'This folder has no documents yet', + emptyFolderWithSubfolders: 'This folder has no documents of its own, but {count} in sub-folders', + folderContentsCount: '{documents} documents / {folders} folder | {documents} documents / {folders} folders', emptySearch: 'No matching documents', collapse: 'Collapse folders', expand: 'Expand folders', diff --git a/frontend/src/i18n/locales/ja-JP.ts b/frontend/src/i18n/locales/ja-JP.ts index 90b3c2d8..dcd179a3 100644 --- a/frontend/src/i18n/locales/ja-JP.ts +++ b/frontend/src/i18n/locales/ja-JP.ts @@ -723,6 +723,8 @@ export default { folderCardCount: '{count}件のドキュメント', searchingSubtree: '(サブフォルダを含む)', emptyFolder: 'このフォルダにはまだドキュメントがありません', + emptyFolderWithSubfolders: 'このフォルダに直接のドキュメントはありませんが、サブフォルダに {count} 件あります', + folderContentsCount: '{documents} 件のドキュメント / {folders} 個のフォルダ', emptySearch: '該当するドキュメントがありません', collapse: 'フォルダを折りたたむ', expand: 'フォルダを展開', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index c54f1a91..69b77e18 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -7670,6 +7670,8 @@ export default { folderCardCount: '문서 {count}개', searchingSubtree: '(하위 폴더 포함)', emptyFolder: '이 폴더에는 아직 문서가 없습니다', + emptyFolderWithSubfolders: '이 폴더에는 직접 문서가 없지만 하위 폴더에 {count}개가 있습니다', + folderContentsCount: '문서 {documents}개 / 폴더 {folders}개', emptySearch: '일치하는 문서가 없습니다', collapse: '폴더 접기', expand: '폴더 펼치기', diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index 1fb85461..85ac97fe 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -7670,6 +7670,8 @@ export default { folderCardCount: 'Документов: {count}', searchingSubtree: '(с вложенными папками)', emptyFolder: 'В этой папке пока нет документов', + emptyFolderWithSubfolders: 'В этой папке нет собственных документов, но в подпапках есть {count}', + folderContentsCount: 'Документов: {documents} / {folders} папка | Документов: {documents} / {folders} папки | Документов: {documents} / {folders} папок', emptySearch: 'Подходящих документов нет', collapse: 'Свернуть папки', expand: 'Развернуть папки', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 05d3412d..610127ee 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -7671,6 +7671,8 @@ export default { folderCardCount: '{count} 个文档', searchingSubtree: '(含子目录)', emptyFolder: '这个文件夹里还没有文档', + emptyFolderWithSubfolders: '这个目录里没有直接文档,子目录里有 {count} 个', + folderContentsCount: '{documents} 个文档 / {folders} 个文件夹', emptySearch: '没有匹配的文档', collapse: '收起目录', expand: '展开目录', diff --git a/frontend/src/i18n/locales/zh-TW.ts b/frontend/src/i18n/locales/zh-TW.ts index 8b2184d2..5216d02c 100644 --- a/frontend/src/i18n/locales/zh-TW.ts +++ b/frontend/src/i18n/locales/zh-TW.ts @@ -7671,6 +7671,8 @@ export default { folderCardCount: '{count} 個文件', searchingSubtree: '(含子目錄)', emptyFolder: '這個資料夾裡還沒有文件', + emptyFolderWithSubfolders: '這個目錄裡沒有直接文件,子目錄裡有 {count} 個', + folderContentsCount: '{documents} 個文件 / {folders} 個資料夾', emptySearch: '沒有比對的文件', collapse: '收起目錄', expand: '展開目錄', diff --git a/frontend/src/i18n/pluralizationRules.ts b/frontend/src/i18n/pluralizationRules.ts new file mode 100644 index 00000000..b23e6f24 --- /dev/null +++ b/frontend/src/i18n/pluralizationRules.ts @@ -0,0 +1,18 @@ +/** + * vue-i18n's built-in plural rule only distinguishes "one" and "other". Russian + * has three forms (one / few / many), so messages written with three pipes need + * a selector that follows the CLDR rules. Only locales listed here are affected; + * everything else keeps the default rule. + */ +export const pluralRules: Record number> = { + ru: russianPluralRule, + 'ru-RU': russianPluralRule, +} + +function russianPluralRule(choice: number, choicesLength: number): number { + if (choicesLength < 3) return Math.abs(choice) === 1 ? 0 : 1 + const value = Math.abs(choice) + if (value % 10 === 1 && value % 100 !== 11) return 0 + if (value % 10 >= 2 && value % 10 <= 4 && (value % 100 < 10 || value % 100 >= 20)) return 1 + return 2 +} diff --git a/frontend/src/views/knowledge/KnowledgeBase.vue b/frontend/src/views/knowledge/KnowledgeBase.vue index 212902b7..50a6e5f6 100644 --- a/frontend/src/views/knowledge/KnowledgeBase.vue +++ b/frontend/src/views/knowledge/KnowledgeBase.vue @@ -68,7 +68,9 @@ import { resolveKnowledgeDownloadFileName } from './knowledgeDownloadFileName'; import { buildUploadFileName, canMoveFolderTo, + childFolders, folderBreadcrumbs as buildFolderBreadcrumbs, + folderDocumentCounts, folderPathExists as folderExistsInTree, isFilteringDocuments, ROOT_FOLDER_PATH, @@ -817,7 +819,50 @@ const isFiltering = computed(() => ); // A row's folder is worth showing only when the list can span folders. const showDocumentFolderPath = computed(() => hasFolders.value && isFiltering.value); +// Browsing a folder lists its direct sub-folders as entries, the way a file +// manager does. Filtering returns matching documents from the whole subtree, +// so folder entries would be noise there. +const visibleSubFolders = computed(() => + isFiltering.value ? [] : childFolders(folderTree.value, selectedFolderPath.value), +); const folderBreadcrumbs = computed(() => buildFolderBreadcrumbs(selectedFolderPath.value)); +// What the breadcrumb reports is the folder's own contents the way a file +// manager counts them: the documents this list can show plus its direct +// sub-folders, which the sidebar tree lists as rows. A recursive document total +// here would not match what the page shows, so that number stays on the tree row +// and in the empty state below. Filtering searches the subtree instead and +// reports only the flat result set, so it adds no folder number. +const folderContentsCount = computed<{ documents: number; folders: number }>(() => ({ + documents: total.value, + folders: isFiltering.value ? 0 : childFolders(folderTree.value, selectedFolderPath.value).length, +})); +// A folder with no sub-folders would otherwise end the breadcrumb with +// "/ 0 folders"; the document-only message is the whole truth there. +const showFolderContentsCount = computed( + () => !isFiltering.value && folderContentsCount.value.folders > 0, +); +const folderContentsMessage = computed(() => ({ + documents: folderContentsCount.value.documents, + folders: folderContentsCount.value.folders, + // vue-i18n selects the plural form from `count`; folders are the noun that + // changes with the number. + count: folderContentsCount.value.folders, +})); +// Documents below the selected folder rather than directly inside it; this is +// what tells "documents live in the sub-folders" apart from "nothing here yet". +const folderSubfolderDocumentCount = computed(() => { + const counts = folderDocumentCounts(folderTree.value, selectedFolderPath.value); + if (!counts) return 0; + return Math.max(0, counts.total - counts.direct); +}); +// Which empty state the document list needs: a search without matches, a folder +// whose documents are all below it, a plain empty folder, or the onboarding +// panel for a knowledge base that has no folders at all. +const folderEmptyState = computed<'search' | 'subfolders' | 'folder' | 'none'>(() => { + if (isFiltering.value) return 'search'; + if (folderSubfolderDocumentCount.value > 0) return 'subfolders'; + return hasFolders.value || selectedFolderPath.value ? 'folder' : 'none'; +}); const filterParams = computed(() => { const [start, end] = updatedTimeRange.value || []; @@ -2457,7 +2502,11 @@ const handleKBEditorSuccess = (kbIdValue: string) => { {{ crumb.name }} - {{ $t(isFiltering ? 'knowledgeBase.folderTree.filteredCount' : 'knowledgeBase.documentCount', { count: total }) }} + + + + + @@ -2590,7 +2639,7 @@ const handleKBEditorSuccess = (kbIdValue: string) => {
@@ -2618,10 +2667,11 @@ const handleKBEditorSuccess = (kbIdValue: string) => {
-