feat: add dayjs
This commit is contained in:
@@ -41,6 +41,7 @@
|
|||||||
"@vben/types": "workspace:*",
|
"@vben/types": "workspace:*",
|
||||||
"@vben/utils": "workspace:*",
|
"@vben/utils": "workspace:*",
|
||||||
"@vueuse/core": "catalog:",
|
"@vueuse/core": "catalog:",
|
||||||
|
"dayjs": "catalog:",
|
||||||
"naive-ui": "catalog:",
|
"naive-ui": "catalog:",
|
||||||
"pinia": "catalog:",
|
"pinia": "catalog:",
|
||||||
"vue": "catalog:",
|
"vue": "catalog:",
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import {
|
|||||||
} from '@vben/locales';
|
} from '@vben/locales';
|
||||||
import { preferences } from '@vben/preferences';
|
import { preferences } from '@vben/preferences';
|
||||||
|
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
const modules = import.meta.glob('./langs/**/*.json');
|
const modules = import.meta.glob('./langs/**/*.json');
|
||||||
|
|
||||||
const localesMap = loadLocalesMapFromDir(
|
const localesMap = loadLocalesMapFromDir(
|
||||||
@@ -22,10 +24,48 @@ const localesMap = loadLocalesMapFromDir(
|
|||||||
* @param lang
|
* @param lang
|
||||||
*/
|
*/
|
||||||
async function loadMessages(lang: SupportedLanguagesType) {
|
async function loadMessages(lang: SupportedLanguagesType) {
|
||||||
const appLocaleMessages = await localesMap[lang]?.();
|
const [appLocaleMessages] = await Promise.all([
|
||||||
|
localesMap[lang]?.(),
|
||||||
|
loadThirdPartyMessage(lang),
|
||||||
|
]);
|
||||||
return appLocaleMessages?.default;
|
return appLocaleMessages?.default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载第三方组件库的语言包
|
||||||
|
* @param lang
|
||||||
|
*/
|
||||||
|
async function loadThirdPartyMessage(lang: SupportedLanguagesType) {
|
||||||
|
await loadDayjsLocale(lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载dayjs的语言包
|
||||||
|
* @param lang
|
||||||
|
*/
|
||||||
|
async function loadDayjsLocale(lang: SupportedLanguagesType) {
|
||||||
|
let locale;
|
||||||
|
switch (lang) {
|
||||||
|
case 'en-US': {
|
||||||
|
locale = await import('dayjs/locale/en');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'zh-CN': {
|
||||||
|
locale = await import('dayjs/locale/zh-cn');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// 默认使用英语
|
||||||
|
default: {
|
||||||
|
locale = await import('dayjs/locale/en');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (locale) {
|
||||||
|
dayjs.locale(locale);
|
||||||
|
} else {
|
||||||
|
console.error(`Failed to load dayjs locale for ${lang}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function setupI18n(app: App, options: LocaleSetupOptions = {}) {
|
async function setupI18n(app: App, options: LocaleSetupOptions = {}) {
|
||||||
await coreSetup(app, {
|
await coreSetup(app, {
|
||||||
defaultLocale: preferences.app.locale,
|
defaultLocale: preferences.app.locale,
|
||||||
|
|||||||
67
pnpm-lock.yaml
generated
67
pnpm-lock.yaml
generated
@@ -42,9 +42,6 @@ catalogs:
|
|||||||
'@form-create/element-ui':
|
'@form-create/element-ui':
|
||||||
specifier: ^3.2.27
|
specifier: ^3.2.27
|
||||||
version: 3.2.31
|
version: 3.2.31
|
||||||
'@form-create/naive-ui':
|
|
||||||
specifier: ^3.2.27
|
|
||||||
version: 3.2.31
|
|
||||||
'@iconify/json':
|
'@iconify/json':
|
||||||
specifier: ^2.2.354
|
specifier: ^2.2.354
|
||||||
version: 2.2.395
|
version: 2.2.395
|
||||||
@@ -951,12 +948,6 @@ importers:
|
|||||||
|
|
||||||
apps/web-naive:
|
apps/web-naive:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@form-create/antd-designer':
|
|
||||||
specifier: 'catalog:'
|
|
||||||
version: 3.3.2(vue@3.5.22(typescript@5.9.3))
|
|
||||||
'@form-create/naive-ui':
|
|
||||||
specifier: 'catalog:'
|
|
||||||
version: 3.2.31(vue@3.5.22(typescript@5.9.3))
|
|
||||||
'@vben/access':
|
'@vben/access':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../../packages/effects/access
|
version: link:../../packages/effects/access
|
||||||
@@ -1002,15 +993,9 @@ importers:
|
|||||||
'@vueuse/core':
|
'@vueuse/core':
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 13.9.0(vue@3.5.22(typescript@5.9.3))
|
version: 13.9.0(vue@3.5.22(typescript@5.9.3))
|
||||||
cropperjs:
|
|
||||||
specifier: 'catalog:'
|
|
||||||
version: 1.6.2
|
|
||||||
dayjs:
|
dayjs:
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 1.11.18
|
version: 1.11.18
|
||||||
highlight.js:
|
|
||||||
specifier: 'catalog:'
|
|
||||||
version: 11.11.1
|
|
||||||
naive-ui:
|
naive-ui:
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 2.43.1(vue@3.5.22(typescript@5.9.3))
|
version: 2.43.1(vue@3.5.22(typescript@5.9.3))
|
||||||
@@ -3885,21 +3870,6 @@ packages:
|
|||||||
'@form-create/component-elm-upload@3.2.31':
|
'@form-create/component-elm-upload@3.2.31':
|
||||||
resolution: {integrity: sha512-2XJr7x8gPf+U0FnPYLyPt0+qLG9+lZSO7tlInT0fw7TJF9pWzrtxicnX6sWvd4EoWCNzYU13HXL33Aq1zP2IeA==}
|
resolution: {integrity: sha512-2XJr7x8gPf+U0FnPYLyPt0+qLG9+lZSO7tlInT0fw7TJF9pWzrtxicnX6sWvd4EoWCNzYU13HXL33Aq1zP2IeA==}
|
||||||
|
|
||||||
'@form-create/component-naive-checkbox@3.2.31':
|
|
||||||
resolution: {integrity: sha512-MLIVLg2A6mHjKnwgrohVX6AtyKJyQ58G3DD6zpS30nPvyaFJNgrL5N1bU5vQ9IwC4YsO8dbBiR1epxRJ+53l2g==}
|
|
||||||
|
|
||||||
'@form-create/component-naive-frame@3.2.31':
|
|
||||||
resolution: {integrity: sha512-XmQ0ywyULRUPyyn0bSKMijRsWIIg1U3Ytju+kQfclOb6gSzSQ0ULJqEQQRXHhIhDMC5g8QsBbq4S/bZgiHWUNA==}
|
|
||||||
|
|
||||||
'@form-create/component-naive-group@3.2.31':
|
|
||||||
resolution: {integrity: sha512-HRINcs+9+kq9ToByqg9HJMR+EWvtTkv0SrprZcBywZ1FWBb+2GDV2Y4CRm8JGxSVNS/SYU5c6q8YOl71ecV2sQ==}
|
|
||||||
|
|
||||||
'@form-create/component-naive-radio@3.2.31':
|
|
||||||
resolution: {integrity: sha512-0XRQvtDAz25BDAuBARW2Ds0J5jCCTKgaVlv4/o7A8Ck16PF2rXdwU8XHaKEFQNb8Q8VMAFZjJgsQk5r+xZxCuw==}
|
|
||||||
|
|
||||||
'@form-create/component-naive-upload@3.2.31':
|
|
||||||
resolution: {integrity: sha512-qYAZxtC09AJw8BaN913Gt22H0vymPfAFQMGhLP0gyJQv74dUa3caFrGAZkf5ie+/YbQEGqPnF5ckXGt5yS4VFg==}
|
|
||||||
|
|
||||||
'@form-create/component-subform@3.1.34':
|
'@form-create/component-subform@3.1.34':
|
||||||
resolution: {integrity: sha512-OJcFH/7MTHx7JLEjDK/weS27qfuFWAI+OK+gXTJ2jIt9aZkGWF/EWkjetiJLt5a0KMw4Z15wOS2XCY9pVK9vlA==}
|
resolution: {integrity: sha512-OJcFH/7MTHx7JLEjDK/weS27qfuFWAI+OK+gXTJ2jIt9aZkGWF/EWkjetiJLt5a0KMw4Z15wOS2XCY9pVK9vlA==}
|
||||||
|
|
||||||
@@ -3921,11 +3891,6 @@ packages:
|
|||||||
peerDependencies:
|
peerDependencies:
|
||||||
vue: ^3.5.17
|
vue: ^3.5.17
|
||||||
|
|
||||||
'@form-create/naive-ui@3.2.31':
|
|
||||||
resolution: {integrity: sha512-mt/IR3TmfkLI/PCpxt1UkUy0rsQpokOZCLJI1SRh+Ptwm0V6jPX1BUiNtJ8+a8i1moJ6AIIGx6FaM0nr0hzidw==}
|
|
||||||
peerDependencies:
|
|
||||||
vue: ^3.5.17
|
|
||||||
|
|
||||||
'@form-create/utils@3.2.31':
|
'@form-create/utils@3.2.31':
|
||||||
resolution: {integrity: sha512-YcisHXuQEF0r9y2VKS2CB2nMQ2q8EkKvQXp4nPR9sjbsCabPZOXq2n2MrkWDMhwQNwep08/0NCf7z0wslHzyWQ==}
|
resolution: {integrity: sha512-YcisHXuQEF0r9y2VKS2CB2nMQ2q8EkKvQXp4nPR9sjbsCabPZOXq2n2MrkWDMhwQNwep08/0NCf7z0wslHzyWQ==}
|
||||||
|
|
||||||
@@ -13738,26 +13703,6 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@form-create/utils': 3.2.31
|
'@form-create/utils': 3.2.31
|
||||||
|
|
||||||
'@form-create/component-naive-checkbox@3.2.31':
|
|
||||||
dependencies:
|
|
||||||
'@form-create/utils': 3.2.31
|
|
||||||
|
|
||||||
'@form-create/component-naive-frame@3.2.31':
|
|
||||||
dependencies:
|
|
||||||
'@form-create/utils': 3.2.31
|
|
||||||
|
|
||||||
'@form-create/component-naive-group@3.2.31':
|
|
||||||
dependencies:
|
|
||||||
'@form-create/utils': 3.2.31
|
|
||||||
|
|
||||||
'@form-create/component-naive-radio@3.2.31':
|
|
||||||
dependencies:
|
|
||||||
'@form-create/utils': 3.2.31
|
|
||||||
|
|
||||||
'@form-create/component-naive-upload@3.2.31':
|
|
||||||
dependencies:
|
|
||||||
'@form-create/utils': 3.2.31
|
|
||||||
|
|
||||||
'@form-create/component-subform@3.1.34': {}
|
'@form-create/component-subform@3.1.34': {}
|
||||||
|
|
||||||
'@form-create/component-wangeditor@3.2.14':
|
'@form-create/component-wangeditor@3.2.14':
|
||||||
@@ -13797,18 +13742,6 @@ snapshots:
|
|||||||
'@form-create/utils': 3.2.31
|
'@form-create/utils': 3.2.31
|
||||||
vue: 3.5.22(typescript@5.9.3)
|
vue: 3.5.22(typescript@5.9.3)
|
||||||
|
|
||||||
'@form-create/naive-ui@3.2.31(vue@3.5.22(typescript@5.9.3))':
|
|
||||||
dependencies:
|
|
||||||
'@form-create/component-naive-checkbox': 3.2.31
|
|
||||||
'@form-create/component-naive-frame': 3.2.31
|
|
||||||
'@form-create/component-naive-group': 3.2.31
|
|
||||||
'@form-create/component-naive-radio': 3.2.31
|
|
||||||
'@form-create/component-naive-upload': 3.2.31
|
|
||||||
'@form-create/component-subform': 3.1.34
|
|
||||||
'@form-create/core': 3.2.31(vue@3.5.22(typescript@5.9.3))
|
|
||||||
'@form-create/utils': 3.2.31
|
|
||||||
vue: 3.5.22(typescript@5.9.3)
|
|
||||||
|
|
||||||
'@form-create/utils@3.2.31': {}
|
'@form-create/utils@3.2.31': {}
|
||||||
|
|
||||||
'@gera2ld/jsx-dom@2.2.2':
|
'@gera2ld/jsx-dom@2.2.2':
|
||||||
|
|||||||
Reference in New Issue
Block a user