2023-09-01 23:57:58 +08:00
|
|
|
import { I18nContext, createI18nContext, useI18n } from '@solid-primitives/i18n'
|
|
|
|
import { makePersisted } from '@solid-primitives/storage'
|
|
|
|
import { ParentComponent, createEffect, createSignal } from 'solid-js'
|
2023-09-01 23:25:37 +08:00
|
|
|
|
|
|
|
const dict = {
|
|
|
|
'en-US': {
|
|
|
|
navs: {
|
|
|
|
overview: 'Overview',
|
|
|
|
proxies: 'Proxies',
|
|
|
|
rules: 'Rules',
|
|
|
|
connections: 'Connections',
|
2023-09-01 23:57:58 +08:00
|
|
|
logs: 'Logs',
|
2023-09-01 23:25:37 +08:00
|
|
|
config: 'Config',
|
|
|
|
},
|
2023-09-01 23:57:58 +08:00
|
|
|
stats: {
|
|
|
|
upload: 'Upload',
|
|
|
|
download: 'Download',
|
|
|
|
uploadTotal: 'Upload Total',
|
|
|
|
downloadTotal: 'Download Total',
|
|
|
|
activeConnections: 'Active Connections',
|
|
|
|
memoryUsage: 'Memory Usage',
|
|
|
|
},
|
2023-09-01 23:25:37 +08:00
|
|
|
},
|
|
|
|
'zh-Hans': {
|
|
|
|
navs: {
|
|
|
|
overview: '概览',
|
|
|
|
proxies: '代理',
|
|
|
|
rules: '规则',
|
|
|
|
connections: '连接',
|
2023-09-01 23:57:58 +08:00
|
|
|
logs: '日志',
|
2023-09-01 23:25:37 +08:00
|
|
|
config: '配置',
|
|
|
|
},
|
2023-09-01 23:57:58 +08:00
|
|
|
stats: {
|
|
|
|
upload: '上传',
|
|
|
|
download: '下载',
|
|
|
|
uploadTotal: '上传总量',
|
|
|
|
downloadTotal: '下载总量',
|
|
|
|
activeConnections: '活动连接',
|
|
|
|
memoryUsage: '内存使用情况',
|
|
|
|
},
|
2023-09-01 23:25:37 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-09-01 23:57:58 +08:00
|
|
|
const useLanguage = () => {
|
|
|
|
const [lang, setLang] = makePersisted(createSignal(navigator.language), {
|
|
|
|
name: 'lang',
|
|
|
|
storage: localStorage,
|
|
|
|
})
|
|
|
|
|
|
|
|
return { lang, setLang }
|
|
|
|
}
|
|
|
|
|
|
|
|
const I18nUpdator: ParentComponent = (props) => {
|
|
|
|
const { setLang } = useLanguage()
|
|
|
|
const [_, { locale }] = useI18n()
|
|
|
|
|
|
|
|
createEffect(() => {
|
|
|
|
setLang(locale())
|
|
|
|
})
|
|
|
|
|
|
|
|
return props.children
|
|
|
|
}
|
|
|
|
|
2023-09-01 23:25:37 +08:00
|
|
|
export const I18nProvider: ParentComponent = (props) => {
|
|
|
|
const { lang } = useLanguage()
|
|
|
|
const value = createI18nContext(dict, lang())
|
|
|
|
|
|
|
|
return (
|
2023-09-01 23:57:58 +08:00
|
|
|
<I18nContext.Provider value={value}>
|
|
|
|
<I18nUpdator>{props.children}</I18nUpdator>
|
|
|
|
</I18nContext.Provider>
|
2023-09-01 23:25:37 +08:00
|
|
|
)
|
|
|
|
}
|