mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-24 09:45:35 +08:00
feat(i18n): new language switcher in config page
This commit is contained in:
parent
81bab5d0ab
commit
21d479a1df
@ -3,7 +3,6 @@ import {
|
|||||||
IconFileStack,
|
IconFileStack,
|
||||||
IconGlobe,
|
IconGlobe,
|
||||||
IconHome,
|
IconHome,
|
||||||
IconLanguage,
|
|
||||||
IconMenu,
|
IconMenu,
|
||||||
IconNetwork,
|
IconNetwork,
|
||||||
IconPalette,
|
IconPalette,
|
||||||
@ -11,9 +10,9 @@ import {
|
|||||||
IconSettings,
|
IconSettings,
|
||||||
} from '@tabler/icons-solidjs'
|
} from '@tabler/icons-solidjs'
|
||||||
import { For, ParentComponent, Show, createSignal } from 'solid-js'
|
import { For, ParentComponent, Show, createSignal } from 'solid-js'
|
||||||
import { Button, LogoText } from '~/components'
|
import { LogoText } from '~/components'
|
||||||
import { LANG, ROUTES, themes } from '~/constants'
|
import { ROUTES, themes } from '~/constants'
|
||||||
import { setLocale, useI18n } from '~/i18n'
|
import { useI18n } from '~/i18n'
|
||||||
import { setCurTheme } from '~/signals'
|
import { setCurTheme } from '~/signals'
|
||||||
|
|
||||||
const Nav: ParentComponent<{ href: string; tooltip: string }> = ({
|
const Nav: ParentComponent<{ href: string; tooltip: string }> = ({
|
||||||
@ -152,14 +151,6 @@ export const Header = () => {
|
|||||||
|
|
||||||
<div class="navbar-end">
|
<div class="navbar-end">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<Button
|
|
||||||
class="btn-circle btn-secondary btn-sm"
|
|
||||||
onClick={() =>
|
|
||||||
setLocale((locale) => (locale === LANG.EN ? LANG.ZH : LANG.EN))
|
|
||||||
}
|
|
||||||
icon={<IconLanguage />}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<ThemeSwitcher />
|
<ThemeSwitcher />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -101,4 +101,6 @@ export default {
|
|||||||
tunModeStack: 'TUN Mode Stack',
|
tunModeStack: 'TUN Mode Stack',
|
||||||
tunDeviceName: 'TUN Device Name',
|
tunDeviceName: 'TUN Device Name',
|
||||||
interfaceName: 'Interface Name',
|
interfaceName: 'Interface Name',
|
||||||
|
en: 'English',
|
||||||
|
zh: 'Chinese',
|
||||||
}
|
}
|
||||||
|
@ -103,4 +103,6 @@ export default {
|
|||||||
tunModeStack: 'TUN 模式堆栈',
|
tunModeStack: 'TUN 模式堆栈',
|
||||||
tunDeviceName: 'TUN 设备名称',
|
tunDeviceName: 'TUN 设备名称',
|
||||||
interfaceName: '接口名称',
|
interfaceName: '接口名称',
|
||||||
|
en: '英文',
|
||||||
|
zh: '中文',
|
||||||
} satisfies Dict
|
} satisfies Dict
|
||||||
|
@ -26,8 +26,8 @@ import {
|
|||||||
upgradingBackend,
|
upgradingBackend,
|
||||||
} from '~/apis'
|
} from '~/apis'
|
||||||
import { Button, ConfigTitle } from '~/components'
|
import { Button, ConfigTitle } from '~/components'
|
||||||
import { MODE_OPTIONS, ROUTES, themes } from '~/constants'
|
import { LANG, MODE_OPTIONS, ROUTES, themes } from '~/constants'
|
||||||
import { useI18n } from '~/i18n'
|
import { locale, setLocale, useI18n } from '~/i18n'
|
||||||
import {
|
import {
|
||||||
autoSwitchTheme,
|
autoSwitchTheme,
|
||||||
favDayTheme,
|
favDayTheme,
|
||||||
@ -354,6 +354,17 @@ const ConfigForm = () => {
|
|||||||
const ConfigForXd = () => {
|
const ConfigForXd = () => {
|
||||||
const [t] = useI18n()
|
const [t] = useI18n()
|
||||||
|
|
||||||
|
const languages = [
|
||||||
|
{
|
||||||
|
label: () => t('en'),
|
||||||
|
value: LANG.EN,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: () => t('zh'),
|
||||||
|
value: LANG.ZH,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
@ -375,14 +386,11 @@ const ConfigForXd = () => {
|
|||||||
|
|
||||||
<select
|
<select
|
||||||
class="select select-bordered"
|
class="select select-bordered"
|
||||||
|
value={favDayTheme()}
|
||||||
onChange={(e) => setFavDayTheme(e.target.value)}
|
onChange={(e) => setFavDayTheme(e.target.value)}
|
||||||
>
|
>
|
||||||
<For each={themes}>
|
<For each={themes}>
|
||||||
{(theme) => (
|
{(theme) => <option value={theme}>{theme}</option>}
|
||||||
<option selected={favDayTheme() === theme} value={theme}>
|
|
||||||
{theme}
|
|
||||||
</option>
|
|
||||||
)}
|
|
||||||
</For>
|
</For>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@ -392,14 +400,11 @@ const ConfigForXd = () => {
|
|||||||
|
|
||||||
<select
|
<select
|
||||||
class="select select-bordered"
|
class="select select-bordered"
|
||||||
|
value={favNightTheme()}
|
||||||
onChange={(e) => setFavNightTheme(e.target.value)}
|
onChange={(e) => setFavNightTheme(e.target.value)}
|
||||||
>
|
>
|
||||||
<For each={themes}>
|
<For each={themes}>
|
||||||
{(theme) => (
|
{(theme) => <option value={theme}>{theme}</option>}
|
||||||
<option selected={favNightTheme() === theme} value={theme}>
|
|
||||||
{theme}
|
|
||||||
</option>
|
|
||||||
)}
|
|
||||||
</For>
|
</For>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@ -407,6 +412,7 @@ const ConfigForXd = () => {
|
|||||||
</Show>
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
<div class="flex flex-col items-center">
|
<div class="flex flex-col items-center">
|
||||||
<ConfigTitle>{t('useTwemoji')}</ConfigTitle>
|
<ConfigTitle>{t('useTwemoji')}</ConfigTitle>
|
||||||
|
|
||||||
@ -417,6 +423,24 @@ const ConfigForXd = () => {
|
|||||||
onChange={(e) => setUseTwemoji(e.target.checked)}
|
onChange={(e) => setUseTwemoji(e.target.checked)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<ConfigTitle>{t('switchLanguage')}</ConfigTitle>
|
||||||
|
|
||||||
|
<select
|
||||||
|
class="select select-bordered"
|
||||||
|
onChange={(e) => setLocale(e.target.value as LANG)}
|
||||||
|
>
|
||||||
|
<For each={languages}>
|
||||||
|
{(lang) => (
|
||||||
|
<option selected={locale() === lang.value} value={lang.value}>
|
||||||
|
{lang.label()}
|
||||||
|
</option>
|
||||||
|
)}
|
||||||
|
</For>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user