mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 21:49:25 +08:00
fix: integrate menu translation for route titles in admin layout (#6377)
* fix: integrate menu translation for route titles in admin layout * fix: add useMenuTranslation hook for improved localization in routes table schema --------- Co-authored-by: chenos <chenlinxh@gmail.com>
This commit is contained in:
parent
28500dd114
commit
216e13f744
@ -42,15 +42,15 @@ import {
|
|||||||
IsSubPageClosedByPageMenuProvider,
|
IsSubPageClosedByPageMenuProvider,
|
||||||
useCurrentPageUid,
|
useCurrentPageUid,
|
||||||
useLocationNoUpdate,
|
useLocationNoUpdate,
|
||||||
useNavigateNoUpdate,
|
|
||||||
} from '../../../application/CustomRouterContextProvider';
|
} from '../../../application/CustomRouterContextProvider';
|
||||||
import { Plugin } from '../../../application/Plugin';
|
import { Plugin } from '../../../application/Plugin';
|
||||||
|
import { withTooltipComponent } from '../../../hoc/withTooltipComponent';
|
||||||
import { menuItemInitializer } from '../../../modules/menu/menuItemInitializer';
|
import { menuItemInitializer } from '../../../modules/menu/menuItemInitializer';
|
||||||
|
import { useMenuTranslation } from '../../../schema-component/antd/menu/locale';
|
||||||
import { KeepAlive } from './KeepAlive';
|
import { KeepAlive } from './KeepAlive';
|
||||||
import { NocoBaseDesktopRoute, NocoBaseDesktopRouteType } from './convertRoutesToSchema';
|
import { NocoBaseDesktopRoute, NocoBaseDesktopRouteType } from './convertRoutesToSchema';
|
||||||
import { MenuSchemaToolbar, ResetThemeTokenAndKeepAlgorithm } from './menuItemSettings';
|
import { MenuSchemaToolbar, ResetThemeTokenAndKeepAlgorithm } from './menuItemSettings';
|
||||||
import { userCenterSettings } from './userCenterSettings';
|
import { userCenterSettings } from './userCenterSettings';
|
||||||
import { withTooltipComponent } from '../../../hoc/withTooltipComponent';
|
|
||||||
|
|
||||||
export { KeepAlive, NocoBaseDesktopRouteType };
|
export { KeepAlive, NocoBaseDesktopRouteType };
|
||||||
|
|
||||||
@ -504,12 +504,13 @@ export const InternalAdminLayout = () => {
|
|||||||
const [isMobile, setIsMobile] = useState(false);
|
const [isMobile, setIsMobile] = useState(false);
|
||||||
const [collapsed, setCollapsed] = useState(false);
|
const [collapsed, setCollapsed] = useState(false);
|
||||||
const doNotChangeCollapsedRef = useRef(false);
|
const doNotChangeCollapsedRef = useRef(false);
|
||||||
|
const { t } = useMenuTranslation();
|
||||||
const route = useMemo(() => {
|
const route = useMemo(() => {
|
||||||
return {
|
return {
|
||||||
path: '/',
|
path: '/',
|
||||||
children: convertRoutesToLayout(allAccessRoutes, { designable, isMobile }),
|
children: convertRoutesToLayout(allAccessRoutes, { designable, isMobile, t }),
|
||||||
};
|
};
|
||||||
}, [allAccessRoutes, designable, isMobile]);
|
}, [allAccessRoutes, designable, isMobile, t]);
|
||||||
const layoutToken = useMemo(() => {
|
const layoutToken = useMemo(() => {
|
||||||
return {
|
return {
|
||||||
header: {
|
header: {
|
||||||
@ -755,7 +756,10 @@ const MenuDesignerButton: FC<{ testId: string }> = (props) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function convertRoutesToLayout(routes: NocoBaseDesktopRoute[], { designable, parentRoute, isMobile, depth = 0 }: any) {
|
function convertRoutesToLayout(
|
||||||
|
routes: NocoBaseDesktopRoute[],
|
||||||
|
{ designable, parentRoute, isMobile, t, depth = 0 }: any,
|
||||||
|
) {
|
||||||
if (!routes) return;
|
if (!routes) return;
|
||||||
|
|
||||||
const getInitializerButton = (testId: string) => {
|
const getInitializerButton = (testId: string) => {
|
||||||
@ -773,7 +777,7 @@ function convertRoutesToLayout(routes: NocoBaseDesktopRoute[], { designable, par
|
|||||||
const result: any[] = routes.map((item) => {
|
const result: any[] = routes.map((item) => {
|
||||||
if (item.type === NocoBaseDesktopRouteType.link) {
|
if (item.type === NocoBaseDesktopRouteType.link) {
|
||||||
return {
|
return {
|
||||||
name: item.title,
|
name: t(item.title),
|
||||||
icon: item.icon ? <Icon type={item.icon} /> : null,
|
icon: item.icon ? <Icon type={item.icon} /> : null,
|
||||||
path: '/',
|
path: '/',
|
||||||
hideInMenu: item.hideInMenu,
|
hideInMenu: item.hideInMenu,
|
||||||
@ -784,7 +788,7 @@ function convertRoutesToLayout(routes: NocoBaseDesktopRoute[], { designable, par
|
|||||||
|
|
||||||
if (item.type === NocoBaseDesktopRouteType.page) {
|
if (item.type === NocoBaseDesktopRouteType.page) {
|
||||||
return {
|
return {
|
||||||
name: item.title,
|
name: t(item.title),
|
||||||
icon: item.icon ? <Icon type={item.icon} /> : null,
|
icon: item.icon ? <Icon type={item.icon} /> : null,
|
||||||
path: `/admin/${item.schemaUid}`,
|
path: `/admin/${item.schemaUid}`,
|
||||||
redirect: `/admin/${item.schemaUid}`,
|
redirect: `/admin/${item.schemaUid}`,
|
||||||
@ -795,7 +799,8 @@ function convertRoutesToLayout(routes: NocoBaseDesktopRoute[], { designable, par
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (item.type === NocoBaseDesktopRouteType.group) {
|
if (item.type === NocoBaseDesktopRouteType.group) {
|
||||||
const children = convertRoutesToLayout(item.children, { designable, parentRoute: item, depth: depth + 1 }) || [];
|
const children =
|
||||||
|
convertRoutesToLayout(item.children, { designable, parentRoute: item, depth: depth + 1, t }) || [];
|
||||||
|
|
||||||
// add a designer button
|
// add a designer button
|
||||||
if (designable && depth === 0) {
|
if (designable && depth === 0) {
|
||||||
@ -803,7 +808,7 @@ function convertRoutesToLayout(routes: NocoBaseDesktopRoute[], { designable, par
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: item.title,
|
name: t(item.title),
|
||||||
icon: item.icon ? <Icon type={item.icon} /> : null,
|
icon: item.icon ? <Icon type={item.icon} /> : null,
|
||||||
path: `/admin/${item.id}`,
|
path: `/admin/${item.id}`,
|
||||||
redirect:
|
redirect:
|
||||||
|
@ -9,3 +9,4 @@
|
|||||||
|
|
||||||
export * from './MenuItemInitializers';
|
export * from './MenuItemInitializers';
|
||||||
export * from './util';
|
export * from './util';
|
||||||
|
export { useMenuTranslation } from './locale';
|
||||||
|
@ -25,6 +25,7 @@ import {
|
|||||||
useDataBlockRequestData,
|
useDataBlockRequestData,
|
||||||
useDataBlockRequestGetter,
|
useDataBlockRequestGetter,
|
||||||
useInsertPageSchema,
|
useInsertPageSchema,
|
||||||
|
useMenuTranslation,
|
||||||
useNocoBaseRoutes,
|
useNocoBaseRoutes,
|
||||||
useRequest,
|
useRequest,
|
||||||
useRouterBasename,
|
useRouterBasename,
|
||||||
@ -492,14 +493,14 @@ export const createRoutesTableSchema = (collectionName: string, basename: string
|
|||||||
type: 'string',
|
type: 'string',
|
||||||
'x-component': function Com(props) {
|
'x-component': function Com(props) {
|
||||||
const record = useCollectionRecordData();
|
const record = useCollectionRecordData();
|
||||||
const { t } = useTranslation();
|
const { t } = useMenuTranslation();
|
||||||
let value = props.value;
|
let value = props.value;
|
||||||
|
|
||||||
if (record.type === NocoBaseDesktopRouteType.tabs && _.isNil(props.value)) {
|
if (record.type === NocoBaseDesktopRouteType.tabs && _.isNil(props.value)) {
|
||||||
value = t('Unnamed');
|
value = t('Unnamed');
|
||||||
}
|
}
|
||||||
|
|
||||||
return <CollectionField {...props} value={value} />;
|
return <CollectionField {...props} value={t(value)} />;
|
||||||
},
|
},
|
||||||
'x-read-pretty': true,
|
'x-read-pretty': true,
|
||||||
'x-component-props': {
|
'x-component-props': {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user