app/docs/components/scripts/i18n.ts

59 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-09-01 20:39:51 +08:00
import {ref} from "vue";
2024-09-01 22:00:17 +08:00
2024-09-01 18:25:37 +08:00
import {useData} from "vitepress";
const i18nData = {
2024-09-01 20:39:51 +08:00
en: {
online: 'Online',
offline: 'Offline',
total: 'Total',
fetching: 'Fetching',
stars: 'Stars',
forks: 'Forks',
issues: 'Issues',
prs: 'Pull Requests',
2024-09-01 21:16:45 +08:00
size: 'Size',
plugins: 'Plugins',
resources: 'Resources',
2024-09-01 20:39:51 +08:00
},
zh: {
online: '在线',
offline: '离线',
total: '实例',
fetching: '获取中',
stars: '星星',
forks: '叉子',
2024-09-01 21:16:45 +08:00
issues: '开启议题',
2024-09-01 20:45:06 +08:00
prs: '合并请求',
2024-09-01 21:16:45 +08:00
size: '大小',
plugins: '插件',
resources: '主题资源',
2024-09-01 20:39:51 +08:00
}
2024-09-01 18:25:37 +08:00
}
2024-09-01 20:39:51 +08:00
let refData = {}
function getText(lang: string, key: string): string {
lang = formatLang(lang);
2024-09-01 22:00:17 +08:00
return i18nData[lang][key];
2024-09-01 20:39:51 +08:00
}
function formatLang(lang: string): string {
if (lang.includes('-')) {
return lang.split('-')[0];
}
return lang;
}
2024-09-01 22:00:17 +08:00
export function updateRefData() {
const lang = formatLang(useData().site.value.lang);
2024-09-01 20:39:51 +08:00
for (let key in refData) {
refData[key].value = getText(lang, key);
}
}
export function getTextRef(key: string): any {
const lang = formatLang(useData().site.value.lang);
2024-09-01 22:00:17 +08:00
refData[key] = getText(lang, key);
2024-09-01 20:39:51 +08:00
return refData[key]
2024-09-01 18:25:37 +08:00
}