From 21d479a1df14c5fa0947e1824c7ce77609180d69 Mon Sep 17 00:00:00 2001 From: kunish Date: Sat, 23 Sep 2023 02:06:57 +0800 Subject: [PATCH] feat(i18n): new language switcher in config page --- src/components/Header.tsx | 15 ++------- src/i18n/en.ts | 2 ++ src/i18n/zh.ts | 2 ++ src/pages/Config.tsx | 64 +++++++++++++++++++++++++++------------ 4 files changed, 51 insertions(+), 32 deletions(-) diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 345a314..a607913 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -3,7 +3,6 @@ import { IconFileStack, IconGlobe, IconHome, - IconLanguage, IconMenu, IconNetwork, IconPalette, @@ -11,9 +10,9 @@ import { IconSettings, } from '@tabler/icons-solidjs' import { For, ParentComponent, Show, createSignal } from 'solid-js' -import { Button, LogoText } from '~/components' -import { LANG, ROUTES, themes } from '~/constants' -import { setLocale, useI18n } from '~/i18n' +import { LogoText } from '~/components' +import { ROUTES, themes } from '~/constants' +import { useI18n } from '~/i18n' import { setCurTheme } from '~/signals' const Nav: ParentComponent<{ href: string; tooltip: string }> = ({ @@ -152,14 +151,6 @@ export const Header = () => { diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 16fc9c0..b670034 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -101,4 +101,6 @@ export default { tunModeStack: 'TUN Mode Stack', tunDeviceName: 'TUN Device Name', interfaceName: 'Interface Name', + en: 'English', + zh: 'Chinese', } diff --git a/src/i18n/zh.ts b/src/i18n/zh.ts index ee06791..63c95be 100644 --- a/src/i18n/zh.ts +++ b/src/i18n/zh.ts @@ -103,4 +103,6 @@ export default { tunModeStack: 'TUN 模式堆栈', tunDeviceName: 'TUN 设备名称', interfaceName: '接口名称', + en: '英文', + zh: '中文', } satisfies Dict diff --git a/src/pages/Config.tsx b/src/pages/Config.tsx index 0938cc4..97b0281 100644 --- a/src/pages/Config.tsx +++ b/src/pages/Config.tsx @@ -26,8 +26,8 @@ import { upgradingBackend, } from '~/apis' import { Button, ConfigTitle } from '~/components' -import { MODE_OPTIONS, ROUTES, themes } from '~/constants' -import { useI18n } from '~/i18n' +import { LANG, MODE_OPTIONS, ROUTES, themes } from '~/constants' +import { locale, setLocale, useI18n } from '~/i18n' import { autoSwitchTheme, favDayTheme, @@ -354,6 +354,17 @@ const ConfigForm = () => { const ConfigForXd = () => { const [t] = useI18n() + const languages = [ + { + label: () => t('en'), + value: LANG.EN, + }, + { + label: () => t('zh'), + value: LANG.ZH, + }, + ] + return (
@@ -375,14 +386,11 @@ const ConfigForXd = () => {
@@ -392,14 +400,11 @@ const ConfigForXd = () => {
@@ -407,15 +412,34 @@ const ConfigForXd = () => { -
- {t('useTwemoji')} +
+
+ {t('useTwemoji')} - setUseTwemoji(e.target.checked)} - /> + setUseTwemoji(e.target.checked)} + /> +
+ +
+ {t('switchLanguage')} + + +
)