Commit 208d4188 by vben

refactor: refactor locales, separate locales within apps,fixed #12

1 parent 35715113
Showing 76 changed files with 247 additions and 186 deletions
...@@ -169,7 +169,10 @@ ...@@ -169,7 +169,10 @@
"packages/@vben-core/shared/design-tokens/src/**/*.css" "packages/@vben-core/shared/design-tokens/src/**/*.css"
], ],
"i18n-ally.localesPaths": ["packages/locales/src/langs"], "i18n-ally.localesPaths": [
"packages/@core/locales/src/langs",
"apps/*/src/locales/langs"
],
"i18n-ally.enabledParsers": ["json", "ts", "js", "yaml"], "i18n-ally.enabledParsers": ["json", "ts", "js", "yaml"],
"i18n-ally.sourceLanguage": "en", "i18n-ally.sourceLanguage": "en",
"i18n-ally.displayLanguage": "zh-CN", "i18n-ally.displayLanguage": "zh-CN",
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
- @vben/constants@5.0.1 - @vben/constants@5.0.1
- @vben/hooks@5.0.1 - @vben/hooks@5.0.1
- @vben/icons@5.0.1 - @vben/icons@5.0.1
- @vben/locales@5.0.1 - #/locales@5.0.1
- @vben/styles@5.0.1 - @vben/styles@5.0.1
- @vben/types@5.0.1 - @vben/types@5.0.1
- @vben/utils@5.0.1 - @vben/utils@5.0.1
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
}, },
"dependencies": { "dependencies": {
"@vben-core/helpers": "workspace:*", "@vben-core/helpers": "workspace:*",
"@vben-core/locales": "workspace:*",
"@vben-core/preferences": "workspace:*", "@vben-core/preferences": "workspace:*",
"@vben-core/request": "workspace:*", "@vben-core/request": "workspace:*",
"@vben-core/stores": "workspace:*", "@vben-core/stores": "workspace:*",
...@@ -34,7 +35,6 @@ ...@@ -34,7 +35,6 @@
"@vben/constants": "workspace:*", "@vben/constants": "workspace:*",
"@vben/icons": "workspace:*", "@vben/icons": "workspace:*",
"@vben/layouts": "workspace:*", "@vben/layouts": "workspace:*",
"@vben/locales": "workspace:*",
"@vben/styles": "workspace:*", "@vben/styles": "workspace:*",
"@vben/types": "workspace:*", "@vben/types": "workspace:*",
"@vben/universal-ui": "workspace:*", "@vben/universal-ui": "workspace:*",
......
...@@ -6,7 +6,7 @@ import { preferences, usePreferences } from '@vben-core/preferences'; ...@@ -6,7 +6,7 @@ import { preferences, usePreferences } from '@vben-core/preferences';
import { App, ConfigProvider, theme } from 'ant-design-vue'; import { App, ConfigProvider, theme } from 'ant-design-vue';
import { antdLocale } from '#/forward'; import { antdLocale } from '#/locales';
defineOptions({ name: 'App' }); defineOptions({ name: 'App' });
......
import { createApp } from 'vue'; import { createApp } from 'vue';
import { setupI18n } from '@vben/locales';
import '@vben/styles'; import '@vben/styles';
import { preferences } from '@vben-core/preferences'; import { preferences } from '@vben-core/preferences';
import { loadThirdPartyMessage } from '#/forward'; import { loadMessages, setupI18n } from '#/locales';
import { setupStore } from '#/store'; import { setupStore } from '#/store';
import App from './app.vue'; import App from './app.vue';
...@@ -16,7 +15,7 @@ async function bootstrap(namespace: string) { ...@@ -16,7 +15,7 @@ async function bootstrap(namespace: string) {
// 国际化 i18n 配置 // 国际化 i18n 配置
await setupI18n(app, { await setupI18n(app, {
defaultLocale: preferences.app.locale, defaultLocale: preferences.app.locale,
loadThirdPartyMessage, loadMessages,
}); });
// 配置 pinia-store // 配置 pinia-store
......
...@@ -2,13 +2,13 @@ import type { GeneratorMenuAndRoutesOptions } from '@vben/access'; ...@@ -2,13 +2,13 @@ import type { GeneratorMenuAndRoutesOptions } from '@vben/access';
import type { ComponentRecordType } from '@vben/types'; import type { ComponentRecordType } from '@vben/types';
import { generateMenusAndRoutes } from '@vben/access'; import { generateMenusAndRoutes } from '@vben/access';
import { $t } from '@vben/locales';
import { preferences } from '@vben-core/preferences'; import { preferences } from '@vben-core/preferences';
import { message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
import { getAllMenus } from '#/apis'; import { getAllMenus } from '#/apis';
import { BasicLayout, IFrameView } from '#/layouts'; import { BasicLayout, IFrameView } from '#/layouts';
import { $t } from '#/locales';
const forbiddenPage = () => import('#/views/_essential/fallback/forbidden.vue'); const forbiddenPage = () => import('#/views/_essential/fallback/forbidden.vue');
......
export * from './locale'; export * from './access';
export * from './request'; export * from './request';
...@@ -7,11 +7,11 @@ import { useRouter } from 'vue-router'; ...@@ -7,11 +7,11 @@ import { useRouter } from 'vue-router';
import { LOGIN_PATH } from '@vben/constants'; import { LOGIN_PATH } from '@vben/constants';
import { IcRoundCreditScore, MdiDriveDocument, MdiGithub } from '@vben/icons'; import { IcRoundCreditScore, MdiDriveDocument, MdiGithub } from '@vben/icons';
import { BasicLayout } from '@vben/layouts'; import { BasicLayout } from '@vben/layouts';
import { $t } from '@vben/locales';
import { openWindow } from '@vben/utils'; import { openWindow } from '@vben/utils';
import { Notification, UserDropdown } from '@vben/widgets'; import { Notification, UserDropdown } from '@vben/widgets';
import { preferences } from '@vben-core/preferences'; import { preferences } from '@vben-core/preferences';
import { $t } from '#/locales';
import { resetRoutes } from '#/router'; import { resetRoutes } from '#/router';
import { useAppStore } from '#/store'; import { useAppStore } from '#/store';
......
...@@ -3,11 +3,41 @@ import type { Locale } from 'ant-design-vue/es/locale'; ...@@ -3,11 +3,41 @@ import type { Locale } from 'ant-design-vue/es/locale';
import { ref } from 'vue'; import { ref } from 'vue';
import { $t, loadLocalesMap, setupI18n } from '@vben-core/locales';
import defaultLocale from 'ant-design-vue/es/locale/zh_CN'; import defaultLocale from 'ant-design-vue/es/locale/zh_CN';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
const antdLocale = ref<Locale>(defaultLocale); const antdLocale = ref<Locale>(defaultLocale);
const modules = import.meta.glob('./langs/*.y(a)?ml');
const localesMap = loadLocalesMap(modules);
/**
* 加载应用特有的语言包
* @param lang
*/
async function loadMessages(lang: SupportedLanguagesType) {
const [appLocaleMessages] = await Promise.all([
localesMap[lang](),
loadThirdPartyMessage(lang),
]);
return appLocaleMessages.default;
}
/**
* 加载第三方组件库的语言包
* @param lang
*/
async function loadThirdPartyMessage(lang: SupportedLanguagesType) {
await Promise.all([loadAntdLocale(lang), loadDayjsLocale(lang)]);
}
/**
* 加载dayjs的语言包
* @param lang
*/
async function loadDayjsLocale(lang: SupportedLanguagesType) { async function loadDayjsLocale(lang: SupportedLanguagesType) {
let locale; let locale;
switch (lang) { switch (lang) {
...@@ -19,13 +49,18 @@ async function loadDayjsLocale(lang: SupportedLanguagesType) { ...@@ -19,13 +49,18 @@ async function loadDayjsLocale(lang: SupportedLanguagesType) {
locale = await import('dayjs/locale/en'); locale = await import('dayjs/locale/en');
break; break;
} }
// 默认使用英语
default: { default: {
locale = await import('dayjs/locale/en'); locale = await import('dayjs/locale/en');
} // 默认使用英语 }
} }
dayjs.locale(locale); dayjs.locale(locale);
} }
/**
* 加载antd的语言包
* @param lang
*/
async function loadAntdLocale(lang: SupportedLanguagesType) { async function loadAntdLocale(lang: SupportedLanguagesType) {
switch (lang) { switch (lang) {
case 'zh-CN': { case 'zh-CN': {
...@@ -41,8 +76,4 @@ async function loadAntdLocale(lang: SupportedLanguagesType) { ...@@ -41,8 +76,4 @@ async function loadAntdLocale(lang: SupportedLanguagesType) {
} }
} }
async function loadThirdPartyMessage(land: SupportedLanguagesType) { export { $t, antdLocale, loadMessages, setupI18n };
await Promise.all([loadAntdLocale(land), loadDayjsLocale(land)]);
}
export { antdLocale, loadThirdPartyMessage };
page:
demos:
title: Demos
access:
title: Access Control
frontend-control: Front-end Control
backend-control: Backend Control
page: Page visit
button: Button control
loading-menu: In the loading menu
access-test-1: Super visit
access-test-2: Admin visit
access-test-3: User visit
nested:
title: Nested Menu
menu1: Menu 1
menu2: Menu 2
menu21: Menu 2-1
menu3: Menu 3
menu31: Menu 3-1
menu32: Menu 3-2
menu321: Menu 3-2-1
outside:
title: External Page
embedded: embedded Page
external-link: External Link
fallback:
title: Fallback Page
page:
demos:
title: 演示
access:
title: 访问控制
frontend-control: 前端控制
backend-control: 后端控制
page: 页面访问
button: 按钮控制
access-test-1: Super 可见
access-test-2: Admin 可见
access-test-3: User 可见
nested:
title: 嵌套菜单
menu1: 菜单 1
menu2: 菜单 2
menu21: 菜单 2-1
menu3: 菜单 3
menu31: 菜单 3-1
menu32: 菜单 3-2
menu321: 菜单 3-2-1
outside:
title: 外部页面
embedded: 内嵌
external-link: 外链
fallback:
title: 缺省页
import type { Router } from 'vue-router'; import type { Router } from 'vue-router';
import { LOGIN_PATH } from '@vben/constants'; import { LOGIN_PATH } from '@vben/constants';
import { $t } from '@vben/locales';
import { startProgress, stopProgress } from '@vben/utils'; import { startProgress, stopProgress } from '@vben/utils';
import { preferences } from '@vben-core/preferences'; import { preferences } from '@vben-core/preferences';
import { useTitle } from '@vueuse/core'; import { useTitle } from '@vueuse/core';
import { generateAccess } from '#/forward/access'; import { generateAccess } from '#/forward';
import { $t } from '#/locales';
import { dynamicRoutes, essentialsRouteNames } from '#/router/routes'; import { dynamicRoutes, essentialsRouteNames } from '#/router/routes';
import { useAccessStore } from '#/store'; import { useAccessStore } from '#/store';
......
import type { RouteRecordRaw } from 'vue-router'; import type { RouteRecordRaw } from 'vue-router';
import { DEFAULT_HOME_PATH } from '@vben/constants'; import { DEFAULT_HOME_PATH } from '@vben/constants';
import { $t } from '@vben/locales';
import { AuthPageLayout } from '#/layouts'; import { AuthPageLayout } from '#/layouts';
import { $t } from '#/locales';
import Login from '#/views/_essential/authentication/login.vue'; import Login from '#/views/_essential/authentication/login.vue';
/** 全局404页面 */ /** 全局404页面 */
......
import type { RouteRecordRaw } from 'vue-router'; import type { RouteRecordRaw } from 'vue-router';
import { $t } from '@vben/locales/helper';
import { BasicLayout } from '#/layouts'; import { BasicLayout } from '#/layouts';
import { $t } from '#/locales';
const routes: RouteRecordRaw[] = [ const routes: RouteRecordRaw[] = [
{ {
......
import type { RouteRecordRaw } from 'vue-router'; import type { RouteRecordRaw } from 'vue-router';
import { $t } from '@vben/locales/helper';
import { BasicLayout, IFrameView } from '#/layouts'; import { BasicLayout, IFrameView } from '#/layouts';
import { $t } from '#/locales';
const routes: RouteRecordRaw[] = [ const routes: RouteRecordRaw[] = [
{ {
......
...@@ -2,9 +2,8 @@ import type { RouteRecordRaw } from 'vue-router'; ...@@ -2,9 +2,8 @@ import type { RouteRecordRaw } from 'vue-router';
import { VBEN_GITHUB_URL, VBEN_LOGO } from '@vben/constants'; import { VBEN_GITHUB_URL, VBEN_LOGO } from '@vben/constants';
import { $t } from '@vben/locales/helper';
import { BasicLayout, IFrameView } from '#/layouts'; import { BasicLayout, IFrameView } from '#/layouts';
import { $t } from '#/locales';
const routes: RouteRecordRaw[] = [ const routes: RouteRecordRaw[] = [
{ {
......
<script lang="ts" setup> <script lang="ts" setup>
import type { LoginAndRegisterParams } from '@vben/universal-ui'; import type { LoginAndRegisterParams } from '@vben/universal-ui';
import { $t } from '@vben/locales';
import { AuthenticationLogin } from '@vben/universal-ui'; import { AuthenticationLogin } from '@vben/universal-ui';
import { App } from 'ant-design-vue'; import { App } from 'ant-design-vue';
import { $t } from '#/locales';
import { useAccessStore } from '#/store'; import { useAccessStore } from '#/store';
defineOptions({ name: 'Login' }); defineOptions({ name: 'Login' });
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
"postcss": "^8.4.39", "postcss": "^8.4.39",
"postcss-antd-fixes": "^0.2.0", "postcss-antd-fixes": "^0.2.0",
"postcss-import": "^16.1.0", "postcss-import": "^16.1.0",
"postcss-preset-env": "^9.5.15", "postcss-preset-env": "^9.5.16",
"tailwindcss": "^3.4.4", "tailwindcss": "^3.4.4",
"tailwindcss-animate": "^1.0.7" "tailwindcss-animate": "^1.0.7"
}, },
......
...@@ -4,7 +4,7 @@ import type { DefineApplicationOptions } from '../typing'; ...@@ -4,7 +4,7 @@ import type { DefineApplicationOptions } from '../typing';
import { defineConfig, loadEnv, mergeConfig } from 'vite'; import { defineConfig, loadEnv, mergeConfig } from 'vite';
import { getApplicationConditionPlugins } from '../plugins'; import { loadApplicationPlugins } from '../plugins';
import { getCommonConfig } from './common'; import { getCommonConfig } from './common';
function defineApplicationConfig(options: DefineApplicationOptions = {}) { function defineApplicationConfig(options: DefineApplicationOptions = {}) {
...@@ -15,7 +15,7 @@ function defineApplicationConfig(options: DefineApplicationOptions = {}) { ...@@ -15,7 +15,7 @@ function defineApplicationConfig(options: DefineApplicationOptions = {}) {
const isBuild = command === 'build'; const isBuild = command === 'build';
const env = loadEnv(mode, root); const env = loadEnv(mode, root);
const plugins = await getApplicationConditionPlugins({ const plugins = await loadApplicationPlugins({
compress: false, compress: false,
compressTypes: ['brotli', 'gzip'], compressTypes: ['brotli', 'gzip'],
devtools: true, devtools: true,
......
...@@ -6,7 +6,7 @@ import { readPackageJSON } from '@vben/node-utils'; ...@@ -6,7 +6,7 @@ import { readPackageJSON } from '@vben/node-utils';
import { defineConfig, mergeConfig } from 'vite'; import { defineConfig, mergeConfig } from 'vite';
import { getLibraryConditionPlugins } from '../plugins'; import { loadLibraryPlugins } from '../plugins';
import { getCommonConfig } from './common'; import { getCommonConfig } from './common';
function defineLibraryConfig(options: DefineLibraryOptions = {}) { function defineLibraryConfig(options: DefineLibraryOptions = {}) {
...@@ -16,7 +16,7 @@ function defineLibraryConfig(options: DefineLibraryOptions = {}) { ...@@ -16,7 +16,7 @@ function defineLibraryConfig(options: DefineLibraryOptions = {}) {
const { library = {}, vite = {} } = options; const { library = {}, vite = {} } = options;
const isBuild = command === 'build'; const isBuild = command === 'build';
const plugins = await getLibraryConditionPlugins({ const plugins = await loadLibraryPlugins({
dts: false, dts: false,
injectLibCss: true, injectLibCss: true,
injectMetadata: true, injectMetadata: true,
......
...@@ -9,7 +9,7 @@ import type { ...@@ -9,7 +9,7 @@ import type {
import { join } from 'node:path'; import { join } from 'node:path';
import { getPackage } from '@vben/node-utils'; import { getPackage, getPackages } from '@vben/node-utils';
import viteVueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'; import viteVueI18nPlugin from '@intlify/unplugin-vue-i18n/vite';
import viteVue from '@vitejs/plugin-vue'; import viteVue from '@vitejs/plugin-vue';
...@@ -33,9 +33,7 @@ import { viteLicensePlugin } from './license'; ...@@ -33,9 +33,7 @@ import { viteLicensePlugin } from './license';
* 获取条件成立的 vite 插件 * 获取条件成立的 vite 插件
* @param conditionPlugins * @param conditionPlugins
*/ */
async function getConditionEstablishedPlugins( async function loadConditionPlugins(conditionPlugins: ConditionPlugin[]) {
conditionPlugins: ConditionPlugin[],
) {
const plugins: PluginOption[] = []; const plugins: PluginOption[] = [];
for (const conditionPlugin of conditionPlugins) { for (const conditionPlugin of conditionPlugins) {
if (conditionPlugin.condition) { if (conditionPlugin.condition) {
...@@ -49,7 +47,7 @@ async function getConditionEstablishedPlugins( ...@@ -49,7 +47,7 @@ async function getConditionEstablishedPlugins(
/** /**
* 根据条件获取通用的vite插件 * 根据条件获取通用的vite插件
*/ */
async function getCommonConditionPlugins( async function loadCommonPlugins(
options: CommonPluginOptions, options: CommonPluginOptions,
): Promise<ConditionPlugin[]> { ): Promise<ConditionPlugin[]> {
const { devtools, injectMetadata, isBuild, visualizer } = options; const { devtools, injectMetadata, isBuild, visualizer } = options;
...@@ -89,7 +87,7 @@ async function getCommonConditionPlugins( ...@@ -89,7 +87,7 @@ async function getCommonConditionPlugins(
/** /**
* 根据条件获取应用类型的vite插件 * 根据条件获取应用类型的vite插件
*/ */
async function getApplicationConditionPlugins( async function loadApplicationPlugins(
options: ApplicationPluginOptions, options: ApplicationPluginOptions,
): Promise<PluginOption[]> { ): Promise<PluginOption[]> {
// 单独取,否则commonOptions拿不到 // 单独取,否则commonOptions拿不到
...@@ -112,15 +110,33 @@ async function getApplicationConditionPlugins( ...@@ -112,15 +110,33 @@ async function getApplicationConditionPlugins(
...commonOptions ...commonOptions
} = options; } = options;
const commonPlugins = await getCommonConditionPlugins(commonOptions); const commonPlugins = await loadCommonPlugins(commonOptions);
return await getConditionEstablishedPlugins([ return await loadConditionPlugins([
...commonPlugins, ...commonPlugins,
{ {
condition: i18n, condition: i18n,
plugins: async () => { plugins: async () => {
const pkg = await getPackage('@vben/locales'); const { packages } = await getPackages();
const include = `${join(pkg?.dir ?? '', isBuild ? 'dist' : 'src', 'langs')}/*.yaml`; const pkg = await getPackage('@vben-core/locales');
const include: string[] = [
`${join(pkg?.dir ?? '', isBuild ? 'dist' : 'src', 'langs')}/*.yaml`,
];
// 加载所有应用的国际化文件
for (const { dir, relativeDir } of packages) {
if (
// 排除非应用目录
!relativeDir.startsWith('apps') ||
// 排除mock目录
relativeDir.includes('backend-mock')
) {
continue;
}
include.push(`${join(dir, 'src', 'locales', 'langs')}/*.yaml`);
}
return [ return [
viteVueI18nPlugin({ viteVueI18nPlugin({
compositionOnly: true, compositionOnly: true,
...@@ -204,14 +220,14 @@ async function getApplicationConditionPlugins( ...@@ -204,14 +220,14 @@ async function getApplicationConditionPlugins(
/** /**
* 根据条件获取库类型的vite插件 * 根据条件获取库类型的vite插件
*/ */
async function getLibraryConditionPlugins( async function loadLibraryPlugins(
options: LibraryPluginOptions, options: LibraryPluginOptions,
): Promise<PluginOption[]> { ): Promise<PluginOption[]> {
// 单独取,否则commonOptions拿不到 // 单独取,否则commonOptions拿不到
const isBuild = options.isBuild; const isBuild = options.isBuild;
const { dts, injectLibCss, ...commonOptions } = options; const { dts, injectLibCss, ...commonOptions } = options;
const commonPlugins = await getCommonConditionPlugins(commonOptions); const commonPlugins = await loadCommonPlugins(commonOptions);
return await getConditionEstablishedPlugins([ return await loadConditionPlugins([
...commonPlugins, ...commonPlugins,
{ {
condition: isBuild && !!dts, condition: isBuild && !!dts,
...@@ -225,8 +241,8 @@ async function getLibraryConditionPlugins( ...@@ -225,8 +241,8 @@ async function getLibraryConditionPlugins(
} }
export { export {
getApplicationConditionPlugins, loadApplicationPlugins,
getLibraryConditionPlugins, loadLibraryPlugins,
viteCompressPlugin, viteCompressPlugin,
viteDtsPlugin, viteDtsPlugin,
viteHtmlPlugin, viteHtmlPlugin,
......
...@@ -5,7 +5,6 @@ export default defineBuildConfig({ ...@@ -5,7 +5,6 @@ export default defineBuildConfig({
declaration: true, declaration: true,
entries: [ entries: [
'src/index', 'src/index',
'src/helper',
{ {
builder: 'mkdist', builder: 'mkdist',
input: './src/langs', input: './src/langs',
......
{ {
"name": "@vben/locales", "name": "@vben-core/locales",
"version": "5.0.0", "version": "5.0.0",
"homepage": "https://github.com/vbenjs/vue-vben-admin", "homepage": "https://github.com/vbenjs/vue-vben-admin",
"bugs": "https://github.com/vbenjs/vue-vben-admin/issues", "bugs": "https://github.com/vbenjs/vue-vben-admin/issues",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/vbenjs/vue-vben-admin.git", "url": "git+https://github.com/vbenjs/vue-vben-admin.git",
"directory": "packages/locales" "directory": "packages/@vben-core/forward/locales"
}, },
"license": "MIT", "license": "MIT",
"type": "module", "type": "module",
...@@ -30,11 +30,6 @@ ...@@ -30,11 +30,6 @@
}, },
"./langs/*": { "./langs/*": {
"default": "./dist/langs/*" "default": "./dist/langs/*"
},
"./helper": {
"types": "./src/helper.ts",
"development": "./src/helper.ts",
"default": "./dist/helper.mjs"
} }
}, },
"publishConfig": { "publishConfig": {
...@@ -45,6 +40,9 @@ ...@@ -45,6 +40,9 @@
} }
} }
}, },
"peerDependencies": {
"vite": "latest"
},
"dependencies": { "dependencies": {
"@intlify/core-base": "^9.13.1", "@intlify/core-base": "^9.13.1",
"@vben-core/typings": "workspace:*", "@vben-core/typings": "workspace:*",
......
...@@ -8,6 +8,7 @@ import { createI18n } from 'vue-i18n'; ...@@ -8,6 +8,7 @@ import { createI18n } from 'vue-i18n';
const loadedLanguages = new Set<string>(); const loadedLanguages = new Set<string>();
// TODO:import.meta.env 和 import.meta.glob 是源码依赖,会导致该包依赖外部项目必须是vite才可以
const i18n = createI18n({ const i18n = createI18n({
globalInjection: true, globalInjection: true,
legacy: false, legacy: false,
...@@ -20,13 +21,22 @@ const i18n = createI18n({ ...@@ -20,13 +21,22 @@ const i18n = createI18n({
const modules = import.meta.glob('./langs/*.y(a)?ml'); const modules = import.meta.glob('./langs/*.y(a)?ml');
const localesMap: Record<Locale, ImportLocaleFn> = {}; const localesMap = loadLocalesMap(modules);
for (const [path, loadLocale] of Object.entries(modules)) { /**
const key = path.match(/([\w-]*)\.y(a)?ml/)?.[1]; * Load locale modules
if (key) { * @param modules
localesMap[key] = loadLocale as ImportLocaleFn; */
function loadLocalesMap(modules: Record<string, () => Promise<unknown>>) {
const localesMap: Record<Locale, ImportLocaleFn> = {};
for (const [path, loadLocale] of Object.entries(modules)) {
const key = path.match(/([\w-]*)\.y(a)?ml/)?.[1];
if (key) {
localesMap[key] = loadLocale as ImportLocaleFn;
}
} }
return localesMap;
} }
/** /**
...@@ -52,11 +62,11 @@ async function loadI18nMessages(lang: SupportedLanguagesType) { ...@@ -52,11 +62,11 @@ async function loadI18nMessages(lang: SupportedLanguagesType) {
return setI18nLanguage(lang); return setI18nLanguage(lang);
} }
const messages = await localesMap[lang](); const message = await localesMap[lang]();
i18n.global.setLocaleMessage(lang, messages.default); i18n.global.setLocaleMessage(lang, message.default);
loadedLanguages.add(lang); loadedLanguages.add(lang);
return setI18nLanguage(lang); return setI18nLanguage(lang);
} }
export { i18n, loadI18nMessages, setI18nLanguage }; export { i18n, loadI18nMessages, loadLocalesMap, setI18nLanguage };
import type { LocaleSetupOptions, SupportedLanguagesType } from './typing'; import type {
ImportLocaleFn,
LoadMessageFn,
LocaleSetupOptions,
SupportedLanguagesType,
} from './typing';
import type { App } from 'vue'; import type { App } from 'vue';
import { i18n, loadI18nMessages } from './i18n'; import { i18n, loadI18nMessages, loadLocalesMap } from './i18n';
const $t = i18n.global.t; const $t = i18n.global.t;
let loadThirdPartyMessage: (lang: SupportedLanguagesType) => Promise<void>; let loadMessages: LoadMessageFn;
async function loadLocaleMessages(lang: SupportedLanguagesType) { async function loadLocaleMessages(lang: SupportedLanguagesType) {
const mergeMessage = await loadMessages(lang);
await loadI18nMessages(lang); await loadI18nMessages(lang);
await loadThirdPartyMessage(lang); i18n.global.mergeLocaleMessage(lang, mergeMessage);
} }
async function setupI18n(app: App, options: LocaleSetupOptions = {}) { async function setupI18n(app: App, options: LocaleSetupOptions = {}) {
const { defaultLocale = 'zh-CN' } = options; const { defaultLocale = 'zh-CN' } = options;
// app可以自行扩展一些第三方库和组件库的国际化 // app可以自行扩展一些第三方库和组件库的国际化
loadThirdPartyMessage = options.loadThirdPartyMessage || (async () => {}); loadMessages = options.loadMessages || (async () => ({}));
app.use(i18n); app.use(i18n);
await loadLocaleMessages(defaultLocale); await loadLocaleMessages(defaultLocale);
} }
export { $t, loadLocaleMessages, setupI18n }; export { $t, loadLocaleMessages, loadLocalesMap, setupI18n };
export type { CompileError } from '@intlify/core-base';
export { useI18n } from 'vue-i18n'; export { useI18n } from 'vue-i18n';
export type { Locale } from 'vue-i18n';
export type { ImportLocaleFn };
page: page:
demos:
title: Demos
access:
title: Access Control
frontend-control: Front-end Control
# menuVisibleWithForbidden: Menu is visible
backend-control: Backend Control
page: Page visit
button: Button control
loading-menu: In the loading menu
access-test-1: Super visit
access-test-2: Admin visit
access-test-3: User visit
nested:
title: Nested Menu
menu1: Menu 1
menu2: Menu 2
menu21: Menu 2-1
menu3: Menu 3
menu31: Menu 3-1
menu32: Menu 3-2
menu321: Menu 3-2-1
outside:
title: External Page
embedded: embedded Page
external-link: External Link
fallback:
title: Fallback Page
essentials: essentials:
login: Login login: Login
register: Register register: Register
......
page: page:
demos:
title: 演示
access:
title: 访问控制
frontend-control: 前端控制
# menuVisibleWithForbidden: 菜单可见
backend-control: 后端控制
page: 页面访问
button: 按钮控制
access-test-1: Super 可见
access-test-2: Admin 可见
access-test-3: User 可见
nested:
title: 嵌套菜单
menu1: 菜单 1
menu2: 菜单 2
menu21: 菜单 2-1
menu3: 菜单 3
menu31: 菜单 3-1
menu32: 菜单 3-2
menu321: 菜单 3-2-1
outside:
title: 外部页面
embedded: 内嵌
external-link: 外链
fallback:
title: 缺省页
essentials: essentials:
login: 登陆 login: 登陆
register: 注册 register: 注册
......
...@@ -2,6 +2,10 @@ import type { SupportedLanguagesType } from '@vben-core/typings'; ...@@ -2,6 +2,10 @@ import type { SupportedLanguagesType } from '@vben-core/typings';
type ImportLocaleFn = () => Promise<{ default: Record<string, string> }>; type ImportLocaleFn = () => Promise<{ default: Record<string, string> }>;
type LoadMessageFn = (
lang: SupportedLanguagesType,
) => Promise<Record<string, string>>;
interface LocaleSetupOptions { interface LocaleSetupOptions {
/** /**
* Default language * Default language
...@@ -9,11 +13,16 @@ interface LocaleSetupOptions { ...@@ -9,11 +13,16 @@ interface LocaleSetupOptions {
*/ */
defaultLocale?: SupportedLanguagesType; defaultLocale?: SupportedLanguagesType;
/** /**
* Load third-party library messages * Load message function
* @param lang * @param lang
* @returns * @returns
*/ */
loadThirdPartyMessage?: (lang: SupportedLanguagesType) => Promise<void>; loadMessages?: LoadMessageFn;
} }
export type { ImportLocaleFn, LocaleSetupOptions, SupportedLanguagesType }; export type {
ImportLocaleFn,
LoadMessageFn,
LocaleSetupOptions,
SupportedLanguagesType,
};
...@@ -37,10 +37,10 @@ ...@@ -37,10 +37,10 @@
} }
}, },
"dependencies": { "dependencies": {
"@vben-core/locales": "workspace:*",
"@vben-core/preferences": "workspace:*", "@vben-core/preferences": "workspace:*",
"@vben-core/stores": "workspace:*", "@vben-core/stores": "workspace:*",
"@vben-core/toolkit": "workspace:*", "@vben-core/toolkit": "workspace:*",
"@vben/locales": "workspace:*",
"vue": "^3.4.31", "vue": "^3.4.31",
"vue-router": "^4.4.0" "vue-router": "^4.4.0"
}, },
......
...@@ -6,7 +6,7 @@ import type { RouteRecordRaw } from 'vue-router'; ...@@ -6,7 +6,7 @@ import type { RouteRecordRaw } from 'vue-router';
import type { GeneratorMenuAndRoutesOptions } from '../types'; import type { GeneratorMenuAndRoutesOptions } from '../types';
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import { mapTree } from '@vben-core/toolkit'; import { mapTree } from '@vben-core/toolkit';
/** /**
......
...@@ -40,13 +40,13 @@ ...@@ -40,13 +40,13 @@
"@vben-core/helpers": "workspace:*", "@vben-core/helpers": "workspace:*",
"@vben-core/iconify": "workspace:*", "@vben-core/iconify": "workspace:*",
"@vben-core/layout-ui": "workspace:*", "@vben-core/layout-ui": "workspace:*",
"@vben-core/locales": "workspace:*",
"@vben-core/menu-ui": "workspace:*", "@vben-core/menu-ui": "workspace:*",
"@vben-core/preferences": "workspace:*", "@vben-core/preferences": "workspace:*",
"@vben-core/shadcn-ui": "workspace:*", "@vben-core/shadcn-ui": "workspace:*",
"@vben-core/stores": "workspace:*", "@vben-core/stores": "workspace:*",
"@vben-core/tabs-ui": "workspace:*", "@vben-core/tabs-ui": "workspace:*",
"@vben-core/toolkit": "workspace:*", "@vben-core/toolkit": "workspace:*",
"@vben/locales": "workspace:*",
"@vben/widgets": "workspace:*", "@vben/widgets": "workspace:*",
"vue": "^3.4.31", "vue": "^3.4.31",
"vue-router": "^4.4.0" "vue-router": "^4.4.0"
......
<script setup lang="ts"> <script setup lang="ts">
import { computed } from 'vue'; import { computed } from 'vue';
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import { preferences, usePreferences } from '@vben-core/preferences'; import { preferences, usePreferences } from '@vben-core/preferences';
import AuthenticationFromView from './from-view.vue'; import AuthenticationFromView from './from-view.vue';
......
...@@ -4,8 +4,8 @@ import type { VbenDropdownMenuItem } from '@vben-core/shadcn-ui'; ...@@ -4,8 +4,8 @@ import type { VbenDropdownMenuItem } from '@vben-core/shadcn-ui';
import { computed } from 'vue'; import { computed } from 'vue';
import { $t } from '@vben/locales';
import { MdiDockBottom, MdiDockLeft, MdiDockRight } from '@vben-core/iconify'; import { MdiDockBottom, MdiDockLeft, MdiDockRight } from '@vben-core/iconify';
import { $t } from '@vben-core/locales';
import { import {
preferences, preferences,
updatePreferences, updatePreferences,
......
<script lang="ts" setup> <script lang="ts" setup>
import { computed } from 'vue'; import { computed } from 'vue';
import { $t } from '@vben/locales';
import { PreferencesWidget } from '@vben/widgets'; import { PreferencesWidget } from '@vben/widgets';
import { VbenAdminLayout } from '@vben-core/layout-ui'; import { VbenAdminLayout } from '@vben-core/layout-ui';
import { $t } from '@vben-core/locales';
import { import {
preferences, preferences,
updatePreferences, updatePreferences,
......
...@@ -8,7 +8,6 @@ import type { ...@@ -8,7 +8,6 @@ import type {
import { computed, ref, watch } from 'vue'; import { computed, ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import { $t, useI18n } from '@vben/locales';
import { import {
IcRoundClose, IcRoundClose,
IcRoundMultipleStop, IcRoundMultipleStop,
...@@ -19,6 +18,7 @@ import { ...@@ -19,6 +18,7 @@ import {
MdiPin, MdiPin,
MdiPinOff, MdiPinOff,
} from '@vben-core/iconify'; } from '@vben-core/iconify';
import { $t, useI18n } from '@vben-core/locales';
import { import {
storeToRefs, storeToRefs,
useCoreAccessStore, useCoreAccessStore,
......
...@@ -5,7 +5,7 @@ import type { IBreadcrumb } from '@vben-core/shadcn-ui'; ...@@ -5,7 +5,7 @@ import type { IBreadcrumb } from '@vben-core/shadcn-ui';
import { computed } from 'vue'; import { computed } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import { VbenBackgroundBreadcrumb, VbenBreadcrumb } from '@vben-core/shadcn-ui'; import { VbenBackgroundBreadcrumb, VbenBreadcrumb } from '@vben-core/shadcn-ui';
interface Props { interface Props {
......
...@@ -42,9 +42,9 @@ ...@@ -42,9 +42,9 @@
"dependencies": { "dependencies": {
"@vben-core/design": "workspace:*", "@vben-core/design": "workspace:*",
"@vben-core/iconify": "workspace:*", "@vben-core/iconify": "workspace:*",
"@vben-core/locales": "workspace:*",
"@vben-core/shadcn-ui": "workspace:*", "@vben-core/shadcn-ui": "workspace:*",
"@vben/constants": "workspace:*", "@vben/constants": "workspace:*",
"@vben/locales": "workspace:*",
"@vben/types": "workspace:*", "@vben/types": "workspace:*",
"@vueuse/integrations": "^10.11.0", "@vueuse/integrations": "^10.11.0",
"qrcode": "^1.5.3", "qrcode": "^1.5.3",
......
...@@ -5,7 +5,7 @@ import { computed, onBeforeUnmount, reactive, ref } from 'vue'; ...@@ -5,7 +5,7 @@ import { computed, onBeforeUnmount, reactive, ref } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { LOGIN_PATH } from '@vben/constants'; import { LOGIN_PATH } from '@vben/constants';
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import { VbenButton, VbenInput, VbenPinInput } from '@vben-core/shadcn-ui'; import { VbenButton, VbenInput, VbenPinInput } from '@vben-core/shadcn-ui';
import Title from './auth-title.vue'; import Title from './auth-title.vue';
......
...@@ -3,7 +3,7 @@ import { computed, reactive } from 'vue'; ...@@ -3,7 +3,7 @@ import { computed, reactive } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { LOGIN_PATH } from '@vben/constants'; import { LOGIN_PATH } from '@vben/constants';
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import { VbenButton, VbenInput } from '@vben-core/shadcn-ui'; import { VbenButton, VbenInput } from '@vben-core/shadcn-ui';
import Title from './auth-title.vue'; import Title from './auth-title.vue';
......
...@@ -4,7 +4,7 @@ import type { LoginEmits } from './typings'; ...@@ -4,7 +4,7 @@ import type { LoginEmits } from './typings';
import { computed, reactive } from 'vue'; import { computed, reactive } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import { import {
VbenButton, VbenButton,
VbenCheckbox, VbenCheckbox,
......
...@@ -3,7 +3,7 @@ import { ref } from 'vue'; ...@@ -3,7 +3,7 @@ import { ref } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { LOGIN_PATH } from '@vben/constants'; import { LOGIN_PATH } from '@vben/constants';
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import { VbenButton } from '@vben-core/shadcn-ui'; import { VbenButton } from '@vben-core/shadcn-ui';
import { useQRCode } from '@vueuse/integrations/useQRCode'; import { useQRCode } from '@vueuse/integrations/useQRCode';
......
...@@ -5,7 +5,7 @@ import { computed, reactive } from 'vue'; ...@@ -5,7 +5,7 @@ import { computed, reactive } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { LOGIN_PATH } from '@vben/constants'; import { LOGIN_PATH } from '@vben/constants';
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import { import {
VbenButton, VbenButton,
VbenCheckbox, VbenCheckbox,
......
<script setup lang="ts"> <script setup lang="ts">
import { $t } from '@vben/locales';
import { MdiGithub, MdiGoogle, MdiQqchat, MdiWechat } from '@vben-core/iconify'; import { MdiGithub, MdiGoogle, MdiQqchat, MdiWechat } from '@vben-core/iconify';
import { $t } from '@vben-core/locales';
import { VbenIconButton } from '@vben-core/shadcn-ui'; import { VbenIconButton } from '@vben-core/shadcn-ui';
defineOptions({ defineOptions({
......
...@@ -4,8 +4,8 @@ import type { FallbackProps } from './fallback'; ...@@ -4,8 +4,8 @@ import type { FallbackProps } from './fallback';
import { computed, defineAsyncComponent } from 'vue'; import { computed, defineAsyncComponent } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { $t } from '@vben/locales';
import { IcRoundArrowBackIosNew, IcRoundRefresh } from '@vben-core/iconify'; import { IcRoundArrowBackIosNew, IcRoundRefresh } from '@vben-core/iconify';
import { $t } from '@vben-core/locales';
import { VbenButton } from '@vben-core/shadcn-ui'; import { VbenButton } from '@vben-core/shadcn-ui';
interface Props extends FallbackProps {} interface Props extends FallbackProps {}
......
...@@ -43,10 +43,10 @@ ...@@ -43,10 +43,10 @@
"@vben-core/colorful": "workspace:*", "@vben-core/colorful": "workspace:*",
"@vben-core/design": "workspace:*", "@vben-core/design": "workspace:*",
"@vben-core/iconify": "workspace:*", "@vben-core/iconify": "workspace:*",
"@vben-core/locales": "workspace:*",
"@vben-core/preferences": "workspace:*", "@vben-core/preferences": "workspace:*",
"@vben-core/shadcn-ui": "workspace:*", "@vben-core/shadcn-ui": "workspace:*",
"@vben-core/toolkit": "workspace:*", "@vben-core/toolkit": "workspace:*",
"@vben/locales": "workspace:*",
"@vueuse/core": "^10.11.0", "@vueuse/core": "^10.11.0",
"vue": "^3.4.31", "vue": "^3.4.31",
"vue-router": "^4.4.0" "vue-router": "^4.4.0"
......
...@@ -51,19 +51,19 @@ onUnmounted(() => { ...@@ -51,19 +51,19 @@ onUnmounted(() => {
}); });
</script> </script>
<template> <template>
<div ref="wrapperEl" class="coze-assistant"></div> <div ref="wrapperEl" class="coze-vben-admin-assistant"></div>
</template> </template>
<style> <style>
.coze-assistant { .coze-vben-admin-assistant {
position: fixed; position: fixed;
right: 30px; right: 30px;
bottom: 60px; bottom: 60px;
z-index: 1000; z-index: 1000;
img { img {
width: 42px !important; width: 50px !important;
height: 42px !important; height: 50px !important;
border-radius: 50%; border-radius: 50%;
} }
} }
......
...@@ -3,7 +3,6 @@ import type { MenuRecordRaw } from '@vben/types'; ...@@ -3,7 +3,6 @@ import type { MenuRecordRaw } from '@vben/types';
import { onMounted, onUnmounted, ref, watch } from 'vue'; import { onMounted, onUnmounted, ref, watch } from 'vue';
import { $t } from '@vben/locales';
import { import {
IcRoundArrowDownward, IcRoundArrowDownward,
IcRoundArrowUpward, IcRoundArrowUpward,
...@@ -11,6 +10,7 @@ import { ...@@ -11,6 +10,7 @@ import {
IcRoundSubdirectoryArrowLeft, IcRoundSubdirectoryArrowLeft,
MdiKeyboardEsc, MdiKeyboardEsc,
} from '@vben-core/iconify'; } from '@vben-core/iconify';
import { $t } from '@vben-core/locales';
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
......
...@@ -4,8 +4,8 @@ import type { MenuRecordRaw } from '@vben/types'; ...@@ -4,8 +4,8 @@ import type { MenuRecordRaw } from '@vben/types';
import { nextTick, onMounted, ref, shallowRef, watch } from 'vue'; import { nextTick, onMounted, ref, shallowRef, watch } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { $t } from '@vben/locales';
import { IcRoundClose, IcRoundSearchOff } from '@vben-core/iconify'; import { IcRoundClose, IcRoundSearchOff } from '@vben-core/iconify';
import { $t } from '@vben-core/locales';
import { VbenIcon, VbenScrollbar } from '@vben-core/shadcn-ui'; import { VbenIcon, VbenScrollbar } from '@vben-core/shadcn-ui';
import { mapTree, traverseTreeValues, uniqueByField } from '@vben-core/toolkit'; import { mapTree, traverseTreeValues, uniqueByField } from '@vben-core/toolkit';
......
<script setup lang="ts"> <script setup lang="ts">
import type { SupportedLanguagesType } from '@vben/types'; import type { SupportedLanguagesType } from '@vben/types';
import { loadLocaleMessages } from '@vben/locales';
import { IcBaselineLanguage } from '@vben-core/iconify'; import { IcBaselineLanguage } from '@vben-core/iconify';
import { loadLocaleMessages } from '@vben-core/locales';
import { import {
SUPPORT_LANGUAGES, SUPPORT_LANGUAGES,
preferences, preferences,
......
<script lang="ts" setup> <script lang="ts" setup>
import type { NotificationItem } from './interface'; import type { NotificationItem } from './interface';
import { $t } from '@vben/locales';
import { import {
IcRoundMarkEmailRead, IcRoundMarkEmailRead,
IcRoundNotificationsNone, IcRoundNotificationsNone,
} from '@vben-core/iconify'; } from '@vben-core/iconify';
import { $t } from '@vben-core/locales';
import { import {
VbenButton, VbenButton,
VbenIconButton, VbenIconButton,
......
<script setup lang="ts"> <script setup lang="ts">
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import SwitchItem from '../switch-item.vue'; import SwitchItem from '../switch-item.vue';
......
<script setup lang="ts"> <script setup lang="ts">
import type { SelectListItem } from '@vben/types'; import type { SelectListItem } from '@vben/types';
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import { SUPPORT_LANGUAGES } from '@vben-core/preferences'; import { SUPPORT_LANGUAGES } from '@vben-core/preferences';
import SelectItem from '../select-item.vue'; import SelectItem from '../select-item.vue';
......
...@@ -3,7 +3,7 @@ import type { SelectListItem } from '@vben/types'; ...@@ -3,7 +3,7 @@ import type { SelectListItem } from '@vben/types';
import { computed } from 'vue'; import { computed } from 'vue';
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import SwitchItem from '../switch-item.vue'; import SwitchItem from '../switch-item.vue';
import ToggleItem from '../toggle-item.vue'; import ToggleItem from '../toggle-item.vue';
......
<script setup lang="ts"> <script setup lang="ts">
import { type Component, computed } from 'vue'; import { type Component, computed } from 'vue';
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import { ContentCompact, ContentWide } from '../../icons'; import { ContentCompact, ContentWide } from '../../icons';
......
<script setup lang="ts"> <script setup lang="ts">
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import InputItem from '../input-item.vue'; import InputItem from '../input-item.vue';
import SwitchItem from '../switch-item.vue'; import SwitchItem from '../switch-item.vue';
......
<script setup lang="ts"> <script setup lang="ts">
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import SwitchItem from '../switch-item.vue'; import SwitchItem from '../switch-item.vue';
......
<script setup lang="ts"> <script setup lang="ts">
import type { LayoutHeaderModeType, SelectListItem } from '@vben/types'; import type { LayoutHeaderModeType, SelectListItem } from '@vben/types';
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import SelectItem from '../select-item.vue'; import SelectItem from '../select-item.vue';
import SwitchItem from '../switch-item.vue'; import SwitchItem from '../switch-item.vue';
......
<script setup lang="ts"> <script setup lang="ts">
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import SwitchItem from '../switch-item.vue'; import SwitchItem from '../switch-item.vue';
......
...@@ -3,8 +3,8 @@ import type { LayoutType } from '@vben/types'; ...@@ -3,8 +3,8 @@ import type { LayoutType } from '@vben/types';
import { type Component, computed } from 'vue'; import { type Component, computed } from 'vue';
import { $t } from '@vben/locales';
import { MdiQuestionMarkCircleOutline } from '@vben-core/iconify'; import { MdiQuestionMarkCircleOutline } from '@vben-core/iconify';
import { $t } from '@vben-core/locales';
import { VbenTooltip } from '@vben-core/shadcn-ui'; import { VbenTooltip } from '@vben-core/shadcn-ui';
import { import {
......
<script setup lang="ts"> <script setup lang="ts">
import type { SelectListItem } from '@vben/types'; import type { SelectListItem } from '@vben/types';
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import SwitchItem from '../switch-item.vue'; import SwitchItem from '../switch-item.vue';
import ToggleItem from '../toggle-item.vue'; import ToggleItem from '../toggle-item.vue';
......
<script setup lang="ts"> <script setup lang="ts">
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import NumberFieldItem from '../number-field-item.vue'; import NumberFieldItem from '../number-field-item.vue';
import SwitchItem from '../switch-item.vue'; import SwitchItem from '../switch-item.vue';
......
<script setup lang="ts"> <script setup lang="ts">
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import SwitchItem from '../switch-item.vue'; import SwitchItem from '../switch-item.vue';
......
<script setup lang="ts"> <script setup lang="ts">
import { computed } from 'vue'; import { computed } from 'vue';
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import { isWindowsOs } from '@vben-core/toolkit'; import { isWindowsOs } from '@vben-core/toolkit';
import SwitchItem from '../switch-item.vue'; import SwitchItem from '../switch-item.vue';
......
...@@ -3,9 +3,9 @@ import type { BuiltinThemeType } from '@vben/types'; ...@@ -3,9 +3,9 @@ import type { BuiltinThemeType } from '@vben/types';
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { $t } from '@vben/locales';
import { TinyColor, convertToHsl } from '@vben-core/colorful'; import { TinyColor, convertToHsl } from '@vben-core/colorful';
import { MdiEditBoxOutline } from '@vben-core/iconify'; import { MdiEditBoxOutline } from '@vben-core/iconify';
import { $t } from '@vben-core/locales';
import { import {
BUILT_IN_THEME_PRESETS, BUILT_IN_THEME_PRESETS,
type BuiltinThemePreset, type BuiltinThemePreset,
......
<script setup lang="ts"> <script setup lang="ts">
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import SwitchItem from '../switch-item.vue'; import SwitchItem from '../switch-item.vue';
......
...@@ -3,12 +3,12 @@ import type { ThemeModeType } from '@vben-core/preferences'; ...@@ -3,12 +3,12 @@ import type { ThemeModeType } from '@vben-core/preferences';
import type { Component } from 'vue'; import type { Component } from 'vue';
import { $t } from '@vben/locales';
import { import {
IcRoundMotionPhotosAuto, IcRoundMotionPhotosAuto,
IcRoundWbSunny, IcRoundWbSunny,
MdiMoonAndStars, MdiMoonAndStars,
} from '@vben-core/iconify'; } from '@vben-core/iconify';
import { $t } from '@vben-core/locales';
import SwitchItem from '../switch-item.vue'; import SwitchItem from '../switch-item.vue';
......
<script lang="ts" setup> <script lang="ts" setup>
import { loadLocaleMessages } from '@vben/locales'; import { loadLocaleMessages } from '@vben-core/locales';
import { preferences, updatePreferences } from '@vben-core/preferences'; import { preferences, updatePreferences } from '@vben-core/preferences';
import Preferences from './preferences.vue'; import Preferences from './preferences.vue';
......
...@@ -15,8 +15,8 @@ import type { SegmentedItem } from '@vben-core/shadcn-ui'; ...@@ -15,8 +15,8 @@ import type { SegmentedItem } from '@vben-core/shadcn-ui';
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { $t, loadLocaleMessages } from '@vben/locales';
import { IcRoundFolderCopy, IcRoundRestartAlt } from '@vben-core/iconify'; import { IcRoundFolderCopy, IcRoundRestartAlt } from '@vben-core/iconify';
import { $t, loadLocaleMessages } from '@vben-core/locales';
import { import {
clearPreferencesCache, clearPreferencesCache,
preferences, preferences,
......
<script setup lang="ts"> <script setup lang="ts">
import { $t } from '@vben/locales'; import { $t } from '@vben-core/locales';
import { VbenButton } from '@vben-core/shadcn-ui'; import { VbenButton } from '@vben-core/shadcn-ui';
import IconSetting from './icons/setting.vue'; import IconSetting from './icons/setting.vue';
......
<script lang="ts" setup> <script lang="ts" setup>
import { $t } from '@vben/locales';
import { import {
IcRoundMotionPhotosAuto, IcRoundMotionPhotosAuto,
IcRoundWbSunny, IcRoundWbSunny,
MdiMoonAndStars, MdiMoonAndStars,
} from '@vben-core/iconify'; } from '@vben-core/iconify';
import { $t } from '@vben-core/locales';
import { import {
type ThemeModeType, type ThemeModeType,
preferences, preferences,
......
...@@ -4,8 +4,8 @@ import type { AnyFunction } from '@vben/types'; ...@@ -4,8 +4,8 @@ import type { AnyFunction } from '@vben/types';
import type { Component } from 'vue'; import type { Component } from 'vue';
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { $t } from '@vben/locales';
import { IcRoundLogout, IcRoundSettingsSuggest } from '@vben-core/iconify'; import { IcRoundLogout, IcRoundSettingsSuggest } from '@vben-core/iconify';
import { $t } from '@vben-core/locales';
import { preferences, usePreferences } from '@vben-core/preferences'; import { preferences, usePreferences } from '@vben-core/preferences';
import { import {
Badge, Badge,
......
/**
* 没有任何实际作用,只用于 IDE 对I18的提示
*/
function $t(key: string) {
return key;
}
export { $t };
...@@ -6,6 +6,7 @@ packages: ...@@ -6,6 +6,7 @@ packages:
- "packages/@core/ui-kit/*" - "packages/@core/ui-kit/*"
- "packages/@core/forward/*" - "packages/@core/forward/*"
- "packages/@core/helpers" - "packages/@core/helpers"
- "packages/@core/locales"
- "packages/business/*" - "packages/business/*"
- "apps/*" - "apps/*"
- "scripts/*" - "scripts/*"
......
...@@ -61,6 +61,10 @@ ...@@ -61,6 +61,10 @@
"path": "packages/@core/forward/stores", "path": "packages/@core/forward/stores",
}, },
{ {
"name": "@vben-core/locales",
"path": "packages/@core/locales",
},
{
"name": "@vben-core/cache", "name": "@vben-core/cache",
"path": "packages/@core/shared/cache", "path": "packages/@core/shared/cache",
}, },
...@@ -133,10 +137,6 @@ ...@@ -133,10 +137,6 @@
"path": "packages/icons", "path": "packages/icons",
}, },
{ {
"name": "@vben/locales",
"path": "packages/locales",
},
{
"name": "@vben/styles", "name": "@vben/styles",
"path": "packages/styles", "path": "packages/styles",
}, },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!