From 85b51fe5c143e68ae49eca0b2dce36bd88d1b36d Mon Sep 17 00:00:00 2001 From: myl7 Date: Sun, 6 Feb 2022 06:55:38 +0800 Subject: [PATCH] add some zh-CN translations --- components/Breadcrumb.tsx | 5 ++++- components/FileListing.tsx | 27 ++++++++++++++++-------- components/FolderListLayout.tsx | 33 ++++++++++++++++-------------- components/MultiFileDownloader.tsx | 7 +++++-- components/Navbar.tsx | 5 ++++- components/SwitchLayout.tsx | 17 +++++++++++++-- public/locales/en/common.json | 33 +++++++++++++++++++++++++++++- public/locales/zh-CN/common.json | 33 +++++++++++++++++++++++++++++- 8 files changed, 128 insertions(+), 32 deletions(-) diff --git a/components/Breadcrumb.tsx b/components/Breadcrumb.tsx index 726ccf1..f452eb1 100644 --- a/components/Breadcrumb.tsx +++ b/components/Breadcrumb.tsx @@ -2,13 +2,16 @@ import type { ParsedUrlQuery } from 'querystring' import Link from 'next/link' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import { useTranslation } from 'next-i18next' const HomeCrumb = () => { + const { t } = useTranslation() + return ( - Home + {t('Home')} ) diff --git a/components/FileListing.tsx b/components/FileListing.tsx index 6dbfa07..1178741 100644 --- a/components/FileListing.tsx +++ b/components/FileListing.tsx @@ -7,6 +7,7 @@ import { FC, MouseEventHandler, SetStateAction, useEffect, useRef, useState } fr import dynamic from 'next/dynamic' import { useRouter } from 'next/router' +import { useTranslation } from 'next-i18next' import useLocalStorage from '../utils/useLocalStorage' import { getPreviewType, preview } from '../utils/getPreviewType' @@ -146,6 +147,8 @@ const FileListing: FC<{ query?: ParsedUrlQuery }> = ({ query }) => { const router = useRouter() const [layout, _] = useLocalStorage('preferredLayout', layouts[0]) + const { t } = useTranslation() + const path = queryToPath(query) const { data, error, size, setSize } = useProtectedSWRInfinite(path) @@ -166,7 +169,7 @@ const FileListing: FC<{ query?: ParsedUrlQuery }> = ({ query }) => { if (!data) { return ( - + ) } @@ -240,13 +243,13 @@ const FileListing: FC<{ query?: ParsedUrlQuery }> = ({ query }) => { downloadMultipleFiles({ toastId, router, files, folder }) .then(() => { setTotalGenerating(false) - toast.success('Finished downloading selected files.', { + toast.success(t('Finished downloading selected files.'), { id: toastId, }) }) .catch(() => { setTotalGenerating(false) - toast.error('Failed to download selected files.', { id: toastId }) + toast.error(t('Failed to download selected files.'), { id: toastId }) }) } } @@ -256,7 +259,13 @@ const FileListing: FC<{ query?: ParsedUrlQuery }> = ({ query }) => { const files = (async function* () { for await (const { meta: c, path: p, isFolder, error } of traverseFolder(path)) { if (error) { - toast.error(`Failed to download folder ${p}: ${error.status} ${error.message} Skipped it to continue.`) + toast.error( + t('Failed to download folder {{path}}: {{status}} {{message}} Skipped it to continue.', { + path: p, + status: error.status, + message: error.message + }) + ) continue } yield { @@ -280,11 +289,11 @@ const FileListing: FC<{ query?: ParsedUrlQuery }> = ({ query }) => { }) .then(() => { setFolderGenerating({ ...folderGenerating, [id]: false }) - toast.success('Finished downloading folder.', { id: toastId }) + toast.success(t('Finished downloading folder.'), { id: toastId }) }) .catch(() => { setFolderGenerating({ ...folderGenerating, [id]: false }) - toast.error('Failed to download folder.', { id: toastId }) + toast.error(t('Failed to download folder.'), { id: toastId }) }) } @@ -324,13 +333,13 @@ const FileListing: FC<{ query?: ParsedUrlQuery }> = ({ query }) => { {isLoadingMore ? ( <> - Loading ...{' '} + {t('Loading ...')}{' '} ) : isReachingEnd ? ( - No more files + {t('No more files')} ) : ( <> - Load more + {t('Load more')} )} diff --git a/components/FolderListLayout.tsx b/components/FolderListLayout.tsx index 897cd70..2c3d7de 100644 --- a/components/FolderListLayout.tsx +++ b/components/FolderListLayout.tsx @@ -4,6 +4,7 @@ import Link from 'next/link' import { FC } from 'react' import { useClipboard } from 'use-clipboard-copy' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import { useTranslation } from 'next-i18next' import { getBaseUrl } from '../utils/getBaseUrl' import { humanFileSize, formatModifiedDateTime } from '../utils/fileDetails' @@ -44,20 +45,22 @@ const FolderListLayout = ({ }) => { const clipboard = useClipboard() + const { t } = useTranslation() + return (
- Name + {t('Name')}
- Last Modified + {t('Last Modified')}
- Size + {t('Size')}
- Actions + {t('Actions')}
@@ -65,13 +68,13 @@ const FolderListLayout = ({ checked={totalSelected} onChange={toggleTotalSelected} indeterminate={true} - title={'Select files'} + title={t('Select files')} /> {totalGenerating ? ( - + ) : (
) diff --git a/components/Navbar.tsx b/components/Navbar.tsx index a2d6236..2ea78a6 100644 --- a/components/Navbar.tsx +++ b/components/Navbar.tsx @@ -8,6 +8,7 @@ import Link from 'next/link' import Image from 'next/image' import { useRouter } from 'next/router' import { Fragment, useEffect, useState } from 'react' +import { useTranslation } from 'next-i18next' import siteConfig from '../config/site.config' import SearchModal from './SearchModal' @@ -37,6 +38,8 @@ const Navbar = () => { setTokenPresent(storedToken()) }, []) + const { t } = useTranslation() + const clearTokens = () => { setIsOpen(false) @@ -71,7 +74,7 @@ const Navbar = () => { >
- Search ... + {t('Search ...')}
diff --git a/components/SwitchLayout.tsx b/components/SwitchLayout.tsx index ebf31b6..af76888 100644 --- a/components/SwitchLayout.tsx +++ b/components/SwitchLayout.tsx @@ -2,6 +2,7 @@ import { Fragment } from 'react' import { IconProp } from '@fortawesome/fontawesome-svg-core' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { Listbox, Transition } from '@headlessui/react' +import { useTranslation } from 'next-i18next' import useLocalStorage from '../utils/useLocalStorage' @@ -13,13 +14,21 @@ export const layouts: Array<{ id: number; name: 'Grid' | 'List'; icon: IconProp export const SwitchLayout = () => { const [preferredLayout, setPreferredLayout] = useLocalStorage('preferredLayout', layouts[0]) + const { t } = useTranslation() + return (
- {preferredLayout.name} + + { + // t('Grid') + // t('List') + t(preferredLayout.name) + } + @@ -39,7 +48,11 @@ export const SwitchLayout = () => { > - {layout.name} + { + // t('Grid') + // t('List') + t(layout.name) + } {layout.name === preferredLayout.name && ( diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 0967ef4..c23ed78 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -1 +1,32 @@ -{} +{ + "Actions": "Actions", + "Cancel": "Cancel", + "Copied folder permalink.": "Copied folder permalink.", + "Copied raw file permalink.": "Copied raw file permalink.", + "Copy folder permalink": "Copy folder permalink", + "Copy raw file permalink": "Copy raw file permalink", + "Download file": "Download file", + "Download folder": "Download folder", + "Download selected files": "Download selected files", + "Downloading folder, refresh page to cancel": "Downloading folder, refresh page to cancel", + "Downloading selected files, refresh page to cancel": "Downloading selected files, refresh page to cancel", + "Downloading selected files...": "Downloading selected files...", + "Downloading {{progress}}%": "Downloading {{progress}}%", + "Failed to download folder {{path}}: {{status}} {{message}} Skipped it to continue.": "Failed to download folder {{path}}: {{status}} {{message}} Skipped it to continue.", + "Failed to download folder.": "Failed to download folder.", + "Failed to download selected files.": "Failed to download selected files.", + "Finished downloading folder.": "Finished downloading folder.", + "Finished downloading selected files.": "Finished downloading selected files.", + "Grid": "Grid", + "Home": "Home", + "Last Modified": "Last Modified", + "List": "List", + "Load more": "Load more", + "Loading ...": "Loading ...", + "Name": "Name", + "No more files": "No more files", + "Search ...": "Search ...", + "Select file": "Select file", + "Select files": "Select files", + "Size": "Size" +} diff --git a/public/locales/zh-CN/common.json b/public/locales/zh-CN/common.json index 0967ef4..c5afe04 100644 --- a/public/locales/zh-CN/common.json +++ b/public/locales/zh-CN/common.json @@ -1 +1,32 @@ -{} +{ + "Actions": "操作", + "Cancel": "取消", + "Copied folder permalink.": "已复制文件夹永久链接。", + "Copied raw file permalink.": "已复制文件永久链接。", + "Copy folder permalink": "复制文件夹永久链接", + "Copy raw file permalink": "复制文件永久链接", + "Download file": "下载此文件", + "Download folder": "下载此文件夹", + "Download selected files": "下载选定文件", + "Downloading folder, refresh page to cancel": "下载文件夹中,刷新页面以取消", + "Downloading selected files, refresh page to cancel": "下载选定文件中,刷新页面以取消", + "Downloading selected files...": "下载选定文件中...", + "Downloading {{progress}}%": "已下载 {{progress}}%", + "Failed to download folder {{path}}: {{status}} {{message}} Skipped it to continue.": "下载文件夹 {{path}} 失败:{{status}} {{message}} 已忽略此错误并继续下载。", + "Failed to download folder.": "下载文件夹失败。", + "Failed to download selected files.": "下载选定文件失败。", + "Finished downloading folder.": "下载文件夹成功。", + "Finished downloading selected files.": "下载选定文件成功。", + "Grid": "图格", + "Home": "首页", + "Last Modified": "最后修改时间", + "List": "列表", + "Load more": "加载更多", + "Loading ...": "加载中……", + "Name": "文件名", + "No more files": "加载完毕", + "Search ...": "搜索……", + "Select file": "选择此文件", + "Select files": "选择以下文件", + "Size": "文件大小" +}