feat: add naive app

This commit is contained in:
vben
2024-07-31 00:19:17 +08:00
parent 832a7bcc58
commit fdee2d2239
68 changed files with 2540 additions and 33 deletions

View File

@@ -0,0 +1,3 @@
# locale
每个app使用的国际化可能不同这里用于扩展国际化的功能例如扩展 dayjs、antd组件库的多语言切换以及app本身的国际化文件。

View File

@@ -0,0 +1,31 @@
import type { LocaleSetupOptions, SupportedLanguagesType } from '@vben/locales';
import type { App } from 'vue';
import { $t, setupI18n as coreSetup, loadLocalesMap } from '@vben/locales';
import { preferences } from '@vben/preferences';
const modules = import.meta.glob('./langs/*.json');
const localesMap = loadLocalesMap(modules);
/**
* 加载应用特有的语言包
* 这里也可以改造为从服务端获取翻译数据
* @param lang
*/
async function loadMessages(lang: SupportedLanguagesType) {
const appLocaleMessages = await localesMap[lang]();
return appLocaleMessages.default;
}
async function setupI18n(app: App, options: LocaleSetupOptions = {}) {
await coreSetup(app, {
defaultLocale: preferences.app.locale,
loadMessages,
missingWarn: !import.meta.env.PROD,
...options,
});
}
export { $t, loadMessages, setupI18n };

View File

@@ -0,0 +1,8 @@
{
"page": {
"demos": {
"title": "Demos",
"naive": "Naive UI"
}
}
}

View File

@@ -0,0 +1,8 @@
{
"page": {
"demos": {
"title": "演示",
"naive": "Naive UI"
}
}
}