feat: proxy type support i18n (#1135)

This commit is contained in:
Plutonium141 2024-11-01 16:03:19 +08:00 committed by GitHub
parent fd45c2e970
commit b0f32b5e55
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 41 additions and 14 deletions

View File

@ -1,22 +1,32 @@
import { LATENCY_QUALITY_MAP_HTTP, PROXIES_ORDERING_TYPE } from '~/constants' import { LATENCY_QUALITY_MAP_HTTP, PROXIES_ORDERING_TYPE } from '~/constants'
import { useI18n } from '~/i18n'
import { latencyQualityMap, useProxies } from '~/signals' import { latencyQualityMap, useProxies } from '~/signals'
export const formatProxyType = (type = '') => { 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')) { if (formatMap.has(lt)) {
return t.replace('shadowsocks', 'SS') // for both ss and ssr 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) => { export const getLatencyClassName = (latency: LATENCY_QUALITY_MAP_HTTP) => {

View File

@ -92,6 +92,14 @@ export default {
global: 'Global', global: 'Global',
rule: 'Rule', rule: 'Rule',
direct: 'Direct', direct: 'Direct',
reject: 'Reject',
rejectdrop: 'Drop',
selector: 'Selector',
urltest: 'Urltest',
loadbalance: 'Balance',
fallback: 'Fallback',
relay: 'Relay',
pass: 'Pass',
active: 'Active', active: 'Active',
closed: 'Closed', closed: 'Closed',
sort: 'Sort', sort: 'Sort',

View File

@ -94,6 +94,14 @@ export default {
global: '全局', global: '全局',
rule: '规则', rule: '规则',
direct: '直连', direct: '直连',
reject: '拒绝',
rejectdrop: '丢弃',
selector: '手动选择',
urltest: '自动选择',
loadbalance: '负载均衡',
fallback: '故障转移',
relay: '链式代理',
pass: '绕过',
active: '活动', active: '活动',
closed: '已关闭', closed: '已关闭',
sort: '排序', sort: '排序',

View File

@ -17,6 +17,7 @@ import {
} from '~/components' } from '~/components'
import { import {
filterProxiesByAvailability, filterProxiesByAvailability,
formatProxyType,
formatTimeFromNow, formatTimeFromNow,
sortProxiesByOrderingType, sortProxiesByOrderingType,
} from '~/helpers' } from '~/helpers'
@ -235,7 +236,7 @@ export default () => {
<div class="flex flex-wrap items-center justify-between gap-2"> <div class="flex flex-wrap items-center justify-between gap-2">
<div class="badge badge-primary badge-sm"> <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}> <Show when={proxyGroup.now?.length > 0}>
<span class="whitespace-nowrap"> <span class="whitespace-nowrap">
&nbsp;::&nbsp; &nbsp;::&nbsp;