diff --git a/src/components/File/index.tsx b/src/components/File/index.tsx index 032dd73..a40d7bc 100644 --- a/src/components/File/index.tsx +++ b/src/components/File/index.tsx @@ -7,7 +7,6 @@ import { FFS_DRAG_FILE } from "src/assets/constants"; import { useExplorer } from "src/hooks/useExplorer"; import FileContent, { FileProps } from "./Content"; -import { ITEM_INFO_COPY } from "src/locales"; import dayjs from "dayjs"; type Props = FileProps & { @@ -38,16 +37,17 @@ const File = ({ file, deleteFile, disableDrag, onOpenFoldersPane }: Props) => { }, [onOpenFoldersPane]); const getAriaLabel = () => { - const { fileModifiedTime, fileCreatedTime } = ITEM_INFO_COPY; - const { ctime, mtime } = file.stat; + const { basename, stat } = file; + const { ctime, mtime } = stat; const format = "YYYY-MM-DD HH:mm"; - const modifiedInfo = - fileModifiedTime[language] + dayjs(mtime).format(format); - const createdInfo = - fileCreatedTime[language] + dayjs(ctime).format(format); + const modifiedInfo = dayjs(mtime).format(format); + const createdInfo = dayjs(ctime).format(format); - return `${file.basename}\n${modifiedInfo}\n${createdInfo}`; + if (language === "en") { + return `${basename}\nLast modified at ${modifiedInfo}\nCreated at ${createdInfo}`; + } + return `${basename}\n最后修改于 ${modifiedInfo}\n创建于 ${createdInfo}`; }; return ( diff --git a/src/components/Folder/index.tsx b/src/components/Folder/index.tsx index b53e2ce..4c4a538 100644 --- a/src/components/Folder/index.tsx +++ b/src/components/Folder/index.tsx @@ -8,7 +8,7 @@ import FolderContent, { FolderProps } from "./Content"; import { useExplorer } from "src/hooks/useExplorer"; import FolderExpandIcon from "./ExpandIcon"; import classNames from "classnames"; -import { ITEM_INFO_COPY, PUNCTUATION_COPY } from "src/locales"; +import { pluralize } from "src/utils"; type Props = FolderProps & { onOpenFilesPane: () => void; @@ -104,22 +104,17 @@ const Folder = ({ }; const getAriaLabel = () => { + const { name } = folder; const filesCount = getFilesinFolder(folder).length; const foldersCount = getFoldersByParent(folder).length; - const { filesCountInFolder, foldersCountInFolder } = ITEM_INFO_COPY; - const filesCountInfo = - filesCount + - " " + - filesCountInFolder[language] + - (filesCount > 1 ? "s" : ""); - const foldersCountInfo = - foldersCount + - " " + - foldersCountInFolder[language] + - (foldersCount > 1 ? "s" : ""); + const filesCountInfo = pluralize(filesCount, "file"); + const foldersCountInfo = pluralize(foldersCount, "folder"); - return `${folder.name}\n${filesCountInfo}${PUNCTUATION_COPY.comma[language]}${foldersCountInfo}`; + if (language === "en") { + return `${name}\n${filesCountInfo}, ${foldersCountInfo}`; + } + return `${name}\n${filesCount} 条笔记,${foldersCount} 个文件夹`; }; const getIndentStyle = () => { diff --git a/src/components/Tag/index.tsx b/src/components/Tag/index.tsx index b6a89be..c399d6b 100644 --- a/src/components/Tag/index.tsx +++ b/src/components/Tag/index.tsx @@ -6,7 +6,7 @@ import { useExplorer } from "src/hooks/useExplorer"; import { ExplorerStore } from "src/store"; import TagExpandIcon from "./ExpandIcon"; import TagContent from "./Content"; -import { ITEM_INFO_COPY, PUNCTUATION_COPY } from "src/locales"; +import { pluralize } from "src/utils"; type Props = { tag: TagNode; @@ -39,22 +39,14 @@ const Tag = ({ const isFocused = tag.fullPath == focusedTag?.fullPath; const getAriaLabel = () => { + const { name } = tag const filesCount = getFilesInTag(tag).length; const tagsCount = getTagsByParent(tag.fullPath).length; - const { filesCountInTag, tagsCountInTag } = ITEM_INFO_COPY; - const filesCountInfo = - filesCount + - " " + - filesCountInTag[language] + - (filesCount > 1 ? "s" : ""); - const tagsCountInfo = - tagsCount + - " " + - tagsCountInTag[language] + - (tagsCount > 1 ? "s" : ""); - - return `${tag.name}\n${filesCountInfo}${PUNCTUATION_COPY.comma[language]}${tagsCountInfo}`; + if (language === "en") { + return `${name}\n${pluralize(filesCount, "file")}, ${pluralize(tagsCount, "tag")}`; + } + return `${name}\n${filesCount} 条笔记,${tagsCount} 个标签`; }; const getIndentStyle = () => { diff --git a/src/locales/index.ts b/src/locales/index.ts index 3e0c77e..4347498 100644 --- a/src/locales/index.ts +++ b/src/locales/index.ts @@ -147,37 +147,3 @@ export const FILE_SORT_RULES_COPY: Copy = { zh: "手动排序", }, }; - -export const PUNCTUATION_COPY: Copy = { - comma: { - en: ", ", - zh: ",", - }, -}; - -export const ITEM_INFO_COPY: Copy = { - filesCountInFolder: { - en: "file", - zh: "条笔记", - }, - foldersCountInFolder: { - en: "folder", - zh: "个文件夹", - }, - filesCountInTag: { - en: "file", - zh: "条笔记", - }, - tagsCountInTag: { - en: "tag", - zh: "个标签", - }, - fileModifiedTime: { - en: "Last modified at ", - zh: "最后修改于 ", - }, - fileCreatedTime: { - en: "Created at ", - zh: "创建于 ", - }, -}; diff --git a/src/utils.ts b/src/utils.ts index 980bf22..99cacc5 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -13,3 +13,7 @@ export const isAbstractFileIncluded = ( files: TAbstractFile[], file: TAbstractFile ): boolean => files.some((f) => f.path === file.path); + +export const pluralize = (count: number, word: string): string => { + return `${count} ${word}${count > 1 ? "s" : ""}`; +};