Skip to content

Commit

Permalink
feat: proxy type support i18n (#1135)
Browse files Browse the repository at this point in the history
  • Loading branch information
Plutonium141 authored Nov 1, 2024
1 parent fd45c2e commit b0f32b5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 15 deletions.
38 changes: 24 additions & 14 deletions src/helpers/proxies.ts
Original file line number Diff line number Diff line change
@@ -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()

if (t.includes('shadowsocks')) {
return t.replace('shadowsocks', 'SS') // for both ss and ssr
}

if (t.includes('hysteria')) {
return t.replace('hysteria', 'HY')
}

if (t === 'wireguard') {
return 'WG'
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 (formatMap.has(lt)) {
return formatMap.get(lt)
} else {
return lt
}

return t
}

export const getLatencyClassName = (latency: LATENCY_QUALITY_MAP_HTTP) => {
Expand Down
8 changes: 8 additions & 0 deletions src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions src/i18n/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ export default {
global: '全局',
rule: '规则',
direct: '直连',
reject: '拒绝',
rejectdrop: '丢弃',
selector: '手动选择',
urltest: '自动选择',
loadbalance: '负载均衡',
fallback: '故障转移',
relay: '链式代理',
pass: '绕过',
active: '活动',
closed: '已关闭',
sort: '排序',
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Proxies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from '~/components'
import {
filterProxiesByAvailability,
formatProxyType,
formatTimeFromNow,
sortProxiesByOrderingType,
} from '~/helpers'
Expand Down Expand Up @@ -235,7 +236,7 @@ export default () => {

<div class="flex flex-wrap items-center justify-between gap-2">
<div class="badge badge-primary badge-sm">
<span class="font-bold">{proxyGroup.type}</span>
<span class="font-bold">{formatProxyType(proxyGroup.type)}</span>
<Show when={proxyGroup.now?.length > 0}>
<span class="whitespace-nowrap">
&nbsp;::&nbsp;
Expand Down

0 comments on commit b0f32b5

Please sign in to comment.