From 15e73c603b0cea8b99eb4166d3804690b75f9271 Mon Sep 17 00:00:00 2001 From: Slinetrac Date: Fri, 31 Oct 2025 18:11:27 +0800 Subject: [PATCH] refactor(i18n/proxies): migrate proxies UI to structured locale keys --- src/components/proxy/provider-button.tsx | 6 ++- src/components/proxy/proxy-chain.tsx | 31 +++++++------- src/components/proxy/proxy-groups.tsx | 6 +-- src/components/proxy/proxy-head.tsx | 26 +++++++----- src/components/proxy/proxy-item-mini.tsx | 4 +- src/components/proxy/proxy-render.tsx | 2 +- src/locales/ar.json | 51 ++++++++++++++++++++++++ src/locales/de.json | 51 ++++++++++++++++++++++++ src/locales/en.json | 51 ++++++++++++++++++++++++ src/locales/es.json | 51 ++++++++++++++++++++++++ src/locales/fa.json | 51 ++++++++++++++++++++++++ src/locales/id.json | 51 ++++++++++++++++++++++++ src/locales/jp.json | 51 ++++++++++++++++++++++++ src/locales/ko.json | 51 ++++++++++++++++++++++++ src/locales/ru.json | 51 ++++++++++++++++++++++++ src/locales/tr.json | 51 ++++++++++++++++++++++++ src/locales/tt.json | 51 ++++++++++++++++++++++++ src/locales/zh.json | 51 ++++++++++++++++++++++++ src/locales/zhtw.json | 51 ++++++++++++++++++++++++ src/pages/proxies.tsx | 29 +++++++++----- 20 files changed, 725 insertions(+), 42 deletions(-) diff --git a/src/components/proxy/provider-button.tsx b/src/components/proxy/provider-button.tsx index 2f196107..d031a5b3 100644 --- a/src/components/proxy/provider-button.tsx +++ b/src/components/proxy/provider-button.tsx @@ -150,7 +150,7 @@ export const ProviderButton = () => { onClick={() => setOpen(true)} sx={{ mr: 1 }} > - {t("Proxy Provider")} + {t("pages.proxies.provider.title")} @@ -160,7 +160,9 @@ export const ProviderButton = () => { justifyContent="space-between" alignItems="center" > - {t("Proxy Provider")} + + {t("pages.proxies.provider.title")} + @@ -526,10 +526,9 @@ export const ProxyChain = ({ sx={{ mb: 2 }} > {proxyChain.length === 1 - ? t( - "Chain proxy requires at least 2 nodes. Please add one more node.", - ) || "链式代理至少需要2个节点,请再添加一个节点。" - : t("Click nodes in order to add to proxy chain") || + ? t("pages.proxies.chain.minimumNodesHint") || + "链式代理至少需要2个节点,请再添加一个节点。" + : t("pages.proxies.chain.instruction") || "按顺序点击节点添加到代理链中"} @@ -544,7 +543,7 @@ export const ProxyChain = ({ color: theme.palette.text.secondary, }} > - {t("No proxy chain configured")} + {t("pages.proxies.chain.empty")} ) : ( { setProxyChain((prev) => { // 检查是否已经存在相同名称的代理,防止重复添加 if (prev.some((item) => item.name === proxy.name)) { - const warningMessage = t("Proxy node already exists in chain"); + const warningMessage = t("pages.proxies.chain.duplicateNode"); setDuplicateWarning({ open: true, message: warningMessage, @@ -403,7 +403,7 @@ export const ProxyGroups = (props: Props) => { variant="h6" sx={{ fontWeight: 600, fontSize: "16px" }} > - {t("Proxy Rules")} + {t("pages.proxies.rules.title")} {currentGroup && ( { variant="body2" sx={{ mr: 0.5, fontSize: "12px" }} > - {t("Select Rules")} + {t("pages.proxies.rules.select")} diff --git a/src/components/proxy/proxy-head.tsx b/src/components/proxy/proxy-head.tsx index 5ba08958..67e50022 100644 --- a/src/components/proxy/proxy-head.tsx +++ b/src/components/proxy/proxy-head.tsx @@ -67,7 +67,7 @@ export const ProxyHead = ({ @@ -76,7 +76,7 @@ export const ProxyHead = ({ { console.log(`[ProxyHead] 点击延迟测试按钮,组: ${groupName}`); // Remind the user that it is custom test url @@ -94,9 +94,11 @@ export const ProxyHead = ({ size="small" color="inherit" title={ - [t("Sort by default"), t("Sort by delay"), t("Sort by name")][ - sortType - ] + [ + t("pages.proxies.tooltips.sortDefault"), + t("pages.proxies.tooltips.sortDelay"), + t("pages.proxies.tooltips.sortName"), + ][sortType] } onClick={() => onHeadState({ sortType: ((sortType + 1) % 3) as ProxySortType }) @@ -110,7 +112,7 @@ export const ProxyHead = ({ onHeadState({ textState: textState === "url" ? null : "url" }) } @@ -125,7 +127,11 @@ export const ProxyHead = ({ onHeadState({ showType: !showType })} > {showType ? : } @@ -134,7 +140,7 @@ export const ProxyHead = ({ onHeadState({ textState: textState === "filter" ? null : "filter" }) } @@ -154,7 +160,7 @@ export const ProxyHead = ({ value={filterText} size="small" variant="outlined" - placeholder={t("Filter conditions")} + placeholder={t("pages.proxies.placeholders.filter")} onChange={(e) => onHeadState({ filterText: e.target.value })} sx={{ ml: 0.5, flex: "1 1 auto", input: { py: 0.65, px: 1 } }} /> @@ -169,7 +175,7 @@ export const ProxyHead = ({ value={testUrl} size="small" variant="outlined" - placeholder={t("Delay check URL")} + placeholder={t("pages.proxies.placeholders.delayCheckUrl")} onChange={(e) => onHeadState({ testUrl: e.target.value })} sx={{ ml: 0.5, flex: "1 1 auto", input: { py: 0.65, px: 1 } }} /> diff --git a/src/components/proxy/proxy-item-mini.tsx b/src/components/proxy/proxy-item-mini.tsx index a6e6e660..e895342a 100644 --- a/src/components/proxy/proxy-item-mini.tsx +++ b/src/components/proxy/proxy-item-mini.tsx @@ -271,7 +271,9 @@ export const ProxyItemMini = (props: Props) => { 📌 diff --git a/src/components/proxy/proxy-render.tsx b/src/components/proxy/proxy-render.tsx index bb9919f5..cf766fff 100644 --- a/src/components/proxy/proxy-render.tsx +++ b/src/components/proxy/proxy-render.tsx @@ -160,7 +160,7 @@ export const ProxyRender = (props: RenderProps) => { }} /> - + (MODES); +const isMode = (value: unknown): value is Mode => + typeof value === "string" && MODE_SET.has(value); + const ProxyPage = () => { const { t } = useTranslation(); @@ -50,11 +56,12 @@ const ProxyPage = () => { const { verge } = useVerge(); - const modeList = useMemo(() => ["rule", "global", "direct"], []); + const modeList = useMemo(() => MODES, []); - const curMode = clashConfig?.mode?.toLowerCase(); + const normalizedMode = clashConfig?.mode?.toLowerCase(); + const curMode = isMode(normalizedMode) ? normalizedMode : undefined; - const onChangeMode = useLockFn(async (mode: string) => { + const onChangeMode = useLockFn(async (mode: Mode) => { // 断开连接 if (mode !== curMode && verge?.auto_close_connection) { closeAllConnections(); @@ -124,16 +131,20 @@ const ProxyPage = () => { }, [isChainMode, updateChainConfigData]); useEffect(() => { - if (curMode && !modeList.includes(curMode)) { + if (normalizedMode && !isMode(normalizedMode)) { onChangeMode("rule"); } - }, [curMode, modeList, onChangeMode]); + }, [normalizedMode, onChangeMode]); return ( @@ -146,7 +157,7 @@ const ProxyPage = () => { onClick={() => onChangeMode(mode)} sx={{ textTransform: "capitalize" }} > - {t(mode)} + {t(`pages.proxies.modes.${mode}`)} ))} @@ -157,13 +168,13 @@ const ProxyPage = () => { onClick={onToggleChainMode} sx={{ ml: 1 }} > - {t("Chain Proxy")} + {t("pages.proxies.actions.toggleChain")} } >