From 45f6158e7dbc292e3784841a75bbc735c644a8c4 Mon Sep 17 00:00:00 2001 From: spencerwooo Date: Tue, 8 Feb 2022 23:30:12 +0800 Subject: [PATCH] switch locale component --- components/FileListing.tsx | 6 ++-- components/Navbar.tsx | 3 ++ components/SwitchLang.tsx | 65 +++++++++++++++++++++++++++++++++++++ components/SwitchLayout.tsx | 14 ++++++-- pages/[...path].tsx | 8 ++--- pages/_app.tsx | 2 ++ pages/index.tsx | 6 ++-- pnpm-lock.yaml | 10 +++--- 8 files changed, 98 insertions(+), 16 deletions(-) create mode 100644 components/SwitchLang.tsx diff --git a/components/FileListing.tsx b/components/FileListing.tsx index 2df9202..3edccf6 100644 --- a/components/FileListing.tsx +++ b/components/FileListing.tsx @@ -20,7 +20,7 @@ import { traverseFolder, } from './MultiFileDownloader' -import { layouts } from './SwitchLayout' +import layouts from './SwitchLayout' import Loading, { LoadingIcon } from './Loading' import FourOhFour from './FourOhFour' import Auth from './Auth' @@ -263,7 +263,7 @@ const FileListing: FC<{ query?: ParsedUrlQuery }> = ({ query }) => { t('Failed to download folder {{path}}: {{status}} {{message}} Skipped it to continue.', { path: p, status: error.status, - message: error.message + message: error.message, }) ) continue @@ -323,7 +323,7 @@ const FileListing: FC<{ query?: ParsedUrlQuery }> = ({ query }) => {
{t('- showing {{count}} page(s) ', { count: size, - totalFileNum: isLoadingMore ? '...' : folderChildren.length + totalFileNum: isLoadingMore ? '...' : folderChildren.length, }) + (isLoadingMore ? t('of {{count}} file(s) -', { count: folderChildren.length, context: 'loading' }) diff --git a/components/Navbar.tsx b/components/Navbar.tsx index 4c9ecce..a876939 100644 --- a/components/Navbar.tsx +++ b/components/Navbar.tsx @@ -12,6 +12,7 @@ import { useTranslation } from 'next-i18next' import siteConfig from '../config/site.config' import SearchModal from './SearchModal' +import SwitchLang from './SwitchLang' import useDeviceOS from '../utils/useDeviceOS' const Navbar = () => { @@ -88,6 +89,8 @@ const Navbar = () => {
+ + {siteConfig.links.length !== 0 && siteConfig.links.map((l: { name: string; link: string }) => ( { + return ( + + {children} + + ) +} + +const localeText = (locale: string): string => { + switch (locale) { + case 'en': + return 'đŸ‡Ŧ🇧 English' + case 'zh-CN': + return '🇨đŸ‡ŗ įŽ€äŊ“中文' + default: + return 'đŸ‡Ŧ🇧 English' + } +} + +const SwitchLang = () => { + const { locales, pathname, query, asPath } = useRouter() + + return ( +
+ + + + + + + + + {locales!.map(locale => ( + + +
+ {localeText(locale)} +
+
+
+ ))} +
+
+
+
+ ) +} + +export default SwitchLang diff --git a/components/SwitchLayout.tsx b/components/SwitchLayout.tsx index af76888..59f1e91 100644 --- a/components/SwitchLayout.tsx +++ b/components/SwitchLayout.tsx @@ -11,7 +11,7 @@ export const layouts: Array<{ id: number; name: 'Grid' | 'List'; icon: IconProp { id: 2, name: 'Grid', icon: 'th' }, ] -export const SwitchLayout = () => { +const SwitchLayout = () => { const [preferredLayout, setPreferredLayout] = useLocalStorage('preferredLayout', layouts[0]) const { t } = useTranslation() @@ -35,7 +35,15 @@ export const SwitchLayout = () => { - + {layouts.map(layout => ( { ) } + +export default SwitchLayout diff --git a/pages/[...path].tsx b/pages/[...path].tsx index f79b095..3c631d3 100644 --- a/pages/[...path].tsx +++ b/pages/[...path].tsx @@ -7,7 +7,7 @@ import Navbar from '../components/Navbar' import FileListing from '../components/FileListing' import Footer from '../components/Footer' import Breadcrumb from '../components/Breadcrumb' -import { SwitchLayout } from '../components/SwitchLayout' +import SwitchLayout from '../components/SwitchLayout' export default function Folders() { const { query } = useRouter() @@ -21,7 +21,7 @@ export default function Folders() {
-