From b0f32b5e5583ca673ade44bbbe058900b4630a74 Mon Sep 17 00:00:00 2001 From: Plutonium141 <62324696+Plutonium141@users.noreply.github.com> Date: Fri, 1 Nov 2024 16:03:19 +0800 Subject: [PATCH] feat: proxy type support i18n (#1135) --- src/helpers/proxies.ts | 36 +++++++++++++++++++++++------------- src/i18n/en.ts | 8 ++++++++ src/i18n/zh.ts | 8 ++++++++ src/pages/Proxies.tsx | 3 ++- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/helpers/proxies.ts b/src/helpers/proxies.ts index 95eb261..8addf7b 100644 --- a/src/helpers/proxies.ts +++ b/src/helpers/proxies.ts @@ -1,22 +1,32 @@ import { LATENCY_QUALITY_MAP_HTTP, PROXIES_ORDERING_TYPE } from '~/constants' +import { useI18n } from '~/i18n' import { latencyQualityMap, useProxies } from '~/signals' export const formatProxyType = (type = '') => { - const t = type.toLowerCase() + const [t] = useI18n() + const lt = type.toLowerCase() + const formatMap = new Map([ + ['shadowsocks', 'SS'], + ['shadowsocksr', 'SSR'], + ['hysteria', 'HY'], + ['hysteria2', 'HY2'], + ['wireguard', 'WG'], + ['selector', t('selector')], + ['urltest', t('urltest')], + ['fallback', t('fallback')], + ['loadbalance', t('loadbalance')], + ['direct', t('direct')], + ['reject', t('reject')], + ['rejectdrop', t('rejectdrop')], + ['relay', t('relay')], + ['pass', t('pass')], + ]) - if (t.includes('shadowsocks')) { - return t.replace('shadowsocks', 'SS') // for both ss and ssr + if (formatMap.has(lt)) { + return formatMap.get(lt) + } else { + return lt } - - if (t.includes('hysteria')) { - return t.replace('hysteria', 'HY') - } - - if (t === 'wireguard') { - return 'WG' - } - - return t } export const getLatencyClassName = (latency: LATENCY_QUALITY_MAP_HTTP) => { diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 6b31626..321a040 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -92,6 +92,14 @@ export default { global: 'Global', rule: 'Rule', direct: 'Direct', + reject: 'Reject', + rejectdrop: 'Drop', + selector: 'Selector', + urltest: 'Urltest', + loadbalance: 'Balance', + fallback: 'Fallback', + relay: 'Relay', + pass: 'Pass', active: 'Active', closed: 'Closed', sort: 'Sort', diff --git a/src/i18n/zh.ts b/src/i18n/zh.ts index 810f9b7..1e902ab 100644 --- a/src/i18n/zh.ts +++ b/src/i18n/zh.ts @@ -94,6 +94,14 @@ export default { global: '全局', rule: '规则', direct: '直连', + reject: '拒绝', + rejectdrop: '丢弃', + selector: '手动选择', + urltest: '自动选择', + loadbalance: '负载均衡', + fallback: '故障转移', + relay: '链式代理', + pass: '绕过', active: '活动', closed: '已关闭', sort: '排序', diff --git a/src/pages/Proxies.tsx b/src/pages/Proxies.tsx index 444e1ab..2335e1f 100644 --- a/src/pages/Proxies.tsx +++ b/src/pages/Proxies.tsx @@ -17,6 +17,7 @@ import { } from '~/components' import { filterProxiesByAvailability, + formatProxyType, formatTimeFromNow, sortProxiesByOrderingType, } from '~/helpers' @@ -235,7 +236,7 @@ export default () => {