feat: layout的title支持国际化

This commit is contained in:
harrywan 2024-10-23 16:45:11 +08:00
parent db358576e8
commit 9b072f828a
5 changed files with 24 additions and 13 deletions

View File

@ -233,7 +233,7 @@ export function layout(layoutConfig, { initialState }) {
- **类型**`String`
- **默认值**:默认为 [编译时配置 title](../../../reference/config/#title)
- **详情**:产品名。
- **详情**:产品名,当配置为"$"开头时,开启国际化,使用`$`后面的内容去匹配语言设置
### logo

View File

@ -11,8 +11,8 @@
>
<div class="layout-logo">
<img v-if="logo" :src="logo" class="logo-img">
<div v-if="title" class="logo-name">
{{ title }}
<div v-if="transformedTitle" class="logo-name">
{{ transformedTitle }}
</div>
</div>
<LayoutMenu
@ -58,8 +58,8 @@
<div>
<div class="layout-logo">
<img v-if="logo" :src="logo" class="logo-img">
<div v-if="title" class="logo-name">
{{ title }}
<div v-if="transformedTitle" class="logo-name">
{{ transformedTitle }}
</div>
</div>
<LayoutMenu
@ -98,8 +98,8 @@
<FHeader ref="headerRef" class="layout-header" :inverted="theme === 'dark'" :fixed="currentFixedHeaderRef">
<div class="layout-logo">
<img v-if="logo" :src="logo" class="logo-img">
<div v-if="title" class="logo-name">
{{ title }}
<div v-if="transformedTitle" class="logo-name">
{{ transformedTitle }}
</div>
</div>
<LayoutMenu
@ -131,8 +131,8 @@
<FHeader ref="headerRef" class="layout-header" :inverted="theme === 'dark'" :fixed="currentFixedHeaderRef">
<div class="layout-logo">
<img v-if="logo" :src="logo" class="logo-img">
<div v-if="title" class="logo-name">
{{ title }}
<div v-if="transformedTitle" class="logo-name">
{{ transformedTitle }}
</div>
</div>
<LayoutMenu
@ -184,8 +184,8 @@
<FHeader ref="headerRef" class="layout-header" :fixed="currentFixedHeaderRef" :inverted="theme === 'dark'">
<div class="layout-logo">
<img v-if="logo" :src="logo" class="logo-img">
<div v-if="title" class="logo-name">
{{ title }}
<div v-if="transformedTitle" class="logo-name">
{{ transformedTitle }}
</div>
</div>
<div class="layout-header-custom">
@ -231,6 +231,7 @@ import { FAside, FFooter, FHeader, FLayout, FMain } from '@fesjs/fes-design';
import { computed, nextTick, ref, watch } from 'vue';
import defaultLogo from '../assets/logo.png';
import { flatNodes } from '../helpers/utils';
import { transTitle } from '../helpers/pluginLocale';
import LayoutMenu from './Menu.vue';
import MultiTabProvider from './MultiTabProvider.vue';
@ -302,6 +303,10 @@ export default {
const route = useRoute();
const router = useRouter();
const transformedTitle = computed(() => {
return transTitle(props.title);
});
const currentNavigation = computed(() => {
if (route.meta.layout && route.meta.layout.navigation !== undefined) {
return route.meta.layout.navigation;
@ -397,6 +402,7 @@ export default {
currentNavigation,
rootMenus,
activeSubMenus,
transformedTitle,
};
},
};

View File

@ -62,6 +62,9 @@ export default (api) => {
const { baseNavigator, ...otherConfig } = userConfig;
const title = api.config.title || 'fes.js';
const isLocaleTitle = title.startsWith('$');
api.writeTmpFile({
path: join(namespace, 'locales.js'),
content: Mustache.render(readFileSync(join(__dirname, 'runtime/locales.js.tpl'), 'utf-8'), {
@ -79,6 +82,8 @@ export default (api) => {
REPLACE_DEFAULT_OPTIONS: JSON.stringify(otherConfig, null, 2),
BASE_NAVIGATOR: baseNavigator,
VUE_I18N_PATH: 'vue-i18n',
TITLE: title.slice(1),
IS_LOCALE_TITle: isLocaleTitle,
}),
});

View File

@ -92,7 +92,7 @@ const locale = {
addLocale,
getAllLocales,
messages,
t
t,
};
export { useI18n, locale, install };

View File

@ -33,7 +33,7 @@ export default defineBuildConfig({
},
},
layout: {
title: 'Fes.js',
title: '$home',
footer: 'Created by MumbleFE',
multiTabs: true,
navigation: 'mixin',