From e4a324625fb38ad524247b48643eb526348df5bb Mon Sep 17 00:00:00 2001 From: kunish Date: Sat, 23 Sep 2023 01:38:36 +0800 Subject: [PATCH] refactor(i18n): add i18n context provider --- package.json | 1 + pnpm-lock.yaml | 11 +++++++++++ src/components/ConnectionsSettingsModal.tsx | 4 ++-- src/components/Header.tsx | 12 +++++------- src/components/Latency.tsx | 2 +- src/components/LogsSettingsModal.tsx | 2 +- src/components/ProxiesSettingsModal.tsx | 2 +- src/components/SubscriptionInfo.tsx | 4 ++-- src/i18n/index.tsx | 20 +++++++++----------- src/main.tsx | 9 ++++++--- src/pages/Config.tsx | 8 ++++---- src/pages/Connections.tsx | 8 ++++---- src/pages/Logs.tsx | 2 +- src/pages/Overview.tsx | 2 +- src/pages/Proxies.tsx | 2 +- src/pages/Rules.tsx | 2 +- src/pages/Setup.tsx | 2 +- src/signals/global.ts | 4 ++-- 18 files changed, 54 insertions(+), 43 deletions(-) diff --git a/package.json b/package.json index 390c70f..8588837 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "@felte/validator-zod": "^1.0.17", "@fontsource/fira-sans": "^5.0.12", "@solid-primitives/clipboard": "^1.5.7", + "@solid-primitives/context": "^0.2.1", "@solid-primitives/event-listener": "^2.3.0", "@solid-primitives/i18n": "^2.0.0", "@solid-primitives/keyed": "^1.2.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 16a3ba0..0eb0682 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,6 +20,9 @@ dependencies: '@solid-primitives/clipboard': specifier: ^1.5.7 version: 1.5.7(solid-js@1.7.12) + '@solid-primitives/context': + specifier: ^0.2.1 + version: 0.2.1(solid-js@1.7.12) '@solid-primitives/event-listener': specifier: ^2.3.0 version: 2.3.0(solid-js@1.7.12) @@ -2032,6 +2035,14 @@ packages: solid-js: 1.7.12 dev: false + /@solid-primitives/context@0.2.1(solid-js@1.7.12): + resolution: {integrity: sha512-XIIwCOWpRKDersgkR9LNFXaJHIV8QlCFo/tq5bV0cAOZklcwOFcqi2bN+uWgEIQSWGjWXU2kc1H1/TzgYzVDlg==} + peerDependencies: + solid-js: ^1.6.12 + dependencies: + solid-js: 1.7.12 + dev: false + /@solid-primitives/event-listener@2.3.0(solid-js@1.7.12): resolution: {integrity: sha512-0DS7DQZvCExWSpurVZC9/wjI8RmkhuOtWOy6Pp1Woq9ElMT9/bfjNpkwXsOwisLpcTqh9eUs17kp7jtpWcC20w==} peerDependencies: diff --git a/src/components/ConnectionsSettingsModal.tsx b/src/components/ConnectionsSettingsModal.tsx index a6670ea..a180199 100644 --- a/src/components/ConnectionsSettingsModal.tsx +++ b/src/components/ConnectionsSettingsModal.tsx @@ -45,7 +45,7 @@ const TagClientSourceIPWithNameForm: Component = () => { sourceIP: z.string().nonempty(), }) - const { t } = useI18n() + const [t] = useI18n() const { form, reset } = createForm>({ extend: validator({ schema }), @@ -113,7 +113,7 @@ export const ConnectionsSettingsModal = (props: { onVisibleChange: (value: ConnectionsTableColumnVisibility) => void }) => { const modalID = MODAL.CONNECTIONS_SETTINGS - const { t } = useI18n() + const [t] = useI18n() const [activeKey, setActiveKey] = createSignal(null) diff --git a/src/components/Header.tsx b/src/components/Header.tsx index a06de4d..345a314 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -13,7 +13,7 @@ import { import { For, ParentComponent, Show, createSignal } from 'solid-js' import { Button, LogoText } from '~/components' import { LANG, ROUTES, themes } from '~/constants' -import { useI18n } from '~/i18n' +import { setLocale, useI18n } from '~/i18n' import { setCurTheme } from '~/signals' const Nav: ParentComponent<{ href: string; tooltip: string }> = ({ @@ -62,7 +62,7 @@ const ThemeSwitcher = () => ( ) export const Header = () => { - const { t, locale } = useI18n() + const [t] = useI18n() const navs = () => [ { href: ROUTES.Overview, @@ -154,11 +154,9 @@ export const Header = () => {