chore(i18n): bump i18n from v1 to v2

This commit is contained in:
kunish 2023-09-22 17:14:35 +08:00
parent 2fbcfbbe20
commit 0efced7e13
No known key found for this signature in database
GPG Key ID: 647A12B4F782C430
19 changed files with 607 additions and 604 deletions

View File

@ -20,7 +20,7 @@
"@fontsource/fira-sans": "^5.0.12", "@fontsource/fira-sans": "^5.0.12",
"@solid-primitives/clipboard": "^1.5.7", "@solid-primitives/clipboard": "^1.5.7",
"@solid-primitives/event-listener": "^2.3.0", "@solid-primitives/event-listener": "^2.3.0",
"@solid-primitives/i18n": "^1.4.1", "@solid-primitives/i18n": "^2.0.0",
"@solid-primitives/keyed": "^1.2.0", "@solid-primitives/keyed": "^1.2.0",
"@solid-primitives/media": "^2.2.5", "@solid-primitives/media": "^2.2.5",
"@solid-primitives/resize-observer": "^2.0.22", "@solid-primitives/resize-observer": "^2.0.22",

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,5 @@
import { createForm } from '@felte/solid' import { createForm } from '@felte/solid'
import { validator } from '@felte/validator-zod' import { validator } from '@felte/validator-zod'
import { useI18n } from '@solid-primitives/i18n'
import { IconX } from '@tabler/icons-solidjs' import { IconX } from '@tabler/icons-solidjs'
import type { import type {
DragEventHandler, DragEventHandler,
@ -27,6 +26,7 @@ import {
MODAL, MODAL,
TAILWINDCSS_SIZE, TAILWINDCSS_SIZE,
} from '~/constants' } from '~/constants'
import { useI18n } from '~/i18n'
import { import {
allConnections, allConnections,
clientSourceIPTags, clientSourceIPTags,
@ -45,7 +45,7 @@ const TagClientSourceIPWithNameForm: Component = () => {
sourceIP: z.string().nonempty(), sourceIP: z.string().nonempty(),
}) })
const [t] = useI18n() const { t } = useI18n()
const { form, reset } = createForm<z.infer<typeof schema>>({ const { form, reset } = createForm<z.infer<typeof schema>>({
extend: validator({ schema }), extend: validator({ schema }),
@ -113,7 +113,7 @@ export const ConnectionsSettingsModal = (props: {
onVisibleChange: (value: ConnectionsTableColumnVisibility) => void onVisibleChange: (value: ConnectionsTableColumnVisibility) => void
}) => { }) => {
const modalID = MODAL.CONNECTIONS_SETTINGS const modalID = MODAL.CONNECTIONS_SETTINGS
const [t] = useI18n() const { t } = useI18n()
const [activeKey, setActiveKey] = const [activeKey, setActiveKey] =
createSignal<CONNECTIONS_TABLE_ACCESSOR_KEY | null>(null) createSignal<CONNECTIONS_TABLE_ACCESSOR_KEY | null>(null)

View File

@ -1,4 +1,3 @@
import { useI18n } from '@solid-primitives/i18n'
import { A, useLocation } from '@solidjs/router' import { A, useLocation } from '@solidjs/router'
import { import {
IconFileStack, IconFileStack,
@ -14,6 +13,7 @@ import {
import { For, ParentComponent, Show, createSignal } from 'solid-js' import { For, ParentComponent, Show, createSignal } from 'solid-js'
import { Button, LogoText } from '~/components' import { Button, LogoText } from '~/components'
import { LANG, ROUTES, themes } from '~/constants' import { LANG, ROUTES, themes } from '~/constants'
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 }> = ({
@ -62,7 +62,7 @@ const ThemeSwitcher = () => (
) )
export const Header = () => { export const Header = () => {
const [t, { locale }] = useI18n() const { t, locale } = useI18n()
const navs = () => [ const navs = () => [
{ {
href: ROUTES.Overview, href: ROUTES.Overview,

View File

@ -1,10 +1,10 @@
import { useI18n } from '@solid-primitives/i18n'
import { Show, createEffect, createMemo, createSignal } from 'solid-js' import { Show, createEffect, createMemo, createSignal } from 'solid-js'
import { LATENCY_QUALITY_MAP_HTTP } from '~/constants' import { LATENCY_QUALITY_MAP_HTTP } from '~/constants'
import { useI18n } from '~/i18n'
import { latencyQualityMap, useProxies } from '~/signals' import { latencyQualityMap, useProxies } from '~/signals'
export const Latency = (props: { name?: string }) => { export const Latency = (props: { name?: string }) => {
const [t] = useI18n() const { t } = useI18n()
const { latencyMap } = useProxies() const { latencyMap } = useProxies()
const [textClassName, setTextClassName] = createSignal('') const [textClassName, setTextClassName] = createSignal('')
const latency = createMemo(() => { const latency = createMemo(() => {

View File

@ -1,4 +1,3 @@
import { useI18n } from '@solid-primitives/i18n'
import { IconX } from '@tabler/icons-solidjs' import { IconX } from '@tabler/icons-solidjs'
import { For } from 'solid-js' import { For } from 'solid-js'
import { Button, ConfigTitle } from '~/components' import { Button, ConfigTitle } from '~/components'
@ -8,6 +7,7 @@ import {
MODAL, MODAL,
TAILWINDCSS_SIZE, TAILWINDCSS_SIZE,
} from '~/constants' } from '~/constants'
import { useI18n } from '~/i18n'
import { import {
logLevel, logLevel,
logMaxRows, logMaxRows,
@ -19,7 +19,7 @@ import {
export const LogsSettingsModal = () => { export const LogsSettingsModal = () => {
const modalID = MODAL.LOGS_SETTINGS const modalID = MODAL.LOGS_SETTINGS
const [t] = useI18n() const { t } = useI18n()
return ( return (
<dialog id={modalID} class="modal modal-bottom sm:modal-middle"> <dialog id={modalID} class="modal modal-bottom sm:modal-middle">

View File

@ -1,8 +1,8 @@
import { useI18n } from '@solid-primitives/i18n'
import { IconX } from '@tabler/icons-solidjs' import { IconX } from '@tabler/icons-solidjs'
import { For } from 'solid-js' import { For } from 'solid-js'
import { Button, ConfigTitle } from '~/components' import { Button, ConfigTitle } from '~/components'
import { MODAL, PROXIES_ORDERING_TYPE, PROXIES_PREVIEW_TYPE } from '~/constants' import { MODAL, PROXIES_ORDERING_TYPE, PROXIES_PREVIEW_TYPE } from '~/constants'
import { useI18n } from '~/i18n'
import { import {
autoCloseConns, autoCloseConns,
hideUnAvailableProxies, hideUnAvailableProxies,
@ -20,7 +20,7 @@ import {
export const ProxiesSettingsModal = () => { export const ProxiesSettingsModal = () => {
const modalID = MODAL.PROXIES_SETTINGS const modalID = MODAL.PROXIES_SETTINGS
const [t] = useI18n() const { t } = useI18n()
return ( return (
<dialog id={modalID} class="modal modal-bottom sm:modal-middle"> <dialog id={modalID} class="modal modal-bottom sm:modal-middle">

View File

@ -1,7 +1,7 @@
import { useI18n } from '@solid-primitives/i18n'
import byteSize from 'byte-size' import byteSize from 'byte-size'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { toFinite } from 'lodash' import { toFinite } from 'lodash'
import { useI18n } from '~/i18n'
import type { SubscriptionInfo as ISubscriptionInfo } from '~/types' import type { SubscriptionInfo as ISubscriptionInfo } from '~/types'
const getSubscriptionsInfo = (subscriptionInfo: ISubscriptionInfo) => { const getSubscriptionsInfo = (subscriptionInfo: ISubscriptionInfo) => {
@ -14,13 +14,13 @@ const getSubscriptionsInfo = (subscriptionInfo: ISubscriptionInfo) => {
const percentage = toFinite((((Download + Upload) / Total) * 100).toFixed(2)) const percentage = toFinite((((Download + Upload) / Total) * 100).toFixed(2))
const expirePrefix = () => { const expirePrefix = () => {
const [t] = useI18n() const { t } = useI18n()
return t('expire') return t('expire')
} }
const expireStr = () => { const expireStr = () => {
const [t] = useI18n() const { t } = useI18n()
if (Expire === 0) { if (Expire === 0) {
return t('noExpire') return t('noExpire')

View File

@ -1,7 +1,10 @@
import { Flatten } from '@solid-primitives/i18n'
import { LANG } from '~/constants' import { LANG } from '~/constants'
import en from './en' import en from './en'
import zh from './zh' import zh from './zh'
export type Dict = Flatten<typeof en>
export default { export default {
[LANG.EN]: en, [LANG.EN]: en,
[LANG.ZH]: zh, [LANG.ZH]: zh,

View File

@ -1,43 +1,32 @@
import { I18nContext, createI18nContext, useI18n } from '@solid-primitives/i18n' import * as i18n from '@solid-primitives/i18n'
import { makePersisted } from '@solid-primitives/storage' import { makePersisted } from '@solid-primitives/storage'
import dayjs from 'dayjs' import { createMemo, createSignal } from 'solid-js'
import { ParentComponent, createEffect, createSignal } from 'solid-js'
import { LANG } from '~/constants' import { LANG } from '~/constants'
import dict from './dict' import dict from './dict'
const useLanguage = () => { const [curLocale, setCurLocale] = makePersisted(
const [lang, setLang] = makePersisted( createSignal<LANG>(
createSignal( Reflect.has(dict, navigator.language)
Reflect.has(dict, navigator.language) ? navigator.language : LANG.EN, ? (navigator.language as LANG)
), : LANG.EN,
{ ),
name: 'lang', {
storage: localStorage, name: 'lang',
}, storage: localStorage,
) },
)
return { lang, setLang } const locale = (localeName?: LANG) => {
if (localeName) {
return setCurLocale(localeName)
}
return curLocale()
} }
const I18nUpdater: ParentComponent = (props) => { export const useI18n = () => {
const { setLang } = useLanguage() const curDict = createMemo(() => i18n.flatten(dict[curLocale()]))!
const [, { locale }] = useI18n() const t = i18n.translator(() => curDict())
createEffect(() => { return { t, locale }
setLang(locale())
dayjs.locale(locale())
})
return props.children
}
export const I18nProvider: ParentComponent = (props) => {
const { lang } = useLanguage()
const value = createI18nContext(dict, lang())
return (
<I18nContext.Provider value={value}>
<I18nUpdater>{props.children}</I18nUpdater>
</I18nContext.Provider>
)
} }

View File

@ -1,3 +1,5 @@
import { Dict } from '~/i18n/dict'
export default { export default {
add: '添加', add: '添加',
overview: '概览', overview: '概览',
@ -97,4 +99,4 @@ export default {
version: '版本', version: '版本',
expire: '到期时间', expire: '到期时间',
noExpire: '不限时', noExpire: '不限时',
} } satisfies Dict

View File

@ -7,17 +7,14 @@ import 'dayjs/locale/zh-cn'
import relativeTime from 'dayjs/plugin/relativeTime' import relativeTime from 'dayjs/plugin/relativeTime'
import { render } from 'solid-js/web' import { render } from 'solid-js/web'
import { App } from '~/App' import { App } from '~/App'
import { I18nProvider } from '~/i18n'
dayjs.extend(relativeTime) dayjs.extend(relativeTime)
render( render(
() => ( () => (
<I18nProvider> <Router source={hashIntegration()}>
<Router source={hashIntegration()}> <App />
<App /> </Router>
</Router>
</I18nProvider>
), ),
document.getElementById('root')!, document.getElementById('root')!,
) )

View File

@ -1,6 +1,5 @@
import { createForm } from '@felte/solid' import { createForm } from '@felte/solid'
import { validator } from '@felte/validator-zod' import { validator } from '@felte/validator-zod'
import { useI18n } from '@solid-primitives/i18n'
import { useNavigate } from '@solidjs/router' import { useNavigate } from '@solidjs/router'
import { import {
For, For,
@ -28,6 +27,7 @@ import {
} from '~/apis' } from '~/apis'
import { Button, ConfigTitle } from '~/components' import { Button, ConfigTitle } from '~/components'
import { MODE_OPTIONS, ROUTES, themes } from '~/constants' import { MODE_OPTIONS, ROUTES, themes } from '~/constants'
import { useI18n } from '~/i18n'
import { import {
autoSwitchTheme, autoSwitchTheme,
favDayTheme, favDayTheme,
@ -48,7 +48,7 @@ const dnsQueryFormSchema = z.object({
}) })
const DNSQueryForm = () => { const DNSQueryForm = () => {
const [t] = useI18n() const { t } = useI18n()
const request = useRequest() const request = useRequest()
const { form, isSubmitting } = createForm<z.infer<typeof dnsQueryFormSchema>>( const { form, isSubmitting } = createForm<z.infer<typeof dnsQueryFormSchema>>(
@ -111,7 +111,7 @@ const configFormSchema = z.object({
}) })
const ConfigForm = () => { const ConfigForm = () => {
const [t] = useI18n() const { t } = useI18n()
const navigate = useNavigate() const navigate = useNavigate()
const portList = [ const portList = [
@ -267,7 +267,7 @@ const ConfigForm = () => {
} }
const ConfigForXd = () => { const ConfigForXd = () => {
const [t] = useI18n() const { t } = useI18n()
return ( return (
<div class="grid grid-cols-2 place-items-center gap-4"> <div class="grid grid-cols-2 place-items-center gap-4">
@ -354,7 +354,7 @@ const Versions = () => {
} }
export default () => { export default () => {
const [t] = useI18n() const { t } = useI18n()
return ( return (
<div class="mx-auto flex max-w-screen-md flex-col gap-4"> <div class="mx-auto flex max-w-screen-md flex-col gap-4">

View File

@ -1,5 +1,4 @@
import { writeClipboard } from '@solid-primitives/clipboard' import { writeClipboard } from '@solid-primitives/clipboard'
import { useI18n } from '@solid-primitives/i18n'
import { makePersisted } from '@solid-primitives/storage' import { makePersisted } from '@solid-primitives/storage'
import { import {
IconInfoSmall, IconInfoSmall,
@ -46,6 +45,7 @@ import {
} from '~/components' } from '~/components'
import { CONNECTIONS_TABLE_ACCESSOR_KEY, MODAL } from '~/constants' import { CONNECTIONS_TABLE_ACCESSOR_KEY, MODAL } from '~/constants'
import { formatTimeFromNow } from '~/helpers' import { formatTimeFromNow } from '~/helpers'
import { useI18n } from '~/i18n'
import { import {
allConnections, allConnections,
clientSourceIPTags, clientSourceIPTags,
@ -78,7 +78,7 @@ const fuzzyFilter: FilterFn<Connection> = (row, columnId, value, addMeta) => {
} }
export default () => { export default () => {
const [t] = useI18n() const { t } = useI18n()
const [activeTab, setActiveTab] = createSignal(ActiveTab.activeConnections) const [activeTab, setActiveTab] = createSignal(ActiveTab.activeConnections)
const { activeConnections, closedConnections, paused, setPaused } = const { activeConnections, closedConnections, paused, setPaused } =
@ -346,7 +346,7 @@ export default () => {
</div> </div>
<select <select
class="select join-item select-bordered select-primary" class="join-item select select-bordered select-primary"
onChange={(e) => setSourceIPFilter(e.target.value)} onChange={(e) => setSourceIPFilter(e.target.value)}
> >
<option value="">{t('all')}</option> <option value="">{t('all')}</option>

View File

@ -1,4 +1,3 @@
import { useI18n } from '@solid-primitives/i18n'
import { makePersisted } from '@solid-primitives/storage' import { makePersisted } from '@solid-primitives/storage'
import { import {
IconSettings, IconSettings,
@ -20,6 +19,7 @@ import { For, Index, createEffect, createMemo, createSignal } from 'solid-js'
import { twMerge } from 'tailwind-merge' import { twMerge } from 'tailwind-merge'
import { Button, LogsSettingsModal } from '~/components' import { Button, LogsSettingsModal } from '~/components'
import { LOG_LEVEL, MODAL } from '~/constants' import { LOG_LEVEL, MODAL } from '~/constants'
import { useI18n } from '~/i18n'
import { logsTableSize, tableSizeClassName, useWsRequest } from '~/signals' import { logsTableSize, tableSizeClassName, useWsRequest } from '~/signals'
import { logLevel, logMaxRows } from '~/signals/config' import { logLevel, logMaxRows } from '~/signals/config'
import { Log } from '~/types' import { Log } from '~/types'
@ -40,7 +40,7 @@ const fuzzyFilter: FilterFn<LogWithSeq> = (row, columnId, value, addMeta) => {
} }
export default () => { export default () => {
const [t] = useI18n() const { t } = useI18n()
let seq = 1 let seq = 1
const [logs, setLogs] = createSignal<LogWithSeq[]>([]) const [logs, setLogs] = createSignal<LogWithSeq[]>([])

View File

@ -1,4 +1,3 @@
import { useI18n } from '@solid-primitives/i18n'
import { makeTimer } from '@solid-primitives/timer' import { makeTimer } from '@solid-primitives/timer'
import type { ApexOptions } from 'apexcharts' import type { ApexOptions } from 'apexcharts'
import byteSize from 'byte-size' import byteSize from 'byte-size'
@ -14,6 +13,7 @@ import {
createSignal, createSignal,
} from 'solid-js' } from 'solid-js'
import { CHART_MAX_XAXIS, DEFAULT_CHART_OPTIONS } from '~/constants' import { CHART_MAX_XAXIS, DEFAULT_CHART_OPTIONS } from '~/constants'
import { useI18n } from '~/i18n'
import { latestConnectionMsg, useWsRequest } from '~/signals' import { latestConnectionMsg, useWsRequest } from '~/signals'
const TrafficWidget: ParentComponent<{ label: JSX.Element }> = (props) => ( const TrafficWidget: ParentComponent<{ label: JSX.Element }> = (props) => (
@ -26,7 +26,7 @@ const TrafficWidget: ParentComponent<{ label: JSX.Element }> = (props) => (
) )
export default () => { export default () => {
const [t] = useI18n() const { t } = useI18n()
const [traffics, setTraffics] = createSignal<{ down: number; up: number }[]>( const [traffics, setTraffics] = createSignal<{ down: number; up: number }[]>(
[], [],

View File

@ -1,4 +1,3 @@
import { useI18n } from '@solid-primitives/i18n'
import { import {
IconBrandSpeedtest, IconBrandSpeedtest,
IconReload, IconReload,
@ -22,6 +21,7 @@ import {
sortProxiesByOrderingType, sortProxiesByOrderingType,
useStringBooleanMap, useStringBooleanMap,
} from '~/helpers' } from '~/helpers'
import { useI18n } from '~/i18n'
import { import {
hideUnAvailableProxies, hideUnAvailableProxies,
proxiesOrderingType, proxiesOrderingType,
@ -34,7 +34,7 @@ enum ActiveTab {
} }
export default () => { export default () => {
const [t] = useI18n() const { t } = useI18n()
const { const {
proxies, proxies,
selectProxyInGroup, selectProxyInGroup,

View File

@ -1,9 +1,9 @@
import { useI18n } from '@solid-primitives/i18n'
import { IconReload } from '@tabler/icons-solidjs' import { IconReload } from '@tabler/icons-solidjs'
import { For, Show, createSignal, onMount } from 'solid-js' import { For, Show, createSignal, onMount } from 'solid-js'
import { twMerge } from 'tailwind-merge' import { twMerge } from 'tailwind-merge'
import { Button } from '~/components' import { Button } from '~/components'
import { formatTimeFromNow, useStringBooleanMap } from '~/helpers' import { formatTimeFromNow, useStringBooleanMap } from '~/helpers'
import { useI18n } from '~/i18n'
import { useRules } from '~/signals' import { useRules } from '~/signals'
enum ActiveTab { enum ActiveTab {
@ -12,7 +12,7 @@ enum ActiveTab {
} }
export default () => { export default () => {
const [t] = useI18n() const { t } = useI18n()
const { const {
rules, rules,
ruleProviders, ruleProviders,

View File

@ -1,6 +1,5 @@
import { createForm } from '@felte/solid' import { createForm } from '@felte/solid'
import { validator } from '@felte/validator-zod' import { validator } from '@felte/validator-zod'
import { useI18n } from '@solid-primitives/i18n'
import { useNavigate } from '@solidjs/router' import { useNavigate } from '@solidjs/router'
import { IconX } from '@tabler/icons-solidjs' import { IconX } from '@tabler/icons-solidjs'
import ky from 'ky' import ky from 'ky'
@ -10,6 +9,7 @@ import { v4 as uuid } from 'uuid'
import { z } from 'zod' import { z } from 'zod'
import { Button } from '~/components' import { Button } from '~/components'
import { transformEndpointURL } from '~/helpers' import { transformEndpointURL } from '~/helpers'
import { useI18n } from '~/i18n'
import { import {
endpointList, endpointList,
selectedEndpoint, selectedEndpoint,
@ -23,7 +23,7 @@ const schema = z.object({
}) })
export default () => { export default () => {
const [t] = useI18n() const { t } = useI18n()
const navigate = useNavigate() const navigate = useNavigate()
const onSetupSuccess = (id: string) => { const onSetupSuccess = (id: string) => {