Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(ui): update titles for ribbon groups to support i18n (#6962)

白熱5223cc34c19a
diff --git a/packages/ui/src/services/menu/__tests__/types.spec.ts b/packages/ui/src/services/menu/__tests__/types.spec.ts
deleted file mode 100644
index 8c77486772..0000000000
--- a/packages/ui/src/services/menu/__tests__/types.spec.ts
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import { describe, expect, it } from 'vitest';
-import {
- ContextMenuGroup,
- ContextMenuPosition,
- MenuManagerPosition,
- RibbonDataGroup,
- RibbonFormulasGroup,
- RibbonInsertGroup,
- RibbonOthersGroup,
- RibbonPosition,
- RibbonStartGroup,
- RibbonViewGroup,
-} from '../types';
-
-describe('menu type enums', () => {
- it('should expose ribbon positions and groups', () => {
- expect(MenuManagerPosition.RIBBON).toBe('ribbon');
- expect(RibbonPosition.START).toBe('ribbon.start');
- expect(RibbonPosition.OTHERS).toBe('ribbon.others');
- expect(RibbonStartGroup.HISTORY).toBe('ribbon.start.history');
- expect(RibbonInsertGroup.MEDIA).toBe('ribbon.insert.media');
- expect(RibbonFormulasGroup.BASIC).toBe('ribbon.formulas.basic');
- expect(RibbonDataGroup.RULES).toBe('ribbon.data.rules');
- expect(RibbonViewGroup.VISIBILITY).toBe('ribbon.view.Visibility');
- expect(RibbonOthersGroup.OTHERS).toBe('ribbon.others.others');
- });
-
- it('should expose context menu positions and groups', () => {
- expect(MenuManagerPosition.CONTEXT_MENU).toBe('contextMenu');
- expect(ContextMenuPosition.MAIN_AREA).toBe('contextMenu.mainArea');
- expect(ContextMenuPosition.PARAGRAPH).toBe('contextMenu.paragraph');
- expect(ContextMenuGroup.QUICK).toBe('contextMenu.quick');
- expect(ContextMenuGroup.OTHERS).toBe('contextMenu.others');
- });
-});
diff --git a/packages/ui/src/services/menu/menu-manager.service.ts b/packages/ui/src/services/menu/menu-manager.service.ts
index cb9a8ccdb9..179cd88c7c 100644
--- a/packages/ui/src/services/menu/menu-manager.service.ts
+++ b/packages/ui/src/services/menu/menu-manager.service.ts
@@ -66,6 +66,7 @@ export class MenuManagerService extends Disposable implements IMenuManagerServic
[MenuManagerPosition.RIBBON]: {
[RibbonPosition.START]: {
order: 0,
+ title: 'ui.ribbon.start',
[RibbonStartGroup.HISTORY]: {
order: 0,
},
@@ -81,6 +82,7 @@ export class MenuManagerService extends Disposable implements IMenuManagerServic
},
[RibbonPosition.INSERT]: {
order: 1,
+ title: 'ui.ribbon.insert',
[RibbonInsertGroup.EDIT]: {
order: 0,
},
@@ -93,6 +95,7 @@ export class MenuManagerService extends Disposable implements IMenuManagerServic
},
[RibbonPosition.FORMULAS]: {
order: 2,
+ title: 'ui.ribbon.formulas',
[RibbonFormulasGroup.BASIC]: {
order: 0,
},
@@ -102,6 +105,7 @@ export class MenuManagerService extends Disposable implements IMenuManagerServic
},
[RibbonPosition.DATA]: {
order: 3,
+ title: 'ui.ribbon.data',
[RibbonDataGroup.FORMULAS]: {
order: 0,
},
@@ -117,6 +121,7 @@ export class MenuManagerService extends Disposable implements IMenuManagerServic
},
[RibbonPosition.VIEW]: {
order: 4,
+ title: 'ui.ribbon.view',
[RibbonViewGroup.DISPLAY]: {
order: 0,
},
@@ -129,6 +134,7 @@ export class MenuManagerService extends Disposable implements IMenuManagerServic
},
[RibbonPosition.OTHERS]: {
order: 5,
+ title: 'ui.ribbon.others',
[RibbonOthersGroup.OTHERS]: {
order: 0,
},
diff --git a/packages/ui/src/views/components/ribbon/MobileRibbon.tsx b/packages/ui/src/views/components/ribbon/MobileRibbon.tsx
index 272058211e..d0f701faad 100644
--- a/packages/ui/src/views/components/ribbon/MobileRibbon.tsx
+++ b/packages/ui/src/views/components/ribbon/MobileRibbon.tsx
@@ -184,7 +184,7 @@ export function MobileRibbon(props: IMobileRibbonProps) {
`)}
onClick={() => selectTab(index)}
>
- {localeService.t(`ui.${group.key}`)}
+ {localeService.t(group.title || group.key)}
{active && (
<span
className="
diff --git a/packages/ui/src/views/components/ribbon/Ribbon.tsx b/packages/ui/src/views/components/ribbon/Ribbon.tsx
index 0fb7ce81db..059b4e726b 100644
--- a/packages/ui/src/views/components/ribbon/Ribbon.tsx
+++ b/packages/ui/src/views/components/ribbon/Ribbon.tsx
@@ -71,6 +71,10 @@ export function Ribbon(props: IRibbonProps) {
return ribbonData;
}, [ribbonType, ribbonData]);
+ const activatedTabTitle = useMemo(() => {
+ return ribbon.find((group) => group.key === activatedTab)?.title || activatedTab;
+ }, [ribbon, activatedTab]);
+
const handleSelectTab = useCallback((group: IMenuSchema) => {
toolbarItemRefs.current = {};
ribbonService.setActivatedTab(group.key);
@@ -247,7 +251,7 @@ export function Ribbon(props: IRibbonProps) {
'univer-justify-center': ribbonType === 'classic',
})}
role="toolbar"
- aria-label={localeService.t(`ui.${activatedTab}`)}
+ aria-label={localeService.t(activatedTabTitle)}
>
{activeGroup.visibleGroups.map((groupItem) => (groupItem.children?.length || groupItem.item) && (
<Fragment key={groupItem.key}>
diff --git a/packages/ui/src/views/components/ribbon/ribbon-menu/ClassicMenu.tsx b/packages/ui/src/views/components/ribbon/ribbon-menu/ClassicMenu.tsx
index 1e6eaa6d1d..92526c62a7 100644
--- a/packages/ui/src/views/components/ribbon/ribbon-menu/ClassicMenu.tsx
+++ b/packages/ui/src/views/components/ribbon/ribbon-menu/ClassicMenu.tsx
@@ -47,7 +47,7 @@ export function ClassicMenu({
type="button"
role="tab"
aria-selected={isActive}
- title={localeService.t(`ui.${group.key}`)}
+ title={localeService.t(group.title || group.key)}
onClick={() => onSelectTab(group)}
className={clsx(`
univer-focus:outline-none univer-focus:ring-2 univer-focus:ring-primary-500
@@ -67,7 +67,7 @@ export function ClassicMenu({
dark:!univer-text-gray-200
`)}
>
- {localeService.t(`ui.${group.key}`)}
+ {localeService.t(group.title || group.key)}
</button>
);
})}
diff --git a/packages/ui/src/views/components/ribbon/ribbon-menu/DefaultMenu.tsx b/packages/ui/src/views/components/ribbon/ribbon-menu/DefaultMenu.tsx
index ac0947c5ea..3fdc4a7d03 100644
--- a/packages/ui/src/views/components/ribbon/ribbon-menu/DefaultMenu.tsx
+++ b/packages/ui/src/views/components/ribbon/ribbon-menu/DefaultMenu.tsx
@@ -41,6 +41,7 @@ export function DefaultMenu({
onSelectTab: (tab: IMenuSchema) => void;
}) {
const localeService = useDependency(LocaleService);
+ const activatedTabTitle = ribbon.find((group) => group.key === activatedTab)?.title || activatedTab;
const [groupSelectorVisible, setGroupSelectorVisible] = useState(false);
@@ -92,10 +93,10 @@ export function DefaultMenu({
dark:!univer-text-gray-200
`}
>
- {localeService.t(`ui.${group.key}`)}
+ {localeService.t(group.title || group.key)}
</strong>
<span className="univer-text-xs univer-text-gray-400">
- {localeService.t(`ui.${group.key}Desc`)}
+ {localeService.t(`${group.title || group.key}Desc`)}
</span>
</span>
</a>
@@ -114,7 +115,7 @@ export function DefaultMenu({
`}
onClick={() => setGroupSelectorVisible(true)}
>
- {localeService.t(`ui.${activatedTab}`)}
+ {localeService.t(activatedTabTitle)}
<MoreDownIcon
className={`
univer-text-gray-200