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.

feat: use type-safe i18n keys for menu titles (#7137)

白熱8b04b8313e5f
diff --git a/packages/action-recorder/src/locale/types.ts b/packages/action-recorder/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/action-recorder/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/action-recorder/src/menu/action-recorder.menu.ts b/packages/action-recorder/src/menu/action-recorder.menu.ts
index c66e6c12b5..8d275870b6 100644
--- a/packages/action-recorder/src/menu/action-recorder.menu.ts
+++ b/packages/action-recorder/src/menu/action-recorder.menu.ts
@@ -16,13 +16,18 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuButtonItem, IMenuSelectorItem, MenuSchemaType } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { MenuItemType, RibbonOthersGroup } from '@univerjs/ui';
-import { ReplayLocalRecordCommand, ReplayLocalRecordOnActiveCommand, ReplayLocalRecordOnNamesakeCommand } from '../commands/commands/replay.command';
+import {
+ ReplayLocalRecordCommand,
+ ReplayLocalRecordOnActiveCommand,
+ ReplayLocalRecordOnNamesakeCommand,
+} from '../commands/commands/replay.command';
import { OpenRecordPanelOperation } from '../commands/operations/operation';
import { ActionRecorderService } from '../services/action-recorder.service';
export const RECORD_MENU_ITEM_ID = 'RECORD_MENU_ITEM';
-export function RecordMenuItemFactory(): IMenuSelectorItem {
+export function RecordMenuItemFactory(): IMenuSelectorItem<LocaleKey> {
return {
id: RECORD_MENU_ITEM_ID,
type: MenuItemType.SUBITEMS,
@@ -31,7 +36,7 @@ export function RecordMenuItemFactory(): IMenuSelectorItem {
};
}
-export function OpenRecorderMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function OpenRecorderMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const actionRecorderService = accessor.get(ActionRecorderService);
return {
@@ -42,7 +47,7 @@ export function OpenRecorderMenuItemFactory(accessor: IAccessor): IMenuButtonIte
};
}
-export function ReplayLocalRecordMenuItemFactory(): IMenuButtonItem {
+export function ReplayLocalRecordMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: ReplayLocalRecordCommand.id,
title: 'action-recorder.menu.replay-local',
@@ -50,7 +55,7 @@ export function ReplayLocalRecordMenuItemFactory(): IMenuButtonItem {
};
}
-export function ReplayLocalRecordOnNamesakeMenuItemFactory(): IMenuButtonItem {
+export function ReplayLocalRecordOnNamesakeMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: ReplayLocalRecordOnNamesakeCommand.id,
title: 'action-recorder.menu.replay-local-name',
@@ -58,7 +63,7 @@ export function ReplayLocalRecordOnNamesakeMenuItemFactory(): IMenuButtonItem {
};
}
-export function ReplayLocalRecordOnActiveMenuItemFactory(): IMenuButtonItem {
+export function ReplayLocalRecordOnActiveMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: ReplayLocalRecordOnActiveCommand.id,
title: 'action-recorder.menu.replay-local-active',
diff --git a/packages/core/src/services/locale/locale.service.ts b/packages/core/src/services/locale/locale.service.ts
index 1fa5de77a2..0fcdda2b85 100644
--- a/packages/core/src/services/locale/locale.service.ts
+++ b/packages/core/src/services/locale/locale.service.ts
@@ -80,7 +80,7 @@ export class LocaleService extends Disposable {
* }
* t('foo.bar', 'World') => 'Hello World'
*/
- t = (key: string, ...args: string[]): string => {
+ t = <TKey extends string = string>(key: TKey, ...args: string[]): string => {
if (!this._locales) throw new Error('[LocaleService]: Locale not initialized');
const keys = key.split('.');
diff --git a/packages/core/src/shared/locale.ts b/packages/core/src/shared/locale.ts
index e03740014c..aceba0306c 100644
--- a/packages/core/src/shared/locale.ts
+++ b/packages/core/src/shared/locale.ts
@@ -24,6 +24,16 @@ export interface ILocales {
[key: string]: ILanguagePack;
}
+export type LocaleLeafKeys<T> = {
+ [K in keyof T & string]: T[K] extends string
+ ? K
+ : T[K] extends readonly unknown[]
+ ? never
+ : T[K] extends Record<string, unknown>
+ ? `${K}.${LocaleLeafKeys<T[K]>}`
+ : never;
+}[keyof T & string];
+
// eslint-disable-next-line ts/no-explicit-any
type MergeLocalesInput = Record<string, any>;
diff --git a/packages/data-validation/src/locale/types.ts b/packages/data-validation/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/data-validation/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/docs-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts b/packages/docs-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts
index 4d5941c5b5..c3235a0e67 100644
--- a/packages/docs-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts
+++ b/packages/docs-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts
@@ -15,6 +15,7 @@
*/
import type { IAccessor, ICommand } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import { CommandType, LocaleService } from '@univerjs/core';
import { IDrawingManagerService } from '@univerjs/drawing';
import { ISidebarService } from '@univerjs/ui';
@@ -35,7 +36,7 @@ export const SidebarDocDrawingOperation: ICommand = {
switch (params.value) {
case 'open':
sidebarService.open({
- header: { title: localeService.t('docs-drawing-ui.panel.title') },
+ header: { title: localeService.t<LocaleKey>('docs-drawing-ui.panel.title') },
children: { label: COMPONENT_DOC_DRAWING_PANEL },
onClose: () => {
drawingManagerService.focusDrawing(null);
diff --git a/packages/docs-drawing-ui/src/controllers/render-controllers/doc-drawing-update.render-controller.ts b/packages/docs-drawing-ui/src/controllers/render-controllers/doc-drawing-update.render-controller.ts
index 84bcff8a67..92ae012504 100644
--- a/packages/docs-drawing-ui/src/controllers/render-controllers/doc-drawing-update.render-controller.ts
+++ b/packages/docs-drawing-ui/src/controllers/render-controllers/doc-drawing-update.render-controller.ts
@@ -20,6 +20,7 @@ import type { IImageIoServiceParam } from '@univerjs/drawing';
import type { Documents, Image, IRenderContext, IRenderModule } from '@univerjs/engine-render';
import type { IInsertDrawingCommandParams } from '../../commands/commands/interfaces';
import type { ISetDrawingArrangeCommandParams } from '../../commands/commands/set-drawing-arrange.command';
+import type { LocaleKey } from '../../locale/types';
import {
BooleanNumber,
Disposable,
@@ -106,7 +107,7 @@ export class DocDrawingUpdateRenderController extends Disposable implements IRen
if (fileLength > DRAWING_IMAGE_COUNT_LIMIT) {
this._messageService.show({
type: MessageType.Error,
- content: this._localeService.t('docs-drawing-ui.update-status.exceedMaxCount', String(DRAWING_IMAGE_COUNT_LIMIT)),
+ content: this._localeService.t<LocaleKey>('docs-drawing-ui.update-status.exceedMaxCount', String(DRAWING_IMAGE_COUNT_LIMIT)),
});
return false;
} else if (fileLength === 0) {
@@ -129,13 +130,13 @@ export class DocDrawingUpdateRenderController extends Disposable implements IRen
switch (type) {
case ImageUploadStatusType.ERROR_EXCEED_SIZE:
- content = this._localeService.t('docs-drawing-ui.update-status.exceedMaxSize', String(getDrawingImageAllowSize() / (1024 * 1024)));
+ content = this._localeService.t<LocaleKey>('docs-drawing-ui.update-status.exceedMaxSize', String(getDrawingImageAllowSize() / (1024 * 1024)));
break;
case ImageUploadStatusType.ERROR_IMAGE_TYPE:
- content = this._localeService.t('docs-drawing-ui.update-status.invalidImageType');
+ content = this._localeService.t<LocaleKey>('docs-drawing-ui.update-status.invalidImageType');
break;
case ImageUploadStatusType.ERROR_IMAGE:
- content = this._localeService.t('docs-drawing-ui.update-status.invalidImage');
+ content = this._localeService.t<LocaleKey>('docs-drawing-ui.update-status.invalidImage');
break;
default:
break;
diff --git a/packages/docs-drawing-ui/src/locale/types.ts b/packages/docs-drawing-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/docs-drawing-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/docs-drawing-ui/src/menu/image.menu.ts b/packages/docs-drawing-ui/src/menu/image.menu.ts
index 8b7a123f7e..90c00eda5c 100644
--- a/packages/docs-drawing-ui/src/menu/image.menu.ts
+++ b/packages/docs-drawing-ui/src/menu/image.menu.ts
@@ -16,6 +16,7 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
@@ -60,7 +61,7 @@ const getDisableWhenSelectionInTableObservable = (accessor: IAccessor) => {
});
};
-export function ImageMenuFactory(accessor: IAccessor): IMenuItem {
+export function ImageMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: DOCS_IMAGE_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -71,17 +72,17 @@ export function ImageMenuFactory(accessor: IAccessor): IMenuItem {
};
}
-export function UploadFloatImageMenuFactory(_accessor: IAccessor): IMenuItem {
+export function UploadFloatImageMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: IMAGE_MENU_UPLOAD_FLOAT_ID,
title: 'docs-drawing-ui.upload.float',
type: MenuItemType.BUTTON,
icon: 'AddImageIcon',
- hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_DOC),
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
-export function UploadFloatImageBelowMenuFactory(_accessor: IAccessor): IMenuItem {
+export function UploadFloatImageBelowMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: `${IMAGE_MENU_UPLOAD_FLOAT_ID}.below`,
commandId: IMAGE_MENU_UPLOAD_FLOAT_ID,
@@ -91,6 +92,6 @@ export function UploadFloatImageBelowMenuFactory(_accessor: IAccessor): IMenuIte
params: {
paragraphMenuPlacement: 'below',
},
- hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_DOC),
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
diff --git a/packages/docs-drawing-ui/src/menu/shape.menu.ts b/packages/docs-drawing-ui/src/menu/shape.menu.ts
index 1373accc81..c5945aa488 100644
--- a/packages/docs-drawing-ui/src/menu/shape.menu.ts
+++ b/packages/docs-drawing-ui/src/menu/shape.menu.ts
@@ -16,14 +16,18 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuButtonItem, IMenuItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { UniverInstanceType } from '@univerjs/core';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
-import { InsertDocEllipseShapeCommand, InsertDocRectangleShapeCommand } from '../commands/commands/insert-shape.command';
+import {
+ InsertDocEllipseShapeCommand,
+ InsertDocRectangleShapeCommand,
+} from '../commands/commands/insert-shape.command';
export const DOCS_SHAPE_MENU_ID = 'doc.command.menu-insert-shape';
export const DOCS_SHAPE_BELOW_MENU_ID = 'doc.command.menu-insert-shape.below';
-export function ShapeMenuFactory(accessor: IAccessor): IMenuItem {
+export function ShapeMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: DOCS_SHAPE_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -34,7 +38,7 @@ export function ShapeMenuFactory(accessor: IAccessor): IMenuItem {
};
}
-export function ShapeBelowMenuFactory(accessor: IAccessor): IMenuItem {
+export function ShapeBelowMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: DOCS_SHAPE_BELOW_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -45,7 +49,7 @@ export function ShapeBelowMenuFactory(accessor: IAccessor): IMenuItem {
};
}
-export function InsertRectangleShapeMenuFactory(accessor: IAccessor): IMenuButtonItem {
+export function InsertRectangleShapeMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: InsertDocRectangleShapeCommand.id,
title: 'docs-drawing-ui.shape.insert.rectangle',
@@ -54,7 +58,7 @@ export function InsertRectangleShapeMenuFactory(accessor: IAccessor): IMenuButto
};
}
-export function InsertEllipseShapeMenuFactory(accessor: IAccessor): IMenuButtonItem {
+export function InsertEllipseShapeMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: InsertDocEllipseShapeCommand.id,
title: 'docs-drawing-ui.shape.insert.ellipse',
@@ -63,7 +67,7 @@ export function InsertEllipseShapeMenuFactory(accessor: IAccessor): IMenuButtonI
};
}
-export function InsertRectangleShapeBelowMenuFactory(accessor: IAccessor): IMenuButtonItem {
+export function InsertRectangleShapeBelowMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: `${InsertDocRectangleShapeCommand.id}.below`,
commandId: InsertDocRectangleShapeCommand.id,
@@ -76,7 +80,7 @@ export function InsertRectangleShapeBelowMenuFactory(accessor: IAccessor): IMenu
};
}
-export function InsertEllipseShapeBelowMenuFactory(accessor: IAccessor): IMenuButtonItem {
+export function InsertEllipseShapeBelowMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: `${InsertDocEllipseShapeCommand.id}.below`,
commandId: InsertDocEllipseShapeCommand.id,
diff --git a/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingPosition.tsx b/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingPosition.tsx
index b03b29bdde..46daaa77b7 100644
--- a/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingPosition.tsx
+++ b/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingPosition.tsx
@@ -17,6 +17,7 @@
import type { ICommandInfo, IDrawingParam, IObjectPositionH, IObjectPositionV, Nullable } from '@univerjs/core';
import type { IDocDrawing } from '@univerjs/docs-drawing';
import type { IDocumentSkeletonDrawing } from '@univerjs/engine-render';
+import type { LocaleKey } from '../../locale/types';
import {
DocumentFlavor,
ICommandService,
@@ -71,30 +72,30 @@ export const DocDrawingPosition = (props: IDocDrawingPositionProps) => {
const transformer = scene.getTransformerByCreate();
const HORIZONTAL_RELATIVE_FROM = [{
- label: localeService.t('docs-drawing-ui.image-position.column'),
+ label: localeService.t<LocaleKey>('docs-drawing-ui.image-position.column'),
value: String(ObjectRelativeFromH.COLUMN),
}, {
- label: localeService.t('docs-drawing-ui.image-position.page'),
+ label: localeService.t<LocaleKey>('docs-drawing-ui.image-position.page'),
value: String(ObjectRelativeFromH.PAGE),
}, {
- label: localeService.t('docs-drawing-ui.image-position.margin'),
+ label: localeService.t<LocaleKey>('docs-drawing-ui.image-position.margin'),
value: String(ObjectRelativeFromH.MARGIN),
}];
const VERTICAL_RELATIVE_FROM = [{
- label: localeService.t('docs-drawing-ui.image-position.line'),
+ label: localeService.t<LocaleKey>('docs-drawing-ui.image-position.line'),
value: String(ObjectRelativeFromV.LINE),
disabled: documentFlavor === DocumentFlavor.MODERN,
}, {
- label: localeService.t('docs-drawing-ui.image-position.page'),
+ label: localeService.t<LocaleKey>('docs-drawing-ui.image-position.page'),
value: String(ObjectRelativeFromV.PAGE),
disabled: documentFlavor === DocumentFlavor.MODERN,
}, {
- label: localeService.t('docs-drawing-ui.image-position.margin'),
+ label: localeService.t<LocaleKey>('docs-drawing-ui.image-position.margin'),
value: String(ObjectRelativeFromV.MARGIN),
disabled: documentFlavor === DocumentFlavor.MODERN,
}, {
- label: localeService.t('docs-drawing-ui.image-position.paragraph'),
+ label: localeService.t<LocaleKey>('docs-drawing-ui.image-position.paragraph'),
value: String(ObjectRelativeFromV.PARAGRAPH),
}];
@@ -378,7 +379,7 @@ export const DocDrawingPosition = (props: IDocDrawingPositionProps) => {
dark:!univer-text-gray-200
`}
>
- <div>{localeService.t('docs-drawing-ui.image-position.title')}</div>
+ <div>{localeService.t<LocaleKey>('docs-drawing-ui.image-position.title')}</div>
</header>
<div
@@ -387,7 +388,7 @@ export const DocDrawingPosition = (props: IDocDrawingPositionProps) => {
dark:!univer-text-gray-200
`}
>
- <div>{localeService.t('docs-drawing-ui.image-position.horizontal')}</div>
+ <div>{localeService.t<LocaleKey>('docs-drawing-ui.image-position.horizontal')}</div>
</div>
<div
@@ -397,7 +398,7 @@ export const DocDrawingPosition = (props: IDocDrawingPositionProps) => {
`}
>
<div>
- <span>{localeService.t('docs-drawing-ui.image-position.absolutePosition')}</span>
+ <span>{localeService.t<LocaleKey>('docs-drawing-ui.image-position.absolutePosition')}</span>
<InputNumber
min={MIN_OFFSET}
max={MAX_OFFSET}
@@ -413,7 +414,7 @@ export const DocDrawingPosition = (props: IDocDrawingPositionProps) => {
/>
</div>
<div>
- <span>{localeService.t('docs-drawing-ui.image-position.toTheRightOf')}</span>
+ <span>{localeService.t<LocaleKey>('docs-drawing-ui.image-position.toTheRightOf')}</span>
<Select
value={String(hPosition.relativeFrom)}
disabled={disabled}
@@ -429,7 +430,7 @@ export const DocDrawingPosition = (props: IDocDrawingPositionProps) => {
dark:!univer-text-gray-200
`}
>
- <div>{localeService.t('docs-drawing-ui.image-position.vertical')}</div>
+ <div>{localeService.t<LocaleKey>('docs-drawing-ui.image-position.vertical')}</div>
</div>
<div
@@ -439,7 +440,7 @@ export const DocDrawingPosition = (props: IDocDrawingPositionProps) => {
`}
>
<div>
- <span>{localeService.t('docs-drawing-ui.image-position.absolutePosition')}</span>
+ <span>{localeService.t<LocaleKey>('docs-drawing-ui.image-position.absolutePosition')}</span>
<InputNumber
min={MIN_OFFSET}
max={MAX_OFFSET}
@@ -455,7 +456,7 @@ export const DocDrawingPosition = (props: IDocDrawingPositionProps) => {
/>
</div>
<div>
- <span>{localeService.t('docs-drawing-ui.image-position.bellow')}</span>
+ <span>{localeService.t<LocaleKey>('docs-drawing-ui.image-position.bellow')}</span>
<Select
disabled={disabled}
value={String(vPosition.relativeFrom)}
@@ -471,7 +472,7 @@ export const DocDrawingPosition = (props: IDocDrawingPositionProps) => {
dark:!univer-text-gray-200
`}
>
- <div>{localeService.t('docs-drawing-ui.image-position.options')}</div>
+ <div>{localeService.t<LocaleKey>('docs-drawing-ui.image-position.options')}</div>
</div>
<div>
@@ -480,7 +481,7 @@ export const DocDrawingPosition = (props: IDocDrawingPositionProps) => {
checked={followTextMove}
onChange={handleFollowTextMoveCheck}
>
- {localeService.t('docs-drawing-ui.image-position.moveObjectWithText')}
+ {localeService.t<LocaleKey>('docs-drawing-ui.image-position.moveObjectWithText')}
</Checkbox>
</div>
</div>
diff --git a/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingTextWrap.tsx b/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingTextWrap.tsx
index b35b0e9e0d..3d218bb8aa 100644
--- a/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingTextWrap.tsx
+++ b/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingTextWrap.tsx
@@ -16,6 +16,7 @@
import type { ICommandInfo, IDrawingParam, Nullable } from '@univerjs/core';
import type { IDocDrawing } from '@univerjs/docs-drawing';
+import type { LocaleKey } from '../../locale/types';
import {
BooleanNumber,
ICommandService,
@@ -285,7 +286,7 @@ export const DocDrawingTextWrap = (props: IDocDrawingTextWrapProps) => {
dark:!univer-text-gray-200
`}
>
- <div>{localeService.t('docs-drawing-ui.image-text-wrap.title')}</div>
+ <div>{localeService.t<LocaleKey>('docs-drawing-ui.image-text-wrap.title')}</div>
</header>
<div
@@ -294,16 +295,16 @@ export const DocDrawingTextWrap = (props: IDocDrawingTextWrapProps) => {
dark:!univer-text-gray-200
`}
>
- <div>{localeService.t('docs-drawing-ui.image-text-wrap.wrappingStyle')}</div>
+ <div>{localeService.t<LocaleKey>('docs-drawing-ui.image-text-wrap.wrappingStyle')}</div>
</div>
<div>
<RadioGroup value={wrappingStyle} onChange={handleWrappingStyleChange} direction="vertical">
- <Radio value={TextWrappingStyle.INLINE}>{localeService.t('docs-drawing-ui.image-text-wrap.inline')}</Radio>
- <Radio value={TextWrappingStyle.WRAP_SQUARE}>{localeService.t('docs-drawing-ui.image-text-wrap.square')}</Radio>
- <Radio value={TextWrappingStyle.WRAP_TOP_AND_BOTTOM}>{localeService.t('docs-drawing-ui.image-text-wrap.topAndBottom')}</Radio>
- <Radio value={TextWrappingStyle.BEHIND_TEXT}>{localeService.t('docs-drawing-ui.image-text-wrap.behindText')}</Radio>
- <Radio value={TextWrappingStyle.IN_FRONT_OF_TEXT}>{localeService.t('docs-drawing-ui.image-text-wrap.inFrontText')}</Radio>
+ <Radio value={TextWrappingStyle.INLINE}>{localeService.t<LocaleKey>('docs-drawing-ui.image-text-wrap.inline')}</Radio>
+ <Radio value={TextWrappingStyle.WRAP_SQUARE}>{localeService.t<LocaleKey>('docs-drawing-ui.image-text-wrap.square')}</Radio>
+ <Radio value={TextWrappingStyle.WRAP_TOP_AND_BOTTOM}>{localeService.t<LocaleKey>('docs-drawing-ui.image-text-wrap.topAndBottom')}</Radio>
+ <Radio value={TextWrappingStyle.BEHIND_TEXT}>{localeService.t<LocaleKey>('docs-drawing-ui.image-text-wrap.behindText')}</Radio>
+ <Radio value={TextWrappingStyle.IN_FRONT_OF_TEXT}>{localeService.t<LocaleKey>('docs-drawing-ui.image-text-wrap.inFrontText')}</Radio>
</RadioGroup>
</div>
@@ -313,14 +314,14 @@ export const DocDrawingTextWrap = (props: IDocDrawingTextWrapProps) => {
dark:!univer-text-gray-200
`}
>
- <div>{localeService.t('docs-drawing-ui.image-text-wrap.wrapText')}</div>
+ <div>{localeService.t<LocaleKey>('docs-drawing-ui.image-text-wrap.wrapText')}</div>
</div>
<div>
<RadioGroup disabled={disableWrapText} value={wrapText} onChange={handleWrapTextChange} direction="horizontal">
- <Radio value={WrapTextType.BOTH_SIDES}>{localeService.t('docs-drawing-ui.image-text-wrap.bothSide')}</Radio>
- <Radio value={WrapTextType.LEFT}>{localeService.t('docs-drawing-ui.image-text-wrap.leftOnly')}</Radio>
- <Radio value={WrapTextType.RIGHT}>{localeService.t('docs-drawing-ui.image-text-wrap.rightOnly')}</Radio>
+ <Radio value={WrapTextType.BOTH_SIDES}>{localeService.t<LocaleKey>('docs-drawing-ui.image-text-wrap.bothSide')}</Radio>
+ <Radio value={WrapTextType.LEFT}>{localeService.t<LocaleKey>('docs-drawing-ui.image-text-wrap.leftOnly')}</Radio>
+ <Radio value={WrapTextType.RIGHT}>{localeService.t<LocaleKey>('docs-drawing-ui.image-text-wrap.rightOnly')}</Radio>
</RadioGroup>
</div>
@@ -330,7 +331,7 @@ export const DocDrawingTextWrap = (props: IDocDrawingTextWrapProps) => {
dark:!univer-text-gray-200
`}
>
- <div>{localeService.t('docs-drawing-ui.image-text-wrap.distanceFromText')}</div>
+ <div>{localeService.t<LocaleKey>('docs-drawing-ui.image-text-wrap.distanceFromText')}</div>
</div>
<div
@@ -340,7 +341,7 @@ export const DocDrawingTextWrap = (props: IDocDrawingTextWrapProps) => {
`}
>
<div>
- <span>{localeService.t('docs-drawing-ui.image-text-wrap.top')}</span>
+ <span>{localeService.t<LocaleKey>('docs-drawing-ui.image-text-wrap.top')}</span>
<InputNumber
min={MIN_MARGIN}
max={MAX_MARGIN}
@@ -351,7 +352,7 @@ export const DocDrawingTextWrap = (props: IDocDrawingTextWrapProps) => {
/>
</div>
<div>
- <span>{localeService.t('docs-drawing-ui.image-text-wrap.left')}</span>
+ <span>{localeService.t<LocaleKey>('docs-drawing-ui.image-text-wrap.left')}</span>
<InputNumber
min={MIN_MARGIN}
max={MAX_MARGIN}
@@ -370,7 +371,7 @@ export const DocDrawingTextWrap = (props: IDocDrawingTextWrapProps) => {
`}
>
<div>
- <span>{localeService.t('docs-drawing-ui.image-text-wrap.bottom')}</span>
+ <span>{localeService.t<LocaleKey>('docs-drawing-ui.image-text-wrap.bottom')}</span>
<InputNumber
min={MIN_MARGIN}
max={MAX_MARGIN}
@@ -381,7 +382,7 @@ export const DocDrawingTextWrap = (props: IDocDrawingTextWrapProps) => {
/>
</div>
<div>
- <span>{localeService.t('docs-drawing-ui.image-text-wrap.right')}</span>
+ <span>{localeService.t<LocaleKey>('docs-drawing-ui.image-text-wrap.right')}</span>
<InputNumber
min={MIN_MARGIN}
max={MAX_MARGIN}
diff --git a/packages/docs-hyper-link-ui/src/locale/types.ts b/packages/docs-hyper-link-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/docs-hyper-link-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/docs-hyper-link-ui/src/menu/menu.ts b/packages/docs-hyper-link-ui/src/menu/menu.ts
index 02b4be6a11..9974b9352e 100644
--- a/packages/docs-hyper-link-ui/src/menu/menu.ts
+++ b/packages/docs-hyper-link-ui/src/menu/menu.ts
@@ -16,6 +16,7 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuButtonItem, IShortcutItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';
import { whenDocAndEditorFocused } from '@univerjs/docs-ui';
@@ -23,7 +24,7 @@ import { getMenuHiddenObservable, KeyCode, MenuItemType, MetaKeys } from '@unive
import { debounceTime, Observable } from 'rxjs';
import { shouldDisableAddLink, ShowDocHyperLinkEditPopupOperation } from '../commands/operations/popup.operation';
-export function AddHyperLinkMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function AddHyperLinkMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: ShowDocHyperLinkEditPopupOperation.id,
type: MenuItemType.BUTTON,
diff --git a/packages/docs-hyper-link-ui/src/views/DocHyperLinkEdit.tsx b/packages/docs-hyper-link-ui/src/views/DocHyperLinkEdit.tsx
index b393a287cc..3e37578d09 100644
--- a/packages/docs-hyper-link-ui/src/views/DocHyperLinkEdit.tsx
+++ b/packages/docs-hyper-link-ui/src/views/DocHyperLinkEdit.tsx
@@ -15,7 +15,16 @@
*/
import type { DocumentDataModel } from '@univerjs/core';
-import { BuildTextUtils, getBodySlice, ICommandService, IUniverInstanceService, LocaleService, Tools, UniverInstanceType } from '@univerjs/core';
+import type { LocaleKey } from '../locale/types';
+import {
+ BuildTextUtils,
+ getBodySlice,
+ ICommandService,
+ IUniverInstanceService,
+ LocaleService,
+ Tools,
+ UniverInstanceType,
+} from '@univerjs/core';
import { borderClassName, Button, clsx, FormLayout, Input } from '@univerjs/design';
import { DocSelectionManagerService } from '@univerjs/docs';
import { KeyCode, useDependency, useObservable } from '@univerjs/ui';
@@ -125,8 +134,8 @@ export const DocHyperLinkEdit = () => {
{editing
? (
<FormLayout
- label={localeService.t('docs-hyper-link-ui.edit.label')}
- error={showError && isBlankInput(label) ? localeService.t('docs-hyper-link-ui.edit.labelError') : ''}
+ label={localeService.t<LocaleKey>('docs-hyper-link-ui.edit.label')}
+ error={showError && isBlankInput(label) ? localeService.t<LocaleKey>('docs-hyper-link-ui.edit.labelError') : ''}
>
<Input
value={label}
@@ -142,8 +151,8 @@ export const DocHyperLinkEdit = () => {
)
: null}
<FormLayout
- label={localeService.t('docs-hyper-link-ui.edit.address')}
- error={showError && !isLegal ? localeService.t('docs-hyper-link-ui.edit.addressError') : ''}
+ label={localeService.t<LocaleKey>('docs-hyper-link-ui.edit.address')}
+ error={showError && !isLegal ? localeService.t<LocaleKey>('docs-hyper-link-ui.edit.addressError') : ''}
>
<Input
value={link}
@@ -159,14 +168,14 @@ export const DocHyperLinkEdit = () => {
</div>
<div className="univer-flex univer-justify-end univer-gap-3">
<Button onClick={handleCancel}>
- {localeService.t('docs-hyper-link-ui.edit.cancel')}
+ {localeService.t<LocaleKey>('docs-hyper-link-ui.edit.cancel')}
</Button>
<Button
variant="primary"
disabled={isBlankInput(link)}
onClick={handleConfirm}
>
- {localeService.t('docs-hyper-link-ui.edit.confirm')}
+ {localeService.t<LocaleKey>('docs-hyper-link-ui.edit.confirm')}
</Button>
</div>
</div>
diff --git a/packages/docs-hyper-link-ui/src/views/DocLinkPopup.tsx b/packages/docs-hyper-link-ui/src/views/DocLinkPopup.tsx
index 8389d0cac2..ffbad3a712 100644
--- a/packages/docs-hyper-link-ui/src/views/DocLinkPopup.tsx
+++ b/packages/docs-hyper-link-ui/src/views/DocLinkPopup.tsx
@@ -15,7 +15,14 @@
*/
import type { DocumentDataModel } from '@univerjs/core';
-import { CustomRangeType, ICommandService, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
+import type { LocaleKey } from '../locale/types';
+import {
+ CustomRangeType,
+ ICommandService,
+ IUniverInstanceService,
+ LocaleService,
+ UniverInstanceType,
+} from '@univerjs/core';
import { borderClassName, clsx, MessageType, Tooltip } from '@univerjs/design';
import { CopyIcon, LinkIcon, UnlinkIcon, WriteIcon } from '@univerjs/icons';
import { IMessageService, useDependency, useObservable } from '@univerjs/ui';
@@ -85,12 +92,12 @@ export const DocLinkPopup = () => {
onClick={() => {
navigator.clipboard.writeText(url);
messageService.show({
- content: localeService.t('docs-hyper-link-ui.info.coped'),
+ content: localeService.t<LocaleKey>('docs-hyper-link-ui.info.coped'),
type: MessageType.Info,
});
}}
>
- <Tooltip placement="bottom" title={localeService.t('docs-hyper-link-ui.info.copy')}>
+ <Tooltip placement="bottom" title={localeService.t<LocaleKey>('docs-hyper-link-ui.info.copy')}>
<CopyIcon />
</Tooltip>
@@ -106,7 +113,7 @@ export const DocLinkPopup = () => {
});
}}
>
- <Tooltip placement="bottom" title={localeService.t('docs-hyper-link-ui.info.edit')}>
+ <Tooltip placement="bottom" title={localeService.t<LocaleKey>('docs-hyper-link-ui.info.edit')}>
<WriteIcon />
</Tooltip>
</div>
@@ -123,7 +130,7 @@ export const DocLinkPopup = () => {
});
}}
>
- <Tooltip placement="bottom" title={localeService.t('docs-hyper-link-ui.info.cancel')}>
+ <Tooltip placement="bottom" title={localeService.t<LocaleKey>('docs-hyper-link-ui.info.cancel')}>
<UnlinkIcon />
</Tooltip>
</div>
diff --git a/packages/docs-quick-insert-ui/src/locale/types.ts b/packages/docs-quick-insert-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/docs-quick-insert-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/docs-quick-insert-ui/src/views/KeywordInputPlaceholder.tsx b/packages/docs-quick-insert-ui/src/views/KeywordInputPlaceholder.tsx
index 4e6f8a4d94..2574e6f34f 100644
--- a/packages/docs-quick-insert-ui/src/views/KeywordInputPlaceholder.tsx
+++ b/packages/docs-quick-insert-ui/src/views/KeywordInputPlaceholder.tsx
@@ -15,6 +15,7 @@
*/
import type { IPopup } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { LocaleService } from '@univerjs/core';
import { ptToPixel } from '@univerjs/engine-render';
import { useDependency } from '@univerjs/ui';
@@ -53,7 +54,7 @@ function measureTextWidth(text: string, font: string) {
export const KeywordInputPlaceholder = ({ popup }: { popup: IPopup<IKeywordInputPlaceholderExtraProps> }) => {
const localeService = useDependency(LocaleService);
- const placeholder = localeService.t('docs-quick-insert-ui.keywordInputPlaceholder');
+ const placeholder = localeService.t<LocaleKey>('docs-quick-insert-ui.keywordInputPlaceholder');
const fontSize = popup.extraProps?.fontSize ?? DEFAULT_FONT_SIZE;
const fontSizePx = ptToPixel(fontSize);
const fontString = popup.extraProps?.fontString ?? `${fontSizePx}px sans-serif`;
diff --git a/packages/docs-quick-insert-ui/src/views/QuickInsertPlaceholder.tsx b/packages/docs-quick-insert-ui/src/views/QuickInsertPlaceholder.tsx
index c179fd0532..b46a926f51 100644
--- a/packages/docs-quick-insert-ui/src/views/QuickInsertPlaceholder.tsx
+++ b/packages/docs-quick-insert-ui/src/views/QuickInsertPlaceholder.tsx
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { LocaleKey } from '../locale/types';
import { LocaleService } from '@univerjs/core';
import { useDependency } from '@univerjs/ui';
@@ -28,7 +29,7 @@ export const QuickInsertPlaceholder = () => {
univer-px-12 univer-py-6 univer-text-gray-400 univer-shadow-lg
`}
>
- <span>{localeService.t('docs-quick-insert-ui.placeholder')}</span>
+ <span>{localeService.t<LocaleKey>('docs-quick-insert-ui.placeholder')}</span>
</div>
);
};
diff --git a/packages/docs-quick-insert-ui/src/views/QuickInsertPopup.tsx b/packages/docs-quick-insert-ui/src/views/QuickInsertPopup.tsx
index 821572f3ab..51493e6dd5 100644
--- a/packages/docs-quick-insert-ui/src/views/QuickInsertPopup.tsx
+++ b/packages/docs-quick-insert-ui/src/views/QuickInsertPopup.tsx
@@ -15,7 +15,15 @@
*/
import type { DocPopupMenu, IDocPopupMenuItem } from '../services/doc-quick-insert-popup.service';
-import { CommandType, Direction, DisposableCollection, generateRandomId, ICommandService, LocaleService, toDisposable } from '@univerjs/core';
+import {
+ CommandType,
+ Direction,
+ DisposableCollection,
+ generateRandomId,
+ ICommandService,
+ LocaleService,
+ toDisposable,
+} from '@univerjs/core';
import { ComponentManager, IShortcutService, KeyCode, useDependency, useObservable } from '@univerjs/ui';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { CloseQuickInsertPopupOperation } from '../commands/operations/quick-insert-popup.operation';
diff --git a/packages/docs-thread-comment-ui/src/locale/types.ts b/packages/docs-thread-comment-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/docs-thread-comment-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/docs-thread-comment-ui/src/menu/menu.ts b/packages/docs-thread-comment-ui/src/menu/menu.ts
index e4cd037336..603776a77d 100644
--- a/packages/docs-thread-comment-ui/src/menu/menu.ts
+++ b/packages/docs-thread-comment-ui/src/menu/menu.ts
@@ -16,12 +16,16 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuButtonItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { IUniverInstanceService, SHEET_EDITOR_UNITS, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService, DocSkeletonManagerService } from '@univerjs/docs';
import { DocumentEditArea, IRenderManagerService, withCurrentTypeOfRenderer } from '@univerjs/engine-render';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { debounceTime, Observable } from 'rxjs';
-import { StartAddCommentOperation, ToggleCommentPanelOperation } from '../commands/operations/show-comment-panel.operation';
+import {
+ StartAddCommentOperation,
+ ToggleCommentPanelOperation,
+} from '../commands/operations/show-comment-panel.operation';
export const shouldDisableAddComment = (accessor: IAccessor) => {
const renderManagerService = accessor.get(IRenderManagerService);
@@ -47,7 +51,7 @@ export const shouldDisableAddComment = (accessor: IAccessor) => {
return false;
};
-export function AddDocCommentMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function AddDocCommentMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: StartAddCommentOperation.id,
type: MenuItemType.BUTTON,
@@ -68,7 +72,7 @@ export function AddDocCommentMenuItemFactory(accessor: IAccessor): IMenuButtonIt
};
}
-export function ToolbarDocCommentMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ToolbarDocCommentMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: ToggleCommentPanelOperation.id,
type: MenuItemType.BUTTON,
diff --git a/packages/docs-ui/src/commands/operations/doc-create-table.operation.ts b/packages/docs-ui/src/commands/operations/doc-create-table.operation.ts
index fc3d455f16..c8ed87af56 100644
--- a/packages/docs-ui/src/commands/operations/doc-create-table.operation.ts
+++ b/packages/docs-ui/src/commands/operations/doc-create-table.operation.ts
@@ -15,6 +15,7 @@
*/
import type { IAccessor, ICommand } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import { CommandType, ICommandService, IConfirmService, LocaleService } from '@univerjs/core';
import { COMPONENT_DOC_CREATE_TABLE_CONFIRM } from '../../views/table/create/component-name';
import { CreateDocTableCommand } from '../commands/table/doc-table-create.command';
@@ -51,7 +52,7 @@ export const DocCreateTableOperation: ICommand = {
},
},
width: 'auto',
- title: { title: localeService.t('docs-ui.toolbar.table.insert') },
+ title: { title: localeService.t<LocaleKey>('docs-ui.toolbar.table.insert') },
onConfirm: () => {
commandService.executeCommand(CreateDocTableCommand.id, tableCreateParams);
confirmService.close(COMPONENT_DOC_CREATE_TABLE_CONFIRM_ID);
diff --git a/packages/docs-ui/src/commands/operations/doc-header-footer-panel.operation.ts b/packages/docs-ui/src/commands/operations/doc-header-footer-panel.operation.ts
index 70f04f817e..e15d883cf7 100644
--- a/packages/docs-ui/src/commands/operations/doc-header-footer-panel.operation.ts
+++ b/packages/docs-ui/src/commands/operations/doc-header-footer-panel.operation.ts
@@ -15,6 +15,7 @@
*/
import type { IAccessor, ICommand } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import { CommandType, LocaleService } from '@univerjs/core';
import { ISidebarService } from '@univerjs/ui';
import { COMPONENT_DOC_HEADER_FOOTER_PANEL } from '../../views/header-footer/panel/component-name';
@@ -33,7 +34,7 @@ export const SidebarDocHeaderFooterPanelOperation: ICommand = {
switch (params.value) {
case 'open':
sidebarService.open({
- header: { title: localeService.t('docs-ui.headerFooter.panel') },
+ header: { title: localeService.t<LocaleKey>('docs-ui.headerFooter.panel') },
children: { label: COMPONENT_DOC_HEADER_FOOTER_PANEL },
onClose: () => {},
width: 400,
diff --git a/packages/docs-ui/src/commands/operations/open-page-setting.operation.ts b/packages/docs-ui/src/commands/operations/open-page-setting.operation.ts
index 6fa42fc624..07c6b6c25f 100644
--- a/packages/docs-ui/src/commands/operations/open-page-setting.operation.ts
+++ b/packages/docs-ui/src/commands/operations/open-page-setting.operation.ts
@@ -16,6 +16,7 @@
import type { ICommand, ModernDocumentWidthMode, PaperType } from '@univerjs/core';
import type { IConfirmPartMethodOptions } from '@univerjs/ui';
+import type { LocaleKey } from '../../locale/types';
import type { IDocPageSetupCommandParams } from '../commands/doc-page-setup.command';
import {
CommandType,
@@ -39,7 +40,7 @@ export const DocOpenPageSettingCommand: ICommand = {
const disposable = confirmService.open({
id: PAGE_SETTING_COMPONENT_ID,
title: {
- label: localeService.t('docs-ui.page-settings.document-setting'),
+ label: localeService.t<LocaleKey>('docs-ui.page-settings.document-setting'),
},
children: {
label: PAGE_SETTING_COMPONENT_ID,
@@ -69,8 +70,8 @@ export const DocOpenPageSettingCommand: ICommand = {
pageSize: paperSize,
} as IDocPageSetupCommandParams);
},
- confirmText: localeService.t('docs-ui.page-settings.confirm'),
- cancelText: localeService.t('docs-ui.page-settings.cancel'),
+ confirmText: localeService.t<LocaleKey>('docs-ui.page-settings.confirm'),
+ cancelText: localeService.t<LocaleKey>('docs-ui.page-settings.cancel'),
});
return true;
diff --git a/packages/docs-ui/src/controllers/doc-header-footer.controller.ts b/packages/docs-ui/src/controllers/doc-header-footer.controller.ts
index 515092a10d..e8e4d84df4 100644
--- a/packages/docs-ui/src/controllers/doc-header-footer.controller.ts
+++ b/packages/docs-ui/src/controllers/doc-header-footer.controller.ts
@@ -15,7 +15,18 @@
*/
import type { DocumentDataModel, ICommandInfo, Nullable } from '@univerjs/core';
-import type { Documents, DocumentViewModel, IMouseEvent, IPageRenderConfig, IPathProps, IPointerEvent, IRenderContext, IRenderModule, RenderComponentType } from '@univerjs/engine-render';
+import type {
+ Documents,
+ DocumentViewModel,
+ IMouseEvent,
+ IPageRenderConfig,
+ IPathProps,
+ IPointerEvent,
+ IRenderContext,
+ IRenderModule,
+ RenderComponentType,
+} from '@univerjs/engine-render';
+import type { LocaleKey } from '../locale/types';
import {
BooleanNumber,
Disposable,
@@ -400,12 +411,12 @@ export class DocHeaderFooterController extends Disposable implements IRenderModu
ctx.translate(0, marginTop + 1);
TextBubbleShape.drawWith(ctx, {
- text: localeService.t('docs-ui.headerFooter.header'),
+ text: localeService.t<LocaleKey>('docs-ui.headerFooter.header'),
color: HEADER_FOOTER_FILL_COLOR,
});
ctx.translate(0, pageHeight - marginTop - marginBottom);
TextBubbleShape.drawWith(ctx, {
- text: localeService.t('docs-ui.headerFooter.footer'),
+ text: localeService.t<LocaleKey>('docs-ui.headerFooter.footer'),
color: HEADER_FOOTER_FILL_COLOR,
});
}
diff --git a/packages/docs-ui/src/controllers/render-controllers/doc-paragraph-placeholder.render-controller.ts b/packages/docs-ui/src/controllers/render-controllers/doc-paragraph-placeholder.render-controller.ts
index b3d0021eb0..3cfb9face2 100644
--- a/packages/docs-ui/src/controllers/render-controllers/doc-paragraph-placeholder.render-controller.ts
+++ b/packages/docs-ui/src/controllers/render-controllers/doc-paragraph-placeholder.render-controller.ts
@@ -27,6 +27,7 @@ import type {
UniverRenderingContext,
} from '@univerjs/engine-render';
import type { IUniverDocsUIConfig } from '../../config/config';
+import type { LocaleKey } from '../../locale/types';
import {
DataStreamTreeTokenType,
Disposable,
@@ -113,13 +114,13 @@ export class DocParagraphPlaceholderRenderController extends Disposable implemen
private _getLocale(): IParagraphPlaceholderLocale {
return {
- heading1: this._localeService.t('docs-ui.placeholder.heading1'),
- heading2: this._localeService.t('docs-ui.placeholder.heading2'),
- heading3: this._localeService.t('docs-ui.placeholder.heading3'),
- heading4: this._localeService.t('docs-ui.placeholder.heading4'),
- heading5: this._localeService.t('docs-ui.placeholder.heading5'),
- listItem: this._localeService.t('docs-ui.placeholder.listItem'),
- normalText: this._localeService.t('docs-ui.placeholder.normalText'),
+ heading1: this._localeService.t<LocaleKey>('docs-ui.placeholder.heading1'),
+ heading2: this._localeService.t<LocaleKey>('docs-ui.placeholder.heading2'),
+ heading3: this._localeService.t<LocaleKey>('docs-ui.placeholder.heading3'),
+ heading4: this._localeService.t<LocaleKey>('docs-ui.placeholder.heading4'),
+ heading5: this._localeService.t<LocaleKey>('docs-ui.placeholder.heading5'),
+ listItem: this._localeService.t<LocaleKey>('docs-ui.placeholder.listItem'),
+ normalText: this._localeService.t<LocaleKey>('docs-ui.placeholder.normalText'),
};
}
}
diff --git a/packages/docs-ui/src/locale/ar-SA.ts b/packages/docs-ui/src/locale/ar-SA.ts
index 75438d1c9d..fe78c1d67b 100644
--- a/packages/docs-ui/src/locale/ar-SA.ts
+++ b/packages/docs-ui/src/locale/ar-SA.ts
@@ -53,6 +53,17 @@ const locale: typeof enUS = {
horizontalLine: 'خط أفقي',
headerFooter: 'رأس وتذييل',
pageSetup: 'إعداد الصفحة',
+ heading: {
+ tooltip: 'Heading',
+ normal: 'Normal text',
+ leading1: 'Heading 1',
+ leading2: 'Heading 2',
+ leading3: 'Heading 3',
+ leading4: 'Heading 4',
+ leading5: 'Heading 5',
+ title: 'Title',
+ subTitle: 'Subtitle',
+ },
},
table: {
insert: 'إدراج',
diff --git a/packages/docs-ui/src/locale/ca-ES.ts b/packages/docs-ui/src/locale/ca-ES.ts
index 8ce62a0d84..8520eff5f1 100644
--- a/packages/docs-ui/src/locale/ca-ES.ts
+++ b/packages/docs-ui/src/locale/ca-ES.ts
@@ -53,6 +53,17 @@ const locale: typeof enUS = {
horizontalLine: 'Línia horitzontal',
headerFooter: 'Capçalera i peu de pàgina',
pageSetup: 'Configuració de pàgina',
+ heading: {
+ tooltip: 'Heading',
+ normal: 'Normal text',
+ leading1: 'Heading 1',
+ leading2: 'Heading 2',
+ leading3: 'Heading 3',
+ leading4: 'Heading 4',
+ leading5: 'Heading 5',
+ title: 'Title',
+ subTitle: 'Subtitle',
+ },
},
table: {
insert: 'Insereix',
diff --git a/packages/docs-ui/src/locale/de-DE.ts b/packages/docs-ui/src/locale/de-DE.ts
index b2c7fc7d8d..d830816cb2 100644
--- a/packages/docs-ui/src/locale/de-DE.ts
+++ b/packages/docs-ui/src/locale/de-DE.ts
@@ -53,6 +53,17 @@ const locale: typeof enUS = {
horizontalLine: 'Horizontale Linie',
headerFooter: 'Kopf- und Fußzeile',
pageSetup: 'Seite einrichten',
+ heading: {
+ tooltip: 'Heading',
+ normal: 'Normal text',
+ leading1: 'Heading 1',
+ leading2: 'Heading 2',
+ leading3: 'Heading 3',
+ leading4: 'Heading 4',
+ leading5: 'Heading 5',
+ title: 'Title',
+ subTitle: 'Subtitle',
+ },
},
table: {
insert: 'Einfügen',
diff --git a/packages/docs-ui/src/locale/en-US.ts b/packages/docs-ui/src/locale/en-US.ts
index aa3b31419b..eaa46e11ec 100644
--- a/packages/docs-ui/src/locale/en-US.ts
+++ b/packages/docs-ui/src/locale/en-US.ts
@@ -51,6 +51,17 @@ const locale = {
horizontalLine: 'Horizontal line',
headerFooter: 'Header & Footer',
pageSetup: 'Page Setup',
+ heading: {
+ tooltip: 'Heading',
+ normal: 'Normal text',
+ leading1: 'Heading 1',
+ leading2: 'Heading 2',
+ leading3: 'Heading 3',
+ leading4: 'Heading 4',
+ leading5: 'Heading 5',
+ title: 'Title',
+ subTitle: 'Subtitle',
+ },
},
table: {
insert: 'Insert',
diff --git a/packages/docs-ui/src/locale/es-ES.ts b/packages/docs-ui/src/locale/es-ES.ts
index d6025c3bb0..7b07d4c40d 100644
--- a/packages/docs-ui/src/locale/es-ES.ts
+++ b/packages/docs-ui/src/locale/es-ES.ts
@@ -53,6 +53,17 @@ const locale: typeof enUS = {
horizontalLine: 'Línea horizontal',
headerFooter: 'Encabezado y pie de página',
pageSetup: 'Configuración de página',
+ heading: {
+ tooltip: 'Heading',
+ normal: 'Normal text',
+ leading1: 'Heading 1',
+ leading2: 'Heading 2',
+ leading3: 'Heading 3',
+ leading4: 'Heading 4',
+ leading5: 'Heading 5',
+ title: 'Title',
+ subTitle: 'Subtitle',
+ },
},
table: {
insert: 'Insertar',
diff --git a/packages/docs-ui/src/locale/fa-IR.ts b/packages/docs-ui/src/locale/fa-IR.ts
index d0ed062f89..3d32adc5c9 100644
--- a/packages/docs-ui/src/locale/fa-IR.ts
+++ b/packages/docs-ui/src/locale/fa-IR.ts
@@ -53,6 +53,17 @@ const locale: typeof enUS = {
horizontalLine: 'Horizontal line',
headerFooter: 'هدر و فوتر',
pageSetup: 'تنظیمات صفحه',
+ heading: {
+ tooltip: 'Heading',
+ normal: 'Normal text',
+ leading1: 'Heading 1',
+ leading2: 'Heading 2',
+ leading3: 'Heading 3',
+ leading4: 'Heading 4',
+ leading5: 'Heading 5',
+ title: 'Title',
+ subTitle: 'Subtitle',
+ },
},
table: {
insert: 'درج',
diff --git a/packages/docs-ui/src/locale/fr-FR.ts b/packages/docs-ui/src/locale/fr-FR.ts
index 886dee3bf8..00e9e88692 100644
--- a/packages/docs-ui/src/locale/fr-FR.ts
+++ b/packages/docs-ui/src/locale/fr-FR.ts
@@ -53,6 +53,17 @@ const locale: typeof enUS = {
horizontalLine: 'Horizontal line',
headerFooter: 'En-tête et pied de page',
pageSetup: 'Paramètres de page',
+ heading: {
+ tooltip: 'Heading',
+ normal: 'Normal text',
+ leading1: 'Heading 1',
+ leading2: 'Heading 2',
+ leading3: 'Heading 3',
+ leading4: 'Heading 4',
+ leading5: 'Heading 5',
+ title: 'Title',
+ subTitle: 'Subtitle',
+ },
},
table: {
insert: 'Insérer',
diff --git a/packages/docs-ui/src/locale/id-ID.ts b/packages/docs-ui/src/locale/id-ID.ts
index 9e434c7c34..ef273c24ff 100644
--- a/packages/docs-ui/src/locale/id-ID.ts
+++ b/packages/docs-ui/src/locale/id-ID.ts
@@ -53,6 +53,17 @@ const locale: typeof enUS = {
horizontalLine: 'Garis horizontal',
headerFooter: 'Header & Footer',
pageSetup: 'Pengaturan Halaman',
+ heading: {
+ tooltip: 'Heading',
+ normal: 'Normal text',
+ leading1: 'Heading 1',
+ leading2: 'Heading 2',
+ leading3: 'Heading 3',
+ leading4: 'Heading 4',
+ leading5: 'Heading 5',
+ title: 'Title',
+ subTitle: 'Subtitle',
+ },
},
table: {
insert: 'Sisipkan',
diff --git a/packages/docs-ui/src/locale/it-IT.ts b/packages/docs-ui/src/locale/it-IT.ts
index c32ad179e9..93e1526078 100644
--- a/packages/docs-ui/src/locale/it-IT.ts
+++ b/packages/docs-ui/src/locale/it-IT.ts
@@ -53,6 +53,17 @@ const locale: typeof enUS = {
horizontalLine: 'Linea orizzontale',
headerFooter: 'Intestazione e Piè di Pagina',
pageSetup: 'Impostazione Pagina',
+ heading: {
+ tooltip: 'Heading',
+ normal: 'Normal text',
+ leading1: 'Heading 1',
+ leading2: 'Heading 2',
+ leading3: 'Heading 3',
+ leading4: 'Heading 4',
+ leading5: 'Heading 5',
+ title: 'Title',
+ subTitle: 'Subtitle',
+ },
},
table: {
insert: 'Inserisci',
diff --git a/packages/docs-ui/src/locale/ja-JP.ts b/packages/docs-ui/src/locale/ja-JP.ts
index 4b38cfe025..601d68a564 100644
--- a/packages/docs-ui/src/locale/ja-JP.ts
+++ b/packages/docs-ui/src/locale/ja-JP.ts
@@ -53,6 +53,17 @@ const locale: typeof enUS = {
horizontalLine: '横線の挿入',
headerFooter: 'ヘッダーとフッター',
pageSetup: 'ページ設定',
+ heading: {
+ tooltip: 'Heading',
+ normal: 'Normal text',
+ leading1: 'Heading 1',
+ leading2: 'Heading 2',
+ leading3: 'Heading 3',
+ leading4: 'Heading 4',
+ leading5: 'Heading 5',
+ title: 'Title',
+ subTitle: 'Subtitle',
+ },
},
table: {
insert: '挿入',
diff --git a/packages/docs-ui/src/locale/ko-KR.ts b/packages/docs-ui/src/locale/ko-KR.ts
index 2b17b92fba..52040da111 100644
--- a/packages/docs-ui/src/locale/ko-KR.ts
+++ b/packages/docs-ui/src/locale/ko-KR.ts
@@ -53,6 +53,17 @@ const locale: typeof enUS = {
horizontalLine: '가로줄 삽입',
headerFooter: '머리글 및 바닥글',
pageSetup: '페이지 설정',
+ heading: {
+ tooltip: 'Heading',
+ normal: 'Normal text',
+ leading1: 'Heading 1',
+ leading2: 'Heading 2',
+ leading3: 'Heading 3',
+ leading4: 'Heading 4',
+ leading5: 'Heading 5',
+ title: 'Title',
+ subTitle: 'Subtitle',
+ },
},
table: {
insert: '삽입',
diff --git a/packages/docs-ui/src/locale/pl-PL.ts b/packages/docs-ui/src/locale/pl-PL.ts
index 8d876f496a..5ff9b44ddd 100644
--- a/packages/docs-ui/src/locale/pl-PL.ts
+++ b/packages/docs-ui/src/locale/pl-PL.ts
@@ -53,6 +53,17 @@ const locale: typeof enUS = {
horizontalLine: 'Linia pozioma',
headerFooter: 'Nagłówek i stopka',
pageSetup: 'Ustawienia strony',
+ heading: {
+ tooltip: 'Heading',
+ normal: 'Normal text',
+ leading1: 'Heading 1',
+ leading2: 'Heading 2',
+ leading3: 'Heading 3',
+ leading4: 'Heading 4',
+ leading5: 'Heading 5',
+ title: 'Title',
+ subTitle: 'Subtitle',
+ },
},
table: {
insert: 'Wstaw',
diff --git a/packages/docs-ui/src/locale/pt-BR.ts b/packages/docs-ui/src/locale/pt-BR.ts
index cf5bef88e3..5dfcc22870 100644
--- a/packages/docs-ui/src/locale/pt-BR.ts
+++ b/packages/docs-ui/src/locale/pt-BR.ts
@@ -53,6 +53,17 @@ const locale: typeof enUS = {
horizontalLine: 'Linha horizontal',
headerFooter: 'Cabeçalho e rodapé',
pageSetup: 'Configurar página',
+ heading: {
+ tooltip: 'Heading',
+ normal: 'Normal text',
+ leading1: 'Heading 1',
+ leading2: 'Heading 2',
+ leading3: 'Heading 3',
+ leading4: 'Heading 4',
+ leading5: 'Heading 5',
+ title: 'Title',
+ subTitle: 'Subtitle',
+ },
},
table: {
insert: 'Inserir',
diff --git a/packages/docs-ui/src/locale/ru-RU.ts b/packages/docs-ui/src/locale/ru-RU.ts
index 6e3389d495..1d4506f5d2 100644
--- a/packages/docs-ui/src/locale/ru-RU.ts
+++ b/packages/docs-ui/src/locale/ru-RU.ts
@@ -53,6 +53,17 @@ const locale: typeof enUS = {
horizontalLine: 'Горизонтальная линия',
headerFooter: 'Верхние и нижние колонтитулы',
pageSetup: 'Настройки страницы',
+ heading: {
+ tooltip: 'Heading',
+ normal: 'Normal text',
+ leading1: 'Heading 1',
+ leading2: 'Heading 2',
+ leading3: 'Heading 3',
+ leading4: 'Heading 4',
+ leading5: 'Heading 5',
+ title: 'Title',
+ subTitle: 'Subtitle',
+ },
},
table: {
insert: 'Вставить',
diff --git a/packages/docs-ui/src/locale/sk-SK.ts b/packages/docs-ui/src/locale/sk-SK.ts
index 618e009d33..f0ba504e22 100644
--- a/packages/docs-ui/src/locale/sk-SK.ts
+++ b/packages/docs-ui/src/locale/sk-SK.ts
@@ -53,6 +53,17 @@ const locale: typeof enUS = {
horizontalLine: 'Vodorovná čiara',
headerFooter: 'Hlavička a päta',
pageSetup: 'Nastavenie stránky',
+ heading: {
+ tooltip: 'Heading',
+ normal: 'Normal text',
+ leading1: 'Heading 1',
+ leading2: 'Heading 2',
+ leading3: 'Heading 3',
+ leading4: 'Heading 4',
+ leading5: 'Heading 5',
+ title: 'Title',
+ subTitle: 'Subtitle',
+ },
},
table: {
insert: 'Vložiť',
diff --git a/packages/docs-ui/src/locale/types.ts b/packages/docs-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/docs-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/docs-ui/src/locale/vi-VN.ts b/packages/docs-ui/src/locale/vi-VN.ts
index 7fe3db85ac..cf0dbd0fd9 100644
--- a/packages/docs-ui/src/locale/vi-VN.ts
+++ b/packages/docs-ui/src/locale/vi-VN.ts
@@ -53,6 +53,17 @@ const locale: typeof enUS = {
horizontalLine: 'Horizontal line',
headerFooter: 'Đầu trang và chân trang',
pageSetup: 'Cài đặt trang',
+ heading: {
+ tooltip: 'Heading',
+ normal: 'Normal text',
+ leading1: 'Heading 1',
+ leading2: 'Heading 2',
+ leading3: 'Heading 3',
+ leading4: 'Heading 4',
+ leading5: 'Heading 5',
+ title: 'Title',
+ subTitle: 'Subtitle',
+ },
},
table: {
insert: 'Chèn',
diff --git a/packages/docs-ui/src/locale/zh-CN.ts b/packages/docs-ui/src/locale/zh-CN.ts
index 218b241d36..9329201f28 100644
--- a/packages/docs-ui/src/locale/zh-CN.ts
+++ b/packages/docs-ui/src/locale/zh-CN.ts
@@ -53,6 +53,17 @@ const locale: typeof enUS = {
horizontalLine: '水平分割线',
headerFooter: '页眉页脚',
pageSetup: '页面设置',
+ heading: {
+ tooltip: '标题',
+ normal: '普通文本',
+ leading1: '标题1',
+ leading2: '标题2',
+ leading3: '标题3',
+ leading4: '标题4',
+ leading5: '标题5',
+ title: '标题',
+ subTitle: '副标题',
+ },
},
table: {
insert: '插入',
diff --git a/packages/docs-ui/src/locale/zh-HK.ts b/packages/docs-ui/src/locale/zh-HK.ts
index 6fa0728e65..83e11db6f1 100644
--- a/packages/docs-ui/src/locale/zh-HK.ts
+++ b/packages/docs-ui/src/locale/zh-HK.ts
@@ -53,6 +53,17 @@ const locale: typeof enUS = {
horizontalLine: 'Horizontal line',
headerFooter: '頁眉頁腳',
pageSetup: '頁面設置',
+ heading: {
+ tooltip: 'Heading',
+ normal: 'Normal text',
+ leading1: 'Heading 1',
+ leading2: 'Heading 2',
+ leading3: 'Heading 3',
+ leading4: 'Heading 4',
+ leading5: 'Heading 5',
+ title: 'Title',
+ subTitle: 'Subtitle',
+ },
},
table: {
insert: 'Insert',
diff --git a/packages/docs-ui/src/locale/zh-TW.ts b/packages/docs-ui/src/locale/zh-TW.ts
index 54fce0ce61..36bc433751 100644
--- a/packages/docs-ui/src/locale/zh-TW.ts
+++ b/packages/docs-ui/src/locale/zh-TW.ts
@@ -53,6 +53,17 @@ const locale: typeof enUS = {
horizontalLine: 'Horizontal line',
headerFooter: '頁眉頁腳',
pageSetup: '頁面設置',
+ heading: {
+ tooltip: '標題',
+ normal: '普通文字',
+ leading1: '標題1',
+ leading2: '標題2',
+ leading3: '標題3',
+ leading4: '標題4',
+ leading5: '標題5',
+ title: '標題',
+ subTitle: '副標題',
+ },
},
table: {
insert: '插入',
diff --git a/packages/docs-ui/src/menu/context-menu.ts b/packages/docs-ui/src/menu/context-menu.ts
index 9220a00364..45b6eee378 100644
--- a/packages/docs-ui/src/menu/context-menu.ts
+++ b/packages/docs-ui/src/menu/context-menu.ts
@@ -18,14 +18,24 @@ import type { IAccessor } from '@univerjs/core';
import type { IRectRangeWithStyle } from '@univerjs/engine-render';
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
import type { Subscriber } from 'rxjs';
+import type { LocaleKey } from '../locale/types';
import { DOC_RANGE_TYPE, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { combineLatest, Observable } from 'rxjs';
import { DocCopyCommand, DocCutCommand, DocPasteCommand } from '../commands/commands/clipboard.command';
import { DeleteLeftCommand } from '../commands/commands/doc-delete.command';
-import { DocTableDeleteColumnsCommand, DocTableDeleteRowsCommand, DocTableDeleteTableCommand } from '../commands/commands/table/doc-table-delete.command';
-import { DocTableInsertColumnLeftCommand, DocTableInsertColumnRightCommand, DocTableInsertRowAboveCommand, DocTableInsertRowBellowCommand } from '../commands/commands/table/doc-table-insert.command';
+import {
+ DocTableDeleteColumnsCommand,
+ DocTableDeleteRowsCommand,
+ DocTableDeleteTableCommand,
+} from '../commands/commands/table/doc-table-delete.command';
+import {
+ DocTableInsertColumnLeftCommand,
+ DocTableInsertColumnRightCommand,
+ DocTableInsertRowAboveCommand,
+ DocTableInsertRowBellowCommand,
+} from '../commands/commands/table/doc-table-insert.command';
import { DocParagraphSettingPanelOperation } from '../commands/operations/doc-paragraph-setting-panel.operation';
const getDisableOnCollapsedObservable = (accessor: IAccessor) => {
@@ -96,7 +106,7 @@ const getDisableWhenSelectionNotInTableObservable = (accessor: IAccessor) => {
});
};
-export const CopyMenuFactory = (accessor: IAccessor): IMenuButtonItem => {
+export function CopyMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DocCopyCommand.name,
commandId: DocCopyCommand.id,
@@ -108,7 +118,7 @@ export const CopyMenuFactory = (accessor: IAccessor): IMenuButtonItem => {
};
};
-export const ParagraphSettingMenuFactory = (accessor: IAccessor): IMenuButtonItem => {
+export function ParagraphSettingMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DocParagraphSettingPanelOperation.id,
type: MenuItemType.BUTTON,
@@ -118,7 +128,7 @@ export const ParagraphSettingMenuFactory = (accessor: IAccessor): IMenuButtonIte
};
};
-export const CutMenuFactory = (accessor: IAccessor): IMenuButtonItem => {
+export function CutMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DocCutCommand.id,
type: MenuItemType.BUTTON,
@@ -129,7 +139,7 @@ export const CutMenuFactory = (accessor: IAccessor): IMenuButtonItem => {
};
};
-export const PasteMenuFactory = (accessor: IAccessor): IMenuButtonItem => {
+export function PasteMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DocPasteCommand.id,
type: MenuItemType.BUTTON,
@@ -139,7 +149,7 @@ export const PasteMenuFactory = (accessor: IAccessor): IMenuButtonItem => {
};
};
-export const DeleteMenuFactory = (accessor: IAccessor): IMenuButtonItem => {
+export function DeleteMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DeleteLeftCommand.id,
type: MenuItemType.BUTTON,
@@ -151,7 +161,7 @@ export const DeleteMenuFactory = (accessor: IAccessor): IMenuButtonItem => {
};
export const TABLE_INSERT_MENU_ID = 'doc.menu.table-insert';
-export function TableInsertMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function TableInsertMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: TABLE_INSERT_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -163,7 +173,7 @@ export function TableInsertMenuItemFactory(accessor: IAccessor): IMenuSelectorIt
};
}
-export function InsertRowBeforeMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function InsertRowBeforeMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DocTableInsertRowAboveCommand.id,
type: MenuItemType.BUTTON,
@@ -174,7 +184,7 @@ export function InsertRowBeforeMenuItemFactory(accessor: IAccessor): IMenuButton
};
}
-export function InsertRowAfterMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function InsertRowAfterMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DocTableInsertRowBellowCommand.id,
type: MenuItemType.BUTTON,
@@ -185,7 +195,7 @@ export function InsertRowAfterMenuItemFactory(accessor: IAccessor): IMenuButtonI
};
}
-export function InsertColumnLeftMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function InsertColumnLeftMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DocTableInsertColumnLeftCommand.id,
type: MenuItemType.BUTTON,
@@ -196,7 +206,7 @@ export function InsertColumnLeftMenuItemFactory(accessor: IAccessor): IMenuButto
};
}
-export function InsertColumnRightMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function InsertColumnRightMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DocTableInsertColumnRightCommand.id,
type: MenuItemType.BUTTON,
@@ -208,7 +218,7 @@ export function InsertColumnRightMenuItemFactory(accessor: IAccessor): IMenuButt
}
export const TABLE_DELETE_MENU_ID = 'doc.menu.table-delete';
-export function TableDeleteMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function TableDeleteMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: TABLE_DELETE_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -220,7 +230,7 @@ export function TableDeleteMenuItemFactory(accessor: IAccessor): IMenuSelectorIt
};
}
-export function DeleteRowsMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function DeleteRowsMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DocTableDeleteRowsCommand.id,
type: MenuItemType.BUTTON,
@@ -231,7 +241,7 @@ export function DeleteRowsMenuItemFactory(accessor: IAccessor): IMenuButtonItem
};
}
-export function DeleteColumnsMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function DeleteColumnsMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DocTableDeleteColumnsCommand.id,
type: MenuItemType.BUTTON,
@@ -242,7 +252,7 @@ export function DeleteColumnsMenuItemFactory(accessor: IAccessor): IMenuButtonIt
};
}
-export function DeleteTableMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function DeleteTableMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DocTableDeleteTableCommand.id,
type: MenuItemType.BUTTON,
diff --git a/packages/docs-ui/src/menu/menu.ts b/packages/docs-ui/src/menu/menu.ts
index 4ab3123c57..0827f08abb 100644
--- a/packages/docs-ui/src/menu/menu.ts
+++ b/packages/docs-ui/src/menu/menu.ts
@@ -17,6 +17,7 @@
import type { DocumentDataModel, IAccessor, ITextRangeParam, Nullable } from '@univerjs/core';
import type { IRichTextEditingMutationParams } from '@univerjs/docs';
import type { IMenuButtonItem, IMenuItem, IMenuSelectorItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import {
BaselineOffset,
BooleanNumber,
@@ -302,14 +303,14 @@ export function hideMenuWhenSelectionInBlockRange(accessor: IAccessor): Observab
});
}
-export function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const commandService = accessor.get(ICommandService);
return {
id: SetInlineFormatBoldCommand.id,
type: MenuItemType.BUTTON,
icon: 'BoldIcon',
- title: 'Set bold',
+ title: 'docs-ui.toolbar.bold',
tooltip: 'docs-ui.toolbar.bold',
activated$: new Observable<boolean>((subscriber) => {
const calc = () => {
@@ -341,14 +342,14 @@ export function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
};
}
-export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const commandService = accessor.get(ICommandService);
return {
id: SetInlineFormatItalicCommand.id,
type: MenuItemType.BUTTON,
icon: 'ItalicIcon',
- title: 'Set italic',
+ title: 'docs-ui.toolbar.italic',
tooltip: 'docs-ui.toolbar.italic',
activated$: new Observable<boolean>((subscriber) => {
const calc = () => {
@@ -380,14 +381,14 @@ export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
};
}
-export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const commandService = accessor.get(ICommandService);
return {
id: SetInlineFormatUnderlineCommand.id,
type: MenuItemType.BUTTON,
icon: 'UnderlineIcon',
- title: 'Set underline',
+ title: 'docs-ui.toolbar.underline',
tooltip: 'docs-ui.toolbar.underline',
activated$: new Observable<boolean>((subscriber) => {
const calc = () => {
@@ -419,14 +420,14 @@ export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
};
}
-export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const commandService = accessor.get(ICommandService);
return {
id: SetInlineFormatStrikethroughCommand.id,
type: MenuItemType.BUTTON,
icon: 'StrikethroughIcon',
- title: 'Set strike through',
+ title: 'docs-ui.toolbar.strikethrough',
tooltip: 'docs-ui.toolbar.strikethrough',
activated$: new Observable<boolean>((subscriber) => {
const calc = () => {
@@ -458,7 +459,7 @@ export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonIt
};
}
-export function SubscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function SubscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const commandService = accessor.get(ICommandService);
return {
@@ -496,7 +497,7 @@ export function SubscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
};
}
-export function SuperscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function SuperscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const commandService = accessor.get(ICommandService);
return {
@@ -534,7 +535,7 @@ export function SuperscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem
};
}
-export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey, string, string> {
const commandService = accessor.get(ICommandService);
return {
@@ -589,7 +590,7 @@ export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSel
};
}
-export function FontSizeSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<number> {
+export function FontSizeSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey, number> {
const commandService = accessor.get(ICommandService);
return {
@@ -635,13 +636,13 @@ export function FontSizeSelectorMenuItemFactory(accessor: IAccessor): IMenuSelec
};
}
-export function HeadingSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<number> {
+export function HeadingSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey, NamedStyleType> {
const commandService = accessor.get(ICommandService);
return {
id: SetParagraphNamedStyleCommand.id,
type: MenuItemType.SELECTOR,
- tooltip: 'ui.toolbar.heading.tooltip',
+ tooltip: 'docs-ui.toolbar.heading.tooltip',
label: {
name: COMMON_LABEL_COMPONENT,
props: {
@@ -694,32 +695,32 @@ export const FLOAT_TOOLBAR_MENU_POSITION = 'doc.menu.float-toolbar';
const FLOAT_TEXT_STYLE_OPTIONS = [
{
icon: 'TextTypeIcon',
- label: 'ui.toolbar.heading.normal',
+ label: 'docs-ui.toolbar.heading.normal',
value: NamedStyleType.NORMAL_TEXT,
},
{
icon: 'H1Icon',
- label: 'ui.toolbar.heading.1',
+ label: 'docs-ui.toolbar.heading.leading1',
value: NamedStyleType.HEADING_1,
},
{
icon: 'H2Icon',
- label: 'ui.toolbar.heading.2',
+ label: 'docs-ui.toolbar.heading.leading2',
value: NamedStyleType.HEADING_2,
},
{
icon: 'H3Icon',
- label: 'ui.toolbar.heading.3',
+ label: 'docs-ui.toolbar.heading.leading3',
value: NamedStyleType.HEADING_3,
},
{
icon: 'H4Icon',
- label: 'ui.toolbar.heading.4',
+ label: 'docs-ui.toolbar.heading.leading4',
value: NamedStyleType.HEADING_4,
},
{
icon: 'H5Icon',
- label: 'ui.toolbar.heading.5',
+ label: 'docs-ui.toolbar.heading.leading5',
value: NamedStyleType.HEADING_5,
},
{
@@ -760,7 +761,7 @@ function normalizeFloatingTextStyleValue(paragraph: ReturnType<typeof getParagra
return paragraph?.paragraphStyle?.namedStyleType ?? NamedStyleType.NORMAL_TEXT;
}
-export function FloatTextStyleMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string | number> {
+export function FloatTextStyleMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey, string | number> {
const commandService = accessor.get(ICommandService);
return {
@@ -768,7 +769,7 @@ export function FloatTextStyleMenuItemFactory(accessor: IAccessor): IMenuSelecto
commandId: SetParagraphNamedStyleCommand.id,
type: MenuItemType.SELECTOR,
icon: 'TextTypeIcon',
- tooltip: 'ui.toolbar.heading.tooltip',
+ tooltip: 'docs-ui.toolbar.heading.tooltip',
selections: FLOAT_TEXT_STYLE_OPTIONS,
value$: new Observable((subscriber) => {
const calc = () => {
@@ -797,7 +798,7 @@ export function FloatTextStyleMenuItemFactory(accessor: IAccessor): IMenuSelecto
};
}
-export function TextColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string, string | undefined> {
+export function TextColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey, string, string | undefined> {
const commandService = accessor.get(ICommandService);
const themeService = accessor.get(ThemeService);
@@ -858,7 +859,7 @@ export function TextColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSele
};
}
-export function HeaderFooterMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function HeaderFooterMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: OpenHeaderFooterPanelCommand.id,
type: MenuItemType.BUTTON,
@@ -873,7 +874,7 @@ export function HeaderFooterMenuItemFactory(accessor: IAccessor): IMenuButtonIte
export const TableIcon = 'GridIcon';
export const TABLE_MENU_ID = 'doc.menu.table';
-export function TableMenuFactory(accessor: IAccessor): IMenuItem {
+export function TableMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: TABLE_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -886,7 +887,7 @@ export function TableMenuFactory(accessor: IAccessor): IMenuItem {
};
}
-export function InsertTableMenuFactory(_accessor: IAccessor): IMenuButtonItem {
+export function InsertTableMenuFactory(_accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DocCreateTableOperation.id,
title: 'docs-ui.toolbar.table.insert',
@@ -896,7 +897,7 @@ export function InsertTableMenuFactory(_accessor: IAccessor): IMenuButtonItem {
};
}
-export function InsertDefaultTableMenuFactory(_accessor: IAccessor): IMenuButtonItem {
+export function InsertDefaultTableMenuFactory(_accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DocCreateTableOperation.id,
commandId: CreateDocTableCommand.id,
@@ -911,7 +912,7 @@ export function InsertDefaultTableMenuFactory(_accessor: IAccessor): IMenuButton
};
}
-export function AlignLeftMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function AlignLeftMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const commandService = accessor.get(ICommandService);
return {
@@ -945,7 +946,7 @@ export function AlignLeftMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
};
}
-export function AlignCenterMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function AlignCenterMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const commandService = accessor.get(ICommandService);
return {
@@ -979,7 +980,7 @@ export function AlignCenterMenuItemFactory(accessor: IAccessor): IMenuButtonItem
};
}
-export function AlignRightMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function AlignRightMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const commandService = accessor.get(ICommandService);
return {
@@ -1013,7 +1014,7 @@ export function AlignRightMenuItemFactory(accessor: IAccessor): IMenuButtonItem
};
}
-export function AlignJustifyMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function AlignJustifyMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const commandService = accessor.get(ICommandService);
return {
@@ -1074,7 +1075,7 @@ const HORIZONTAL_ALIGN_OPTIONS = [
},
];
-export function AlignMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<HorizontalAlign, HorizontalAlign> {
+export function AlignMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey, HorizontalAlign, HorizontalAlign> {
const commandService = accessor.get(ICommandService);
const value$ = new Observable<HorizontalAlign>((subscriber) => {
@@ -1105,7 +1106,7 @@ export function AlignMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<Hor
};
}
-export function HorizontalLineFactory(accessor: IAccessor): IMenuButtonItem {
+export function HorizontalLineFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: HorizontalLineCommand.id,
type: MenuItemType.BUTTON,
@@ -1158,7 +1159,7 @@ const listValueFactory$ = (accessor: IAccessor) => {
});
};
-export function OrderListMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<PresetListType, PresetListType | undefined> {
+export function OrderListMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey, PresetListType | undefined, PresetListType | undefined> {
return {
id: OrderListCommand.id,
type: MenuItemType.BUTTON_SELECTOR,
@@ -1181,7 +1182,7 @@ export function OrderListMenuItemFactory(accessor: IAccessor): IMenuSelectorItem
};
}
-export function BulletListMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<PresetListType, PresetListType | undefined> {
+export function BulletListMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey, PresetListType | undefined, PresetListType | undefined> {
return {
id: BulletListCommand.id,
type: MenuItemType.BUTTON_SELECTOR,
@@ -1204,7 +1205,7 @@ export function BulletListMenuItemFactory(accessor: IAccessor): IMenuSelectorIte
};
}
-export function CheckListMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function CheckListMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: CheckListCommand.id,
type: MenuItemType.BUTTON,
@@ -1216,7 +1217,7 @@ export function CheckListMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
};
}
-export function DocSwitchModeMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function DocSwitchModeMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const commandService = accessor.get(ICommandService);
const univerInstanceService = accessor.get(IUniverInstanceService);
@@ -1244,7 +1245,7 @@ export function DocSwitchModeMenuItemFactory(accessor: IAccessor): IMenuButtonIt
};
}
-export function ResetTextColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ResetTextColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: ResetInlineFormatTextColorCommand.id,
type: MenuItemType.BUTTON,
@@ -1253,7 +1254,7 @@ export function ResetTextColorMenuItemFactory(accessor: IAccessor): IMenuButtonI
};
}
-export function ResetBackgroundColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ResetBackgroundColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: ResetInlineFormatTextBackgroundColorCommand.id,
type: MenuItemType.BUTTON,
@@ -1262,7 +1263,7 @@ export function ResetBackgroundColorMenuItemFactory(accessor: IAccessor): IMenuB
};
}
-export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string, string | undefined> {
+export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey, string, string | undefined> {
const commandService = accessor.get(ICommandService);
const themeService = accessor.get(ThemeService);
@@ -1405,7 +1406,7 @@ export function getParagraphStyleAtCursor(accessor: IAccessor) {
return null;
}
-export function PageSettingMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function PageSettingMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DocOpenPageSettingCommand.id,
type: MenuItemType.BUTTON,
diff --git a/packages/docs-ui/src/menu/paragraph-menu.ts b/packages/docs-ui/src/menu/paragraph-menu.ts
index ea8c724205..ef627280da 100644
--- a/packages/docs-ui/src/menu/paragraph-menu.ts
+++ b/packages/docs-ui/src/menu/paragraph-menu.ts
@@ -16,6 +16,7 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuButtonItem, IMenuItem, IMenuSelectorItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { ICommandService, NamedStyleType, ThemeService, UniverInstanceType } from '@univerjs/core';
import { SetTextSelectionsOperation } from '@univerjs/docs';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
@@ -125,104 +126,104 @@ function getHeadingActivatedObservable(accessor: IAccessor, headingType: NamedSt
});
}
-export function H1HeadingMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function H1HeadingMenuItemFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: H1HeadingCommand.id,
type: MenuItemType.BUTTON,
icon: 'H1Icon',
- title: 'ui.toolbar.heading.1',
- tooltip: 'ui.toolbar.heading.1',
+ title: 'docs-ui.toolbar.heading.leading1',
+ tooltip: 'docs-ui.toolbar.heading.leading1',
disabled$: disableMenuWhenNoDocRange(accessor),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
activated$: getHeadingActivatedObservable(accessor, NamedStyleType.HEADING_1),
};
}
-export function H2HeadingMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function H2HeadingMenuItemFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: H2HeadingCommand.id,
type: MenuItemType.BUTTON,
icon: 'H2Icon',
- title: 'ui.toolbar.heading.2',
- tooltip: 'ui.toolbar.heading.2',
+ title: 'docs-ui.toolbar.heading.leading2',
+ tooltip: 'docs-ui.toolbar.heading.leading2',
disabled$: disableMenuWhenNoDocRange(accessor),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
activated$: getHeadingActivatedObservable(accessor, NamedStyleType.HEADING_2),
};
}
-export function H3HeadingMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function H3HeadingMenuItemFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: H3HeadingCommand.id,
type: MenuItemType.BUTTON,
icon: 'H3Icon',
- title: 'ui.toolbar.heading.3',
- tooltip: 'ui.toolbar.heading.3',
+ title: 'docs-ui.toolbar.heading.leading3',
+ tooltip: 'docs-ui.toolbar.heading.leading3',
disabled$: disableMenuWhenNoDocRange(accessor),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
activated$: getHeadingActivatedObservable(accessor, NamedStyleType.HEADING_3),
};
}
-export function H4HeadingMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function H4HeadingMenuItemFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: H4HeadingCommand.id,
type: MenuItemType.BUTTON,
icon: 'H4Icon',
- title: 'ui.toolbar.heading.4',
- tooltip: 'ui.toolbar.heading.4',
+ title: 'docs-ui.toolbar.heading.leading4',
+ tooltip: 'docs-ui.toolbar.heading.leading4',
disabled$: disableMenuWhenNoDocRange(accessor),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
activated$: getHeadingActivatedObservable(accessor, NamedStyleType.HEADING_4),
};
}
-export function H5HeadingMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function H5HeadingMenuItemFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: H5HeadingCommand.id,
type: MenuItemType.BUTTON,
icon: 'H5Icon',
- title: 'ui.toolbar.heading.5',
- tooltip: 'ui.toolbar.heading.5',
+ title: 'docs-ui.toolbar.heading.leading5',
+ tooltip: 'docs-ui.toolbar.heading.leading5',
disabled$: disableMenuWhenNoDocRange(accessor),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
activated$: getHeadingActivatedObservable(accessor, NamedStyleType.HEADING_5),
};
}
-export function NormalTextHeadingMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function NormalTextHeadingMenuItemFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: NormalTextHeadingCommand.id,
type: MenuItemType.BUTTON,
icon: 'TextTypeIcon',
- title: 'ui.toolbar.heading.normal',
- tooltip: 'ui.toolbar.heading.normal',
+ title: 'docs-ui.toolbar.heading.normal',
+ tooltip: 'docs-ui.toolbar.heading.normal',
disabled$: disableMenuWhenNoDocRange(accessor),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
activated$: getHeadingActivatedObservable(accessor, NamedStyleType.NORMAL_TEXT),
};
}
-export function TitleHeadingMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function TitleHeadingMenuItemFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: TitleHeadingCommand.id,
type: MenuItemType.BUTTON,
icon: 'TitleTypeIcon',
- title: 'ui.toolbar.heading.title',
- tooltip: 'ui.toolbar.heading.title',
+ title: 'docs-ui.toolbar.heading.title',
+ tooltip: 'docs-ui.toolbar.heading.title',
disabled$: disableMenuWhenNoDocRange(accessor),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
activated$: getHeadingActivatedObservable(accessor, NamedStyleType.TITLE),
};
}
-export function SubtitleHeadingMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function SubtitleHeadingMenuItemFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: SubtitleHeadingCommand.id,
type: MenuItemType.BUTTON,
icon: 'SubtitleTypeIcon',
- title: 'ui.toolbar.heading.subTitle',
- tooltip: 'ui.toolbar.heading.subTitle',
+ title: 'docs-ui.toolbar.heading.subTitle',
+ tooltip: 'docs-ui.toolbar.heading.subTitle',
disabled$: disableMenuWhenNoDocRange(accessor),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
activated$: getHeadingActivatedObservable(accessor, NamedStyleType.SUBTITLE),
@@ -230,67 +231,67 @@ export function SubtitleHeadingMenuItemFactory(accessor: IAccessor): IMenuItem {
}
export const EMPTY_PARAGRAPH_MENU_ID = 'doc.menu.empty-paragraph';
-export function EmptyParagraphH1MenuItemFactory(_accessor: IAccessor): IMenuButtonItem {
+export function EmptyParagraphH1MenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: H1HeadingCommand.id,
type: MenuItemType.BUTTON,
icon: 'H1Icon',
- title: 'ui.toolbar.heading.1',
- tooltip: 'ui.toolbar.heading.1',
+ title: 'docs-ui.toolbar.heading.leading1',
+ tooltip: 'docs-ui.toolbar.heading.leading1',
};
}
-export function EmptyParagraphH2MenuItemFactory(_accessor: IAccessor): IMenuButtonItem {
+export function EmptyParagraphH2MenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: H2HeadingCommand.id,
type: MenuItemType.BUTTON,
icon: 'H2Icon',
- title: 'ui.toolbar.heading.2',
- tooltip: 'ui.toolbar.heading.2',
+ title: 'docs-ui.toolbar.heading.leading2',
+ tooltip: 'docs-ui.toolbar.heading.leading2',
};
}
-export function EmptyParagraphH3MenuItemFactory(_accessor: IAccessor): IMenuButtonItem {
+export function EmptyParagraphH3MenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: H3HeadingCommand.id,
type: MenuItemType.BUTTON,
icon: 'H3Icon',
- title: 'ui.toolbar.heading.3',
- tooltip: 'ui.toolbar.heading.3',
+ title: 'docs-ui.toolbar.heading.leading3',
+ tooltip: 'docs-ui.toolbar.heading.leading3',
};
}
-export function EmptyParagraphH4MenuItemFactory(_accessor: IAccessor): IMenuButtonItem {
+export function EmptyParagraphH4MenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: H4HeadingCommand.id,
type: MenuItemType.BUTTON,
icon: 'H4Icon',
- title: 'ui.toolbar.heading.4',
- tooltip: 'ui.toolbar.heading.4',
+ title: 'docs-ui.toolbar.heading.leading4',
+ tooltip: 'docs-ui.toolbar.heading.leading4',
};
}
-export function EmptyParagraphH5MenuItemFactory(_accessor: IAccessor): IMenuButtonItem {
+export function EmptyParagraphH5MenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: H5HeadingCommand.id,
type: MenuItemType.BUTTON,
icon: 'H5Icon',
- title: 'ui.toolbar.heading.5',
- tooltip: 'ui.toolbar.heading.5',
+ title: 'docs-ui.toolbar.heading.leading5',
+ tooltip: 'docs-ui.toolbar.heading.leading5',
};
}
-export function EmptyParagraphNormalTextMenuItemFactory(_accessor: IAccessor): IMenuButtonItem {
+export function EmptyParagraphNormalTextMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: NormalTextHeadingCommand.id,
type: MenuItemType.BUTTON,
icon: 'TextTypeIcon',
- title: 'ui.toolbar.heading.normal',
- tooltip: 'ui.toolbar.heading.normal',
+ title: 'docs-ui.toolbar.heading.normal',
+ tooltip: 'docs-ui.toolbar.heading.normal',
};
}
-export function EmptyParagraphOrderListMenuItemFactory(_accessor: IAccessor): IMenuButtonItem {
+export function EmptyParagraphOrderListMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: OrderListCommand.id,
type: MenuItemType.BUTTON,
@@ -300,7 +301,7 @@ export function EmptyParagraphOrderListMenuItemFactory(_accessor: IAccessor): IM
};
}
-export function EmptyParagraphBulletListMenuItemFactory(_accessor: IAccessor): IMenuButtonItem {
+export function EmptyParagraphBulletListMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: BulletListCommand.id,
type: MenuItemType.BUTTON,
@@ -310,7 +311,7 @@ export function EmptyParagraphBulletListMenuItemFactory(_accessor: IAccessor): I
};
}
-export function EmptyParagraphCheckListMenuItemFactory(_accessor: IAccessor): IMenuButtonItem {
+export function EmptyParagraphCheckListMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: CheckListCommand.id,
type: MenuItemType.BUTTON,
@@ -320,7 +321,7 @@ export function EmptyParagraphCheckListMenuItemFactory(_accessor: IAccessor): IM
};
}
-export function EmptyParagraphHorizontalLineMenuItemFactory(_accessor: IAccessor): IMenuButtonItem {
+export function EmptyParagraphHorizontalLineMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: HorizontalLineCommand.id,
type: MenuItemType.BUTTON,
@@ -330,7 +331,7 @@ export function EmptyParagraphHorizontalLineMenuItemFactory(_accessor: IAccessor
};
}
-export function CopyCurrentParagraphMenuItemFactory(_accessor: IAccessor): IMenuItem {
+export function CopyCurrentParagraphMenuItemFactory(): IMenuItem<LocaleKey> {
return {
id: DocCopyCurrentParagraphCommand.id,
type: MenuItemType.BUTTON,
@@ -339,7 +340,7 @@ export function CopyCurrentParagraphMenuItemFactory(_accessor: IAccessor): IMenu
};
}
-export function CutCurrentParagraphMenuItemFactory(_accessor: IAccessor): IMenuItem {
+export function CutCurrentParagraphMenuItemFactory(): IMenuItem<LocaleKey> {
return {
id: DocCutCurrentParagraphCommand.id,
type: MenuItemType.BUTTON,
@@ -348,7 +349,7 @@ export function CutCurrentParagraphMenuItemFactory(_accessor: IAccessor): IMenuI
};
}
-export function DeleteCurrentParagraphMenuItemFactory(_accessor: IAccessor): IMenuItem {
+export function DeleteCurrentParagraphMenuItemFactory(): IMenuItem<LocaleKey> {
return {
id: DeleteCurrentParagraphCommand.id,
type: MenuItemType.BUTTON,
@@ -357,7 +358,7 @@ export function DeleteCurrentParagraphMenuItemFactory(_accessor: IAccessor): IMe
};
}
-export function InsertBulletListBellowMenuItemFactory(_accessor: IAccessor): IMenuItem {
+export function InsertBulletListBellowMenuItemFactory(): IMenuItem<LocaleKey> {
return {
id: InsertBulletListBellowCommand.id,
type: MenuItemType.BUTTON,
@@ -367,7 +368,7 @@ export function InsertBulletListBellowMenuItemFactory(_accessor: IAccessor): IMe
};
}
-export function InsertOrderListBellowMenuItemFactory(_accessor: IAccessor): IMenuItem {
+export function InsertOrderListBellowMenuItemFactory(): IMenuItem<LocaleKey> {
return {
id: InsertOrderListBellowCommand.id,
type: MenuItemType.BUTTON,
@@ -377,7 +378,7 @@ export function InsertOrderListBellowMenuItemFactory(_accessor: IAccessor): IMen
};
}
-export function InsertCheckListBellowMenuItemFactory(_accessor: IAccessor): IMenuItem {
+export function InsertCheckListBellowMenuItemFactory(): IMenuItem<LocaleKey> {
return {
id: InsertCheckListBellowCommand.id,
type: MenuItemType.BUTTON,
@@ -387,7 +388,7 @@ export function InsertCheckListBellowMenuItemFactory(_accessor: IAccessor): IMen
};
}
-export function InsertHorizontalLineBellowMenuItemFactory(_accessor: IAccessor): IMenuItem {
+export function InsertHorizontalLineBellowMenuItemFactory(): IMenuItem<LocaleKey> {
return {
id: InsertHorizontalLineBellowCommand.id,
type: MenuItemType.BUTTON,
@@ -415,7 +416,7 @@ export function getDocBlockRangeMenuId(blockType: string): string {
return `doc.block-range.${blockType}.menu`;
}
-export function TableBlockCopyMenuItemFactory(_accessor: IAccessor): IMenuItem {
+export function TableBlockCopyMenuItemFactory(): IMenuItem<LocaleKey> {
return {
id: DocCopyCommand.name,
commandId: DocCopyCommand.id,
@@ -425,7 +426,7 @@ export function TableBlockCopyMenuItemFactory(_accessor: IAccessor): IMenuItem {
};
}
-export function TableBlockPasteMenuItemFactory(_accessor: IAccessor): IMenuItem {
+export function TableBlockPasteMenuItemFactory(): IMenuItem<LocaleKey> {
return {
id: DocPasteCommand.id,
type: MenuItemType.BUTTON,
@@ -434,7 +435,7 @@ export function TableBlockPasteMenuItemFactory(_accessor: IAccessor): IMenuItem
};
}
-export function TableBlockDeleteMenuItemFactory(_accessor: IAccessor): IMenuItem {
+export function TableBlockDeleteMenuItemFactory(): IMenuItem<LocaleKey> {
return {
id: DocTableDeleteTableCommand.id,
type: MenuItemType.BUTTON,
@@ -443,7 +444,7 @@ export function TableBlockDeleteMenuItemFactory(_accessor: IAccessor): IMenuItem
};
}
-export function DocInsertBellowMenuItemFactory(_accessor: IAccessor): IMenuSelectorItem<string> {
+export function DocInsertBellowMenuItemFactory(): IMenuSelectorItem<LocaleKey> {
return {
id: INSERT_BELLOW_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -451,7 +452,7 @@ export function DocInsertBellowMenuItemFactory(_accessor: IAccessor): IMenuSelec
};
}
-export function ParagraphMenuAlignSubmenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function ParagraphMenuAlignSubmenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: DOC_PARAGRAPH_T_ALIGN_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -462,7 +463,7 @@ export function ParagraphMenuAlignSubmenuItemFactory(accessor: IAccessor): IMenu
};
}
-export function ParagraphMenuColorsSubmenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function ParagraphMenuColorsSubmenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: DOC_PARAGRAPH_T_COLORS_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -473,8 +474,8 @@ export function ParagraphMenuColorsSubmenuItemFactory(accessor: IAccessor): IMen
};
}
-export function ParagraphMenuTextColorHeaderActionMenuItemFactory(accessor: IAccessor): IMenuItem {
- const baseItem = TextColorSelectorMenuItemFactory(accessor) as IMenuSelectorItem<string, string | undefined>;
+export function ParagraphMenuTextColorHeaderActionMenuItemFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
+ const baseItem = TextColorSelectorMenuItemFactory(accessor);
return {
...baseItem,
@@ -484,8 +485,8 @@ export function ParagraphMenuTextColorHeaderActionMenuItemFactory(accessor: IAcc
};
}
-export function ParagraphMenuBackgroundColorHeaderActionMenuItemFactory(accessor: IAccessor): IMenuItem {
- const baseItem = BackgroundColorSelectorMenuItemFactory(accessor) as IMenuSelectorItem<string, string | undefined>;
+export function ParagraphMenuBackgroundColorHeaderActionMenuItemFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
+ const baseItem = BackgroundColorSelectorMenuItemFactory(accessor);
return {
...baseItem,
@@ -495,7 +496,7 @@ export function ParagraphMenuBackgroundColorHeaderActionMenuItemFactory(accessor
};
}
-export function ParagraphMenuInsertBelowSubmenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function ParagraphMenuInsertBelowSubmenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: DOC_PARAGRAPH_T_INSERT_BELOW_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -506,72 +507,72 @@ export function ParagraphMenuInsertBelowSubmenuItemFactory(accessor: IAccessor):
};
}
-export function ParagraphMenuInsertBelowHeadingH1MenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ParagraphMenuInsertBelowHeadingH1MenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: `${DOC_PARAGRAPH_T_INSERT_BELOW_COMMAND_ID}.h1`,
commandId: DOC_PARAGRAPH_T_INSERT_BELOW_COMMAND_ID,
type: MenuItemType.BUTTON,
icon: 'H1Icon',
- title: 'ui.toolbar.heading.1',
- tooltip: 'ui.toolbar.heading.1',
+ title: 'docs-ui.toolbar.heading.leading1',
+ tooltip: 'docs-ui.toolbar.heading.leading1',
params: { commandId: H1HeadingCommand.id, paragraphMenuPlacement: 'below', paragraphMenuInsertMode: 'breakline' },
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
-export function ParagraphMenuInsertBelowHeadingH2MenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ParagraphMenuInsertBelowHeadingH2MenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: `${DOC_PARAGRAPH_T_INSERT_BELOW_COMMAND_ID}.h2`,
commandId: DOC_PARAGRAPH_T_INSERT_BELOW_COMMAND_ID,
type: MenuItemType.BUTTON,
icon: 'H2Icon',
- title: 'ui.toolbar.heading.2',
- tooltip: 'ui.toolbar.heading.2',
+ title: 'docs-ui.toolbar.heading.leading2',
+ tooltip: 'docs-ui.toolbar.heading.leading2',
params: { commandId: H2HeadingCommand.id, paragraphMenuPlacement: 'below', paragraphMenuInsertMode: 'breakline' },
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
-export function ParagraphMenuInsertBelowHeadingH3MenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ParagraphMenuInsertBelowHeadingH3MenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: `${DOC_PARAGRAPH_T_INSERT_BELOW_COMMAND_ID}.h3`,
commandId: DOC_PARAGRAPH_T_INSERT_BELOW_COMMAND_ID,
type: MenuItemType.BUTTON,
icon: 'H3Icon',
- title: 'ui.toolbar.heading.3',
- tooltip: 'ui.toolbar.heading.3',
+ title: 'docs-ui.toolbar.heading.leading3',
+ tooltip: 'docs-ui.toolbar.heading.leading3',
params: { commandId: H3HeadingCommand.id, paragraphMenuPlacement: 'below', paragraphMenuInsertMode: 'breakline' },
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
-export function ParagraphMenuInsertBelowHeadingH4MenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ParagraphMenuInsertBelowHeadingH4MenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: `${DOC_PARAGRAPH_T_INSERT_BELOW_COMMAND_ID}.h4`,
commandId: DOC_PARAGRAPH_T_INSERT_BELOW_COMMAND_ID,
type: MenuItemType.BUTTON,
icon: 'H4Icon',
- title: 'ui.toolbar.heading.4',
- tooltip: 'ui.toolbar.heading.4',
+ title: 'docs-ui.toolbar.heading.leading4',
+ tooltip: 'docs-ui.toolbar.heading.leading4',
params: { commandId: H4HeadingCommand.id, paragraphMenuPlacement: 'below', paragraphMenuInsertMode: 'breakline' },
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
-export function ParagraphMenuInsertBelowHeadingH5MenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ParagraphMenuInsertBelowHeadingH5MenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: `${DOC_PARAGRAPH_T_INSERT_BELOW_COMMAND_ID}.h5`,
commandId: DOC_PARAGRAPH_T_INSERT_BELOW_COMMAND_ID,
type: MenuItemType.BUTTON,
icon: 'H5Icon',
- title: 'ui.toolbar.heading.5',
- tooltip: 'ui.toolbar.heading.5',
+ title: 'docs-ui.toolbar.heading.leading5',
+ tooltip: 'docs-ui.toolbar.heading.leading5',
params: { commandId: H5HeadingCommand.id, paragraphMenuPlacement: 'below', paragraphMenuInsertMode: 'breakline' },
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
};
}
-export function ParagraphMenuInsertBelowTableMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ParagraphMenuInsertBelowTableMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: `${DocCreateTableOperation.id}.below`,
commandId: DocCreateTableOperation.id,
@@ -584,7 +585,7 @@ export function ParagraphMenuInsertBelowTableMenuItemFactory(accessor: IAccessor
};
}
-export function ParagraphMenuIndentIncreaseMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ParagraphMenuIndentIncreaseMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DOC_PARAGRAPH_T_INDENT_INCREASE_ID,
type: MenuItemType.BUTTON,
@@ -595,7 +596,7 @@ export function ParagraphMenuIndentIncreaseMenuItemFactory(accessor: IAccessor):
};
}
-export function ParagraphMenuIndentDecreaseMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ParagraphMenuIndentDecreaseMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DOC_PARAGRAPH_T_INDENT_DECREASE_ID,
type: MenuItemType.BUTTON,
@@ -606,7 +607,7 @@ export function ParagraphMenuIndentDecreaseMenuItemFactory(accessor: IAccessor):
};
}
-export function ParagraphMenuDefaultTextColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ParagraphMenuDefaultTextColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: `${SetInlineFormatTextColorCommand.id}.default`,
commandId: SetInlineFormatTextColorCommand.id,
@@ -618,7 +619,7 @@ export function ParagraphMenuDefaultTextColorMenuItemFactory(accessor: IAccessor
};
}
-export function ParagraphMenuNoBackgroundMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ParagraphMenuNoBackgroundMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: ResetInlineFormatTextBackgroundColorCommand.id,
type: MenuItemType.BUTTON,
@@ -628,7 +629,7 @@ export function ParagraphMenuNoBackgroundMenuItemFactory(accessor: IAccessor): I
};
}
-export function ParagraphMenuResetTextColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ParagraphMenuResetTextColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: ResetInlineFormatTextColorCommand.id,
type: MenuItemType.BUTTON,
@@ -639,7 +640,7 @@ export function ParagraphMenuResetTextColorMenuItemFactory(accessor: IAccessor):
};
}
-export function ParagraphMenuResetColorsMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ParagraphMenuResetColorsMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DOC_PARAGRAPH_T_RESET_COLORS_ID,
type: MenuItemType.BUTTON,
@@ -650,11 +651,11 @@ export function ParagraphMenuResetColorsMenuItemFactory(accessor: IAccessor): IM
};
}
-export const ParagraphMenuTextColorSwatchMenuItemFactories = TEXT_COLORS.reduce<Record<string, { order: number; menuItemFactory: (accessor: IAccessor) => IMenuButtonItem }>>((items, color, index) => {
+export const ParagraphMenuTextColorSwatchMenuItemFactories = TEXT_COLORS.reduce<Record<string, { order: number; menuItemFactory: (accessor: IAccessor) => IMenuButtonItem<LocaleKey> }>>((items, color, index) => {
const id = `doc.menu.paragraph-t.text-color.${index}`;
items[id] = {
order: index,
- menuItemFactory: (accessor: IAccessor): IMenuButtonItem => ({
+ menuItemFactory: (accessor: IAccessor): IMenuButtonItem<LocaleKey> => ({
id,
commandId: SetInlineFormatTextColorCommand.id,
type: MenuItemType.BUTTON,
@@ -668,11 +669,11 @@ export const ParagraphMenuTextColorSwatchMenuItemFactories = TEXT_COLORS.reduce<
return items;
}, {});
-export const ParagraphMenuBackgroundColorSwatchMenuItemFactories = BACKGROUND_COLOR_SWATCH_ICONS.reduce<Record<string, { order: number; menuItemFactory: (accessor: IAccessor) => IMenuButtonItem }>>((items, icon, index) => {
+export const ParagraphMenuBackgroundColorSwatchMenuItemFactories = BACKGROUND_COLOR_SWATCH_ICONS.reduce<Record<string, { order: number; menuItemFactory: (accessor: IAccessor) => IMenuButtonItem<LocaleKey> }>>((items, icon, index) => {
const id = `doc.menu.paragraph-t.background-color.${index}`;
items[id] = {
order: index,
- menuItemFactory: (accessor: IAccessor): IMenuButtonItem => {
+ menuItemFactory: (accessor: IAccessor): IMenuButtonItem<LocaleKey> => {
const themeService = accessor.get(ThemeService);
const color = getHighlightBackgroundColor(themeService, index);
diff --git a/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterOptions.tsx b/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterOptions.tsx
index 5a9a88ad40..c406e35085 100644
--- a/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterOptions.tsx
+++ b/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterOptions.tsx
@@ -16,6 +16,7 @@
import type { IDocumentStyle } from '@univerjs/core';
import type { IHeaderFooterProps } from '../../../commands/commands/doc-header-footer.command';
+import type { LocaleKey } from '../../../locale/types';
import {
BooleanNumber,
generateRandomId,
@@ -227,7 +228,7 @@ export const DocHeaderFooterOptions = (props: IDocHeaderFooterOptionsProps) => {
checked={options.useFirstPageHeaderFooter === BooleanNumber.TRUE}
onChange={(val) => { handleCheckboxChange(val as boolean, 'useFirstPageHeaderFooter'); }}
>
- {localeService.t('docs-ui.headerFooter.firstPageCheckBox')}
+ {localeService.t<LocaleKey>('docs-ui.headerFooter.firstPageCheckBox')}
</Checkbox>
</div>
<div>
@@ -235,14 +236,14 @@ export const DocHeaderFooterOptions = (props: IDocHeaderFooterOptionsProps) => {
checked={options.evenAndOddHeaders === BooleanNumber.TRUE}
onChange={(val) => { handleCheckboxChange(val as boolean, 'evenAndOddHeaders'); }}
>
- {localeService.t('docs-ui.headerFooter.oddEvenCheckBox')}
+ {localeService.t<LocaleKey>('docs-ui.headerFooter.oddEvenCheckBox')}
</Checkbox>
</div>
</div>
<div className="univer-mb-1 univer-flex">
<div>
- <span>{localeService.t('docs-ui.headerFooter.headerTopMargin')}</span>
+ <span>{localeService.t<LocaleKey>('docs-ui.headerFooter.headerTopMargin')}</span>
<InputNumber
className="univer-mt-1.5 univer-w-4/5"
min={0}
@@ -253,7 +254,7 @@ export const DocHeaderFooterOptions = (props: IDocHeaderFooterOptionsProps) => {
/>
</div>
<div>
- <span>{localeService.t('docs-ui.headerFooter.footerBottomMargin')}</span>
+ <span>{localeService.t<LocaleKey>('docs-ui.headerFooter.footerBottomMargin')}</span>
<InputNumber
className="univer-mt-1.5 univer-w-4/5"
min={0}
@@ -266,7 +267,7 @@ export const DocHeaderFooterOptions = (props: IDocHeaderFooterOptionsProps) => {
</div>
<div className="univer-flex univer-justify-end">
- <Button onClick={closeHeaderFooter}>{localeService.t('docs-ui.headerFooter.closeHeaderFooter')}</Button>
+ <Button onClick={closeHeaderFooter}>{localeService.t<LocaleKey>('docs-ui.headerFooter.closeHeaderFooter')}</Button>
</div>
</div>
);
diff --git a/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterPanel.tsx b/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterPanel.tsx
index afb6f03fb1..23e14f8be8 100644
--- a/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterPanel.tsx
+++ b/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterPanel.tsx
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { LocaleKey } from '../../../locale/types';
import { IUniverInstanceService, LocaleService } from '@univerjs/core';
import { DocSkeletonManagerService } from '@univerjs/docs';
import { DocumentEditArea, IRenderManagerService } from '@univerjs/engine-render';
@@ -52,7 +53,7 @@ export const DocHeaderFooterPanel = () => {
<div className="univer-text-sm">
{isEditHeaderFooter
? <DocHeaderFooterOptions unitId={unitId} />
- : <div className="univer-text-gray-400">{localeService.t('docs-ui.headerFooter.disableText')}</div>}
+ : <div className="univer-text-gray-400">{localeService.t<LocaleKey>('docs-ui.headerFooter.disableText')}</div>}
</div>
);
};
diff --git a/packages/docs-ui/src/views/paragraph-setting/Setting.tsx b/packages/docs-ui/src/views/paragraph-setting/Setting.tsx
index be5db7913e..0c8183c171 100644
--- a/packages/docs-ui/src/views/paragraph-setting/Setting.tsx
+++ b/packages/docs-ui/src/views/paragraph-setting/Setting.tsx
@@ -15,6 +15,7 @@
*/
import type { ReactNode } from 'react';
+import type { LocaleKey } from '../../locale/types';
import { HorizontalAlign, LocaleService } from '@univerjs/core';
import { borderClassName, Button, clsx, InputNumber, Select, Tooltip } from '@univerjs/design';
import { AlignTextBothIcon, HorizontallyIcon, LeftJustifyingIcon, RightJustifyingIcon } from '@univerjs/icons';
@@ -111,10 +112,10 @@ export function ParagraphSetting() {
const localeService = useDependency(LocaleService);
const alignmentOptions = useMemo(() => [
- { label: localeService.t('docs-ui.toolbar.alignLeft'), value: String(HorizontalAlign.LEFT), icon: <LeftJustifyingIcon /> },
- { label: localeService.t('docs-ui.toolbar.alignCenter'), value: String(HorizontalAlign.CENTER), icon: <HorizontallyIcon /> },
- { label: localeService.t('docs-ui.toolbar.alignRight'), value: String(HorizontalAlign.RIGHT), icon: <RightJustifyingIcon /> },
- { label: localeService.t('docs-ui.toolbar.alignJustify'), value: String(HorizontalAlign.JUSTIFIED), icon: <AlignTextBothIcon /> },
+ { label: localeService.t<LocaleKey>('docs-ui.toolbar.alignLeft'), value: String(HorizontalAlign.LEFT), icon: <LeftJustifyingIcon /> },
+ { label: localeService.t<LocaleKey>('docs-ui.toolbar.alignCenter'), value: String(HorizontalAlign.CENTER), icon: <HorizontallyIcon /> },
+ { label: localeService.t<LocaleKey>('docs-ui.toolbar.alignRight'), value: String(HorizontalAlign.RIGHT), icon: <RightJustifyingIcon /> },
+ { label: localeService.t<LocaleKey>('docs-ui.toolbar.alignJustify'), value: String(HorizontalAlign.JUSTIFIED), icon: <AlignTextBothIcon /> },
], []);
const currentParagraph = useCurrentParagraph();
@@ -135,7 +136,7 @@ export function ParagraphSetting() {
return (
<div className="univer-box-border univer-w-full">
- <ParagraphSettingSection title={localeService.t('docs-ui.doc.paragraphSetting.alignment')} first>
+ <ParagraphSettingSection title={localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.alignment')} first>
<div
className={clsx(`
univer-flex univer-grid-cols-4 univer-items-center univer-justify-around univer-gap-2
@@ -171,32 +172,32 @@ export function ParagraphSetting() {
</div>
</ParagraphSettingSection>
- <ParagraphSettingSection title={localeService.t('docs-ui.doc.paragraphSetting.indentation')}>
+ <ParagraphSettingSection title={localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.indentation')}>
<div className="univer-grid univer-gap-3">
- <ParagraphSettingRow label={`${localeService.t('docs-ui.doc.paragraphSetting.left')}(px)`}>
+ <ParagraphSettingRow label={`${localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.left')}(px)`}>
<AutoFocusInputNumber value={indentStart} onChange={(v) => setIndentStart(v ?? 0)} />
</ParagraphSettingRow>
- <ParagraphSettingRow label={`${localeService.t('docs-ui.doc.paragraphSetting.right')}(px)`}>
+ <ParagraphSettingRow label={`${localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.right')}(px)`}>
<AutoFocusInputNumber value={indentEnd} onChange={(v) => setIndentEnd(v ?? 0)} />
</ParagraphSettingRow>
- <ParagraphSettingRow label={`${localeService.t('docs-ui.doc.paragraphSetting.firstLine')}(px)`}>
+ <ParagraphSettingRow label={`${localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.firstLine')}(px)`}>
<AutoFocusInputNumber value={indentFirstLine} onChange={(v) => setIndentFirstLine(v ?? 0)} />
</ParagraphSettingRow>
- <ParagraphSettingRow label={`${localeService.t('docs-ui.doc.paragraphSetting.hanging')}(px)`}>
+ <ParagraphSettingRow label={`${localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.hanging')}(px)`}>
<AutoFocusInputNumber value={hanging} onChange={(v) => setHanging(v ?? 0)} />
</ParagraphSettingRow>
</div>
</ParagraphSettingSection>
- <ParagraphSettingSection title={localeService.t('docs-ui.doc.paragraphSetting.spacing')}>
+ <ParagraphSettingSection title={localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.spacing')}>
<div className="univer-grid univer-gap-3">
- <ParagraphSettingRow label={`${localeService.t('docs-ui.doc.paragraphSetting.before')}(px)`}>
+ <ParagraphSettingRow label={`${localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.before')}(px)`}>
<AutoFocusInputNumber value={spaceAbove} onChange={(v) => setSpaceAbove(v ?? 0)} />
</ParagraphSettingRow>
- <ParagraphSettingRow label={`${localeService.t('docs-ui.doc.paragraphSetting.after')}(px)`}>
+ <ParagraphSettingRow label={`${localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.after')}(px)`}>
<AutoFocusInputNumber value={spaceBelow} onChange={(v) => setSpaceBelow(v ?? 0)} />
</ParagraphSettingRow>
- <ParagraphSettingRow label={localeService.t('docs-ui.doc.paragraphSetting.lineSpace')}>
+ <ParagraphSettingRow label={localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.lineSpace')}>
<div className="univer-flex univer-w-full univer-flex-col univer-gap-2">
<Select
className="univer-w-full"
diff --git a/packages/docs-ui/src/views/paragraph-setting/line-spacing.ts b/packages/docs-ui/src/views/paragraph-setting/line-spacing.ts
index da865ef8da..a414fb66ca 100644
--- a/packages/docs-ui/src/views/paragraph-setting/line-spacing.ts
+++ b/packages/docs-ui/src/views/paragraph-setting/line-spacing.ts
@@ -15,6 +15,7 @@
*/
import type { LocaleService } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import { DEFAULT_DOCUMENT_PARAGRAPH_LINE_SPACING, DEFAULT_STYLES, SpacingRule } from '@univerjs/core';
interface ILineSpacingMetrics {
@@ -50,9 +51,9 @@ function clamp(value: number, min: number, max: number) {
export function getLineSpacingRuleOptions(localeService: LocaleService) {
return [
- { label: localeService.t('docs-ui.doc.paragraphSetting.multiSpace'), value: `${SpacingRule.AUTO}` },
- { label: localeService.t('docs-ui.doc.paragraphSetting.atLeast'), value: `${SpacingRule.AT_LEAST}` },
- { label: localeService.t('docs-ui.doc.paragraphSetting.exactly'), value: `${SpacingRule.EXACT}` },
+ { label: localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.multiSpace'), value: `${SpacingRule.AUTO}` },
+ { label: localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.atLeast'), value: `${SpacingRule.AT_LEAST}` },
+ { label: localeService.t<LocaleKey>('docs-ui.doc.paragraphSetting.exactly'), value: `${SpacingRule.EXACT}` },
];
}
diff --git a/packages/docs-ui/src/views/table/create/TableCreate.tsx b/packages/docs-ui/src/views/table/create/TableCreate.tsx
index 9bca4f99d6..c3c6c49c58 100644
--- a/packages/docs-ui/src/views/table/create/TableCreate.tsx
+++ b/packages/docs-ui/src/views/table/create/TableCreate.tsx
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { LocaleKey } from '../../../locale/types';
import { LocaleService } from '@univerjs/core';
import { InputNumber } from '@univerjs/design';
import { useDependency } from '@univerjs/ui';
@@ -50,7 +51,7 @@ export const DocCreateTableConfirm = ({
return (
<div className="univer-flex univer-items-center univer-justify-between univer-gap-2">
<div className="univer-flex univer-items-center univer-gap-2">
- <span>{localeService.t('docs-ui.toolbar.table.rowCount')}</span>
+ <span>{localeService.t<LocaleKey>('docs-ui.toolbar.table.rowCount')}</span>
<InputNumber
className="univer-w-28"
min={1}
@@ -61,7 +62,7 @@ export const DocCreateTableConfirm = ({
/>
</div>
<div className="univer-flex univer-items-center univer-gap-2">
- <span>{localeService.t('docs-ui.toolbar.table.colCount')}</span>
+ <span>{localeService.t<LocaleKey>('docs-ui.toolbar.table.colCount')}</span>
<InputNumber
className="univer-w-28"
min={1}
diff --git a/packages/drawing-ui/src/controllers/image-cropper.controller.ts b/packages/drawing-ui/src/controllers/image-cropper.controller.ts
index 89d33e5047..f0298df938 100644
--- a/packages/drawing-ui/src/controllers/image-cropper.controller.ts
+++ b/packages/drawing-ui/src/controllers/image-cropper.controller.ts
@@ -18,13 +18,31 @@ import type { ICommandInfo, IDrawingSearch, ISrcRect, ITransformState, Nullable,
import type { IImageData } from '@univerjs/drawing';
import type { BaseObject, Scene } from '@univerjs/engine-render';
import type { IOpenImageCropOperationBySrcRectParams } from '../commands/operations/image-crop.operation';
-import { checkIfMove, Disposable, ICommandService, Inject, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
+import type { LocaleKey } from '../locale/types';
+import {
+ checkIfMove,
+ Disposable,
+ ICommandService,
+ Inject,
+ IUniverInstanceService,
+ LocaleService,
+ UniverInstanceType,
+} from '@univerjs/core';
import { MessageType } from '@univerjs/design';
-import { getDrawingShapeKeyByDrawingSearch, IDrawingManagerService, SetDrawingSelectedOperation } from '@univerjs/drawing';
+import {
+ getDrawingShapeKeyByDrawingSearch,
+ IDrawingManagerService,
+ SetDrawingSelectedOperation,
+} from '@univerjs/drawing';
import { CURSOR_TYPE, degToRad, Image, IRenderManagerService, precisionTo, Vector2 } from '@univerjs/engine-render';
import { IMessageService } from '@univerjs/ui';
import { of, switchMap } from 'rxjs';
-import { AutoImageCropOperation, CloseImageCropOperation, CropType, OpenImageCropOperation } from '../commands/operations/image-crop.operation';
+import {
+ AutoImageCropOperation,
+ CloseImageCropOperation,
+ CropType,
+ OpenImageCropOperation,
+} from '../commands/operations/image-crop.operation';
import { ImageCropperObject } from '../views/crop/image-cropper-object';
export class ImageCropperController extends Disposable {
@@ -94,7 +112,7 @@ export class ImageCropperController extends Disposable {
if (!(imageShape instanceof Image)) {
this._messageService.show({
type: MessageType.Error,
- content: this._localeService.t('drawing-ui.image-cropper.error'),
+ content: this._localeService.t<LocaleKey>('drawing-ui.image-cropper.error'),
});
return;
}
@@ -240,7 +258,7 @@ export class ImageCropperController extends Disposable {
if (!(imageShape instanceof Image)) {
this._messageService.show({
type: MessageType.Error,
- content: this._localeService.t('drawing-ui.image-cropper.error'),
+ content: this._localeService.t<LocaleKey>('drawing-ui.image-cropper.error'),
});
return;
}
diff --git a/packages/drawing-ui/src/locale/types.ts b/packages/drawing-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/drawing-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/drawing-ui/src/menu/align.menu.ts b/packages/drawing-ui/src/menu/align.menu.ts
index 1596fd6db1..9be77770a7 100644
--- a/packages/drawing-ui/src/menu/align.menu.ts
+++ b/packages/drawing-ui/src/menu/align.menu.ts
@@ -16,6 +16,7 @@
import type { IAccessor, IDrawingParam } from '@univerjs/core';
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { IDrawingManagerService } from '@univerjs/drawing';
import { MenuItemType } from '@univerjs/ui';
import { Observable } from 'rxjs';
@@ -61,7 +62,7 @@ const getMenuStateByDrawingFocusChangedObservable$ = (accessor: IAccessor): Obse
};
export const DRAWING_ALIGN_CONTEXT_MENU_ID = 'contextMenu.drawing-align';
-export function DrawingAlignContextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function DrawingAlignContextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: DRAWING_ALIGN_CONTEXT_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -71,7 +72,7 @@ export function DrawingAlignContextMenuItemFactory(accessor: IAccessor): IMenuSe
};
}
-export function SetDrawingAlignLeftMenuItemFactory(): IMenuButtonItem {
+export function SetDrawingAlignLeftMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: SetDrawingAlignLeftOperation.id,
type: MenuItemType.BUTTON,
@@ -80,7 +81,7 @@ export function SetDrawingAlignLeftMenuItemFactory(): IMenuButtonItem {
};
}
-export function SetDrawingAlignCenterMenuItemFactory(): IMenuButtonItem {
+export function SetDrawingAlignCenterMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: SetDrawingAlignCenterOperation.id,
type: MenuItemType.BUTTON,
@@ -89,7 +90,7 @@ export function SetDrawingAlignCenterMenuItemFactory(): IMenuButtonItem {
};
}
-export function SetDrawingAlignRightMenuItemFactory(): IMenuButtonItem {
+export function SetDrawingAlignRightMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: SetDrawingAlignRightOperation.id,
type: MenuItemType.BUTTON,
@@ -98,7 +99,7 @@ export function SetDrawingAlignRightMenuItemFactory(): IMenuButtonItem {
};
}
-export function SetDrawingAlignTopMenuItemFactory(): IMenuButtonItem {
+export function SetDrawingAlignTopMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: SetDrawingAlignTopOperation.id,
type: MenuItemType.BUTTON,
@@ -107,7 +108,7 @@ export function SetDrawingAlignTopMenuItemFactory(): IMenuButtonItem {
};
}
-export function SetDrawingAlignMiddleMenuItemFactory(): IMenuButtonItem {
+export function SetDrawingAlignMiddleMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: SetDrawingAlignMiddleOperation.id,
type: MenuItemType.BUTTON,
@@ -116,7 +117,7 @@ export function SetDrawingAlignMiddleMenuItemFactory(): IMenuButtonItem {
};
}
-export function SetDrawingAlignBottomMenuItemFactory(): IMenuButtonItem {
+export function SetDrawingAlignBottomMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: SetDrawingAlignBottomOperation.id,
type: MenuItemType.BUTTON,
@@ -125,7 +126,7 @@ export function SetDrawingAlignBottomMenuItemFactory(): IMenuButtonItem {
};
}
-export function SetDrawingAlignHorizonMenuItemFactory(): IMenuButtonItem {
+export function SetDrawingAlignHorizonMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: SetDrawingAlignHorizonOperation.id,
type: MenuItemType.BUTTON,
@@ -134,7 +135,7 @@ export function SetDrawingAlignHorizonMenuItemFactory(): IMenuButtonItem {
};
}
-export function SetDrawingAlignVerticalMenuItemFactory(): IMenuButtonItem {
+export function SetDrawingAlignVerticalMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: SetDrawingAlignVerticalOperation.id,
type: MenuItemType.BUTTON,
diff --git a/packages/drawing-ui/src/menu/arrange.menu.ts b/packages/drawing-ui/src/menu/arrange.menu.ts
index 1c785a510b..c0222f73c2 100644
--- a/packages/drawing-ui/src/menu/arrange.menu.ts
+++ b/packages/drawing-ui/src/menu/arrange.menu.ts
@@ -15,6 +15,7 @@
*/
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { MenuItemType } from '@univerjs/ui';
import {
SetDrawingArrangeBackOperation,
@@ -24,7 +25,7 @@ import {
} from '../commands/operations/drawing-arrange.operation';
export const DRAWING_ARRANGE_CONTEXT_MENU_ID = 'contextMenu.drawing-arrange';
-export function DrawingArrangeContextMenuItemFactory(): IMenuSelectorItem<string> {
+export function DrawingArrangeContextMenuItemFactory(): IMenuSelectorItem<LocaleKey> {
return {
id: DRAWING_ARRANGE_CONTEXT_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -33,7 +34,7 @@ export function DrawingArrangeContextMenuItemFactory(): IMenuSelectorItem<string
};
}
-export function SetDrawingArrangeFrontMenuItemFactory(): IMenuButtonItem {
+export function SetDrawingArrangeFrontMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: SetDrawingArrangeFrontOperation.id,
type: MenuItemType.BUTTON,
@@ -42,7 +43,7 @@ export function SetDrawingArrangeFrontMenuItemFactory(): IMenuButtonItem {
};
}
-export function SetDrawingArrangeForwardMenuItemFactory(): IMenuButtonItem {
+export function SetDrawingArrangeForwardMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: SetDrawingArrangeForwardOperation.id,
type: MenuItemType.BUTTON,
@@ -51,7 +52,7 @@ export function SetDrawingArrangeForwardMenuItemFactory(): IMenuButtonItem {
};
}
-export function SetDrawingArrangeBackMenuItemFactory(): IMenuButtonItem {
+export function SetDrawingArrangeBackMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: SetDrawingArrangeBackOperation.id,
type: MenuItemType.BUTTON,
@@ -60,7 +61,7 @@ export function SetDrawingArrangeBackMenuItemFactory(): IMenuButtonItem {
};
}
-export function SetDrawingArrangeBackwardMenuItemFactory(): IMenuButtonItem {
+export function SetDrawingArrangeBackwardMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: SetDrawingArrangeBackwardOperation.id,
type: MenuItemType.BUTTON,
diff --git a/packages/drawing-ui/src/menu/group.menu.ts b/packages/drawing-ui/src/menu/group.menu.ts
index fa3710a4dd..66244c47ed 100644
--- a/packages/drawing-ui/src/menu/group.menu.ts
+++ b/packages/drawing-ui/src/menu/group.menu.ts
@@ -16,13 +16,21 @@
import type { IAccessor, IDrawingParam } from '@univerjs/core';
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { DrawingTypeEnum } from '@univerjs/core';
import { IDrawingManagerService } from '@univerjs/drawing';
import { MenuItemType } from '@univerjs/ui';
import { Observable } from 'rxjs';
-import { CancelDrawingGroupOperation, DRAWING_GROUP_TYPES, SetDrawingGroupOperation } from '../commands/operations/drawing-group.operation';
+import {
+ CancelDrawingGroupOperation,
+ DRAWING_GROUP_TYPES,
+ SetDrawingGroupOperation,
+} from '../commands/operations/drawing-group.operation';
-const getMenuStateByDrawingFocusChangedObservable$ = (accessor: IAccessor, type?: 'group' | 'unGroup'): Observable<boolean> => {
+function getMenuStateByDrawingFocusChangedObservable$(
+ accessor: IAccessor,
+ type?: 'group' | 'unGroup'
+): Observable<boolean> {
const drawingManagerService = accessor.get(IDrawingManagerService);
return new Observable((subscriber) => {
@@ -72,7 +80,7 @@ const getMenuStateByDrawingFocusChangedObservable$ = (accessor: IAccessor, type?
};
export const DRAWING_GROUP_CONTEXT_MENU_ID = 'contextMenu.drawing-group';
-export function DrawingGroupContextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function DrawingGroupContextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: DRAWING_GROUP_CONTEXT_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -82,7 +90,7 @@ export function DrawingGroupContextMenuItemFactory(accessor: IAccessor): IMenuSe
};
}
-export function SetDrawingGroupMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function SetDrawingGroupMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: SetDrawingGroupOperation.id,
type: MenuItemType.BUTTON,
@@ -92,7 +100,7 @@ export function SetDrawingGroupMenuItemFactory(accessor: IAccessor): IMenuButton
};
}
-export function CancelDrawingGroupMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function CancelDrawingGroupMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: CancelDrawingGroupOperation.id,
type: MenuItemType.BUTTON,
diff --git a/packages/drawing-ui/src/views/panel/DrawingAlign.tsx b/packages/drawing-ui/src/views/panel/DrawingAlign.tsx
index 533a81ee5f..b85f68ba87 100644
--- a/packages/drawing-ui/src/views/panel/DrawingAlign.tsx
+++ b/packages/drawing-ui/src/views/panel/DrawingAlign.tsx
@@ -15,6 +15,7 @@
*/
import type { IDrawingParam } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import { ICommandService, LocaleService } from '@univerjs/core';
import { clsx, Select } from '@univerjs/design';
import { useDependency } from '@univerjs/ui';
@@ -35,21 +36,21 @@ export const DrawingAlign = (props: IDrawingAlignProps) => {
const [alignValue, setAlignValue] = useState<string>(AlignType.default as string);
const alignOptions = [
{
- label: localeService.t('drawing-ui.image-panel.align.default'),
+ label: localeService.t<LocaleKey>('drawing-ui.image-panel.align.default'),
value: AlignType.default,
},
{
options: [
{
- label: localeService.t('drawing-ui.image-panel.align.left'),
+ label: localeService.t<LocaleKey>('drawing-ui.image-panel.align.left'),
value: AlignType.left,
},
{
- label: localeService.t('drawing-ui.image-panel.align.center'),
+ label: localeService.t<LocaleKey>('drawing-ui.image-panel.align.center'),
value: AlignType.center,
},
{
- label: localeService.t('drawing-ui.image-panel.align.right'),
+ label: localeService.t<LocaleKey>('drawing-ui.image-panel.align.right'),
value: AlignType.right,
},
],
@@ -57,15 +58,15 @@ export const DrawingAlign = (props: IDrawingAlignProps) => {
{
options: [
{
- label: localeService.t('drawing-ui.image-panel.align.top'),
+ label: localeService.t<LocaleKey>('drawing-ui.image-panel.align.top'),
value: AlignType.top,
},
{
- label: localeService.t('drawing-ui.image-panel.align.middle'),
+ label: localeService.t<LocaleKey>('drawing-ui.image-panel.align.middle'),
value: AlignType.middle,
},
{
- label: localeService.t('drawing-ui.image-panel.align.bottom'),
+ label: localeService.t<LocaleKey>('drawing-ui.image-panel.align.bottom'),
value: AlignType.bottom,
},
],
@@ -73,11 +74,11 @@ export const DrawingAlign = (props: IDrawingAlignProps) => {
{
options: [
{
- label: localeService.t('drawing-ui.image-panel.align.horizon'),
+ label: localeService.t<LocaleKey>('drawing-ui.image-panel.align.horizon'),
value: AlignType.horizon,
},
{
- label: localeService.t('drawing-ui.image-panel.align.vertical'),
+ label: localeService.t<LocaleKey>('drawing-ui.image-panel.align.vertical'),
value: AlignType.vertical,
},
],
@@ -104,7 +105,7 @@ export const DrawingAlign = (props: IDrawingAlignProps) => {
dark:!univer-text-gray-200
`}
>
- <div>{localeService.t('drawing-ui.image-panel.align.title')}</div>
+ <div>{localeService.t<LocaleKey>('drawing-ui.image-panel.align.title')}</div>
</header>
<div className="univer-relative univer-mt-2.5 univer-flex univer-h-full">
diff --git a/packages/drawing-ui/src/views/panel/DrawingArrange.tsx b/packages/drawing-ui/src/views/panel/DrawingArrange.tsx
index fc4e97462b..839b9bf81b 100644
--- a/packages/drawing-ui/src/views/panel/DrawingArrange.tsx
+++ b/packages/drawing-ui/src/views/panel/DrawingArrange.tsx
@@ -15,6 +15,7 @@
*/
import type { IDrawingParam } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import { ArrangeTypeEnum, ICommandService, LocaleService } from '@univerjs/core';
import { Button, clsx } from '@univerjs/design';
import { IDrawingManagerService } from '@univerjs/drawing';
@@ -68,25 +69,25 @@ export const DrawingArrange = (props: IDrawingArrangeProps) => {
dark:!univer-text-gray-200
`}
>
- <div>{localeService.t('drawing-ui.image-panel.arrange.title')}</div>
+ <div>{localeService.t<LocaleKey>('drawing-ui.image-panel.arrange.title')}</div>
</header>
<div className="univer-grid univer-grid-cols-2 univer-gap-2">
<Button onClick={() => { onArrangeBtnClick(ArrangeTypeEnum.forward); }}>
<MoveUpIcon />
- {localeService.t('drawing-ui.image-panel.arrange.forward')}
+ {localeService.t<LocaleKey>('drawing-ui.image-panel.arrange.forward')}
</Button>
<Button onClick={() => { onArrangeBtnClick(ArrangeTypeEnum.backward); }}>
<MoveDownIcon />
- {localeService.t('drawing-ui.image-panel.arrange.backward')}
+ {localeService.t<LocaleKey>('drawing-ui.image-panel.arrange.backward')}
</Button>
<Button onClick={() => { onArrangeBtnClick(ArrangeTypeEnum.front); }}>
<TopmostIcon />
- {localeService.t('drawing-ui.image-panel.arrange.front')}
+ {localeService.t<LocaleKey>('drawing-ui.image-panel.arrange.front')}
</Button>
<Button onClick={() => { onArrangeBtnClick(ArrangeTypeEnum.back); }}>
<BottomIcon />
- {localeService.t('drawing-ui.image-panel.arrange.back')}
+ {localeService.t<LocaleKey>('drawing-ui.image-panel.arrange.back')}
</Button>
</div>
</div>
diff --git a/packages/drawing-ui/src/views/panel/DrawingCommonPanel.tsx b/packages/drawing-ui/src/views/panel/DrawingCommonPanel.tsx
index 52ec9407af..b549971de0 100644
--- a/packages/drawing-ui/src/views/panel/DrawingCommonPanel.tsx
+++ b/packages/drawing-ui/src/views/panel/DrawingCommonPanel.tsx
@@ -15,6 +15,7 @@
*/
import type { IDrawingParam } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import { LocaleService } from '@univerjs/core';
import { clsx } from '@univerjs/design';
import { IDrawingManagerService } from '@univerjs/drawing';
@@ -172,7 +173,7 @@ export const DrawingCommonPanel = (props: IDrawingCommonPanelProps) => {
>
<div className="univer-flex univer-h-full univer-items-center univer-justify-center">
<span>
- {localeService.t('drawing-ui.image-panel.null')}
+ {localeService.t<LocaleKey>('drawing-ui.image-panel.null')}
</span>
</div>
</div>
diff --git a/packages/drawing-ui/src/views/panel/DrawingGroup.tsx b/packages/drawing-ui/src/views/panel/DrawingGroup.tsx
index 0059fcef9c..e6c4768388 100644
--- a/packages/drawing-ui/src/views/panel/DrawingGroup.tsx
+++ b/packages/drawing-ui/src/views/panel/DrawingGroup.tsx
@@ -15,13 +15,17 @@
*/
import type { IDrawingParam } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import { DrawingTypeEnum, ICommandService, LocaleService } from '@univerjs/core';
import { Button, clsx } from '@univerjs/design';
import { IDrawingManagerService } from '@univerjs/drawing';
import { IRenderManagerService } from '@univerjs/engine-render';
import { IconManager, useDependency } from '@univerjs/ui';
import { useEffect, useState } from 'react';
-import { CancelDrawingGroupOperation, SetDrawingGroupOperation } from '../../commands/operations/drawing-group.operation';
+import {
+ CancelDrawingGroupOperation,
+ SetDrawingGroupOperation,
+} from '../../commands/operations/drawing-group.operation';
import { getUpdateParams } from '../../utils/get-update-params';
export interface IDrawingGroupProps {
@@ -115,7 +119,7 @@ export const DrawingGroup = (props: IDrawingGroupProps) => {
dark:!univer-text-gray-200
`}
>
- <div>{localeService.t('drawing-ui.image-panel.group.title')}</div>
+ <div>{localeService.t<LocaleKey>('drawing-ui.image-panel.group.title')}</div>
</header>
<div className="univer-flex univer-items-center univer-justify-center univer-gap-2">
@@ -126,7 +130,7 @@ export const DrawingGroup = (props: IDrawingGroupProps) => {
onClick={onGroupBtnClick}
>
<GroupIcon />
- {localeService.t('drawing-ui.image-panel.group.group')}
+ {localeService.t<LocaleKey>('drawing-ui.image-panel.group.group')}
</Button>
<Button
className={clsx({
@@ -135,7 +139,7 @@ export const DrawingGroup = (props: IDrawingGroupProps) => {
onClick={onUngroupBtnClick}
>
<UngroupIcon />
- {localeService.t('drawing-ui.image-panel.group.unGroup')}
+ {localeService.t<LocaleKey>('drawing-ui.image-panel.group.unGroup')}
</Button>
</div>
</div>
diff --git a/packages/drawing-ui/src/views/panel/DrawingTransform.tsx b/packages/drawing-ui/src/views/panel/DrawingTransform.tsx
index 0c66f9bdcf..0b7685be8a 100644
--- a/packages/drawing-ui/src/views/panel/DrawingTransform.tsx
+++ b/packages/drawing-ui/src/views/panel/DrawingTransform.tsx
@@ -16,6 +16,7 @@
import type { IDrawingParam, Nullable } from '@univerjs/core';
import type { IChangeObserverConfig, Scene } from '@univerjs/engine-render';
+import type { LocaleKey } from '../../locale/types';
import { debounce, LocaleService } from '@univerjs/core';
import { Checkbox, clsx, InputNumber } from '@univerjs/design';
import { IDrawingManagerService } from '@univerjs/drawing';
@@ -360,7 +361,7 @@ export const DrawingTransform = (props: IDrawingTransformProps) => {
dark:!univer-text-gray-200
`}
>
- <div>{localeService.t('drawing-ui.image-panel.transform.title')}</div>
+ <div>{localeService.t<LocaleKey>('drawing-ui.image-panel.transform.title')}</div>
</header>
<div
@@ -370,7 +371,7 @@ export const DrawingTransform = (props: IDrawingTransformProps) => {
`}
>
<div>
- <span>{localeService.t('drawing-ui.image-panel.transform.width')}</span>
+ <span>{localeService.t<LocaleKey>('drawing-ui.image-panel.transform.width')}</span>
<InputNumber
precision={1}
value={width}
@@ -379,7 +380,7 @@ export const DrawingTransform = (props: IDrawingTransformProps) => {
/>
</div>
<div>
- <span>{localeService.t('drawing-ui.image-panel.transform.height')}</span>
+ <span>{localeService.t<LocaleKey>('drawing-ui.image-panel.transform.height')}</span>
<InputNumber
precision={1}
value={height}
@@ -388,7 +389,7 @@ export const DrawingTransform = (props: IDrawingTransformProps) => {
/>
</div>
<div>
- <span>{localeService.t('drawing-ui.image-panel.transform.lock')}</span>
+ <span>{localeService.t<LocaleKey>('drawing-ui.image-panel.transform.lock')}</span>
<div className="univer-text-center">
<Checkbox checked={lockRatio} onChange={handleLockRatioChange} />
</div>
@@ -402,15 +403,15 @@ export const DrawingTransform = (props: IDrawingTransformProps) => {
`}
>
<div>
- <span>{localeService.t('drawing-ui.image-panel.transform.x')}</span>
+ <span>{localeService.t<LocaleKey>('drawing-ui.image-panel.transform.x')}</span>
<InputNumber precision={1} value={xPosition} onChange={(val) => { handleXChange(val); }} />
</div>
<div>
- <span>{localeService.t('drawing-ui.image-panel.transform.y')}</span>
+ <span>{localeService.t<LocaleKey>('drawing-ui.image-panel.transform.y')}</span>
<InputNumber precision={1} value={yPosition} onChange={(val) => { handleYChange(val); }} />
</div>
<div>
- <span>{localeService.t('drawing-ui.image-panel.transform.rotate')}</span>
+ <span>{localeService.t<LocaleKey>('drawing-ui.image-panel.transform.rotate')}</span>
<InputNumber
precision={1}
value={rotation}
diff --git a/packages/drawing-ui/src/views/panel/ImageCropper.tsx b/packages/drawing-ui/src/views/panel/ImageCropper.tsx
index f66e744bd9..ad0ee7a871 100644
--- a/packages/drawing-ui/src/views/panel/ImageCropper.tsx
+++ b/packages/drawing-ui/src/views/panel/ImageCropper.tsx
@@ -15,6 +15,7 @@
*/
import type { IDrawingParam } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import { ICommandService, LocaleService } from '@univerjs/core';
import { Button, clsx, Select } from '@univerjs/design';
import { CreateCopyIcon } from '@univerjs/icons';
@@ -53,7 +54,7 @@ export const ImageCropper = (props: IImageCropperProps) => {
const cropOptions = [
{
- label: localeService.t('drawing-ui.image-panel.crop.mode'),
+ label: localeService.t<LocaleKey>('drawing-ui.image-panel.crop.mode'),
value: CropType.FREE,
},
{
@@ -137,13 +138,13 @@ export const ImageCropper = (props: IImageCropperProps) => {
dark:!univer-text-gray-200
`}
>
- <div>{localeService.t('drawing-ui.image-panel.crop.title')}</div>
+ <div>{localeService.t<LocaleKey>('drawing-ui.image-panel.crop.title')}</div>
</header>
<div className="univer-flex univer-items-center univer-justify-center univer-gap-2">
<Button onClick={() => { onCropperBtnClick(cropValue as CropType); }}>
<CreateCopyIcon />
- {localeService.t('drawing-ui.image-panel.crop.start')}
+ {localeService.t<LocaleKey>('drawing-ui.image-panel.crop.start')}
</Button>
<Select value={cropValue} options={cropOptions} onChange={handleCropChange} />
diff --git a/packages/find-replace/src/controllers/find-replace.controller.ts b/packages/find-replace/src/controllers/find-replace.controller.ts
index 7d0b5dada2..626e72ee59 100644
--- a/packages/find-replace/src/controllers/find-replace.controller.ts
+++ b/packages/find-replace/src/controllers/find-replace.controller.ts
@@ -15,6 +15,7 @@
*/
import type { IDisposable, Nullable } from '@univerjs/core';
+import type { LocaleKey } from '../locale/types';
import {
ICommandService,
Inject,
@@ -116,7 +117,7 @@ export class FindReplaceController extends RxDisposable {
id: FIND_REPLACE_DIALOG_ID,
draggable: true,
width: FIND_REPLACE_PANEL_WIDTH,
- title: { title: this._localeService.t('find-replace.dialog.title') },
+ title: { title: this._localeService.t<LocaleKey>('find-replace.dialog.title') },
children: { label: 'FindReplaceDialog' },
destroyOnClose: true,
mask: false,
@@ -126,11 +127,13 @@ export class FindReplaceController extends RxDisposable {
onClose: () => this.closePanel(),
});
- this._closingListenerDisposable = toDisposable(this._univerInstanceService.focused$.pipe(takeUntil(this.dispose$)).subscribe((focused) => {
- if (!focused || !this._univerInstanceService.getUniverSheetInstance(focused)) {
- this.closePanel();
- }
- }));
+ this._closingListenerDisposable = toDisposable(
+ this._univerInstanceService.focused$.pipe(takeUntil(this.dispose$)).subscribe((focused) => {
+ if (!focused || !this._univerInstanceService.getUniverSheetInstance(focused)) {
+ this.closePanel();
+ }
+ })
+ );
}
private _closingListenerDisposable: Nullable<IDisposable>;
diff --git a/packages/find-replace/src/locale/types.ts b/packages/find-replace/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/find-replace/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/find-replace/src/menu/find-replace.menu.ts b/packages/find-replace/src/menu/find-replace.menu.ts
index 42dae0a173..a274f64207 100644
--- a/packages/find-replace/src/menu/find-replace.menu.ts
+++ b/packages/find-replace/src/menu/find-replace.menu.ts
@@ -16,13 +16,13 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuButtonItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { EDITOR_ACTIVATED, FOCUSING_SHEET, IContextService, UniverInstanceType } from '@univerjs/core';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { combineLatest, map } from 'rxjs';
-
import { OpenFindDialogOperation } from '../commands/operations/find-replace.operation';
-export function FindReplaceMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function FindReplaceMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const contextService = accessor.get(IContextService);
return {
diff --git a/packages/find-replace/src/views/dialog/FindReplaceDialog.tsx b/packages/find-replace/src/views/dialog/FindReplaceDialog.tsx
index 00ef2a6fa1..d42eb605fc 100644
--- a/packages/find-replace/src/views/dialog/FindReplaceDialog.tsx
+++ b/packages/find-replace/src/views/dialog/FindReplaceDialog.tsx
@@ -16,6 +16,7 @@
import type { IDisposable, Nullable } from '@univerjs/core';
import type { ForwardedRef } from 'react';
+import type { LocaleKey } from '../../locale/types';
import { ICommandService, IContextService, LocaleService } from '@univerjs/core';
import { Button, Checkbox, FormDualColumnLayout, FormLayout, Input, MessageType, Select } from '@univerjs/design';
import { ILayoutService, IMessageService, useDebounceFn, useDependency, useObservable } from '@univerjs/ui';
@@ -88,7 +89,7 @@ export const FindDialog = forwardRef(function FindDialogImpl(_props, ref) {
`}
onClick={revealReplace}
>
- {localeService.t('find-replace.dialog.advanced-finding')}
+ {localeService.t<LocaleKey>('find-replace.dialog.advanced-finding')}
</a>
</div>
</>
@@ -166,7 +167,7 @@ export const ReplaceDialog = forwardRef(function ReplaceDialogImpl(_props, ref)
if (shouldDisplayNoMatchInfo) {
messageService.show({
- content: localeService.t('find-replace.dialog.no-match'),
+ content: localeService.t<LocaleKey>('find-replace.dialog.no-match'),
type: MessageType.Warning,
duration: 5000,
});
@@ -175,7 +176,7 @@ export const ReplaceDialog = forwardRef(function ReplaceDialogImpl(_props, ref)
return (
<div>
- <FormLayout label={localeService.t('find-replace.dialog.find')}>
+ <FormLayout label={localeService.t<LocaleKey>('find-replace.dialog.find')}>
<SearchInput
findCompleted={findCompleted}
className="univer-find-input"
@@ -186,22 +187,22 @@ export const ReplaceDialog = forwardRef(function ReplaceDialogImpl(_props, ref)
onChange={onFindStringChange}
/>
</FormLayout>
- <FormLayout label={localeService.t('find-replace.dialog.replace')}>
+ <FormLayout label={localeService.t<LocaleKey>('find-replace.dialog.replace')}>
<Input
- placeholder={localeService.t('find-replace.dialog.replace-placeholder')}
+ placeholder={localeService.t<LocaleKey>('find-replace.dialog.replace-placeholder')}
value={replaceString}
onChange={(value) => onReplaceStringChange(value)}
/>
</FormLayout>
- <FormLayout label={localeService.t('find-replace.dialog.find-direction.title')}>
+ <FormLayout label={localeService.t<LocaleKey>('find-replace.dialog.find-direction.title')}>
<Select value={findDirection} options={findDirectionOptions} onChange={onChangeFindDirection} />
</FormLayout>
<FormDualColumnLayout>
<>
- <FormLayout label={localeService.t('find-replace.dialog.find-scope.title')}>
+ <FormLayout label={localeService.t<LocaleKey>('find-replace.dialog.find-scope.title')}>
<Select value={findScope} options={findScopeOptions} onChange={onChangeFindScope} />
</FormLayout>
- <FormLayout label={localeService.t('find-replace.dialog.find-by.title')}>
+ <FormLayout label={localeService.t<LocaleKey>('find-replace.dialog.find-by.title')}>
<Select value={findBy} options={findByOptions} onChange={onChangeFindBy} />
</FormLayout>
</>
@@ -215,7 +216,7 @@ export const ReplaceDialog = forwardRef(function ReplaceDialogImpl(_props, ref)
findReplaceService.changeCaseSensitive(checked as boolean);
}}
>
- {localeService.t('find-replace.dialog.case-sensitive')}
+ {localeService.t<LocaleKey>('find-replace.dialog.case-sensitive')}
</Checkbox>
</FormLayout>
<FormLayout>
@@ -225,16 +226,16 @@ export const ReplaceDialog = forwardRef(function ReplaceDialogImpl(_props, ref)
findReplaceService.changeMatchesTheWholeCell(checked as boolean);
}}
>
- {localeService.t('find-replace.dialog.match-the-whole-cell')}
+ {localeService.t<LocaleKey>('find-replace.dialog.match-the-whole-cell')}
</Checkbox>
</FormLayout>
</>
</FormDualColumnLayout>
<div className="univer-mt-6 univer-flex univer-justify-between">
- <Button variant="primary" onClick={onClickFindButton} disabled={findDisabled}>{localeService.t('find-replace.dialog.find')}</Button>
+ <Button variant="primary" onClick={onClickFindButton} disabled={findDisabled}>{localeService.t<LocaleKey>('find-replace.dialog.find')}</Button>
<span className="univer-inline-flex univer-gap-2">
- <Button disabled={replaceDisabled} onClick={onClickReplaceButton}>{localeService.t('find-replace.dialog.replace')}</Button>
- <Button disabled={replaceAllDisabled} onClick={onClickReplaceAllButton}>{localeService.t('find-replace.dialog.replace-all')}</Button>
+ <Button disabled={replaceDisabled} onClick={onClickReplaceButton}>{localeService.t<LocaleKey>('find-replace.dialog.replace')}</Button>
+ <Button disabled={replaceAllDisabled} onClick={onClickReplaceAllButton}>{localeService.t<LocaleKey>('find-replace.dialog.replace-all')}</Button>
</span>
</div>
</div>
@@ -306,8 +307,8 @@ function useFindScopeOptions(localeService: LocaleService): Array<{ label: strin
const locale = localeService.getCurrentLocale();
const options = useMemo(() => {
return [
- { label: localeService.t('find-replace.dialog.find-scope.current-sheet'), value: FindScope.SUBUNIT },
- { label: localeService.t('find-replace.dialog.find-scope.workbook'), value: FindScope.UNIT },
+ { label: localeService.t<LocaleKey>('find-replace.dialog.find-scope.current-sheet'), value: FindScope.SUBUNIT },
+ { label: localeService.t<LocaleKey>('find-replace.dialog.find-scope.workbook'), value: FindScope.UNIT },
];
}, [locale]);
@@ -318,8 +319,8 @@ function useFindDirectionOptions(localeService: LocaleService): Array<{ label: s
const locale = localeService.getCurrentLocale();
const options = useMemo(() => {
return [
- { label: localeService.t('find-replace.dialog.find-direction.row'), value: FindDirection.ROW },
- { label: localeService.t('find-replace.dialog.find-direction.column'), value: FindDirection.COLUMN },
+ { label: localeService.t<LocaleKey>('find-replace.dialog.find-direction.row'), value: FindDirection.ROW },
+ { label: localeService.t<LocaleKey>('find-replace.dialog.find-direction.column'), value: FindDirection.COLUMN },
];
}, [locale]);
@@ -330,8 +331,8 @@ function useFindByOptions(localeService: LocaleService): Array<{ label: string;
const locale = localeService.getCurrentLocale();
const options = useMemo(() => {
return [
- { label: localeService.t('find-replace.dialog.find-by.value'), value: FindBy.VALUE },
- { label: localeService.t('find-replace.dialog.find-by.formula'), value: FindBy.FORMULA },
+ { label: localeService.t<LocaleKey>('find-replace.dialog.find-by.value'), value: FindBy.VALUE },
+ { label: localeService.t<LocaleKey>('find-replace.dialog.find-by.formula'), value: FindBy.FORMULA },
];
}, [locale]);
diff --git a/packages/find-replace/src/views/dialog/SearchInput.tsx b/packages/find-replace/src/views/dialog/SearchInput.tsx
index 422891fb17..6ce0533eab 100644
--- a/packages/find-replace/src/views/dialog/SearchInput.tsx
+++ b/packages/find-replace/src/views/dialog/SearchInput.tsx
@@ -15,6 +15,7 @@
*/
import type { IInputProps } from '@univerjs/design';
+import type { LocaleKey } from '../../locale/types';
import type { IFindReplaceService } from '../../services/find-replace.service';
import { LocaleService } from '@univerjs/core';
import { Input, Pager } from '@univerjs/design';
@@ -45,7 +46,7 @@ export function SearchInput(props: ISearchInputProps) {
const [value, setValue] = useState(initialFindString);
const noResult = findComplete && matchesCount === 0;
const text = noResult
- ? localeService.t('find-replace.dialog.no-result')
+ ? localeService.t<LocaleKey>('find-replace.dialog.no-result')
: matchesCount === 0
? ' '
: undefined;
@@ -67,7 +68,7 @@ export function SearchInput(props: ISearchInputProps) {
<Input
data-u-comp="search-input"
autoFocus
- placeholder={localeService.t('find-replace.dialog.find-placeholder')}
+ placeholder={localeService.t<LocaleKey>('find-replace.dialog.find-placeholder')}
value={value}
onChange={(value) => {
setValue(value);
diff --git a/packages/sheets-conditional-formatting-ui/src/controllers/cf.panel.controller.ts b/packages/sheets-conditional-formatting-ui/src/controllers/cf.panel.controller.ts
index 14e9e44ea2..6dad4cc04f 100644
--- a/packages/sheets-conditional-formatting-ui/src/controllers/cf.panel.controller.ts
+++ b/packages/sheets-conditional-formatting-ui/src/controllers/cf.panel.controller.ts
@@ -16,6 +16,7 @@
import type { IDisposable } from '@univerjs/core';
import type { IConditionFormattingRule } from '@univerjs/sheets-conditional-formatting';
+import type { LocaleKey } from '../locale/types';
import { Disposable, generateRandomId, Inject, Injector, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
import { ComponentManager, ISidebarService } from '@univerjs/ui';
@@ -52,7 +53,7 @@ export class ConditionalFormattingPanelController extends Disposable {
openPanel(rule?: IConditionFormattingRule) {
const props = {
id: CF_PANEL_KEY,
- header: { title: this._localeService.t('sheets-conditional-formatting-ui.title') },
+ header: { title: this._localeService.t<LocaleKey>('sheets-conditional-formatting-ui.title') },
children: {
label: CF_PANEL_KEY,
rule,
diff --git a/packages/sheets-conditional-formatting-ui/src/controllers/cf.permission.controller.ts b/packages/sheets-conditional-formatting-ui/src/controllers/cf.permission.controller.ts
index da3122dc2c..5bd3250730 100644
--- a/packages/sheets-conditional-formatting-ui/src/controllers/cf.permission.controller.ts
+++ b/packages/sheets-conditional-formatting-ui/src/controllers/cf.permission.controller.ts
@@ -16,8 +16,15 @@
import type { ICommandInfo } from '@univerjs/core';
import type { IAddCfCommandParams } from '@univerjs/sheets-conditional-formatting';
+import type { LocaleKey } from '../locale/types';
import { Disposable, ICommandService, Inject, LocaleService } from '@univerjs/core';
-import { RangeProtectionPermissionEditPoint, SheetPermissionCheckController, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission } from '@univerjs/sheets';
+import {
+ RangeProtectionPermissionEditPoint,
+ SheetPermissionCheckController,
+ WorkbookEditablePermission,
+ WorksheetEditPermission,
+ WorksheetSetCellStylePermission,
+} from '@univerjs/sheets';
import { AddCfCommand } from '@univerjs/sheets-conditional-formatting';
export class ConditionalFormattingPermissionController extends Disposable {
@@ -43,7 +50,9 @@ export class ConditionalFormattingPermissionController extends Disposable {
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
}, ranges, unitId, subUnitId);
if (!permission) {
- this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t('sheets-conditional-formatting-ui.permission.dialog.setStyleErr'));
+ this._sheetPermissionCheckController.blockExecuteWithoutPermission(
+ this._localeService.t<LocaleKey>('sheets-conditional-formatting-ui.permission.dialog.setStyleErr')
+ );
}
}
})
diff --git a/packages/sheets-conditional-formatting-ui/src/locale/types.ts b/packages/sheets-conditional-formatting-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-conditional-formatting-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-conditional-formatting-ui/src/menu/manage-rule.ts b/packages/sheets-conditional-formatting-ui/src/menu/manage-rule.ts
index b8ae551f99..2a30964845 100644
--- a/packages/sheets-conditional-formatting-ui/src/menu/manage-rule.ts
+++ b/packages/sheets-conditional-formatting-ui/src/menu/manage-rule.ts
@@ -15,7 +15,8 @@
*/
import type { IAccessor, Workbook } from '@univerjs/core';
-import type { IMenuSelectorItem } from '@univerjs/ui';
+import type { IMenuSelectorItem, IValueOption } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { ICommandService, IUniverInstanceService, Rectangle, UniverInstanceType } from '@univerjs/core';
import {
checkRangesEditablePermission,
@@ -50,7 +51,7 @@ const commandList = [
MoveConditionalRuleMutation.id,
];
-const commonSelections = [
+const commonSelections: IValueOption<LocaleKey>[] = [
{
label: {
name: 'sheets-conditional-formatting-ui.ruleType.highlightCell',
@@ -125,7 +126,7 @@ const commonSelections = [
];
// eslint-disable-next-line max-lines-per-function
-export const FactoryManageConditionalFormattingRule = (accessor: IAccessor): IMenuSelectorItem => {
+export function FactoryManageConditionalFormattingRule(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
const selectionManagerService = accessor.get(SheetsSelectionsService);
const commandService = accessor.get(ICommandService);
const univerInstanceService = accessor.get(IUniverInstanceService);
@@ -137,7 +138,9 @@ export const FactoryManageConditionalFormattingRule = (accessor: IAccessor): IMe
new Observable<null>((commandSubscribe) => {
const disposable = commandService.onCommandExecuted((commandInfo) => {
const { id, params } = commandInfo;
- const unitId = univerInstanceService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET)?.getUnitId();
+ const unitId = univerInstanceService
+ .getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET)
+ ?.getUnitId();
if (commandList.includes(id) && (params as { unitId: string }).unitId === unitId) {
commandSubscribe.next(null);
}
@@ -186,7 +189,7 @@ export const FactoryManageConditionalFormattingRule = (accessor: IAccessor): IMe
subscriber.next(hasPermission);
})
);
- const selections$ = new Observable((subscriber) => {
+ const selections$ = new Observable<IValueOption<LocaleKey>[]>((subscriber) => {
clearRangeEnable$.subscribe((v) => {
const item = commonSelections.find((item) => item.value === CF_MENU_OPERATION.clearRangeRules);
if (item) {
@@ -210,6 +213,10 @@ export const FactoryManageConditionalFormattingRule = (accessor: IAccessor): IMe
tooltip: 'sheets-conditional-formatting-ui.title',
selections: selections$,
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetSetCellStylePermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
- } as IMenuSelectorItem;
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetSetCellStylePermission, WorksheetEditPermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
+ };
};
diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/RuleEdit.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/RuleEdit.tsx
index e20e669cf0..b8c88ed332 100644
--- a/packages/sheets-conditional-formatting-ui/src/views/panel/RuleEdit.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/RuleEdit.tsx
@@ -21,6 +21,7 @@ import type {
IConditionFormattingRule,
ISetCfCommandParams,
} from '@univerjs/sheets-conditional-formatting';
+import type { LocaleKey } from '../../locale/types';
import type { IStyleEditorProps } from './rule-edit/type';
import {
ICommandService,
@@ -92,12 +93,12 @@ export const RuleEdit = (props: IRuleEditProps) => {
}, [props.rule]);
const options = [
- { label: localeService.t('sheets-conditional-formatting-ui.ruleType.highlightCell'), value: '1' },
- { label: localeService.t('sheets-conditional-formatting-ui.panel.rankAndAverage'), value: '2' },
- { label: localeService.t('sheets-conditional-formatting-ui.ruleType.dataBar'), value: '3' },
- { label: localeService.t('sheets-conditional-formatting-ui.ruleType.colorScale'), value: '4' },
- { label: localeService.t('sheets-conditional-formatting-ui.ruleType.formula'), value: '5' },
- { label: localeService.t('sheets-conditional-formatting-ui.ruleType.iconSet'), value: '6' },
+ { label: localeService.t<LocaleKey>('sheets-conditional-formatting-ui.ruleType.highlightCell'), value: '1' },
+ { label: localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.rankAndAverage'), value: '2' },
+ { label: localeService.t<LocaleKey>('sheets-conditional-formatting-ui.ruleType.dataBar'), value: '3' },
+ { label: localeService.t<LocaleKey>('sheets-conditional-formatting-ui.ruleType.colorScale'), value: '4' },
+ { label: localeService.t<LocaleKey>('sheets-conditional-formatting-ui.ruleType.formula'), value: '5' },
+ { label: localeService.t<LocaleKey>('sheets-conditional-formatting-ui.ruleType.iconSet'), value: '6' },
];
const [ruleType, setRuleType] = useState(() => {
@@ -213,7 +214,7 @@ export const RuleEdit = (props: IRuleEditProps) => {
};
const ranges = getRanges();
if (ranges.length < 1) {
- setErrorText(localeService.t('sheets-conditional-formatting-ui.errorMessage.rangeError'));
+ setErrorText(localeService.t<LocaleKey>('sheets-conditional-formatting-ui.errorMessage.rangeError'));
return;
}
const beforeSubmitResult = interceptorManager.fetchThroughInterceptors(interceptorManager.getInterceptPoints().beforeSubmit)(true, null);
@@ -253,12 +254,12 @@ export const RuleEdit = (props: IRuleEditProps) => {
if (v) {
if (rangeText.length < 1) {
- setErrorText(localeService.t('sheets-conditional-formatting-ui.errorMessage.rangeError'));
+ setErrorText(localeService.t<LocaleKey>('sheets-conditional-formatting-ui.errorMessage.rangeError'));
} else {
setErrorText(undefined);
}
} else {
- setErrorText(localeService.t('sheets-conditional-formatting-ui.errorMessage.rangeError'));
+ setErrorText(localeService.t<LocaleKey>('sheets-conditional-formatting-ui.errorMessage.rangeError'));
}
};
return (
@@ -269,7 +270,7 @@ export const RuleEdit = (props: IRuleEditProps) => {
dark:!univer-text-gray-200
`}
>
- {localeService.t('sheets-conditional-formatting-ui.panel.range')}
+ {localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.range')}
</div>
<div className="univer-mt-4">
<RangeSelector
@@ -287,7 +288,7 @@ export const RuleEdit = (props: IRuleEditProps) => {
dark:!univer-text-gray-200
`}
>
- {localeService.t('sheets-conditional-formatting-ui.panel.styleType')}
+ {localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.styleType')}
</div>
<Select
className="univer-mt-4 univer-w-full"
@@ -301,9 +302,9 @@ export const RuleEdit = (props: IRuleEditProps) => {
onChange={onStyleChange}
/>
<div className="univer-mt-4 univer-flex univer-justify-end">
- <Button onClick={handleCancel}>{localeService.t('sheets-conditional-formatting-ui.panel.cancel')}</Button>
+ <Button onClick={handleCancel}>{localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.cancel')}</Button>
<Button className="univer-ml-3" variant="primary" onClick={handleSubmit}>
- {localeService.t('sheets-conditional-formatting-ui.panel.submit')}
+ {localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.submit')}
</Button>
</div>
</div>
diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/RuleList.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/RuleList.tsx
index f97d5ddea3..6f1baa4ffb 100644
--- a/packages/sheets-conditional-formatting-ui/src/views/panel/RuleList.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/RuleList.tsx
@@ -15,12 +15,29 @@
*/
import type { IRange, Workbook } from '@univerjs/core';
-import type { IConditionFormattingRule, IDeleteCfCommandParams, IMoveCfCommandParams } from '@univerjs/sheets-conditional-formatting';
-import { ICommandService, Injector, IUniverInstanceService, LocaleService, Rectangle, UniverInstanceType } from '@univerjs/core';
+import type {
+ IConditionFormattingRule,
+ IDeleteCfCommandParams,
+ IMoveCfCommandParams,
+} from '@univerjs/sheets-conditional-formatting';
+import type { LocaleKey } from '../../locale/types';
+import {
+ ICommandService,
+ Injector,
+ IUniverInstanceService,
+ LocaleService,
+ Rectangle,
+ UniverInstanceType,
+} from '@univerjs/core';
import { clsx, DraggableList, Select, Tooltip } from '@univerjs/design';
import { serializeRange } from '@univerjs/engine-formula';
import { DeleteIcon, GripVerticalIcon, IncreaseIcon } from '@univerjs/icons';
-import { checkRangesEditablePermission, SetSelectionsOperation, SetWorksheetActiveOperation, SheetsSelectionsService } from '@univerjs/sheets';
+import {
+ checkRangesEditablePermission,
+ SetSelectionsOperation,
+ SetWorksheetActiveOperation,
+ SheetsSelectionsService,
+} from '@univerjs/sheets';
import {
AddConditionalRuleMutation,
CFRuleType,
@@ -48,56 +65,56 @@ const getRuleDescribe = (rule: IConditionFormattingRule, localeService: LocaleSe
const ruleConfig = rule.rule;
switch (ruleConfig.type) {
case CFRuleType.colorScale: {
- return localeService.t('sheets-conditional-formatting-ui.ruleType.colorScale');
+ return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.ruleType.colorScale');
}
case CFRuleType.dataBar: {
- return localeService.t('sheets-conditional-formatting-ui.ruleType.dataBar');
+ return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.ruleType.dataBar');
}
case CFRuleType.iconSet: {
- return localeService.t('sheets-conditional-formatting-ui.ruleType.iconSet');
+ return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.ruleType.iconSet');
}
case CFRuleType.highlightCell: {
switch (ruleConfig.subType) {
case CFSubRuleType.average: {
const operator = ruleConfig.operator;
- return localeService.t(`sheets-conditional-formatting-ui.preview.describe.${operator}`, localeService.t('sheets-conditional-formatting-ui.subRuleType.average'));
+ return localeService.t<LocaleKey>(`sheets-conditional-formatting-ui.preview.describe.${operator}`, localeService.t<LocaleKey>('sheets-conditional-formatting-ui.subRuleType.average'));
}
case CFSubRuleType.duplicateValues: {
- return localeService.t('sheets-conditional-formatting-ui.subRuleType.duplicateValues');
+ return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.subRuleType.duplicateValues');
}
case CFSubRuleType.uniqueValues: {
- return localeService.t('sheets-conditional-formatting-ui.subRuleType.uniqueValues');
+ return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.subRuleType.uniqueValues');
}
case CFSubRuleType.number: {
const operator = ruleConfig.operator;
- return localeService.t(`sheets-conditional-formatting-ui.preview.describe.${operator}`, ...Array.isArray(ruleConfig.value) ? (ruleConfig.value.map((e) => String(e))) : [String(ruleConfig.value || '')]);
+ return localeService.t<LocaleKey>(`sheets-conditional-formatting-ui.preview.describe.${operator}`, ...Array.isArray(ruleConfig.value) ? (ruleConfig.value.map((e) => String(e))) : [String(ruleConfig.value || '')]);
}
case CFSubRuleType.text: {
const operator = ruleConfig.operator;
- return localeService.t(`sheets-conditional-formatting-ui.preview.describe.${operator}`, ruleConfig.value || '');
+ return localeService.t<LocaleKey>(`sheets-conditional-formatting-ui.preview.describe.${operator}`, ruleConfig.value || '');
}
case CFSubRuleType.timePeriod: {
const operator = ruleConfig.operator;
- return localeService.t(`sheets-conditional-formatting-ui.preview.describe.${operator}`);
+ return localeService.t<LocaleKey>(`sheets-conditional-formatting-ui.preview.describe.${operator}`);
}
case CFSubRuleType.rank: {
if (ruleConfig.isPercent) {
if (ruleConfig.isBottom) {
- return localeService.t('sheets-conditional-formatting-ui.preview.describe.bottomNPercent', String(ruleConfig.value));
+ return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.preview.describe.bottomNPercent', String(ruleConfig.value));
} else {
- return localeService.t('sheets-conditional-formatting-ui.preview.describe.topNPercent', String(ruleConfig.value));
+ return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.preview.describe.topNPercent', String(ruleConfig.value));
}
} else {
if (ruleConfig.isBottom) {
- return localeService.t('sheets-conditional-formatting-ui.preview.describe.bottomN', String(ruleConfig.value));
+ return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.preview.describe.bottomN', String(ruleConfig.value));
} else {
- return localeService.t('sheets-conditional-formatting-ui.preview.describe.topN', String(ruleConfig.value));
+ return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.preview.describe.topN', String(ruleConfig.value));
}
}
}
case CFSubRuleType.formula: {
- return localeService.t('sheets-conditional-formatting-ui.ruleType.formula');
+ return localeService.t<LocaleKey>('sheets-conditional-formatting-ui.ruleType.formula');
}
}
}
@@ -130,8 +147,8 @@ export const RuleList = (props: IRuleListProps) => {
const [draggingId, setDraggingId] = useState<string>('');
const selectOption = [
- { label: localeService.t('sheets-conditional-formatting-ui.panel.workSheet'), value: '2' },
- { label: localeService.t('sheets-conditional-formatting-ui.panel.selectedRange'), value: '1' },
+ { label: localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.workSheet'), value: '2' },
+ { label: localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.selectedRange'), value: '1' },
];
const getRuleList = () => {
@@ -291,7 +308,7 @@ export const RuleList = (props: IRuleListProps) => {
).map((ele, index) => <span key={index}>{ele}</span>)}
</div>
<div className="univer-flex univer-justify-end univer-space-x-2">
- <Tooltip title={localeService.t('sheets-conditional-formatting-ui.panel.createRule')} placement="bottom">
+ <Tooltip title={localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.createRule')} placement="bottom">
<a
className="univer-size-5 univer-cursor-pointer"
onClick={handleCreate}
@@ -301,7 +318,7 @@ export const RuleList = (props: IRuleListProps) => {
</Tooltip>
{(ruleList.length && isHasAllRuleEditPermission)
? (
- <Tooltip title={localeService.t('sheets-conditional-formatting-ui.panel.clear')} placement="bottom">
+ <Tooltip title={localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.clear')} placement="bottom">
<a
className="univer-size-5 univer-cursor-pointer"
onClick={handleClear}
diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/DataBar.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/DataBar.tsx
index 25d5438612..659c836a4e 100644
--- a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/DataBar.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/DataBar.tsx
@@ -17,10 +17,17 @@
import type { Workbook } from '@univerjs/core';
import type { IConditionalFormattingRuleConfig, IValueConfig } from '@univerjs/sheets-conditional-formatting';
import type { IFormulaEditorRef } from '@univerjs/sheets-formula-ui';
+import type { LocaleKey } from '../../../locale/types';
import type { IStyleEditorProps } from './type';
import { IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
import { borderClassName, Checkbox, clsx, InputNumber, Radio, RadioGroup, Select } from '@univerjs/design';
-import { CFRuleType, CFValueType, createDefaultValueByValueType, defaultDataBarNativeColor, defaultDataBarPositiveColor } from '@univerjs/sheets-conditional-formatting';
+import {
+ CFRuleType,
+ CFValueType,
+ createDefaultValueByValueType,
+ defaultDataBarNativeColor,
+ defaultDataBarPositiveColor,
+} from '@univerjs/sheets-conditional-formatting';
import { FormulaEditor } from '@univerjs/sheets-formula-ui';
import { useDependency, useSidebarClick } from '@univerjs/ui';
import { useEffect, useMemo, useRef, useState } from 'react';
@@ -28,7 +35,7 @@ import { ColorPicker } from '../../ColorPicker';
import { Preview } from '../../Preview';
import { previewClassName } from './styles';
-const createOptionItem = (text: CFValueType, localeService: LocaleService) => ({ label: localeService.t(`sheets-conditional-formatting-ui.valueType.${text}`), value: text });
+const createOptionItem = (text: CFValueType, localeService: LocaleService) => ({ label: localeService.t<LocaleKey>(`sheets-conditional-formatting-ui.valueType.${text}`), value: text });
const InputText = (props: { disabled?: boolean; id: string; className: string; type: CFValueType; value: string | number; onChange: (v: string | number) => void }) => {
const { onChange, className, value, type, id, disabled = false } = props;
@@ -261,7 +268,7 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {
dark:!univer-text-gray-200
`}
>
- {localeService.t('sheets-conditional-formatting-ui.panel.styleRule')}
+ {localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.styleRule')}
</div>
<div className={previewClassName}>
<Preview
@@ -284,7 +291,7 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {
dark:!univer-text-gray-200
`}
>
- {localeService.t('sheets-conditional-formatting-ui.panel.fillType')}
+ {localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.fillType')}
</div>
<div className="univer-ml-1 univer-mt-3 univer-flex univer-items-center">
@@ -305,10 +312,10 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {
}}
>
<Radio value="0">
- <span className="univer-text-xs">{localeService.t('sheets-conditional-formatting-ui.panel.pureColor')}</span>
+ <span className="univer-text-xs">{localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.pureColor')}</span>
</Radio>
<Radio value="1">
- <span className="univer-text-xs">{localeService.t('sheets-conditional-formatting-ui.panel.gradient')}</span>
+ <span className="univer-text-xs">{localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.gradient')}</span>
</Radio>
</RadioGroup>
<div className="univer-ml-6 univer-flex univer-items-center univer-text-xs">
@@ -328,7 +335,7 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {
});
}}
/>
- {localeService.t('sheets-conditional-formatting-ui.panel.onlyShowDataBar')}
+ {localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.onlyShowDataBar')}
</div>
</div>
</div>
@@ -339,12 +346,12 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {
dark:!univer-text-gray-200
`}
>
- {localeService.t('sheets-conditional-formatting-ui.panel.colorSet')}
+ {localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.colorSet')}
</div>
<div className="univer-ml-1 univer-mt-3 univer-flex univer-items-center">
<div className="univer-flex univer-items-center">
<div className="univer-text-xs">
- {localeService.t('sheets-conditional-formatting-ui.panel.native')}
+ {localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.native')}
</div>
<ColorPicker
color={nativeColor}
@@ -353,7 +360,7 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {
</div>
<div className="univer-ml-3 univer-flex univer-items-center">
<div className="univer-text-xs">
- {localeService.t('sheets-conditional-formatting-ui.panel.positive')}
+ {localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.positive')}
</div>
<ColorPicker
color={positiveColor}
@@ -370,7 +377,7 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {
dark:!univer-text-gray-200
`}
>
- {localeService.t('sheets-conditional-formatting-ui.valueType.min')}
+ {localeService.t<LocaleKey>('sheets-conditional-formatting-ui.valueType.min')}
</div>
<div className="univer-mt-3 univer-flex univer-items-center">
<Select
@@ -421,7 +428,7 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {
dark:!univer-text-gray-200
`}
>
- {localeService.t('sheets-conditional-formatting-ui.valueType.max')}
+ {localeService.t<LocaleKey>('sheets-conditional-formatting-ui.valueType.max')}
</div>
<div className="univer-mt-3 univer-flex univer-items-center">
<Select
diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/Formula.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/Formula.tsx
index f11b3224da..656ddc2c09 100644
--- a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/Formula.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/Formula.tsx
@@ -22,6 +22,7 @@ import type {
IRankHighlightCell,
} from '@univerjs/sheets-conditional-formatting';
import type { IFormulaEditorRef } from '@univerjs/sheets-formula-ui';
+import type { LocaleKey } from '../../../locale/types';
import type { IStyleEditorProps } from './type';
import { IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
import { borderClassName, clsx } from '@univerjs/design';
@@ -85,7 +86,7 @@ export const FormulaStyleEditor = (props: IStyleEditorProps) => {
&& lexerTreeBuilder.checkIfAddBracket(formula) === 0;
if (formulaError || !isFormulaValid) {
- setFormulaError(localeService.t('sheets-conditional-formatting-ui.errorMessage.formulaError'));
+ setFormulaError(localeService.t<LocaleKey>('sheets-conditional-formatting-ui.errorMessage.formulaError'));
return false;
}
return next(v);
@@ -120,7 +121,7 @@ export const FormulaStyleEditor = (props: IStyleEditorProps) => {
dark:!univer-text-gray-200
`}
>
- {localeService.t('sheets-conditional-formatting-ui.panel.styleRule')}
+ {localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.styleRule')}
</div>
<div className="univer-mt-3">
<FormulaEditor
@@ -145,7 +146,7 @@ export const FormulaStyleEditor = (props: IStyleEditorProps) => {
}}
onVerify={(result, formula) => {
if (!result || formula.length === 1) {
- setFormulaError(localeService.t('sheets-conditional-formatting-ui.errorMessage.formulaError'));
+ setFormulaError(localeService.t<LocaleKey>('sheets-conditional-formatting-ui.errorMessage.formulaError'));
} else {
setFormulaError(undefined);
}
diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/Rank.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/Rank.tsx
index 9fd823bf7c..6da4a02e26 100644
--- a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/Rank.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/Rank.tsx
@@ -14,7 +14,13 @@
* limitations under the License.
*/
-import type { IAverageHighlightCell, IConditionalFormattingRuleConfig, IHighlightCell, IRankHighlightCell } from '@univerjs/sheets-conditional-formatting';
+import type {
+ IAverageHighlightCell,
+ IConditionalFormattingRuleConfig,
+ IHighlightCell,
+ IRankHighlightCell,
+} from '@univerjs/sheets-conditional-formatting';
+import type { LocaleKey } from '../../../locale/types';
import type { IStyleEditorProps } from './type';
import { LocaleService } from '@univerjs/core';
import { Checkbox, InputNumber, Select } from '@univerjs/design';
@@ -30,7 +36,7 @@ export const RankStyleEditor = (props: IStyleEditorProps) => {
const localeService = useDependency(LocaleService);
const rule = props.rule?.type === CFRuleType.highlightCell ? props.rule : undefined as IRankHighlightCell | IAverageHighlightCell | undefined;
- const options = [{ label: localeService.t('sheets-conditional-formatting-ui.panel.isNotBottom'), value: 'isNotBottom' }, { label: localeService.t('sheets-conditional-formatting-ui.panel.isBottom'), value: 'isBottom' }, { label: localeService.t('sheets-conditional-formatting-ui.panel.greaterThanAverage'), value: 'greaterThanAverage' }, { label: localeService.t('sheets-conditional-formatting-ui.panel.lessThanAverage'), value: 'lessThanAverage' }];
+ const options = [{ label: localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.isNotBottom'), value: 'isNotBottom' }, { label: localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.isBottom'), value: 'isBottom' }, { label: localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.greaterThanAverage'), value: 'greaterThanAverage' }, { label: localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.lessThanAverage'), value: 'lessThanAverage' }];
const [type, setType] = useState(() => {
const defaultV = options[0].value;
@@ -147,7 +153,7 @@ export const RankStyleEditor = (props: IStyleEditorProps) => {
dark:!univer-text-gray-200
`}
>
- {localeService.t('sheets-conditional-formatting-ui.panel.styleRule')}
+ {localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.styleRule')}
</div>
<Select
className="univer-mt-3 univer-w-full"
@@ -180,7 +186,7 @@ export const RankStyleEditor = (props: IStyleEditorProps) => {
_onChange({ type, isPercent: !!v, value, style });
}}
/>
- {localeService.t('sheets-conditional-formatting-ui.valueType.percent')}
+ {localeService.t<LocaleKey>('sheets-conditional-formatting-ui.valueType.percent')}
</div>
</div>
diff --git a/packages/sheets-conditional-formatting/src/locale/types.ts b/packages/sheets-conditional-formatting/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-conditional-formatting/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-crosshair-highlight/src/locale/types.ts b/packages/sheets-crosshair-highlight/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-crosshair-highlight/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-crosshair-highlight/src/menu/crosshair.menu.ts b/packages/sheets-crosshair-highlight/src/menu/crosshair.menu.ts
index dc9cd366de..b98f4ccffc 100644
--- a/packages/sheets-crosshair-highlight/src/menu/crosshair.menu.ts
+++ b/packages/sheets-crosshair-highlight/src/menu/crosshair.menu.ts
@@ -16,14 +16,18 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuSelectorItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { UniverInstanceType } from '@univerjs/core';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
-import { SetCrosshairHighlightColorOperation, ToggleCrosshairHighlightOperation } from '../commands/operations/operation';
+import {
+ SetCrosshairHighlightColorOperation,
+ ToggleCrosshairHighlightOperation,
+} from '../commands/operations/operation';
import { SheetsCrosshairHighlightService } from '../services/crosshair.service';
export const CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT = 'CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT';
-export function CrosshairHighlightMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function CrosshairHighlightMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
const crosshairHighlightService = accessor.get(SheetsCrosshairHighlightService);
return {
diff --git a/packages/sheets-data-validation-ui/src/controllers/dv-alert.controller.ts b/packages/sheets-data-validation-ui/src/controllers/dv-alert.controller.ts
index b17b1af127..dc9a6c3b1e 100644
--- a/packages/sheets-data-validation-ui/src/controllers/dv-alert.controller.ts
+++ b/packages/sheets-data-validation-ui/src/controllers/dv-alert.controller.ts
@@ -16,7 +16,15 @@
import type { Workbook } from '@univerjs/core';
import type { BaseDataValidator } from '@univerjs/data-validation';
-import { DataValidationStatus, Disposable, Inject, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
+import type { LocaleKey } from '../locale/types';
+import {
+ DataValidationStatus,
+ Disposable,
+ Inject,
+ IUniverInstanceService,
+ LocaleService,
+ UniverInstanceType,
+} from '@univerjs/core';
import { SheetDataValidationModel } from '@univerjs/sheets-data-validation';
import { CellAlertManagerService, CellAlertType, HoverManagerService } from '@univerjs/sheets-ui';
import { debounceTime } from 'rxjs';
@@ -73,7 +81,7 @@ export class DataValidationAlertController extends Disposable {
}
this._cellAlertManagerService.showAlert({
type: CellAlertType.ERROR,
- title: this._localeService.t('sheets-data-validation-ui.error.title'),
+ title: this._localeService.t<LocaleKey>('sheets-data-validation-ui.error.title'),
message: validator?.getRuleFinalError(rule, cellPos.location),
location: cellPos.location,
width: 200,
diff --git a/packages/sheets-data-validation-ui/src/controllers/dv-permission.controller.ts b/packages/sheets-data-validation-ui/src/controllers/dv-permission.controller.ts
index 6ae841733e..3396e16162 100644
--- a/packages/sheets-data-validation-ui/src/controllers/dv-permission.controller.ts
+++ b/packages/sheets-data-validation-ui/src/controllers/dv-permission.controller.ts
@@ -15,9 +15,19 @@
*/
import type { ICommandInfo } from '@univerjs/core';
-import type { IAddSheetDataValidationCommandParams, IUpdateSheetDataValidationRangeCommandParams } from '@univerjs/sheets-data-validation';
+import type {
+ IAddSheetDataValidationCommandParams,
+ IUpdateSheetDataValidationRangeCommandParams,
+} from '@univerjs/sheets-data-validation';
+import type { LocaleKey } from '../locale/types';
import { Disposable, ICommandService, Inject, LocaleService } from '@univerjs/core';
-import { RangeProtectionPermissionEditPoint, SheetPermissionCheckController, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission } from '@univerjs/sheets';
+import {
+ RangeProtectionPermissionEditPoint,
+ SheetPermissionCheckController,
+ WorkbookEditablePermission,
+ WorksheetEditPermission,
+ WorksheetSetCellStylePermission,
+} from '@univerjs/sheets';
import { AddSheetDataValidationCommand, UpdateSheetDataValidationRangeCommand } from '@univerjs/sheets-data-validation';
export class DataValidationPermissionController extends Disposable {
@@ -41,7 +51,7 @@ export class DataValidationPermissionController extends Disposable {
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
}, ranges, unitId, subUnitId);
if (!permission) {
- this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t('sheets-data-validation-ui.permission.dialog.setStyleErr'));
+ this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t<LocaleKey>('sheets-data-validation-ui.permission.dialog.setStyleErr'));
}
}
if (command.id === UpdateSheetDataValidationRangeCommand.id) {
@@ -52,7 +62,7 @@ export class DataValidationPermissionController extends Disposable {
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
}, ranges, unitId, subUnitId);
if (!permission) {
- this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t('sheets-data-validation-ui.permission.dialog.setStyleErr'));
+ this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t<LocaleKey>('sheets-data-validation-ui.permission.dialog.setStyleErr'));
}
}
})
diff --git a/packages/sheets-data-validation-ui/src/controllers/dv-reject-input.controller.ts b/packages/sheets-data-validation-ui/src/controllers/dv-reject-input.controller.ts
index e0b0069a87..29947bf240 100644
--- a/packages/sheets-data-validation-ui/src/controllers/dv-reject-input.controller.ts
+++ b/packages/sheets-data-validation-ui/src/controllers/dv-reject-input.controller.ts
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { LocaleKey } from '../locale/types';
import { DataValidationErrorStyle, DataValidationStatus, Disposable, Inject, LocaleService } from '@univerjs/core';
import { DataValidatorRegistryService } from '@univerjs/data-validation';
import { Button } from '@univerjs/design';
@@ -64,7 +65,7 @@ export class DataValidationRejectInputController extends Disposable {
this._dialogService.open({
width: 368,
title: {
- title: this._localeService.t('sheets-data-validation-ui.alert.title'),
+ title: this._localeService.t<LocaleKey>('sheets-data-validation-ui.alert.title'),
},
id: 'reject-input-dialog',
children: {
@@ -77,7 +78,7 @@ export class DataValidationRejectInputController extends Disposable {
variant: 'primary',
onClick: () => this._dialogService.close('reject-input-dialog'),
},
- this._localeService.t('sheets-data-validation-ui.alert.ok')
+ this._localeService.t<LocaleKey>('sheets-data-validation-ui.alert.ok')
),
},
onClose: () => {
@@ -95,7 +96,7 @@ export class DataValidationRejectInputController extends Disposable {
this._dialogService.open({
width: 368,
title: {
- title: this._localeService.t('sheets-data-validation-ui.alert.title'),
+ title: this._localeService.t<LocaleKey>('sheets-data-validation-ui.alert.title'),
},
id: 'reject-input-dialog',
children: {
@@ -108,7 +109,7 @@ export class DataValidationRejectInputController extends Disposable {
variant: 'primary',
onClick: () => this._dialogService.close('reject-input-dialog'),
},
- this._localeService.t('sheets-data-validation-ui.alert.ok')
+ this._localeService.t<LocaleKey>('sheets-data-validation-ui.alert.ok')
),
},
onClose: () => {
diff --git a/packages/sheets-data-validation-ui/src/locale/types.ts b/packages/sheets-data-validation-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-data-validation-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-data-validation-ui/src/menu/dv.menu.ts b/packages/sheets-data-validation-ui/src/menu/dv.menu.ts
index 3c1a3d19d8..14b863f647 100644
--- a/packages/sheets-data-validation-ui/src/menu/dv.menu.ts
+++ b/packages/sheets-data-validation-ui/src/menu/dv.menu.ts
@@ -16,8 +16,14 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { UniverInstanceType } from '@univerjs/core';
-import { RangeProtectionPermissionEditPoint, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission } from '@univerjs/sheets';
+import {
+ RangeProtectionPermissionEditPoint,
+ WorkbookEditablePermission,
+ WorksheetEditPermission,
+ WorksheetSetCellStylePermission,
+} from '@univerjs/sheets';
import { getCurrentRangeDisable$ } from '@univerjs/sheets-ui';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { AddSheetDataValidationAndOpenCommand } from '../commands/commands/data-validation-ui.command';
@@ -25,18 +31,22 @@ import { OpenValidationPanelOperation } from '../commands/operations/data-valida
export const DATA_VALIDATION_MENU_ID = 'sheet.menu.data-validation';
-export function dataValidationMenuFactory(accessor: IAccessor): IMenuItem {
+export function dataValidationMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: DATA_VALIDATION_MENU_ID,
type: MenuItemType.SUBITEMS,
icon: 'DataValidationIcon',
tooltip: 'sheets-data-validation-ui.title',
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetSetCellStylePermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetSetCellStylePermission, WorksheetEditPermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
};
}
-export function openDataValidationMenuFactory(_accessor: IAccessor): IMenuItem {
+export function openDataValidationMenuFactory(): IMenuItem<LocaleKey> {
return {
id: OpenValidationPanelOperation.id,
title: 'sheets-data-validation-ui.panel.title',
@@ -44,7 +54,7 @@ export function openDataValidationMenuFactory(_accessor: IAccessor): IMenuItem {
};
}
-export function addDataValidationMenuFactory(_accessor: IAccessor): IMenuItem {
+export function addDataValidationMenuFactory(): IMenuItem<LocaleKey> {
return {
id: AddSheetDataValidationAndOpenCommand.id,
title: 'sheets-data-validation-ui.panel.add',
diff --git a/packages/sheets-data-validation-ui/src/views/components/DataValidationList.tsx b/packages/sheets-data-validation-ui/src/views/components/DataValidationList.tsx
index 276d427006..c3b5c988ac 100644
--- a/packages/sheets-data-validation-ui/src/views/components/DataValidationList.tsx
+++ b/packages/sheets-data-validation-ui/src/views/components/DataValidationList.tsx
@@ -16,10 +16,16 @@
import type { ISheetDataValidationRule, Workbook } from '@univerjs/core';
import type { IAddSheetDataValidationCommandParams } from '@univerjs/sheets-data-validation';
+import type { LocaleKey } from '../../locale/types';
import { ICommandService, Injector, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
import { Button } from '@univerjs/design';
import { checkRangesEditablePermission } from '@univerjs/sheets';
-import { AddSheetDataValidationCommand, createDefaultNewRule, RemoveSheetAllDataValidationCommand, SheetDataValidationModel } from '@univerjs/sheets-data-validation';
+import {
+ AddSheetDataValidationCommand,
+ createDefaultNewRule,
+ RemoveSheetAllDataValidationCommand,
+ SheetDataValidationModel,
+} from '@univerjs/sheets-data-validation';
import { useDependency, useObservable } from '@univerjs/ui';
import { useEffect, useState } from 'react';
import { DataValidationPanelService } from '../../services/data-validation-panel.service';
@@ -119,12 +125,12 @@ export function DataValidationList(props: { workbook: Workbook }) {
{(rules.length && !hasDisableRule)
? (
<Button onClick={handleRemoveAll}>
- {localeService.t('sheets-data-validation-ui.panel.removeAll')}
+ {localeService.t<LocaleKey>('sheets-data-validation-ui.panel.removeAll')}
</Button>
)
: null}
<Button variant="primary" onClick={handleAddRule}>
- {localeService.t('sheets-data-validation-ui.panel.add')}
+ {localeService.t<LocaleKey>('sheets-data-validation-ui.panel.add')}
</Button>
</div>
</div>
diff --git a/packages/sheets-data-validation-ui/src/views/components/DataValidationOptions.tsx b/packages/sheets-data-validation-ui/src/views/components/DataValidationOptions.tsx
index 36ee201e9e..b6e65d5e96 100644
--- a/packages/sheets-data-validation-ui/src/views/components/DataValidationOptions.tsx
+++ b/packages/sheets-data-validation-ui/src/views/components/DataValidationOptions.tsx
@@ -15,6 +15,7 @@
*/
import type { IDataValidationRuleOptions } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import { DataValidationErrorStyle, LocaleService } from '@univerjs/core';
import { Checkbox, FormLayout, Input, Radio, RadioGroup } from '@univerjs/design';
import { MoreDownIcon, MoreUpIcon } from '@univerjs/icons';
@@ -44,7 +45,7 @@ export function DataValidationOptions(props: IDataValidationOptionsParams) {
`}
onClick={() => setShow(!show)}
>
- {localeService.t('sheets-data-validation-ui.panel.options')}
+ {localeService.t<LocaleKey>('sheets-data-validation-ui.panel.options')}
{show
? (
<MoreUpIcon className="univer-ml-1" />
@@ -57,22 +58,22 @@ export function DataValidationOptions(props: IDataValidationOptionsParams) {
<>
{ExtraOptions ? <ExtraOptions value={value} onChange={onChange} /> : null}
<FormLayout
- label={localeService.t('sheets-data-validation-ui.panel.invalid')}
+ label={localeService.t<LocaleKey>('sheets-data-validation-ui.panel.invalid')}
>
<RadioGroup
value={`${value.errorStyle ?? DataValidationErrorStyle.WARNING}`}
onChange={(errorStyle) => onChange({ ...value, errorStyle: +errorStyle })}
>
<Radio value={`${DataValidationErrorStyle.WARNING}`}>
- {localeService.t('sheets-data-validation-ui.panel.showWarning')}
+ {localeService.t<LocaleKey>('sheets-data-validation-ui.panel.showWarning')}
</Radio>
<Radio value={`${DataValidationErrorStyle.STOP}`}>
- {localeService.t('sheets-data-validation-ui.panel.rejectInput')}
+ {localeService.t<LocaleKey>('sheets-data-validation-ui.panel.rejectInput')}
</Radio>
</RadioGroup>
</FormLayout>
<FormLayout
- label={localeService.t('sheets-data-validation-ui.panel.messageInfo')}
+ label={localeService.t<LocaleKey>('sheets-data-validation-ui.panel.messageInfo')}
>
<Checkbox
checked={value.showErrorMessage}
@@ -81,7 +82,7 @@ export function DataValidationOptions(props: IDataValidationOptionsParams) {
showErrorMessage: !value.showErrorMessage,
})}
>
- {localeService.t('sheets-data-validation-ui.panel.showInfo')}
+ {localeService.t<LocaleKey>('sheets-data-validation-ui.panel.showInfo')}
</Checkbox>
</FormLayout>
{value.showErrorMessage
diff --git a/packages/sheets-data-validation-ui/src/views/components/DateShowTimeOption.tsx b/packages/sheets-data-validation-ui/src/views/components/DateShowTimeOption.tsx
index dc39b6576f..5c66e36a14 100644
--- a/packages/sheets-data-validation-ui/src/views/components/DateShowTimeOption.tsx
+++ b/packages/sheets-data-validation-ui/src/views/components/DateShowTimeOption.tsx
@@ -15,6 +15,7 @@
*/
import type { IDataValidationRuleOptions } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import { LocaleService } from '@univerjs/core';
import { Checkbox, FormLayout } from '@univerjs/design';
import { useDependency } from '@univerjs/ui';
@@ -43,7 +44,7 @@ export function DateShowTimeOption(props: IDateShowTimeOptionProps) {
});
}}
>
- {localeService.t('sheets-data-validation-ui.showTime.label')}
+ {localeService.t<LocaleKey>('sheets-data-validation-ui.showTime.label')}
</Checkbox>
</FormLayout>
);
diff --git a/packages/sheets-data-validation-ui/src/views/components/ListRenderModeInput.tsx b/packages/sheets-data-validation-ui/src/views/components/ListRenderModeInput.tsx
index b6d1dfa82f..17b60231b4 100644
--- a/packages/sheets-data-validation-ui/src/views/components/ListRenderModeInput.tsx
+++ b/packages/sheets-data-validation-ui/src/views/components/ListRenderModeInput.tsx
@@ -15,6 +15,7 @@
*/
import type { IDataValidationRuleOptions } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import { DataValidationRenderMode, LocaleService } from '@univerjs/core';
import { FormLayout, Radio, RadioGroup } from '@univerjs/design';
import { useDependency } from '@univerjs/ui';
@@ -30,16 +31,16 @@ export function ListRenderModeInput(props: IListRenderModeInputProps) {
const localeService = useDependency(LocaleService);
return (
- <FormLayout label={localeService.t('sheets-data-validation-ui.renderMode.label')}>
+ <FormLayout label={localeService.t<LocaleKey>('sheets-data-validation-ui.renderMode.label')}>
<RadioGroup value={`${value.renderMode ?? DataValidationRenderMode.CUSTOM}`} onChange={(renderMode) => onChange({ ...value, renderMode: +renderMode })}>
<Radio value={`${DataValidationRenderMode.CUSTOM}`}>
- {localeService.t('sheets-data-validation-ui.renderMode.chip')}
+ {localeService.t<LocaleKey>('sheets-data-validation-ui.renderMode.chip')}
</Radio>
<Radio value={`${DataValidationRenderMode.ARROW}`}>
- {localeService.t('sheets-data-validation-ui.renderMode.arrow')}
+ {localeService.t<LocaleKey>('sheets-data-validation-ui.renderMode.arrow')}
</Radio>
<Radio value={`${DataValidationRenderMode.TEXT}`}>
- {localeService.t('sheets-data-validation-ui.renderMode.text')}
+ {localeService.t<LocaleKey>('sheets-data-validation-ui.renderMode.text')}
</Radio>
</RadioGroup>
</FormLayout>
diff --git a/packages/sheets-data-validation-ui/src/views/components/formula-input/BaseFormulaInput.tsx b/packages/sheets-data-validation-ui/src/views/components/formula-input/BaseFormulaInput.tsx
index 426d70b0c9..f9d730cfc0 100644
--- a/packages/sheets-data-validation-ui/src/views/components/formula-input/BaseFormulaInput.tsx
+++ b/packages/sheets-data-validation-ui/src/views/components/formula-input/BaseFormulaInput.tsx
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { LocaleKey } from '../../../locale/types';
import type { IFormulaInputProps } from './interface';
import { LocaleService } from '@univerjs/core';
import { FormLayout, Input } from '@univerjs/design';
@@ -31,7 +32,7 @@ export const BaseFormulaInput = (props: IFormulaInputProps) => {
<FormLayout error={formula1Res}>
<Input
className="univer-w-full"
- placeholder={localeService.t('sheets-data-validation-ui.panel.formulaPlaceholder')}
+ placeholder={localeService.t<LocaleKey>('sheets-data-validation-ui.panel.formulaPlaceholder')}
value={value?.formula1}
onChange={(newValue) => {
onChange?.({
@@ -42,12 +43,12 @@ export const BaseFormulaInput = (props: IFormulaInputProps) => {
/>
</FormLayout>
<div className="-univer-mt-2 univer-mb-1 univer-text-sm univer-text-gray-400">
- {localeService.t('sheets-data-validation-ui.panel.formulaAnd')}
+ {localeService.t<LocaleKey>('sheets-data-validation-ui.panel.formulaAnd')}
</div>
<FormLayout error={formula2Res}>
<Input
className="univer-w-full"
- placeholder={localeService.t('sheets-data-validation-ui.panel.formulaPlaceholder')}
+ placeholder={localeService.t<LocaleKey>('sheets-data-validation-ui.panel.formulaPlaceholder')}
value={value?.formula2}
onChange={(newValue) => {
onChange?.({
@@ -65,7 +66,7 @@ export const BaseFormulaInput = (props: IFormulaInputProps) => {
<FormLayout error={formula1Res}>
<Input
className="univer-w-full"
- placeholder={localeService.t('sheets-data-validation-ui.panel.formulaPlaceholder')}
+ placeholder={localeService.t<LocaleKey>('sheets-data-validation-ui.panel.formulaPlaceholder')}
value={value?.formula1}
onChange={(newValue) => {
onChange?.({ formula1: newValue });
diff --git a/packages/sheets-data-validation-ui/src/views/components/formula-input/CheckboxFormulaInput.tsx b/packages/sheets-data-validation-ui/src/views/components/formula-input/CheckboxFormulaInput.tsx
index 541bb0585b..ea3354d8c3 100644
--- a/packages/sheets-data-validation-ui/src/views/components/formula-input/CheckboxFormulaInput.tsx
+++ b/packages/sheets-data-validation-ui/src/views/components/formula-input/CheckboxFormulaInput.tsx
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { LocaleKey } from '../../../locale/types';
import type { IFormulaInputProps } from './interface';
import { LocaleService } from '@univerjs/core';
import { Checkbox, FormLayout, Input } from '@univerjs/design';
@@ -46,15 +47,15 @@ export function CheckboxFormulaInput(props: IFormulaInputProps) {
}
}}
>
- {localeService.t('sheets-data-validation-ui.checkbox.tips')}
+ {localeService.t<LocaleKey>('sheets-data-validation-ui.checkbox.tips')}
</Checkbox>
</FormLayout>
{checked
? (
- <FormLayout label={localeService.t('sheets-data-validation-ui.checkbox.checked')} error={formula1Res}>
+ <FormLayout label={localeService.t<LocaleKey>('sheets-data-validation-ui.checkbox.checked')} error={formula1Res}>
<Input
className="univer-w-full"
- placeholder={localeService.t('sheets-data-validation-ui.panel.valuePlaceholder')}
+ placeholder={localeService.t<LocaleKey>('sheets-data-validation-ui.panel.valuePlaceholder')}
value={value?.formula1}
onChange={(newValue) => {
onChange?.({
@@ -68,10 +69,10 @@ export function CheckboxFormulaInput(props: IFormulaInputProps) {
: null}
{checked
? (
- <FormLayout label={localeService.t('sheets-data-validation-ui.checkbox.unchecked')} error={formula2Res}>
+ <FormLayout label={localeService.t<LocaleKey>('sheets-data-validation-ui.checkbox.unchecked')} error={formula2Res}>
<Input
className="univer-w-full"
- placeholder={localeService.t('sheets-data-validation-ui.panel.valuePlaceholder')}
+ placeholder={localeService.t<LocaleKey>('sheets-data-validation-ui.panel.valuePlaceholder')}
value={value?.formula2}
onChange={(newValue) => {
onChange?.({
diff --git a/packages/sheets-data-validation-ui/src/views/components/formula-input/ListFormulaInput.tsx b/packages/sheets-data-validation-ui/src/views/components/formula-input/ListFormulaInput.tsx
index 210cf9d076..81940d878a 100644
--- a/packages/sheets-data-validation-ui/src/views/components/formula-input/ListFormulaInput.tsx
+++ b/packages/sheets-data-validation-ui/src/views/components/formula-input/ListFormulaInput.tsx
@@ -16,6 +16,7 @@
import type { ListValidator } from '@univerjs/sheets-data-validation';
import type { IFormulaEditorRef } from '@univerjs/sheets-formula-ui';
+import type { LocaleKey } from '../../../locale/types';
import type { IFormulaInputProps } from './interface';
import { awaitTime, DataValidationType, generateRandomId, isFormulaString, LocaleService } from '@univerjs/core';
import { DataValidationModel, DataValidatorRegistryService } from '@univerjs/data-validation';
@@ -295,7 +296,7 @@ export function ListFormulaInput(props: IFormulaInputProps) {
formula2,
});
setFormulaStr('=');
- setLocalError(localeService.t('sheets-data-validation-ui.validFail.formulaError'));
+ setLocalError(localeService.t<LocaleKey>('sheets-data-validation-ui.validFail.formulaError'));
}
});
@@ -317,7 +318,7 @@ export function ListFormulaInput(props: IFormulaInputProps) {
return (
<>
- <FormLayout label={localeService.t('sheets-data-validation-ui.list.options')}>
+ <FormLayout label={localeService.t<LocaleKey>('sheets-data-validation-ui.list.options')}>
<RadioGroup
value={isFormulaStr}
onChange={(v) => {
@@ -331,8 +332,8 @@ export function ListFormulaInput(props: IFormulaInputProps) {
}
}}
>
- <Radio value="0">{localeService.t('sheets-data-validation-ui.list.customOptions')}</Radio>
- <Radio value="1">{localeService.t('sheets-data-validation-ui.list.refOptions')}</Radio>
+ <Radio value="0">{localeService.t<LocaleKey>('sheets-data-validation-ui.list.customOptions')}</Radio>
+ <Radio value="1">{localeService.t<LocaleKey>('sheets-data-validation-ui.list.refOptions')}</Radio>
</RadioGroup>
</FormLayout>
{isFormulaStr === '1'
@@ -407,7 +408,7 @@ export function ListFormulaInput(props: IFormulaInputProps) {
onClick={handleAdd}
>
<IncreaseIcon className="univer-mr-1" />
- {localeService.t('sheets-data-validation-ui.list.add')}
+ {localeService.t<LocaleKey>('sheets-data-validation-ui.list.add')}
</a>
</div>
</FormLayout>
diff --git a/packages/sheets-data-validation/src/locale/types.ts b/packages/sheets-data-validation/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-data-validation/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-data-validation/src/validators/any-validator.ts b/packages/sheets-data-validation/src/validators/any-validator.ts
index b7c8b3c76f..56613f9416 100644
--- a/packages/sheets-data-validation/src/validators/any-validator.ts
+++ b/packages/sheets-data-validation/src/validators/any-validator.ts
@@ -16,6 +16,7 @@
import type { CellValue, DataValidationOperator, IDataValidationRule, IDataValidationRuleBase } from '@univerjs/core';
import type { IFormulaResult, IFormulaValidResult, IValidatorCellInfo } from '@univerjs/data-validation';
+import type { LocaleKey } from '../locale/types';
import { DataValidationType } from '@univerjs/core';
import { BaseSheetValidator } from './base-sheet-validator';
@@ -47,6 +48,6 @@ export class AnyValidator extends BaseSheetValidator {
}
override generateRuleErrorMessage(rule: IDataValidationRuleBase): string {
- return this.localeService.t('sheets-data-validation.any.error');
+ return this.localeService.t<LocaleKey>('sheets-data-validation.any.error');
}
}
diff --git a/packages/sheets-data-validation/src/validators/checkbox-validator.ts b/packages/sheets-data-validation/src/validators/checkbox-validator.ts
index ebe2d3829f..9ba5ac06ba 100644
--- a/packages/sheets-data-validation/src/validators/checkbox-validator.ts
+++ b/packages/sheets-data-validation/src/validators/checkbox-validator.ts
@@ -14,8 +14,17 @@
* limitations under the License.
*/
-import type { CellValue, DataValidationOperator, IDataValidationRule, IDataValidationRuleBase, ISheetDataValidationRule, LocaleService, Nullable } from '@univerjs/core';
+import type {
+ CellValue,
+ DataValidationOperator,
+ IDataValidationRule,
+ IDataValidationRuleBase,
+ ISheetDataValidationRule,
+ LocaleService,
+ Nullable,
+} from '@univerjs/core';
import type { IFormulaResult, IFormulaValidResult, IValidatorCellInfo } from '@univerjs/data-validation';
+import type { LocaleKey } from '../locale/types';
import { DataValidationType, isFormulaString, Tools, WrapStrategy } from '@univerjs/core';
import { DataValidationFormulaService } from '../services/dv-formula.service';
import { getFormulaResult, isLegalFormulaResult } from '../utils/formula';
@@ -31,11 +40,11 @@ interface ICheckboxFormulaResult extends IFormulaResult {
function getFailMessage(formula: string | undefined, localeService: LocaleService) {
if (Tools.isBlank(formula)) {
- return localeService.t('sheets-data-validation.validFail.value');
+ return localeService.t<LocaleKey>('sheets-data-validation.validFail.value');
}
if (isFormulaString(formula)) {
- return localeService.t('sheets-data-validation.validFail.primitive');
+ return localeService.t<LocaleKey>('sheets-data-validation.validFail.primitive');
}
return '';
@@ -81,8 +90,8 @@ export class CheckboxValidator extends BaseSheetValidator {
if (isEqual) {
return {
success: false,
- formula1: this.localeService.t('sheets-data-validation.validFail.checkboxEqual'),
- formula2: this.localeService.t('sheets-data-validation.validFail.checkboxEqual'),
+ formula1: this.localeService.t<LocaleKey>('sheets-data-validation.validFail.checkboxEqual'),
+ formula2: this.localeService.t<LocaleKey>('sheets-data-validation.validFail.checkboxEqual'),
};
}
@@ -151,7 +160,7 @@ export class CheckboxValidator extends BaseSheetValidator {
}
override generateRuleErrorMessage(rule: IDataValidationRuleBase): string {
- return this.localeService.t('sheets-data-validation.checkbox.error');
+ return this.localeService.t<LocaleKey>('sheets-data-validation.checkbox.error');
}
override generateRuleName(rule: IDataValidationRuleBase): string {
diff --git a/packages/sheets-data-validation/src/validators/custom-validator.ts b/packages/sheets-data-validation/src/validators/custom-validator.ts
index 387628281c..672a58b924 100644
--- a/packages/sheets-data-validation/src/validators/custom-validator.ts
+++ b/packages/sheets-data-validation/src/validators/custom-validator.ts
@@ -16,6 +16,7 @@
import type { CellValue, DataValidationOperator, IDataValidationRule, IDataValidationRuleBase } from '@univerjs/core';
import type { IFormulaResult, IFormulaValidResult, IValidatorCellInfo } from '@univerjs/data-validation';
+import type { LocaleKey } from '../locale/types';
import { CellValueType, DataValidationType, isFormulaString, Tools } from '@univerjs/core';
import { LexerTreeBuilder, operatorToken } from '@univerjs/engine-formula';
import { DataValidationCustomFormulaService } from '../services/dv-custom-formula.service';
@@ -40,7 +41,7 @@ export class CustomFormulaValidator extends BaseSheetValidator {
return {
success: success && valid,
- formula1: success && valid ? '' : this.localeService.t('sheets-data-validation.validFail.formula'),
+ formula1: success && valid ? '' : this.localeService.t<LocaleKey>('sheets-data-validation.validFail.formula'),
};
}
@@ -85,10 +86,10 @@ export class CustomFormulaValidator extends BaseSheetValidator {
}
override generateRuleErrorMessage(rule: IDataValidationRuleBase): string {
- return this.localeService.t('sheets-data-validation.custom.error');
+ return this.localeService.t<LocaleKey>('sheets-data-validation.custom.error');
}
override generateRuleName(rule: IDataValidationRuleBase): string {
- return (this.localeService.t('sheets-data-validation.custom.ruleName')).replace('{FORMULA1}', rule.formula1 ?? '');
+ return (this.localeService.t<LocaleKey>('sheets-data-validation.custom.ruleName')).replace('{FORMULA1}', rule.formula1 ?? '');
}
}
diff --git a/packages/sheets-data-validation/src/validators/list-validator.ts b/packages/sheets-data-validation/src/validators/list-validator.ts
index bcfc99ce68..cfd340a820 100644
--- a/packages/sheets-data-validation/src/validators/list-validator.ts
+++ b/packages/sheets-data-validation/src/validators/list-validator.ts
@@ -14,10 +14,36 @@
* limitations under the License.
*/
-import type { CellValue, DataValidationOperator, ICellData, IDataValidationRule, IRange, ISheetDataValidationRule, IStyleData, Nullable, Workbook } from '@univerjs/core';
+import type {
+ CellValue,
+ DataValidationOperator,
+ ICellData,
+ IDataValidationRule,
+ IRange,
+ ISheetDataValidationRule,
+ IStyleData,
+ Nullable,
+ Workbook,
+} from '@univerjs/core';
import type { IFormulaResult, IFormulaValidResult, IValidatorCellInfo } from '@univerjs/data-validation';
-import { DataValidationRenderMode, DataValidationType, isFormulaString, IUniverInstanceService, numfmt, Rectangle, Tools, UniverInstanceType, WrapStrategy } from '@univerjs/core';
-import { deserializeRangeWithSheet, isReferenceString, LexerTreeBuilder, sequenceNodeType } from '@univerjs/engine-formula';
+import type { LocaleKey } from '../locale/types';
+import {
+ DataValidationRenderMode,
+ DataValidationType,
+ isFormulaString,
+ IUniverInstanceService,
+ numfmt,
+ Rectangle,
+ Tools,
+ UniverInstanceType,
+ WrapStrategy,
+} from '@univerjs/core';
+import {
+ deserializeRangeWithSheet,
+ isReferenceString,
+ LexerTreeBuilder,
+ sequenceNodeType,
+} from '@univerjs/engine-formula';
import { deserializeListOptions } from '@univerjs/sheets';
import { DataValidationFormulaService } from '../services/dv-formula.service';
import { DataValidationListCacheService } from '../services/dv-list-cache.service';
@@ -123,9 +149,9 @@ export class ListValidator extends BaseSheetValidator {
? valid
? !isIntersects ?
undefined :
- this.localeService.t('sheets-data-validation.validFail.listIntersects') :
- this.localeService.t('sheets-data-validation.validFail.listInvalid')
- : this.localeService.t('sheets-data-validation.validFail.list'),
+ this.localeService.t<LocaleKey>('sheets-data-validation.validFail.listIntersects') :
+ this.localeService.t<LocaleKey>('sheets-data-validation.validFail.listInvalid')
+ : this.localeService.t<LocaleKey>('sheets-data-validation.validFail.list'),
};
}
@@ -184,11 +210,11 @@ export class ListValidator extends BaseSheetValidator {
}
override generateRuleName() {
- return this.localeService.t('sheets-data-validation.list.name');
+ return this.localeService.t<LocaleKey>('sheets-data-validation.list.name');
}
override generateRuleErrorMessage(): string {
- return this.localeService.t('sheets-data-validation.list.error');
+ return this.localeService.t<LocaleKey>('sheets-data-validation.list.error');
}
private _getUnitAndSubUnit(currentUnitId?: string, currentSubUnitId?: string): { unitId: string; subUnitId: string } | null {
diff --git a/packages/sheets-drawing-ui/src/commands/commands/save-cell-images.command.ts b/packages/sheets-drawing-ui/src/commands/commands/save-cell-images.command.ts
index fa5dcc4ec5..39004660b2 100644
--- a/packages/sheets-drawing-ui/src/commands/commands/save-cell-images.command.ts
+++ b/packages/sheets-drawing-ui/src/commands/commands/save-cell-images.command.ts
@@ -15,6 +15,7 @@
*/
import type { ICommand } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import { CommandType, LocaleService } from '@univerjs/core';
import { IDialogService } from '@univerjs/ui';
import { IBatchSaveImagesService } from '../../services/batch-save-images.service';
@@ -43,7 +44,7 @@ export const SaveCellImagesCommand: ICommand = {
// Multiple images: open batch save dialog
const localeService = accessor.get(LocaleService);
const selectionRange = batchSaveService.getSelectionRangeNotation();
- const titleText = `${localeService.t('sheets-drawing-ui.save.title')} (${selectionRange})`;
+ const titleText = `${localeService.t<LocaleKey>('sheets-drawing-ui.save.title')} (${selectionRange})`;
dialogService.open({
id: BATCH_SAVE_IMAGES_DIALOG_ID,
diff --git a/packages/sheets-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts b/packages/sheets-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts
index 09fd945a19..1b772508fc 100644
--- a/packages/sheets-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts
+++ b/packages/sheets-drawing-ui/src/commands/operations/open-drawing-panel.operation.ts
@@ -15,6 +15,7 @@
*/
import type { IAccessor, ICommand } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import { CommandType, ICommandService, IUniverInstanceService, LocaleService } from '@univerjs/core';
import { SetDrawingSelectedOperation } from '@univerjs/drawing';
import { getSheetCommandTarget } from '@univerjs/sheets';
@@ -41,7 +42,7 @@ export const SidebarSheetDrawingOperation: ICommand = {
switch (params.value) {
case 'open':
sidebarService.open({
- header: { title: localeService.t('sheets-drawing-ui.panel.title') },
+ header: { title: localeService.t<LocaleKey>('sheets-drawing-ui.panel.title') },
children: { label: COMPONENT_SHEET_DRAWING_PANEL },
onClose: () => {
commandService.syncExecuteCommand(SetDrawingSelectedOperation.id, []);
diff --git a/packages/sheets-drawing-ui/src/controllers/sheet-cell-image-copy-paste.controller.ts b/packages/sheets-drawing-ui/src/controllers/sheet-cell-image-copy-paste.controller.ts
index 97e798fe34..c30c5a2eda 100644
--- a/packages/sheets-drawing-ui/src/controllers/sheet-cell-image-copy-paste.controller.ts
+++ b/packages/sheets-drawing-ui/src/controllers/sheet-cell-image-copy-paste.controller.ts
@@ -16,7 +16,19 @@
import type { DocumentDataModel, IDocDrawingBase } from '@univerjs/core';
import type { IInnerPasteCommandParams } from '@univerjs/docs-ui';
-import { BuildTextUtils, createDocumentModelWithStyle, Disposable, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, ICommandService, Inject, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
+import type { LocaleKey } from '../locale/types';
+import {
+ BuildTextUtils,
+ createDocumentModelWithStyle,
+ Disposable,
+ DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,
+ DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
+ ICommandService,
+ Inject,
+ IUniverInstanceService,
+ LocaleService,
+ UniverInstanceType,
+} from '@univerjs/core';
import { InnerPasteCommand } from '@univerjs/docs-ui';
import { getCurrentTypeOfRenderer, IRenderManagerService } from '@univerjs/engine-render';
import { EditingRenderController, SetCellEditVisibleOperation } from '@univerjs/sheets-ui';
@@ -86,10 +98,10 @@ export class SheetCellImageCopyPasteController extends Disposable {
this._dialogService.open({
id: 'sheet-cell-image-copy-paste',
title: {
- label: this._localeService.t('sheets-drawing-ui.cell-image.pasteTitle'),
+ label: this._localeService.t<LocaleKey>('sheets-drawing-ui.cell-image.pasteTitle'),
},
children: {
- label: this._localeService.t('sheets-drawing-ui.cell-image.pasteContent'),
+ label: this._localeService.t<LocaleKey>('sheets-drawing-ui.cell-image.pasteContent'),
},
width: 320,
destroyOnClose: true,
diff --git a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-permission.controller.ts b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-permission.controller.ts
index e766a412a6..51fdeb6ea2 100644
--- a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-permission.controller.ts
+++ b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-permission.controller.ts
@@ -15,11 +15,38 @@
*/
import type { Workbook, Worksheet } from '@univerjs/core';
-import type { IDeleteDrawingCommandParams, IInsertDrawingCommandParams, ISetDrawingArrangeCommandParams, ISetDrawingCommandParams } from '@univerjs/sheets-drawing';
-import { Disposable, ICommandService, Inject, IPermissionService, IUniverInstanceService, LocaleService, UniverInstanceType, UserManagerService } from '@univerjs/core';
+import type {
+ IDeleteDrawingCommandParams,
+ IInsertDrawingCommandParams,
+ ISetDrawingArrangeCommandParams,
+ ISetDrawingCommandParams,
+} from '@univerjs/sheets-drawing';
+import type { LocaleKey } from '../locale/types';
+import {
+ Disposable,
+ ICommandService,
+ Inject,
+ IPermissionService,
+ IUniverInstanceService,
+ LocaleService,
+ UniverInstanceType,
+ UserManagerService,
+} from '@univerjs/core';
import { IRenderManagerService, ObjectType } from '@univerjs/engine-render';
-import { SheetPermissionCheckController, WorkbookEditablePermission, WorkbookViewPermission, WorksheetEditPermission, WorksheetViewPermission } from '@univerjs/sheets';
-import { InsertSheetDrawingCommand, ISheetDrawingService, RemoveSheetDrawingCommand, SetDrawingArrangeCommand, SetSheetDrawingCommand } from '@univerjs/sheets-drawing';
+import {
+ SheetPermissionCheckController,
+ WorkbookEditablePermission,
+ WorkbookViewPermission,
+ WorksheetEditPermission,
+ WorksheetViewPermission,
+} from '@univerjs/sheets';
+import {
+ InsertSheetDrawingCommand,
+ ISheetDrawingService,
+ RemoveSheetDrawingCommand,
+ SetDrawingArrangeCommand,
+ SetSheetDrawingCommand,
+} from '@univerjs/sheets-drawing';
import { combineLatest, distinctUntilChanged, EMPTY, map, switchMap, tap } from 'rxjs';
const drawingObjectTypes = [
@@ -430,7 +457,7 @@ export class SheetDrawingPermissionController extends Disposable {
worksheetTypes: [WorksheetEditPermission],
}, unitId, subUnitId);
if (!permission) {
- this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t('sheets-drawing-ui.permission.dialog.editErr'));
+ this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t<LocaleKey>('sheets-drawing-ui.permission.dialog.editErr'));
}
})
);
diff --git a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts
index f31f2da6d7..5187c6f0dd 100644
--- a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts
+++ b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts
@@ -18,7 +18,14 @@ import type { IAccessor, IDrawingParam, IRange, Nullable, Workbook } from '@univ
import type { IImageData, IImageIoServiceParam } from '@univerjs/drawing';
import type { IRenderContext, IRenderModule, SpreadsheetSkeleton } from '@univerjs/engine-render';
import type { ISheetLocationBase, WorkbookSelectionModel } from '@univerjs/sheets';
-import type { IInsertDrawingCommandParams, ISetDrawingArrangeCommandParams, ISetDrawingCommandParams, ISheetDrawing, ISheetDrawingPosition } from '@univerjs/sheets-drawing';
+import type {
+ IInsertDrawingCommandParams,
+ ISetDrawingArrangeCommandParams,
+ ISetDrawingCommandParams,
+ ISheetDrawing,
+ ISheetDrawingPosition,
+} from '@univerjs/sheets-drawing';
+import type { LocaleKey } from '../locale/types';
import {
BooleanNumber,
BuildTextUtils,
@@ -54,7 +61,13 @@ import {
SetDrawingSelectedOperation,
} from '@univerjs/drawing';
import { IRenderManagerService } from '@univerjs/engine-render';
-import { attachRangeWithCoord, SetRangeValuesCommand, SheetInterceptorService, SheetSkeletonService, SheetsSelectionsService } from '@univerjs/sheets';
+import {
+ attachRangeWithCoord,
+ SetRangeValuesCommand,
+ SheetInterceptorService,
+ SheetSkeletonService,
+ SheetsSelectionsService,
+} from '@univerjs/sheets';
import {
drawingPositionToTransform,
InsertSheetDrawingCommand,
@@ -164,7 +177,7 @@ export class SheetDrawingUpdateController extends Disposable implements IRenderM
if (fileLength > DRAWING_IMAGE_COUNT_LIMIT) {
this._messageService.show({
type: MessageType.Error,
- content: this._localeService.t('sheets-drawing-ui.update-status.exceedMaxCount', String(DRAWING_IMAGE_COUNT_LIMIT)),
+ content: this._localeService.t<LocaleKey>('sheets-drawing-ui.update-status.exceedMaxCount', String(DRAWING_IMAGE_COUNT_LIMIT)),
});
return false;
} else if (fileLength === 0) {
@@ -202,17 +215,17 @@ export class SheetDrawingUpdateController extends Disposable implements IRenderM
if (type === ImageUploadStatusType.ERROR_EXCEED_SIZE) {
this._messageService.show({
type: MessageType.Error,
- content: this._localeService.t('sheets-drawing-ui.update-status.exceedMaxSize', String(getDrawingImageAllowSize() / (1024 * 1024))),
+ content: this._localeService.t<LocaleKey>('sheets-drawing-ui.update-status.exceedMaxSize', String(getDrawingImageAllowSize() / (1024 * 1024))),
});
} else if (type === ImageUploadStatusType.ERROR_IMAGE_TYPE) {
this._messageService.show({
type: MessageType.Error,
- content: this._localeService.t('sheets-drawing-ui.update-status.invalidImageType'),
+ content: this._localeService.t<LocaleKey>('sheets-drawing-ui.update-status.invalidImageType'),
});
} else if (type === ImageUploadStatusType.ERROR_IMAGE) {
this._messageService.show({
type: MessageType.Error,
- content: this._localeService.t('sheets-drawing-ui.update-status.invalidImage'),
+ content: this._localeService.t<LocaleKey>('sheets-drawing-ui.update-status.invalidImage'),
});
}
}
@@ -274,17 +287,17 @@ export class SheetDrawingUpdateController extends Disposable implements IRenderM
if (type === ImageUploadStatusType.ERROR_EXCEED_SIZE) {
this._messageService.show({
type: MessageType.Error,
- content: this._localeService.t('sheets-drawing-ui.update-status.exceedMaxSize', String(getDrawingImageAllowSize() / (1024 * 1024))),
+ content: this._localeService.t<LocaleKey>('sheets-drawing-ui.update-status.exceedMaxSize', String(getDrawingImageAllowSize() / (1024 * 1024))),
});
} else if (type === ImageUploadStatusType.ERROR_IMAGE_TYPE) {
this._messageService.show({
type: MessageType.Error,
- content: this._localeService.t('sheets-drawing-ui.update-status.invalidImageType'),
+ content: this._localeService.t<LocaleKey>('sheets-drawing-ui.update-status.invalidImageType'),
});
} else if (type === ImageUploadStatusType.ERROR_IMAGE) {
this._messageService.show({
type: MessageType.Error,
- content: this._localeService.t('sheets-drawing-ui.update-status.invalidImage'),
+ content: this._localeService.t<LocaleKey>('sheets-drawing-ui.update-status.invalidImage'),
});
}
}
diff --git a/packages/sheets-drawing-ui/src/locale/types.ts b/packages/sheets-drawing-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-drawing-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-drawing-ui/src/menu/drawing-popup-menu.controller.ts b/packages/sheets-drawing-ui/src/menu/drawing-popup-menu.controller.ts
index b0ddfe4c11..7bbbc04736 100644
--- a/packages/sheets-drawing-ui/src/menu/drawing-popup-menu.controller.ts
+++ b/packages/sheets-drawing-ui/src/menu/drawing-popup-menu.controller.ts
@@ -18,10 +18,28 @@ import type { IDisposable, Nullable, Workbook } from '@univerjs/core';
import type { ImageIoService } from '@univerjs/drawing';
import type { BaseObject, Scene } from '@univerjs/engine-render';
import type { ISheetFloatDom } from '@univerjs/sheets-drawing';
-import { DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, ICommandService, IContextService, IImageIoService, Inject, Injector, IUniverInstanceService, LocaleService, RxDisposable, UniverInstanceType } from '@univerjs/core';
+import type { LocaleKey } from '../locale/types';
+import {
+ DrawingTypeEnum,
+ FOCUSING_COMMON_DRAWINGS,
+ ICommandService,
+ IContextService,
+ IImageIoService,
+ Inject,
+ Injector,
+ IUniverInstanceService,
+ LocaleService,
+ RxDisposable,
+ UniverInstanceType,
+} from '@univerjs/core';
import { MessageType } from '@univerjs/design';
import { IDrawingManagerService, SetDrawingSelectedOperation } from '@univerjs/drawing';
-import { COMPONENT_IMAGE_POPUP_MENU, ImageCropperObject, ImageResetSizeOperation, OpenImageCropOperation } from '@univerjs/drawing-ui';
+import {
+ COMPONENT_IMAGE_POPUP_MENU,
+ ImageCropperObject,
+ ImageResetSizeOperation,
+ OpenImageCropOperation,
+} from '@univerjs/drawing-ui';
import { IRenderManagerService } from '@univerjs/engine-render';
import { RemoveSheetDrawingCommand } from '@univerjs/sheets-drawing';
import { SheetCanvasPopManagerService } from '@univerjs/sheets-ui';
@@ -66,7 +84,7 @@ export class DrawingPopupMenuController extends RxDisposable {
messageDisposable = this._messageService.show({
id: MESSAGE_ID,
type: MessageType.Loading,
- content: `${this._localeService.t('sheets-drawing-ui.uploadLoading.loading')}: ${status}`,
+ content: `${this._localeService.t<LocaleKey>('sheets-drawing-ui.uploadLoading.loading')}: ${status}`,
duration: 0,
});
} else if (status === 0) {
diff --git a/packages/sheets-drawing-ui/src/menu/image.menu.ts b/packages/sheets-drawing-ui/src/menu/image.menu.ts
index de615aa643..45e952c2bb 100644
--- a/packages/sheets-drawing-ui/src/menu/image.menu.ts
+++ b/packages/sheets-drawing-ui/src/menu/image.menu.ts
@@ -16,39 +16,48 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { UniverInstanceType } from '@univerjs/core';
-import { RangeProtectionPermissionEditPoint, WorkbookEditablePermission, WorksheetEditPermission } from '@univerjs/sheets';
+import {
+ RangeProtectionPermissionEditPoint,
+ WorkbookEditablePermission,
+ WorksheetEditPermission,
+} from '@univerjs/sheets';
import { getCurrentRangeDisable$ } from '@univerjs/sheets-ui';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { InsertCellImageCommand, InsertFloatImageCommand } from '../commands/commands/insert-image.command';
export const SHEETS_IMAGE_MENU_ID = 'sheet.menu.image';
-export function ImageMenuFactory(accessor: IAccessor): IMenuItem {
+export function ImageMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: SHEETS_IMAGE_MENU_ID,
type: MenuItemType.SUBITEMS,
icon: 'AddImageIcon',
tooltip: 'sheets-drawing-ui.title',
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetEditPermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
};
}
-export function UploadFloatImageMenuFactory(_accessor: IAccessor): IMenuItem {
+export function UploadFloatImageMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: InsertFloatImageCommand.id,
title: 'sheets-drawing-ui.upload.float',
type: MenuItemType.BUTTON,
- hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_SHEET),
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
};
}
-export function UploadCellImageMenuFactory(_accessor: IAccessor): IMenuItem {
+export function UploadCellImageMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: InsertCellImageCommand.id,
title: 'sheets-drawing-ui.upload.cell',
type: MenuItemType.BUTTON,
- hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_SHEET),
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
};
}
diff --git a/packages/sheets-drawing-ui/src/menu/save-images.menu.ts b/packages/sheets-drawing-ui/src/menu/save-images.menu.ts
index c1bfdb0708..0335232a76 100644
--- a/packages/sheets-drawing-ui/src/menu/save-images.menu.ts
+++ b/packages/sheets-drawing-ui/src/menu/save-images.menu.ts
@@ -16,6 +16,7 @@
import type { IAccessor, ICellData, IRange, Nullable, Workbook } from '@univerjs/core';
import type { IMenuItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { SheetsSelectionsService } from '@univerjs/sheets';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
@@ -63,7 +64,7 @@ function isFileSystemAccessSupported(): boolean {
return 'showDirectoryPicker' in window;
}
-export function SaveCellImagesMenuFactory(accessor: IAccessor): IMenuItem {
+export function SaveCellImagesMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionService = accessor.get(SheetsSelectionsService);
diff --git a/packages/sheets-drawing-ui/src/views/batch-save-images/BatchSaveImagesDialog.tsx b/packages/sheets-drawing-ui/src/views/batch-save-images/BatchSaveImagesDialog.tsx
index a4108f94d0..cec4e68c30 100644
--- a/packages/sheets-drawing-ui/src/views/batch-save-images/BatchSaveImagesDialog.tsx
+++ b/packages/sheets-drawing-ui/src/views/batch-save-images/BatchSaveImagesDialog.tsx
@@ -15,6 +15,7 @@
*/
import type { IRange } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import { LocaleService } from '@univerjs/core';
import { Button, Checkbox, CheckboxGroup, FormLayout, Select } from '@univerjs/design';
import { useHighlightRange } from '@univerjs/sheets-ui';
@@ -102,7 +103,7 @@ export function BatchSaveImagesDialog() {
dialogService.close(BATCH_SAVE_IMAGES_DIALOG_ID);
} catch (err) {
console.error('Failed to save images:', err);
- setError(localeService.t('sheets-drawing-ui.save.error'));
+ setError(localeService.t<LocaleKey>('sheets-drawing-ui.save.error'));
} finally {
setSaving(false);
}
@@ -112,25 +113,25 @@ export function BatchSaveImagesDialog() {
return (
<div className="univer-flex univer-flex-col">
- <FormLayout label={localeService.t('sheets-drawing-ui.save.imageCount')}>
+ <FormLayout label={localeService.t<LocaleKey>('sheets-drawing-ui.save.imageCount')}>
<div className="univer-text-sm univer-text-gray-600">{images.length}</div>
</FormLayout>
- <FormLayout label={localeService.t('sheets-drawing-ui.save.fileNameConfig')}>
+ <FormLayout label={localeService.t<LocaleKey>('sheets-drawing-ui.save.fileNameConfig')}>
<CheckboxGroup value={fileNameParts} onChange={handleFileNamePartsChange} direction="vertical">
<Checkbox value={FileNamePart.CELL_ADDRESS} disabled={!hasAvailableColumns}>
- {localeService.t('sheets-drawing-ui.save.useRowCol')}
+ {localeService.t<LocaleKey>('sheets-drawing-ui.save.useRowCol')}
</Checkbox>
{hasAvailableColumns && (
<Checkbox value={FileNamePart.COLUMN_VALUE}>
- {localeService.t('sheets-drawing-ui.save.useColumnValue')}
+ {localeService.t<LocaleKey>('sheets-drawing-ui.save.useColumnValue')}
</Checkbox>
)}
</CheckboxGroup>
</FormLayout>
{showColumnSelect && (
- <FormLayout label={localeService.t('sheets-drawing-ui.save.selectColumn')}>
+ <FormLayout label={localeService.t<LocaleKey>('sheets-drawing-ui.save.selectColumn')}>
<Select
value={selectedColumn}
options={columnOptions}
@@ -149,14 +150,14 @@ export function BatchSaveImagesDialog() {
`}
>
<Button onClick={handleCancel} disabled={saving}>
- {localeService.t('sheets-drawing-ui.save.cancel')}
+ {localeService.t<LocaleKey>('sheets-drawing-ui.save.cancel')}
</Button>
<Button
variant="primary"
onClick={handleConfirm}
disabled={saving || images.length === 0}
>
- {saving ? localeService.t('sheets-drawing-ui.save.saving') : localeService.t('sheets-drawing-ui.save.confirm')}
+ {saving ? localeService.t<LocaleKey>('sheets-drawing-ui.save.saving') : localeService.t<LocaleKey>('sheets-drawing-ui.save.confirm')}
</Button>
</div>
</div>
diff --git a/packages/sheets-drawing-ui/src/views/sheet-image-panel/SheetDrawingAnchor.tsx b/packages/sheets-drawing-ui/src/views/sheet-image-panel/SheetDrawingAnchor.tsx
index 288b8b3686..020958d7ff 100644
--- a/packages/sheets-drawing-ui/src/views/sheet-image-panel/SheetDrawingAnchor.tsx
+++ b/packages/sheets-drawing-ui/src/views/sheet-image-panel/SheetDrawingAnchor.tsx
@@ -17,6 +17,7 @@
import type { IDrawingParam, Nullable } from '@univerjs/core';
import type { BaseObject } from '@univerjs/engine-render';
import type { ISheetDrawing } from '@univerjs/sheets-drawing';
+import type { LocaleKey } from '../../locale/types';
import { ICommandService, LocaleService } from '@univerjs/core';
import { clsx, Radio, RadioGroup } from '@univerjs/design';
import { IDrawingManagerService } from '@univerjs/drawing';
@@ -146,14 +147,14 @@ export const SheetDrawingAnchor = (props: ISheetDrawingAnchorProps) => {
dark:!univer-text-gray-200
`}
>
- <div>{localeService.t('sheets-drawing-ui.drawing-anchor.title')}</div>
+ <div>{localeService.t<LocaleKey>('sheets-drawing-ui.drawing-anchor.title')}</div>
</header>
<div>
<RadioGroup value={value} onChange={handleChange} direction="vertical">
- <Radio value={SheetDrawingAnchorType.Both}>{localeService.t('sheets-drawing-ui.drawing-anchor.both')}</Radio>
- <Radio value={SheetDrawingAnchorType.Position}>{localeService.t('sheets-drawing-ui.drawing-anchor.position')}</Radio>
- <Radio value={SheetDrawingAnchorType.None}>{localeService.t('sheets-drawing-ui.drawing-anchor.none')}</Radio>
+ <Radio value={SheetDrawingAnchorType.Both}>{localeService.t<LocaleKey>('sheets-drawing-ui.drawing-anchor.both')}</Radio>
+ <Radio value={SheetDrawingAnchorType.Position}>{localeService.t<LocaleKey>('sheets-drawing-ui.drawing-anchor.position')}</Radio>
+ <Radio value={SheetDrawingAnchorType.None}>{localeService.t<LocaleKey>('sheets-drawing-ui.drawing-anchor.none')}</Radio>
</RadioGroup>
</div>
</div>
diff --git a/packages/sheets-filter-ui/src/locale/types.ts b/packages/sheets-filter-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-filter-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-filter-ui/src/menu/sheets-filter.menu.ts b/packages/sheets-filter-ui/src/menu/sheets-filter.menu.ts
index 5686bbe0f2..64f6eb134a 100644
--- a/packages/sheets-filter-ui/src/menu/sheets-filter.menu.ts
+++ b/packages/sheets-filter-ui/src/menu/sheets-filter.menu.ts
@@ -16,6 +16,7 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { UniverInstanceType } from '@univerjs/core';
import {
RangeProtectionPermissionViewPoint,
@@ -32,7 +33,7 @@ import { getCurrentRangeDisable$, getObservableWithExclusiveRange$ } from '@univ
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { map, of, switchMap } from 'rxjs';
-export function SmartToggleFilterMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {
+export function SmartToggleFilterMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
const sheetsFilterService = accessor.get(SheetsFilterService);
return {
@@ -55,7 +56,7 @@ export function SmartToggleFilterMenuItemFactory(accessor: IAccessor): IMenuSele
};
}
-export function ClearFilterCriteriaMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ClearFilterCriteriaMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const sheetsFilterService = accessor.get(SheetsFilterService);
return {
@@ -63,11 +64,13 @@ export function ClearFilterCriteriaMenuItemFactory(accessor: IAccessor): IMenuBu
type: MenuItemType.BUTTON,
title: 'sheets-filter-ui.toolbar.clear-filter-criteria',
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
- disabled$: sheetsFilterService.activeFilterModel$.pipe(switchMap((model) => model?.hasCriteria$.pipe(map((m) => !m)) ?? of(true))),
+ disabled$: sheetsFilterService
+ .activeFilterModel$
+ .pipe(switchMap((model) => model?.hasCriteria$.pipe(map((m) => !m)) ?? of(true))),
};
}
-export function ReCalcFilterMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ReCalcFilterMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const sheetsFilterService = accessor.get(SheetsFilterService);
return {
@@ -75,6 +78,8 @@ export function ReCalcFilterMenuItemFactory(accessor: IAccessor): IMenuButtonIte
type: MenuItemType.BUTTON,
title: 'sheets-filter-ui.toolbar.re-calc-filter-conditions',
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
- disabled$: sheetsFilterService.activeFilterModel$.pipe(switchMap((model) => model?.hasCriteria$.pipe(map((m) => !m)) ?? of(true))),
+ disabled$: sheetsFilterService
+ .activeFilterModel$
+ .pipe(switchMap((model) => model?.hasCriteria$.pipe(map((m) => !m)) ?? of(true))),
};
}
diff --git a/packages/sheets-filter-ui/src/views/components/SheetsFilterByColorsPanel.tsx b/packages/sheets-filter-ui/src/views/components/SheetsFilterByColorsPanel.tsx
index 2c79993ca3..b1edeb5753 100644
--- a/packages/sheets-filter-ui/src/views/components/SheetsFilterByColorsPanel.tsx
+++ b/packages/sheets-filter-ui/src/views/components/SheetsFilterByColorsPanel.tsx
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { LocaleKey } from '../../locale/types';
import type { ByColorsModel, IFilterByColorItem } from '../../services/sheets-filter-panel.service';
import { LocaleService } from '@univerjs/core';
import { borderClassName, clsx } from '@univerjs/design';
@@ -58,7 +59,7 @@ export function FilterByColor(props: { model: ByColorsModel }) {
dark:!univer-text-white
`}
>
- {localeService.t('sheets-filter-ui.panel.filter-by-cell-fill-color')}
+ {localeService.t<LocaleKey>('sheets-filter-ui.panel.filter-by-cell-fill-color')}
</div>
<div
className={`
@@ -110,7 +111,7 @@ export function FilterByColor(props: { model: ByColorsModel }) {
dark:!univer-text-white
`}
>
- {localeService.t('sheets-filter-ui.panel.filter-by-cell-text-color')}
+ {localeService.t<LocaleKey>('sheets-filter-ui.panel.filter-by-cell-text-color')}
</div>
<div
className={`
@@ -150,7 +151,7 @@ export function FilterByColor(props: { model: ByColorsModel }) {
dark:!univer-text-gray-200
`}
>
- {localeService.t('sheets-filter-ui.panel.filter-by-color-none')}
+ {localeService.t<LocaleKey>('sheets-filter-ui.panel.filter-by-color-none')}
</div>
)}
</div>
diff --git a/packages/sheets-filter-ui/src/views/components/SheetsFilterByValuesPanel.tsx b/packages/sheets-filter-ui/src/views/components/SheetsFilterByValuesPanel.tsx
index dca07af203..a435e00865 100644
--- a/packages/sheets-filter-ui/src/views/components/SheetsFilterByValuesPanel.tsx
+++ b/packages/sheets-filter-ui/src/views/components/SheetsFilterByValuesPanel.tsx
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { LocaleKey } from '../../locale/types';
import type { ByValuesModel, IFilterByValueWithTreeItem } from '../../services/sheets-filter-panel.service';
import { LocaleService } from '@univerjs/core';
import { borderClassName, Checkbox, clsx, Input, Tree } from '@univerjs/design';
@@ -31,7 +32,7 @@ export function FilterByValue(props: { model: ByValuesModel }) {
const searchText = useObservable(model.searchString$, '', true);
const items = useObservable(model.filterItems$, undefined, true);
- const filterOnly = localeService.t('sheets-filter-ui.panel.filter-only');
+ const filterOnly = localeService.t<LocaleKey>('sheets-filter-ui.panel.filter-only');
const stat = statisticFilterByValueItems(items);
const allChecked = stat.checked > 0 && stat.unchecked === 0;
@@ -68,7 +69,7 @@ export function FilterByValue(props: { model: ByValuesModel }) {
<Input
autoFocus
value={searchText}
- placeholder={localeService.t('sheets-filter-ui.panel.search-placeholder')}
+ placeholder={localeService.t<LocaleKey>('sheets-filter-ui.panel.search-placeholder')}
onChange={onSearchValueChange}
/>
<div
@@ -103,7 +104,7 @@ export function FilterByValue(props: { model: ByValuesModel }) {
dark:!univer-text-white
`}
>
- {`${localeService.t('sheets-filter-ui.panel.select-all')}`}
+ {`${localeService.t<LocaleKey>('sheets-filter-ui.panel.select-all')}`}
</span>
<span
data-u-comp="sheets-filter-panel-values-item-count"
diff --git a/packages/sheets-filter-ui/src/views/components/SheetsFilterPanel.tsx b/packages/sheets-filter-ui/src/views/components/SheetsFilterPanel.tsx
index d284d2d046..88ebe14575 100644
--- a/packages/sheets-filter-ui/src/views/components/SheetsFilterPanel.tsx
+++ b/packages/sheets-filter-ui/src/views/components/SheetsFilterPanel.tsx
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { LocaleKey } from '../../locale/types';
import type { ByColorsModel, ByConditionsModel, ByValuesModel } from '../../services/sheets-filter-panel.service';
import { ICommandService, LocaleService } from '@univerjs/core';
import { Button, Segmented } from '@univerjs/design';
@@ -115,14 +116,14 @@ export function FilterPanel() {
`}
>
<Button variant="link" onClick={onClearCriteria} disabled={clearFilterDisabled}>
- {localeService.t('sheets-filter-ui.panel.clear-filter')}
+ {localeService.t<LocaleKey>('sheets-filter-ui.panel.clear-filter')}
</Button>
<span className="univer-flex univer-gap-2">
<Button variant="default" onClick={onCancel}>
- {localeService.t('sheets-filter-ui.panel.cancel')}
+ {localeService.t<LocaleKey>('sheets-filter-ui.panel.cancel')}
</Button>
<Button disabled={!canApply} variant="primary" onClick={onApply}>
- {localeService.t('sheets-filter-ui.panel.confirm')}
+ {localeService.t<LocaleKey>('sheets-filter-ui.panel.confirm')}
</Button>
</span>
</div>
@@ -134,8 +135,8 @@ export const FILTER_PANEL_POPUP_KEY = 'FILTER_PANEL_POPUP';
function useFilterByOptions(localeService: LocaleService) {
const locale = localeService.getCurrentLocale();
return useMemo(() => [
- { label: localeService.t('sheets-filter-ui.panel.by-values'), value: FilterBy.VALUES },
- { label: localeService.t('sheets-filter-ui.panel.by-colors'), value: FilterBy.COLORS },
- { label: localeService.t('sheets-filter-ui.panel.by-conditions'), value: FilterBy.CONDITIONS },
+ { label: localeService.t<LocaleKey>('sheets-filter-ui.panel.by-values'), value: FilterBy.VALUES },
+ { label: localeService.t<LocaleKey>('sheets-filter-ui.panel.by-colors'), value: FilterBy.COLORS },
+ { label: localeService.t<LocaleKey>('sheets-filter-ui.panel.by-conditions'), value: FilterBy.CONDITIONS },
], [locale, localeService]);
}
diff --git a/packages/sheets-filter-ui/src/views/components/SheetsFilterSyncSwitch.tsx b/packages/sheets-filter-ui/src/views/components/SheetsFilterSyncSwitch.tsx
index 7f87c87a10..c5b9605f4e 100644
--- a/packages/sheets-filter-ui/src/views/components/SheetsFilterSyncSwitch.tsx
+++ b/packages/sheets-filter-ui/src/views/components/SheetsFilterSyncSwitch.tsx
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { LocaleKey } from '../../locale/types';
import { LocaleService } from '@univerjs/core';
import { MessageType, Switch, Tooltip } from '@univerjs/design';
import { InfoIcon } from '@univerjs/icons';
@@ -37,11 +38,11 @@ export function FilterSyncSwitch() {
`}
>
<div className="univer-flex univer-items-center univer-gap-1">
- <span>{localeService.t('sheets-filter-ui.sync.title')}</span>
+ <span>{localeService.t<LocaleKey>('sheets-filter-ui.sync.title')}</span>
<Tooltip
title={enabled
- ? localeService.t('sheets-filter-ui.sync.statusTips.off')
- : localeService.t('sheets-filter-ui.sync.statusTips.on')}
+ ? localeService.t<LocaleKey>('sheets-filter-ui.sync.statusTips.off')
+ : localeService.t<LocaleKey>('sheets-filter-ui.sync.statusTips.on')}
asChild
>
<InfoIcon className="univer-block" />
@@ -51,8 +52,8 @@ export function FilterSyncSwitch() {
defaultChecked={enabled}
onChange={(checked) => {
const message = checked
- ? localeService.t('sheets-filter-ui.sync.switchTips.on')
- : localeService.t('sheets-filter-ui.sync.switchTips.off');
+ ? localeService.t<LocaleKey>('sheets-filter-ui.sync.switchTips.on')
+ : localeService.t<LocaleKey>('sheets-filter-ui.sync.switchTips.off');
sheetsFilterSyncController.setEnabled(checked);
messageService.show({
content: message,
diff --git a/packages/sheets-filter/src/commands/commands/sheets-filter.command.ts b/packages/sheets-filter/src/commands/commands/sheets-filter.command.ts
index 828154a725..680748f1e5 100644
--- a/packages/sheets-filter/src/commands/commands/sheets-filter.command.ts
+++ b/packages/sheets-filter/src/commands/commands/sheets-filter.command.ts
@@ -16,13 +16,37 @@
import type { IAccessor, ICommand, IMutationInfo, IRange, Nullable, Workbook } from '@univerjs/core';
import type { IMarkDirtyFilterChangeMutationParams, ISheetCommandSharedParams } from '@univerjs/sheets';
+import type { LocaleKey } from '../../locale/types';
import type { FilterColumn } from '../../models/filter-model';
import type { IAutoFilter, IFilterColumn } from '../../models/types';
-import type { ISetSheetsFilterCriteriaMutationParams, ISetSheetsFilterRangeMutationParams } from '../mutations/sheets-filter.mutation';
-import { CommandType, ErrorService, ICommandService, IUndoRedoService, IUniverInstanceService, LocaleService, sequenceExecute, UniverInstanceType } from '@univerjs/core';
-import { expandToContinuousRange, getSheetCommandTarget, isSingleCellSelection, MarkDirtyFilterChangeMutation, SheetsSelectionsService } from '@univerjs/sheets';
+import type {
+ ISetSheetsFilterCriteriaMutationParams,
+ ISetSheetsFilterRangeMutationParams,
+} from '../mutations/sheets-filter.mutation';
+import {
+ CommandType,
+ ErrorService,
+ ICommandService,
+ IUndoRedoService,
+ IUniverInstanceService,
+ LocaleService,
+ sequenceExecute,
+ UniverInstanceType,
+} from '@univerjs/core';
+import {
+ expandToContinuousRange,
+ getSheetCommandTarget,
+ isSingleCellSelection,
+ MarkDirtyFilterChangeMutation,
+ SheetsSelectionsService,
+} from '@univerjs/sheets';
import { SheetsFilterService } from '../../services/sheet-filter.service';
-import { ReCalcSheetsFilterMutation, RemoveSheetsFilterMutation, SetSheetsFilterCriteriaMutation, SetSheetsFilterRangeMutation } from '../mutations/sheets-filter.mutation';
+import {
+ ReCalcSheetsFilterMutation,
+ RemoveSheetsFilterMutation,
+ SetSheetsFilterCriteriaMutation,
+ SetSheetsFilterRangeMutation,
+} from '../mutations/sheets-filter.mutation';
/**
* Parameters of command {@link SetSheetFilterRangeCommand}.
@@ -56,7 +80,7 @@ export const SetSheetFilterRangeCommand: ICommand<ISetSheetFilterRangeCommandPar
if (range.endRow === range.startRow) {
const errorService = accessor.get(ErrorService);
const localeService = accessor.get(LocaleService);
- errorService.emit(localeService.t('sheets-filter.command.not-valid-filter-range'));
+ errorService.emit(localeService.t<LocaleKey>('sheets-filter.command.not-valid-filter-range'));
return false;
}
diff --git a/packages/sheets-filter/src/locale/types.ts b/packages/sheets-filter/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-filter/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-formula-ui/src/locale/types.ts b/packages/sheets-formula-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-formula-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-formula-ui/src/menu/menu.ts b/packages/sheets-formula-ui/src/menu/menu.ts
index 1c461f18ca..94c5de54e2 100644
--- a/packages/sheets-formula-ui/src/menu/menu.ts
+++ b/packages/sheets-formula-ui/src/menu/menu.ts
@@ -16,6 +16,7 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuItem, IValueOption } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { UniverInstanceType } from '@univerjs/core';
import { FunctionType } from '@univerjs/engine-formula';
import {
@@ -31,13 +32,31 @@ import { IDescriptionService } from '@univerjs/sheets-formula';
import { getCurrentRangeDisable$, menuClipboardDisabledObservable } from '@univerjs/sheets-ui';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { combineLatestWith, map } from 'rxjs';
-import { SheetCopyFormulaOnlyCommand, SheetOnlyPasteFormulaCommand } from '../commands/commands/formula-clipboard.command';
+import {
+ SheetCopyFormulaOnlyCommand,
+ SheetOnlyPasteFormulaCommand,
+} from '../commands/commands/formula-clipboard.command';
import { InsertFunctionOperation } from '../commands/operations/insert-function.operation';
import { MoreFunctionsOperation } from '../commands/operations/more-functions.operation';
-export function InsertCommonFunctionMenuItemFactory(accessor: IAccessor): IMenuItem {
+type FunctionCategoryKey =
+ | 'financial'
+ | 'logical'
+ | 'text'
+ | 'date'
+ | 'lookup'
+ | 'math'
+ | 'statistical'
+ | 'engineering'
+ | 'information'
+ | 'database';
+
+type EnsureLocaleKey<T extends LocaleKey> = T;
+type FunctionCategoryLocaleKey = EnsureLocaleKey<`sheets-formula-ui.functionType.${FunctionCategoryKey}`>;
+
+export function InsertCommonFunctionMenuItemFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
const commonFunctions = ['SUMIF', 'SUM', 'AVERAGE', 'IF', 'COUNT', 'SIN', 'MAX'];
- let selections: IValueOption[] = commonFunctions.map((name) => ({
+ let selections: IValueOption<LocaleKey>[] = commonFunctions.map((name) => ({
label: {
name,
selectable: false,
@@ -73,9 +92,13 @@ export function InsertCommonFunctionMenuItemFactory(accessor: IAccessor): IMenuI
};
}
-function createInsertFunctionCategoryMenuItemFactory(functionType: FunctionType, categoryKey: string, icon?: string) {
- return function insertFunctionCategoryMenuItemFactory(accessor: IAccessor): IMenuItem {
- let selections: IValueOption[] = [];
+function createInsertFunctionCategoryMenuItemFactory(
+ functionType: FunctionType,
+ categoryKey: FunctionCategoryKey,
+ icon?: string
+) {
+ return function insertFunctionCategoryMenuItemFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
+ let selections: IValueOption<LocaleKey>[] = [];
try {
const descriptionService = accessor.get(IDescriptionService);
@@ -93,7 +116,7 @@ function createInsertFunctionCategoryMenuItemFactory(functionType: FunctionType,
return {
id: `${InsertFunctionOperation.id}.${categoryKey}`,
commandId: InsertFunctionOperation.id,
- title: `sheets-formula-ui.functionType.${categoryKey}`,
+ title: `sheets-formula-ui.functionType.${categoryKey}` as FunctionCategoryLocaleKey,
tooltip: 'sheets-formula-ui.insert.tooltip',
icon,
type: MenuItemType.SELECTOR,
@@ -115,7 +138,7 @@ export const InsertInformationFunctionMenuItemFactory = createInsertFunctionCate
export const InsertDatabaseFunctionMenuItemFactory = createInsertFunctionCategoryMenuItemFactory(FunctionType.Database, 'database');
// All Functions entry displayed at the bottom of category dropdowns.
-export function AllFunctionsMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function AllFunctionsMenuItemFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: MoreFunctionsOperation.id,
title: 'sheets-formula-ui.moreFunctions.allFunctions',
@@ -131,7 +154,7 @@ export function AllFunctionsMenuItemFactory(accessor: IAccessor): IMenuItem {
}
// Right click menu - Copy Formula Only
-export function CopyFormulaOnlyMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function CopyFormulaOnlyMenuItemFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: SheetCopyFormulaOnlyCommand.id,
type: MenuItemType.BUTTON,
@@ -146,7 +169,7 @@ export function CopyFormulaOnlyMenuItemFactory(accessor: IAccessor): IMenuItem {
}
// Right click menu - Paste Formula
-export function PasteFormulaMenuItemFactory(accessor: IAccessor): IMenuItem {
+export function PasteFormulaMenuItemFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: SheetOnlyPasteFormulaCommand.id,
type: MenuItemType.BUTTON,
diff --git a/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx b/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx
index 02143885f0..8c08e1ad3b 100644
--- a/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx
+++ b/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx
@@ -16,6 +16,7 @@
import type { Editor } from '@univerjs/docs-ui';
import type { IFunctionParam } from '@univerjs/engine-formula';
+import type { LocaleKey } from '../../../locale/types';
import { LocaleService, noop } from '@univerjs/core';
import { borderClassName, borderTopClassName, clsx, scrollbarClassName } from '@univerjs/design';
import { CloseIcon, MoreIcon } from '@univerjs/icons';
@@ -98,8 +99,8 @@ export function HelpFunction(props: IHelpFunctionProps) {
const hidden = !useObservable(editorBridgeService.helpFunctionVisible$);
const [contentVisible, setContentVisible] = useState(false);
const localeService = useDependency(LocaleService);
- const required = localeService.t('sheets-formula-ui.prompt.required');
- const optional = localeService.t('sheets-formula-ui.prompt.optional');
+ const required = localeService.t<LocaleKey>('sheets-formula-ui.prompt.required');
+ const optional = localeService.t<LocaleKey>('sheets-formula-ui.prompt.optional');
const editorId = editor.getEditorId();
const [position$] = useEditorPosition(editorId, !!functionInfo, [functionInfo, paramIndex]);
function handleSwitchActive(paramIndex: number) {
@@ -188,13 +189,13 @@ export function HelpFunction(props: IHelpFunctionProps) {
>
<div className="univer-mt-3">
<Params
- title={localeService.t('sheets-formula-ui.prompt.helpExample')}
+ title={localeService.t<LocaleKey>('sheets-formula-ui.prompt.helpExample')}
value={`${functionInfo.functionName}(${functionInfo.functionParameter
.map((item) => item.example)
.join(',')})`}
/>
<Params
- title={localeService.t('sheets-formula-ui.prompt.helpAbstract')}
+ title={localeService.t<LocaleKey>('sheets-formula-ui.prompt.helpAbstract')}
value={functionInfo.description}
/>
{functionInfo &&
diff --git a/packages/sheets-formula-ui/src/views/more-functions/MoreFunctions.tsx b/packages/sheets-formula-ui/src/views/more-functions/MoreFunctions.tsx
index dc6c1dcd32..c251a1ff22 100644
--- a/packages/sheets-formula-ui/src/views/more-functions/MoreFunctions.tsx
+++ b/packages/sheets-formula-ui/src/views/more-functions/MoreFunctions.tsx
@@ -15,7 +15,14 @@
*/
import type { IFunctionInfo } from '@univerjs/engine-formula';
-import { DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, ICommandService, IUniverInstanceService, LocaleService } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
+import {
+ DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,
+ DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
+ ICommandService,
+ IUniverInstanceService,
+ LocaleService,
+} from '@univerjs/core';
import { Button } from '@univerjs/design';
import { IEditorService } from '@univerjs/docs-ui';
import { DeviceInputEventType } from '@univerjs/engine-render';
@@ -77,12 +84,12 @@ export function MoreFunctions() {
onClick={handleClickNextPrev}
className="univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0"
>
- {localeService.t('sheets-formula-ui.moreFunctions.next')}
+ {localeService.t<LocaleKey>('sheets-formula-ui.moreFunctions.next')}
</Button>
)}
{inputParams && (
<Button onClick={handleClickNextPrev} className="univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0">
- {localeService.t('sheets-formula-ui.moreFunctions.prev')}
+ {localeService.t<LocaleKey>('sheets-formula-ui.moreFunctions.prev')}
</Button>
)}
{selectFunction && !!workbook && (
@@ -92,7 +99,7 @@ export function MoreFunctions() {
onClick={handleConfirm}
className="univer-mb-5 univer-ml-4 univer-mr-0 univer-mt-0"
>
- {localeService.t('sheets-formula-ui.moreFunctions.confirm')}
+ {localeService.t<LocaleKey>('sheets-formula-ui.moreFunctions.confirm')}
</Button>
)}
</div>
diff --git a/packages/sheets-formula-ui/src/views/more-functions/select-function/SelectFunction.tsx b/packages/sheets-formula-ui/src/views/more-functions/select-function/SelectFunction.tsx
index ab32410d22..48a6894810 100644
--- a/packages/sheets-formula-ui/src/views/more-functions/select-function/SelectFunction.tsx
+++ b/packages/sheets-formula-ui/src/views/more-functions/select-function/SelectFunction.tsx
@@ -18,6 +18,7 @@ import type { IFunctionInfo, IFunctionParam } from '@univerjs/engine-formula';
import type { ISearchItem, IUniverSheetsFormulaBaseConfig } from '@univerjs/sheets-formula';
import type { ISidebarMethodOptions } from '@univerjs/ui';
import type { KeyboardEvent } from 'react';
+import type { LocaleKey } from '../../../locale/types';
import { IConfigService, LocaleService } from '@univerjs/core';
import { borderClassName, clsx, Input, scrollbarClassName, Select } from '@univerjs/design';
import { CheckMarkIcon } from '@univerjs/icons';
@@ -56,12 +57,12 @@ export function SelectFunction(props: ISelectFunctionProps) {
);
options.unshift({
- label: localeService.t('sheets-formula-ui.moreFunctions.allFunctions'),
+ label: localeService.t<LocaleKey>('sheets-formula-ui.moreFunctions.allFunctions'),
value: allTypeValue,
});
- const required = localeService.t('sheets-formula-ui.prompt.required');
- const optional = localeService.t('sheets-formula-ui.prompt.optional');
+ const required = localeService.t<LocaleKey>('sheets-formula-ui.prompt.required');
+ const optional = localeService.t<LocaleKey>('sheets-formula-ui.prompt.optional');
useEffect(() => {
handleSelectChange(allTypeValue);
@@ -161,7 +162,7 @@ export function SelectFunction(props: ISelectFunctionProps) {
<Select value={typeSelected} options={options} onChange={handleSelectChange} />
<Input
- placeholder={localeService.t('sheets-formula-ui.moreFunctions.searchFunctionPlaceholder')}
+ placeholder={localeService.t<LocaleKey>('sheets-formula-ui.moreFunctions.searchFunctionPlaceholder')}
onKeyDown={handleSelectListKeyDown}
value={searchText}
onChange={handleSearchInputChange}
@@ -212,12 +213,12 @@ export function SelectFunction(props: ISelectFunctionProps) {
<FunctionParams title={functionInfo.functionName} value={functionInfo.description} />
<FunctionParams
- title={localeService.t('sheets-formula-ui.moreFunctions.syntax')}
+ title={localeService.t<LocaleKey>('sheets-formula-ui.moreFunctions.syntax')}
value={<FunctionHelp prefix={functionInfo.functionName} value={functionInfo.functionParameter} />}
/>
<FunctionParams
- title={localeService.t('sheets-formula-ui.prompt.helpExample')}
+ title={localeService.t<LocaleKey>('sheets-formula-ui.prompt.helpExample')}
value={`${functionInfo.functionName}(${functionInfo.functionParameter
.map((item) => item.example)
.join(',')})`}
diff --git a/packages/sheets-formula-ui/src/views/range-selector/index.tsx b/packages/sheets-formula-ui/src/views/range-selector/index.tsx
index 61096b51e0..22fa0ce4c0 100644
--- a/packages/sheets-formula-ui/src/views/range-selector/index.tsx
+++ b/packages/sheets-formula-ui/src/views/range-selector/index.tsx
@@ -18,10 +18,18 @@ import type { IUnitRangeName, Nullable } from '@univerjs/core';
import type { Editor, IRichTextEditorProps } from '@univerjs/docs-ui';
import type { ISelectionWithStyle, ISetSelectionsOperationParams } from '@univerjs/sheets';
import type { RefObject } from 'react';
+import type { LocaleKey } from '../../locale/types';
import { ICommandService, LocaleService, RichTextBuilder } from '@univerjs/core';
import { Button, clsx, Dialog, Input, scrollbarClassName, Tooltip } from '@univerjs/design';
import { IEditorService, RichTextEditor } from '@univerjs/docs-ui';
-import { deserializeRangeWithSheet, LexerTreeBuilder, matchToken, sequenceNodeType, serializeRange, serializeRangeWithSheet } from '@univerjs/engine-formula';
+import {
+ deserializeRangeWithSheet,
+ LexerTreeBuilder,
+ matchToken,
+ sequenceNodeType,
+ serializeRange,
+ serializeRangeWithSheet,
+} from '@univerjs/engine-formula';
import { DeleteIcon, IncreaseIcon, SelectRangeIcon } from '@univerjs/icons';
import { SetSelectionsOperation } from '@univerjs/sheets';
import { useDependency, useEvent } from '@univerjs/ui';
@@ -160,13 +168,13 @@ export function RangeSelectorDialog(props: IRangeSelectorDialogProps) {
<Dialog
width="328px"
open={visible}
- title={localeService.t('sheets-formula-ui.rangeSelector.title')}
+ title={localeService.t<LocaleKey>('sheets-formula-ui.rangeSelector.title')}
draggable
mask={false}
maskClosable={false}
footer={(
<footer className="univer-flex univer-gap-2">
- <Button onClick={onClose}>{localeService.t('sheets-formula-ui.rangeSelector.cancel')}</Button>
+ <Button onClick={onClose}>{localeService.t<LocaleKey>('sheets-formula-ui.rangeSelector.cancel')}</Button>
<Button
variant="primary"
onClick={() => {
@@ -180,7 +188,7 @@ export function RangeSelectorDialog(props: IRangeSelectorDialogProps) {
);
}}
>
- {localeService.t('sheets-formula-ui.rangeSelector.confirm')}
+ {localeService.t<LocaleKey>('sheets-formula-ui.rangeSelector.confirm')}
</Button>
</footer>
)}
@@ -199,7 +207,7 @@ export function RangeSelectorDialog(props: IRangeSelectorDialogProps) {
className={clsx('univer-w-full', {
'univer-border-primary-600': focusIndex === index,
})}
- placeholder={localeService.t('sheets-formula-ui.rangeSelector.placeHolder')}
+ placeholder={localeService.t<LocaleKey>('sheets-formula-ui.rangeSelector.placeHolder')}
onFocus={() => setFocusIndex(index)}
value={text}
onChange={(value) => handleRangeInput(index, value)}
@@ -216,7 +224,7 @@ export function RangeSelectorDialog(props: IRangeSelectorDialogProps) {
<div>
<Button variant="link" onClick={handleRangeAdd}>
<IncreaseIcon />
- <span>{localeService.t('sheets-formula-ui.rangeSelector.addAnotherRange')}</span>
+ <span>{localeService.t<LocaleKey>('sheets-formula-ui.rangeSelector.addAnotherRange')}</span>
</Button>
</div>
)}
@@ -338,7 +346,7 @@ export function RangeSelector(props: IRangeSelectorProps) {
onClickOutside?.();
}}
icon={(
- <Tooltip title={localeService.t('sheets-formula-ui.rangeSelector.buttonTooltip')} placement="bottom">
+ <Tooltip title={localeService.t<LocaleKey>('sheets-formula-ui.rangeSelector.buttonTooltip')} placement="bottom">
<SelectRangeIcon
className={`
univer-cursor-pointer
diff --git a/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts b/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts
index 60b7ceeba6..fd24a3ec55 100644
--- a/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts
+++ b/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts
@@ -28,7 +28,17 @@ import type {
} from '@univerjs/engine-formula';
import type { ISetRangeValuesMutationParams } from '@univerjs/sheets';
import type { IUniverSheetsFormulaBaseConfig } from '../config/config';
-import { Disposable, ICommandService, IConfigService, ILogService, Inject, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
+import type { LocaleKey } from '../locale/types';
+import {
+ Disposable,
+ ICommandService,
+ IConfigService,
+ ILogService,
+ Inject,
+ IUniverInstanceService,
+ LocaleService,
+ UniverInstanceType,
+} from '@univerjs/core';
import {
ENGINE_FORMULA_CYCLE_REFERENCE_COUNT,
ENGINE_FORMULA_RETURN_DEPENDENCY_TREE,
@@ -108,7 +118,7 @@ export class TriggerCalculationController extends Disposable {
this._doneCalculationTaskCount = 0;
this._totalCalculationTaskCount = 1;
- const analyzing = this._localeService.t('sheets-formula.progress.analyzing');
+ const analyzing = this._localeService.t<LocaleKey>('sheets-formula.progress.analyzing');
this._emitProgress(analyzing);
}
@@ -129,7 +139,7 @@ export class TriggerCalculationController extends Disposable {
private _completeProgress(): void {
this._doneCalculationTaskCount = this._totalCalculationTaskCount = 1;
- const done = this._localeService.t('sheets-formula.progress.done');
+ const done = this._localeService.t<LocaleKey>('sheets-formula.progress.done');
this._emitProgress(done);
}
@@ -445,21 +455,21 @@ export class TriggerCalculationController extends Disposable {
this._executionInProgressParams = params.stageInfo;
if (startDependencyTimer === null) {
- const calculating = this._localeService.t('sheets-formula.progress.calculating');
+ const calculating = this._localeService.t<LocaleKey>('sheets-formula.progress.calculating');
this._calculateProgress(calculating);
}
} else if (stage === FormulaExecuteStageType.START_DEPENDENCY_ARRAY_FORMULA) {
this._executionInProgressParams = params.stageInfo;
if (startDependencyTimer === null) {
- const arrayAnalysis = this._localeService.t('sheets-formula.progress.array-analysis');
+ const arrayAnalysis = this._localeService.t<LocaleKey>('sheets-formula.progress.array-analysis');
this._calculateProgress(arrayAnalysis);
}
} else if (stage === FormulaExecuteStageType.CURRENTLY_CALCULATING_ARRAY_FORMULA) {
this._executionInProgressParams = params.stageInfo;
if (startDependencyTimer === null) {
- const arrayCalculation = this._localeService.t('sheets-formula.progress.array-calculation');
+ const arrayCalculation = this._localeService.t<LocaleKey>('sheets-formula.progress.array-calculation');
this._calculateProgress(arrayCalculation);
}
}
diff --git a/packages/sheets-formula/src/locale/types.ts b/packages/sheets-formula/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-formula/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-hyper-link-ui/src/locale/types.ts b/packages/sheets-hyper-link-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-hyper-link-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-hyper-link-ui/src/menu/menu.ts b/packages/sheets-hyper-link-ui/src/menu/menu.ts
index 3c94ba4ea9..44026fa718 100644
--- a/packages/sheets-hyper-link-ui/src/menu/menu.ts
+++ b/packages/sheets-hyper-link-ui/src/menu/menu.ts
@@ -17,10 +17,23 @@
import type { DocumentDataModel, IAccessor, Nullable } from '@univerjs/core';
import type { IEditorBridgeServiceVisibleParam } from '@univerjs/sheets-ui';
import type { IMenuItem, IShortcutItem } from '@univerjs/ui';
-import { DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
+import type { LocaleKey } from '../locale/types';
+import {
+ DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,
+ DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
+ IUniverInstanceService,
+ UniverInstanceType,
+} from '@univerjs/core';
import { DocSelectionRenderService } from '@univerjs/docs-ui';
import { IRenderManagerService } from '@univerjs/engine-render';
-import { getSheetCommandTarget, RangeProtectionPermissionEditPoint, WorkbookEditablePermission, WorksheetEditPermission, WorksheetInsertHyperlinkPermission, WorksheetSetCellValuePermission } from '@univerjs/sheets';
+import {
+ getSheetCommandTarget,
+ RangeProtectionPermissionEditPoint,
+ WorkbookEditablePermission,
+ WorksheetEditPermission,
+ WorksheetInsertHyperlinkPermission,
+ WorksheetSetCellValuePermission,
+} from '@univerjs/sheets';
import { getCurrentRangeDisable$, IEditorBridgeService, whenSheetEditorFocused } from '@univerjs/sheets-ui';
import { getMenuHiddenObservable, KeyCode, MenuItemType, MetaKeys } from '@univerjs/ui';
import { combineLatest, map, of, switchMap } from 'rxjs';
@@ -29,7 +42,9 @@ import { DisableLinkType, getShouldDisableCellLink, shouldDisableAddLink } from
const getEditingLinkDisable$ = (accessor: IAccessor, unitId = DOCS_NORMAL_EDITOR_UNIT_ID_KEY) => {
const univerInstanceService = accessor.get(IUniverInstanceService);
- const docSelctionService = accessor.get(IRenderManagerService).getRenderById(unitId)?.with(DocSelectionRenderService);
+ const docSelctionService = accessor.get(IRenderManagerService)
+ .getRenderById(unitId)
+ ?.with(DocSelectionRenderService);
if (!docSelctionService) {
return of(true);
}
@@ -62,7 +77,10 @@ const getLinkDisable$ = (accessor: IAccessor) => {
if (!state) {
return (DisableLinkType.DISABLED_BY_CELL);
}
- const target = getSheetCommandTarget(univerInstanceService, { unitId: state.unitId, subUnitId: state.sheetId });
+ const target = getSheetCommandTarget(univerInstanceService, {
+ unitId: state.unitId,
+ subUnitId: state.sheetId,
+ });
if (!target) {
return (DisableLinkType.DISABLED_BY_CELL);
}
@@ -75,7 +93,10 @@ const getLinkDisable$ = (accessor: IAccessor) => {
}
const isEditing$ = (editorBridgeService ? editorBridgeService.visible$ : of<Nullable<IEditorBridgeServiceVisibleParam>>(null));
- return combineLatest([isEditing$, univerInstanceService.getCurrentTypeOfUnit$<DocumentDataModel>(UniverInstanceType.UNIVER_DOC)]).pipe(
+ return combineLatest([
+ isEditing$,
+ univerInstanceService.getCurrentTypeOfUnit$<DocumentDataModel>(UniverInstanceType.UNIVER_DOC),
+ ]).pipe(
switchMap(
([editing, focusingDoc]) => {
return editing?.visible ?
@@ -94,40 +115,39 @@ const getLinkDisable$ = (accessor: IAccessor) => {
if (disableCell) {
return of(true);
} else {
- return getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetInsertHyperlinkPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }, true);
+ return getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [
+ WorksheetEditPermission,
+ WorksheetSetCellValuePermission,
+ WorksheetInsertHyperlinkPermission,
+ ],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }, true);
}
})
);
};
-const linkMenu = {
- commandId: InsertHyperLinkOperation.id,
- type: MenuItemType.BUTTON,
- title: 'sheets-hyper-link-ui.menu.add',
- icon: 'LinkIcon',
-};
-
-export const insertLinkMenuFactory = (accessor: IAccessor) => {
+export const insertLinkMenuFactory = (accessor: IAccessor): IMenuItem<LocaleKey> => {
return {
- ...linkMenu,
- id: linkMenu.commandId,
+ commandId: InsertHyperLinkOperation.id,
+ type: MenuItemType.BUTTON,
+ title: 'sheets-hyper-link-ui.menu.add',
+ icon: 'LinkIcon',
+ id: InsertHyperLinkOperation.id,
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
disabled$: getLinkDisable$(accessor),
- // disabled$: getObservableWithExclusiveRange$(accessor, getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetInsertHyperlinkPermission], rangeTypes: [RangeProtectionPermissionEditPoint] })),
- } as IMenuItem;
-};
-
-const linkToolbarMenu = {
- tooltip: 'sheets-hyper-link-ui.form.addTitle',
- commandId: InsertHyperLinkToolbarOperation.id,
- type: MenuItemType.BUTTON,
- icon: 'LinkIcon',
+ };
};
-export const insertLinkMenuToolbarFactory = (accessor: IAccessor) => {
+export const insertLinkMenuToolbarFactory = (accessor: IAccessor): IMenuItem<LocaleKey> => {
return {
- ...linkToolbarMenu,
- id: linkToolbarMenu.commandId,
+ tooltip: 'sheets-hyper-link-ui.form.addTitle',
+ commandId: InsertHyperLinkToolbarOperation.id,
+ type: MenuItemType.BUTTON,
+ icon: 'LinkIcon',
+ id: InsertHyperLinkToolbarOperation.id,
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
disabled$: getLinkDisable$(accessor),
};
diff --git a/packages/sheets-hyper-link-ui/src/services/resolver.service.ts b/packages/sheets-hyper-link-ui/src/services/resolver.service.ts
index 539b37e2dd..2d653b7b75 100644
--- a/packages/sheets-hyper-link-ui/src/services/resolver.service.ts
+++ b/packages/sheets-hyper-link-ui/src/services/resolver.service.ts
@@ -18,7 +18,19 @@ import type { IRange, Workbook, Worksheet } from '@univerjs/core';
import type { ISetSelectionsOperationParams } from '@univerjs/sheets';
import type { ISheetHyperLinkInfo, ISheetUrlParams } from '@univerjs/sheets-hyper-link';
import type { IUniverSheetsHyperLinkUIConfig } from '../config/config';
-import { ICommandService, IConfigService, Inject, isSafeUrl, isValidRange, IUniverInstanceService, LocaleService, RANGE_TYPE, Rectangle, UniverInstanceType } from '@univerjs/core';
+import type { LocaleKey } from '../locale/types';
+import {
+ ICommandService,
+ IConfigService,
+ Inject,
+ isSafeUrl,
+ isValidRange,
+ IUniverInstanceService,
+ LocaleService,
+ RANGE_TYPE,
+ Rectangle,
+ UniverInstanceType,
+} from '@univerjs/core';
import { MessageType } from '@univerjs/design';
import { deserializeRangeWithSheet, IDefinedNamesService } from '@univerjs/engine-formula';
import { SetSelectionsOperation, SetWorksheetActiveOperation } from '@univerjs/sheets';
@@ -94,7 +106,7 @@ export class SheetsHyperLinkResolverService {
if (!worksheet) {
this._messageService.show({
- content: this._localeService.t('sheets-hyper-link-ui.message.refError'),
+ content: this._localeService.t<LocaleKey>('sheets-hyper-link-ui.message.refError'),
type: MessageType.Error,
});
return;
@@ -105,7 +117,7 @@ export class SheetsHyperLinkResolverService {
// The worksheet may be hidden
if (isHidden) {
this._messageService.show({
- content: this._localeService.t('sheets-hyper-link-ui.message.hiddenSheet'),
+ content: this._localeService.t<LocaleKey>('sheets-hyper-link-ui.message.hiddenSheet'),
type: MessageType.Error,
});
return;
@@ -170,7 +182,7 @@ export class SheetsHyperLinkResolverService {
if (!targetSheet) {
this._messageService.show({
- content: this._localeService.t('sheets-hyper-link-ui.message.noSheet'),
+ content: this._localeService.t<LocaleKey>('sheets-hyper-link-ui.message.noSheet'),
type: MessageType.Error,
});
return false;
@@ -178,7 +190,7 @@ export class SheetsHyperLinkResolverService {
if (workbook.getHiddenWorksheets().indexOf(subUnitId) > -1) {
this._messageService.show({
- content: this._localeService.t('sheets-hyper-link-ui.message.hiddenSheet'),
+ content: this._localeService.t<LocaleKey>('sheets-hyper-link-ui.message.hiddenSheet'),
type: MessageType.Error,
});
return false;
diff --git a/packages/sheets-hyper-link-ui/src/views/CellLinkEdit.tsx b/packages/sheets-hyper-link-ui/src/views/CellLinkEdit.tsx
index 031792990b..0290d00320 100644
--- a/packages/sheets-hyper-link-ui/src/views/CellLinkEdit.tsx
+++ b/packages/sheets-hyper-link-ui/src/views/CellLinkEdit.tsx
@@ -16,6 +16,7 @@
import type { DocumentDataModel, Nullable, Workbook } from '@univerjs/core';
import type { ISelectionWithStyle } from '@univerjs/sheets';
+import type { LocaleKey } from '../locale/types';
import {
BuildTextUtils,
ColorKit,
@@ -33,11 +34,23 @@ import {
import { borderClassName, Button, clsx, FormLayout, Input, Select } from '@univerjs/design';
import { DocSelectionManagerService } from '@univerjs/docs';
import { DocSelectionRenderService } from '@univerjs/docs-ui';
-import { deserializeRangeWithSheet, IDefinedNamesService, serializeRange, serializeRangeWithSheet } from '@univerjs/engine-formula';
+import {
+ deserializeRangeWithSheet,
+ IDefinedNamesService,
+ serializeRange,
+ serializeRangeWithSheet,
+} from '@univerjs/engine-formula';
import { IRenderManagerService } from '@univerjs/engine-render';
import { SetWorksheetActiveOperation, SheetsSelectionsService } from '@univerjs/sheets';
import { RangeSelector } from '@univerjs/sheets-formula-ui';
-import { AddHyperLinkCommand, AddRichHyperLinkCommand, SheetHyperLinkType, SheetsHyperLinkParserService, UpdateHyperLinkCommand, UpdateRichHyperLinkCommand } from '@univerjs/sheets-hyper-link';
+import {
+ AddHyperLinkCommand,
+ AddRichHyperLinkCommand,
+ SheetHyperLinkType,
+ SheetsHyperLinkParserService,
+ UpdateHyperLinkCommand,
+ UpdateRichHyperLinkCommand,
+} from '@univerjs/sheets-hyper-link';
import { IEditorBridgeService, IMarkSelectionService, ScrollToRangeOperation } from '@univerjs/sheets-ui';
import { KeyCode, useDependency, useEvent, useObservable } from '@univerjs/ui';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
@@ -290,19 +303,19 @@ export const CellLinkEdit = () => {
value: SheetHyperLinkType | string;
}> = [
{
- label: localeService.t('sheets-hyper-link-ui.form.link'),
+ label: localeService.t<LocaleKey>('sheets-hyper-link-ui.form.link'),
value: SheetHyperLinkType.URL,
},
{
- label: localeService.t('sheets-hyper-link-ui.form.range'),
+ label: localeService.t<LocaleKey>('sheets-hyper-link-ui.form.range'),
value: SheetHyperLinkType.RANGE,
},
{
- label: localeService.t('sheets-hyper-link-ui.form.worksheet'),
+ label: localeService.t<LocaleKey>('sheets-hyper-link-ui.form.worksheet'),
value: SheetHyperLinkType.SHEET,
},
{
- label: localeService.t('sheets-hyper-link-ui.form.definedName'),
+ label: localeService.t<LocaleKey>('sheets-hyper-link-ui.form.definedName'),
value: SheetHyperLinkType.DEFINE_NAME,
},
...sidePanelOptions,
@@ -421,8 +434,8 @@ export const CellLinkEdit = () => {
{showLabel
? (
<FormLayout
- label={localeService.t('sheets-hyper-link-ui.form.label')}
- error={showError && isBlankInput(display) ? localeService.t('sheets-hyper-link-ui.form.inputError') : ''}
+ label={localeService.t<LocaleKey>('sheets-hyper-link-ui.form.label')}
+ error={showError && isBlankInput(display) ? localeService.t<LocaleKey>('sheets-hyper-link-ui.form.inputError') : ''}
>
<Input
value={display}
@@ -430,7 +443,7 @@ export const CellLinkEdit = () => {
setDisplay(v);
setDisplaySyncedWithPayload(false);
}}
- placeholder={localeService.t('sheets-hyper-link-ui.form.labelPlaceholder')}
+ placeholder={localeService.t<LocaleKey>('sheets-hyper-link-ui.form.labelPlaceholder')}
autoFocus
onKeyDown={(e) => {
if (e.keyCode === KeyCode.ENTER) {
@@ -441,7 +454,7 @@ export const CellLinkEdit = () => {
</FormLayout>
)
: null}
- <FormLayout label={localeService.t('sheets-hyper-link-ui.form.type')}>
+ <FormLayout label={localeService.t<LocaleKey>('sheets-hyper-link-ui.form.type')}>
<Select
className="univer-w-full"
options={linkTypeOptions}
@@ -454,7 +467,7 @@ export const CellLinkEdit = () => {
</FormLayout>
{type === SheetHyperLinkType.URL && (
<FormLayout
- error={showError ? !payload ? localeService.t('sheets-hyper-link-ui.form.inputError') : !isLegalLink(payload) ? localeService.t('sheets-hyper-link-ui.form.linkError') : '' : ''}
+ error={showError ? !payload ? localeService.t<LocaleKey>('sheets-hyper-link-ui.form.inputError') : !isLegalLink(payload) ? localeService.t<LocaleKey>('sheets-hyper-link-ui.form.linkError') : '' : ''}
>
<Input
value={payload}
@@ -465,7 +478,7 @@ export const CellLinkEdit = () => {
setDisplaySyncedWithPayload(true);
}
}}
- placeholder={localeService.t('sheets-hyper-link-ui.form.linkPlaceholder')}
+ placeholder={localeService.t<LocaleKey>('sheets-hyper-link-ui.form.linkPlaceholder')}
autoFocus
onKeyDown={(e) => {
if (e.keyCode === KeyCode.ENTER) {
@@ -476,7 +489,7 @@ export const CellLinkEdit = () => {
</FormLayout>
)}
{type === SheetHyperLinkType.RANGE && (
- <FormLayout error={showError && !payload ? localeService.t('sheets-hyper-link-ui.form.inputError') : ''}>
+ <FormLayout error={showError && !payload ? localeService.t<LocaleKey>('sheets-hyper-link-ui.form.inputError') : ''}>
<RangeSelector
unitId={workbook.getUnitId()}
subUnitId={subUnitId}
@@ -503,7 +516,7 @@ export const CellLinkEdit = () => {
</FormLayout>
)}
{type === SheetHyperLinkType.SHEET && (
- <FormLayout error={showError && !payload ? localeService.t('sheets-hyper-link-ui.form.selectError') : ''}>
+ <FormLayout error={showError && !payload ? localeService.t<LocaleKey>('sheets-hyper-link-ui.form.selectError') : ''}>
<Select
className="univer-w-full"
options={sheetsOption}
@@ -521,7 +534,7 @@ export const CellLinkEdit = () => {
</FormLayout>
)}
{type === SheetHyperLinkType.DEFINE_NAME && (
- <FormLayout error={showError && !payload ? localeService.t('sheets-hyper-link-ui.form.selectError') : ''}>
+ <FormLayout error={showError && !payload ? localeService.t<LocaleKey>('sheets-hyper-link-ui.form.selectError') : ''}>
<Select
className="univer-w-full"
options={definedNames}
@@ -562,7 +575,7 @@ export const CellLinkEdit = () => {
commandService.executeCommand(CloseHyperLinkPopupOperation.id);
}}
>
- {localeService.t('sheets-hyper-link-ui.form.cancel')}
+ {localeService.t<LocaleKey>('sheets-hyper-link-ui.form.cancel')}
</Button>
<Button
variant="primary"
@@ -570,7 +583,7 @@ export const CellLinkEdit = () => {
handleSubmit();
}}
>
- {localeService.t('sheets-hyper-link-ui.form.ok')}
+ {localeService.t<LocaleKey>('sheets-hyper-link-ui.form.ok')}
</Button>
</div>
</div>
diff --git a/packages/sheets-hyper-link-ui/src/views/CellLinkPopup.tsx b/packages/sheets-hyper-link-ui/src/views/CellLinkPopup.tsx
index 8e376395c9..62940c5f6d 100644
--- a/packages/sheets-hyper-link-ui/src/views/CellLinkPopup.tsx
+++ b/packages/sheets-hyper-link-ui/src/views/CellLinkPopup.tsx
@@ -15,11 +15,17 @@
*/
import type { ICustomRange, Nullable, Workbook } from '@univerjs/core';
+import type { LocaleKey } from '../locale/types';
import type { IHyperLinkPopup } from '../services/popup.service';
import { ICommandService, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
import { borderClassName, clsx, MessageType, Tooltip } from '@univerjs/design';
import { AllBorderIcon, CopyIcon, LinkIcon, UnlinkIcon, WriteIcon, XlsxMultiIcon } from '@univerjs/icons';
-import { CancelHyperLinkCommand, CancelRichHyperLinkCommand, SheetHyperLinkType, SheetsHyperLinkParserService } from '@univerjs/sheets-hyper-link';
+import {
+ CancelHyperLinkCommand,
+ CancelRichHyperLinkCommand,
+ SheetHyperLinkType,
+ SheetsHyperLinkParserService,
+} from '@univerjs/sheets-hyper-link';
import { IEditorBridgeService } from '@univerjs/sheets-ui';
import { IMessageService, useDependency } from '@univerjs/ui';
import { useEffect, useState } from 'react';
@@ -123,12 +129,12 @@ export const CellLinkPopupPure = (props: ICellLinkPopupPureProps) => {
navigator.clipboard.writeText(linkObj.url);
}
messageService.show({
- content: localeService.t('sheets-hyper-link-ui.message.coped'),
+ content: localeService.t<LocaleKey>('sheets-hyper-link-ui.message.coped'),
type: MessageType.Info,
});
}}
>
- <Tooltip placement="bottom" title={localeService.t('sheets-hyper-link-ui.popup.copy')}>
+ <Tooltip placement="bottom" title={localeService.t<LocaleKey>('sheets-hyper-link-ui.popup.copy')}>
<CopyIcon className="dark:!univer-text-white" />
</Tooltip>
</div>
@@ -153,7 +159,7 @@ export const CellLinkPopupPure = (props: ICellLinkPopupPureProps) => {
});
}}
>
- <Tooltip placement="bottom" title={localeService.t('sheets-hyper-link-ui.popup.edit')}>
+ <Tooltip placement="bottom" title={localeService.t<LocaleKey>('sheets-hyper-link-ui.popup.edit')}>
<WriteIcon className="dark:!univer-text-white" />
</Tooltip>
</div>
@@ -178,7 +184,7 @@ export const CellLinkPopupPure = (props: ICellLinkPopupPureProps) => {
}
}}
>
- <Tooltip placement="bottom" title={localeService.t('sheets-hyper-link-ui.popup.cancel')}>
+ <Tooltip placement="bottom" title={localeService.t<LocaleKey>('sheets-hyper-link-ui.popup.cancel')}>
<UnlinkIcon className="dark:!univer-text-white" />
</Tooltip>
</div>
diff --git a/packages/sheets-hyper-link/src/locale/types.ts b/packages/sheets-hyper-link/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-hyper-link/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-hyper-link/src/services/parser.service.ts b/packages/sheets-hyper-link/src/services/parser.service.ts
index adbd061d68..45f0633b7f 100644
--- a/packages/sheets-hyper-link/src/services/parser.service.ts
+++ b/packages/sheets-hyper-link/src/services/parser.service.ts
@@ -15,8 +15,14 @@
*/
import type { IRange, Nullable, Workbook } from '@univerjs/core';
+import type { LocaleKey } from '../locale/types';
import { Inject, isValidRange, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
-import { deserializeRangeWithSheet, IDefinedNamesService, serializeRange, serializeRangeWithSheet } from '@univerjs/engine-formula';
+import {
+ deserializeRangeWithSheet,
+ IDefinedNamesService,
+ serializeRange,
+ serializeRangeWithSheet,
+} from '@univerjs/engine-formula';
import { ERROR_RANGE } from '../types/const';
import { SheetHyperLinkType } from '../types/enums/hyper-link-type';
@@ -91,7 +97,7 @@ export class SheetsHyperLinkParserService {
: this._univerInstanceService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET);
const invalidLink = {
type: SheetHyperLinkType.INVALID,
- name: this._localeService.t('sheets-hyper-link.message.refError'),
+ name: this._localeService.t<LocaleKey>('sheets-hyper-link.message.refError'),
};
if (!workbook) {
diff --git a/packages/sheets-note-ui/src/locale/types.ts b/packages/sheets-note-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-note-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-note-ui/src/menu/note.menu.ts b/packages/sheets-note-ui/src/menu/note.menu.ts
index 3f11ad4d32..447cc1a968 100644
--- a/packages/sheets-note-ui/src/menu/note.menu.ts
+++ b/packages/sheets-note-ui/src/menu/note.menu.ts
@@ -15,10 +15,16 @@
*/
import type { IAccessor } from '@univerjs/core';
-import type { IMenuItem } from '@univerjs/ui';
+import type { IMenuButtonItem } from '@univerjs/ui';
import type { Observable } from 'rxjs';
+import type { LocaleKey } from '../locale/types';
import { IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
-import { getSheetCommandTarget, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission } from '@univerjs/sheets';
+import {
+ getSheetCommandTarget,
+ SheetsSelectionsService,
+ WorkbookEditablePermission,
+ WorksheetEditPermission,
+} from '@univerjs/sheets';
import { SheetDeleteNoteCommand, SheetsNoteModel, SheetToggleNotePopupCommand } from '@univerjs/sheets-note';
import { getCurrentRangeDisable$ } from '@univerjs/sheets-ui';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
@@ -41,30 +47,38 @@ function getHasNote$(accessor: IAccessor): Observable<boolean> {
}));
}
-export function sheetNoteContextMenuFactory(accessor: IAccessor): IMenuItem {
+export function sheetNoteContextMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: AddNotePopupOperation.id,
type: MenuItemType.BUTTON,
title: 'sheets-note-ui.rightClick.addNote',
icon: 'AddNoteIcon',
- hidden$: combineLatest([getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET), getHasNote$(accessor)])
- .pipe(map(([hidden, hasNote]) => hidden || hasNote)),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission] }),
+ hidden$: combineLatest([
+ getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ getHasNote$(accessor),
+ ]).pipe(map(([hidden, hasNote]) => hidden || hasNote)),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetEditPermission],
+ }),
commandId: AddNotePopupOperation.id,
};
}
-export function sheetDeleteNoteMenuFactory(accessor: IAccessor): IMenuItem {
+export function sheetDeleteNoteMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: SheetDeleteNoteCommand.id,
type: MenuItemType.BUTTON,
title: 'sheets-note-ui.rightClick.deleteNote',
icon: 'DeleteNoteIcon',
hidden$: getHasNote$(accessor).pipe(map((hasNote) => !hasNote)),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetEditPermission],
+ }),
};
}
-export function sheetNoteToggleMenuFactory(accessor: IAccessor): IMenuItem {
+export function sheetNoteToggleMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: SheetToggleNotePopupCommand.id,
type: MenuItemType.BUTTON,
diff --git a/packages/sheets-note-ui/src/views/Note.tsx b/packages/sheets-note-ui/src/views/Note.tsx
index 943ab0a439..5db2039d89 100644
--- a/packages/sheets-note-ui/src/views/Note.tsx
+++ b/packages/sheets-note-ui/src/views/Note.tsx
@@ -18,6 +18,7 @@ import type { ISheetLocationBase } from '@univerjs/sheets';
import type { ISheetNote } from '@univerjs/sheets-note';
import type { IPopup } from '@univerjs/ui';
import type { IUniverSheetsNoteUIConfig } from '../config/config';
+import type { LocaleKey } from '../locale/types';
import { generateRandomId, ICommandService, LocaleService } from '@univerjs/core';
import { clsx, Textarea } from '@univerjs/design';
import { IRenderManagerService } from '@univerjs/engine-render';
@@ -142,7 +143,7 @@ export const SheetsNote = (props: { popup: IPopup<{ location: INotePopupLocation
dark:!univer-bg-gray-800
`)}
value={note?.note}
- placeholder={localeService.t('sheets-note-ui.note.placeholder')}
+ placeholder={localeService.t<LocaleKey>('sheets-note-ui.note.placeholder')}
onResize={handleResize}
onValueChange={handleNoteChange}
onWheel={(e) => {
diff --git a/packages/sheets-numfmt-ui/src/controllers/numfmt-alert-render.controller.ts b/packages/sheets-numfmt-ui/src/controllers/numfmt-alert-render.controller.ts
index 2e8cc0e193..2237a76f75 100644
--- a/packages/sheets-numfmt-ui/src/controllers/numfmt-alert-render.controller.ts
+++ b/packages/sheets-numfmt-ui/src/controllers/numfmt-alert-render.controller.ts
@@ -17,6 +17,7 @@
import type { CellValue, Workbook } from '@univerjs/core';
import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
import type { IUniverSheetsNumfmtConfig } from '@univerjs/sheets-numfmt';
+import type { LocaleKey } from '../locale/types';
import { Disposable, IConfigService, Inject, isRealNum, isTextFormat, LocaleService, Tools } from '@univerjs/core';
import { INumfmtService } from '@univerjs/sheets';
import { SHEETS_NUMFMT_PLUGIN_CONFIG_KEY } from '@univerjs/sheets-numfmt';
@@ -94,8 +95,8 @@ export class NumfmtAlertRenderController extends Disposable implements IRenderMo
this._cellAlertManagerService.showAlert({
type: CellAlertType.ERROR,
- title: this._localeService.t('sheets-numfmt-ui.info.error'),
- message: this._localeService.t('sheets-numfmt-ui.info.forceStringInfo'),
+ title: this._localeService.t<LocaleKey>('sheets-numfmt-ui.info.error'),
+ message: this._localeService.t<LocaleKey>('sheets-numfmt-ui.info.forceStringInfo'),
location,
width: 200,
height: 74,
diff --git a/packages/sheets-numfmt-ui/src/controllers/ui.controller.ts b/packages/sheets-numfmt-ui/src/controllers/ui.controller.ts
index b3df3e89b2..be018424f0 100644
--- a/packages/sheets-numfmt-ui/src/controllers/ui.controller.ts
+++ b/packages/sheets-numfmt-ui/src/controllers/ui.controller.ts
@@ -17,6 +17,7 @@
import type { IDisposable, IRange, Workbook } from '@univerjs/core';
import type { ISetNumfmtMutationParams } from '@univerjs/sheets';
import type { ISetNumfmtCommandParams } from '@univerjs/sheets-numfmt';
+import type { LocaleKey } from '../locale/types';
import type { ISheetNumfmtPanelProps } from '../views/SheetNumfmtPanel';
import {
CellValueType,
@@ -152,7 +153,9 @@ export class SheetNumfmtUIController extends Disposable {
};
this._sidebarDisposable = sidebarService.open({
- header: { title: localeService.t('sheets-numfmt-ui.title') },
+ header: {
+ title: localeService.t<LocaleKey>('sheets-numfmt-ui.title'),
+ },
children: {
label: SHEET_NUMFMT_PANEL,
...(props as any), // need passthrough to react props.
diff --git a/packages/sheets-numfmt-ui/src/locale/types.ts b/packages/sheets-numfmt-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-numfmt-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-numfmt-ui/src/menu/menu.ts b/packages/sheets-numfmt-ui/src/menu/menu.ts
index 9cf1f91d98..44169d160a 100644
--- a/packages/sheets-numfmt-ui/src/menu/menu.ts
+++ b/packages/sheets-numfmt-ui/src/menu/menu.ts
@@ -15,8 +15,18 @@
*/
import type { IAccessor } from '@univerjs/core';
-import type { IMenuSelectorItem } from '@univerjs/ui';
-import { DEFAULT_TEXT_FORMAT_EXCEL, fromCallback, ICommandService, isDefaultFormat, isPatternEqualWithoutDecimal, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
+import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
+import {
+ DEFAULT_TEXT_FORMAT_EXCEL,
+ fromCallback,
+ ICommandService,
+ isDefaultFormat,
+ isPatternEqualWithoutDecimal,
+ IUniverInstanceService,
+ LocaleService,
+ UniverInstanceType,
+} from '@univerjs/core';
import {
RangeProtectionPermissionEditPoint,
RemoveNumfmtMutation,
@@ -26,14 +36,24 @@ import {
WorksheetEditPermission,
WorksheetSetCellStylePermission,
} from '@univerjs/sheets';
-import { AddDecimalCommand, getCurrencySymbolByLocale, getCurrencySymbolIconByLocale, SetCurrencyCommand, SetPercentCommand, SubtractDecimalCommand } from '@univerjs/sheets-numfmt';
+import {
+ AddDecimalCommand,
+ getCurrencySymbolByLocale,
+ getCurrencySymbolIconByLocale,
+ SetCurrencyCommand,
+ SetPercentCommand,
+ SubtractDecimalCommand,
+} from '@univerjs/sheets-numfmt';
import { deriveStateFromActiveSheet$, getCurrentRangeDisable$ } from '@univerjs/sheets-ui';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { filter, merge, Observable } from 'rxjs';
import { OpenNumfmtPanelOperator } from '../commands/operations/open.numfmt.panel.operation';
import { MORE_NUMFMT_TYPE_KEY, OPTIONS_KEY } from '../views/components/MoreNumfmtType';
-export const MENU_OPTIONS = (currencySymbol: string): Array<{ label: string; pattern: string | null } | '|'> => {
+export const MENU_OPTIONS = (currencySymbol: string): Array<{
+ label: LocaleKey;
+ pattern: string | null;
+} | '|'> => {
return [
{
label: 'sheets-numfmt-ui.general',
@@ -95,10 +115,10 @@ export const MENU_OPTIONS = (currencySymbol: string): Array<{ label: string; pat
label: 'sheets-numfmt-ui.moreFmt',
pattern: '',
},
- ] as Array<{ label: string; pattern: string | null } | '|'>;
+ ];
};
-export const CurrencySymbolIconMenuItem = (accessor: IAccessor) => {
+export function CurrencySymbolIconMenuItem(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
icon: new Observable<string>((subscribe) => {
const localeService = accessor.get(LocaleService);
@@ -112,11 +132,15 @@ export const CurrencySymbolIconMenuItem = (accessor: IAccessor) => {
tooltip: 'sheets-numfmt-ui.currency',
type: MenuItemType.BUTTON,
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
};
};
-export const AddDecimalMenuItem = (accessor: IAccessor) => {
+export function AddDecimalMenuItem(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
icon: 'AddDigitsIcon',
id: AddDecimalCommand.id,
@@ -124,11 +148,15 @@ export const AddDecimalMenuItem = (accessor: IAccessor) => {
tooltip: 'sheets-numfmt-ui.addDecimal',
type: MenuItemType.BUTTON,
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
};
};
-export const SubtractDecimalMenuItem = (accessor: IAccessor) => {
+export function SubtractDecimalMenuItem(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
icon: 'ReduceDigitsIcon',
id: SubtractDecimalCommand.id,
@@ -136,11 +164,15 @@ export const SubtractDecimalMenuItem = (accessor: IAccessor) => {
tooltip: 'sheets-numfmt-ui.subtractDecimal',
type: MenuItemType.BUTTON,
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
};
};
-export const PercentMenuItem = (accessor: IAccessor) => {
+export function PercentMenuItem(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
icon: 'PercentIcon',
id: SetPercentCommand.id,
@@ -148,12 +180,16 @@ export const PercentMenuItem = (accessor: IAccessor) => {
tooltip: 'sheets-numfmt-ui.percent',
type: MenuItemType.BUTTON,
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
};
};
-export const FactoryOtherMenuItem = (accessor: IAccessor): IMenuSelectorItem => {
+export function FactoryOtherMenuItem(accessor: IAccessor): IMenuSelectorItem<LocaleKey, string> {
const univerInstanceService = accessor.get(IUniverInstanceService);
const commandService = accessor.get(ICommandService);
const localeService = accessor.get(LocaleService);
@@ -180,7 +216,7 @@ export const FactoryOtherMenuItem = (accessor: IAccessor): IMenuSelectorItem =>
const currencySymbol = getCurrencySymbolByLocale(localeService.getCurrentLocale());
// Adapts the 'General' obtained during import, or the 'General' set manually
- let value: string = localeService.t('sheets-numfmt-ui.general');
+ let value: string = localeService.t<LocaleKey>('sheets-numfmt-ui.general');
if (isDefaultFormat(pattern)) {
subscribe.next(value);
@@ -192,9 +228,9 @@ export const FactoryOtherMenuItem = (accessor: IAccessor): IMenuSelectorItem =>
(item) => isPatternEqualWithoutDecimal(pattern, (item as { pattern: string }).pattern)
);
if (item && typeof item === 'object' && item.pattern) {
- value = localeService.t(item.label);
+ value = localeService.t<LocaleKey>(item.label);
} else {
- value = localeService.t('sheets-numfmt-ui.moreFmt');
+ value = localeService.t<LocaleKey>('sheets-numfmt-ui.moreFmt');
}
}
@@ -219,6 +255,10 @@ export const FactoryOtherMenuItem = (accessor: IAccessor): IMenuSelectorItem =>
}],
value$,
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetSetCellStylePermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetSetCellStylePermission, WorksheetEditPermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
};
};
diff --git a/packages/sheets-numfmt-ui/src/views/SheetNumfmtPanel.tsx b/packages/sheets-numfmt-ui/src/views/SheetNumfmtPanel.tsx
index 482e65ed00..44b382172c 100644
--- a/packages/sheets-numfmt-ui/src/views/SheetNumfmtPanel.tsx
+++ b/packages/sheets-numfmt-ui/src/views/SheetNumfmtPanel.tsx
@@ -15,7 +15,8 @@
*/
import type { ISelectProps } from '@univerjs/design';
-import type { FC } from 'react';
+import type { ComponentType } from 'react';
+import type { LocaleKey } from '../locale/types';
import type { IBusinessComponentProps } from './components/interface';
import { LocaleService } from '@univerjs/core';
import { Button, clsx, scrollbarClassName, Select } from '@univerjs/design';
@@ -37,21 +38,25 @@ export interface ISheetNumfmtPanelProps {
onChange: (config: { type: 'change' | 'cancel' | 'confirm'; value: string }) => void;
}
-export const SheetNumfmtPanel: FC<ISheetNumfmtPanelProps> = (props) => {
+export function SheetNumfmtPanel(props: ISheetNumfmtPanelProps) {
const { defaultValue, defaultPattern, row, col } = props.value;
const localeService = useDependency(LocaleService);
- const getCurrentPattern = useRef<() => string | null>(() => '');
+ const currentPatternRef = useRef<() => string | null>(() => '');
const nextTick = useNextTick();
+
const typeOptions = useMemo(
- () =>
- [
+ () => {
+ const typeOptions: Array<{ label: LocaleKey; component: ComponentType<IBusinessComponentProps> }> = [
{ label: 'sheets-numfmt-ui.general', component: GeneralPanel },
{ label: 'sheets-numfmt-ui.accounting', component: AccountingPanel },
{ label: 'sheets-numfmt-ui.currency', component: CurrencyPanel },
{ label: 'sheets-numfmt-ui.date', component: DatePanel },
{ label: 'sheets-numfmt-ui.thousandthPercentile', component: ThousandthPercentilePanel },
{ label: 'sheets-numfmt-ui.customFormat', component: CustomFormat },
- ].map((item) => ({ ...item, label: localeService.t(item.label) })),
+ ];
+
+ return typeOptions.map((item) => ({ ...item, label: localeService.t<LocaleKey>(item.label) }));
+ },
[localeService]
);
const [type, setType] = useState(findDefaultType);
@@ -76,7 +81,7 @@ export const SheetNumfmtPanel: FC<ISheetNumfmtPanelProps> = (props) => {
const handleSelect: ISelectProps['onChange'] = (value) => {
setType(value);
// after the BusinessComponent render.
- nextTick(() => props.onChange({ type: 'change', value: getCurrentPattern.current() || '' }));
+ nextTick(() => props.onChange({ type: 'change', value: currentPatternRef.current() || '' }));
};
const handleChange = useCallback((v: string) => {
@@ -84,11 +89,11 @@ export const SheetNumfmtPanel: FC<ISheetNumfmtPanelProps> = (props) => {
}, []);
const handleActionChange = useCallback((action: () => string | null) => {
- getCurrentPattern.current = action;
+ currentPatternRef.current = action;
}, []);
const handleConfirm = () => {
- const pattern = getCurrentPattern.current() || '';
+ const pattern = currentPatternRef.current() || '';
const currency = getCurrencyType(pattern);
if (currency) {
mark(currency);
@@ -114,12 +119,15 @@ export const SheetNumfmtPanel: FC<ISheetNumfmtPanelProps> = (props) => {
return (
<div
- className={clsx(`
- univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5
- `, scrollbarClassName)}
+ className={clsx(
+ 'univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5',
+ scrollbarClassName
+ )}
>
<div>
- <div className="univer-mt-3.5 univer-text-sm univer-text-gray-400">{localeService.t('sheets-numfmt-ui.numfmtType')}</div>
+ <div className="univer-mt-3.5 univer-text-sm univer-text-gray-400">
+ {localeService.t<LocaleKey>('sheets-numfmt-ui.numfmtType')}
+ </div>
<div className="univer-mt-2">
<Select className="univer-w-full" value={type} options={selectOptions} onChange={handleSelect} />
</div>
@@ -134,10 +142,10 @@ export const SheetNumfmtPanel: FC<ISheetNumfmtPanelProps> = (props) => {
<div className="univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end">
<Button onClick={handleCancel} className="univer-mr-3">
- {localeService.t('sheets-numfmt-ui.cancel')}
+ {localeService.t<LocaleKey>('sheets-numfmt-ui.cancel')}
</Button>
<Button variant="primary" onClick={handleConfirm}>
- {localeService.t('sheets-numfmt-ui.confirm')}
+ {localeService.t<LocaleKey>('sheets-numfmt-ui.confirm')}
</Button>
</div>
</div>
diff --git a/packages/sheets-numfmt-ui/src/views/components/Accounting.tsx b/packages/sheets-numfmt-ui/src/views/components/Accounting.tsx
index 4b2f93ac99..a0d5fee450 100644
--- a/packages/sheets-numfmt-ui/src/views/components/Accounting.tsx
+++ b/packages/sheets-numfmt-ui/src/views/components/Accounting.tsx
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { FC } from 'react';
+import type { LocaleKey } from '../../locale/types';
import type { IBusinessComponentProps } from './interface';
import { LocaleService } from '@univerjs/core';
import { InputNumber, Select } from '@univerjs/design';
@@ -28,7 +28,7 @@ export const isAccountingPanel = (pattern: string) => {
return !!type && pattern.startsWith('_(');
};
-export const AccountingPanel: FC<IBusinessComponentProps> = (props) => {
+export function AccountingPanel(props: IBusinessComponentProps) {
const { defaultPattern, onActionChange, onChange } = props;
const [decimal, setDecimal] = useState(() => getDecimalFromPattern(defaultPattern || '', 2));
@@ -57,7 +57,9 @@ export const AccountingPanel: FC<IBusinessComponentProps> = (props) => {
<div>
<div className="univer-mt-4 univer-flex univer-justify-between">
<div className="option">
- <div className="univer-text-sm univer-text-gray-400">{localeService.t('sheets-numfmt-ui.decimalLength')}</div>
+ <div className="univer-text-sm univer-text-gray-400">
+ {localeService.t<LocaleKey>('sheets-numfmt-ui.decimalLength')}
+ </div>
<div className="univer-mt-2 univer-w-32">
<InputNumber
@@ -71,7 +73,9 @@ export const AccountingPanel: FC<IBusinessComponentProps> = (props) => {
</div>
</div>
<div className="option">
- <div className="univer-text-sm univer-text-gray-400">{localeService.t('sheets-numfmt-ui.currencyType')}</div>
+ <div className="univer-text-sm univer-text-gray-400">
+ {localeService.t<LocaleKey>('sheets-numfmt-ui.currencyType')}
+ </div>
<div className="univer-mt-2 univer-w-36">
<Select
@@ -83,7 +87,9 @@ export const AccountingPanel: FC<IBusinessComponentProps> = (props) => {
</div>
</div>
- <div className="univer-mt-4 univer-text-sm univer-text-gray-400">{localeService.t('sheets-numfmt-ui.accountingDes')}</div>
+ <div className="univer-mt-4 univer-text-sm univer-text-gray-400">
+ {localeService.t<LocaleKey>('sheets-numfmt-ui.accountingDes')}
+ </div>
</div>
);
};
diff --git a/packages/sheets-numfmt-ui/src/views/components/Currency.tsx b/packages/sheets-numfmt-ui/src/views/components/Currency.tsx
index bdd0757666..610d88d1c6 100644
--- a/packages/sheets-numfmt-ui/src/views/components/Currency.tsx
+++ b/packages/sheets-numfmt-ui/src/views/components/Currency.tsx
@@ -14,11 +14,16 @@
* limitations under the License.
*/
-import type { FC } from 'react';
+import type { LocaleKey } from '../../locale/types';
import type { IBusinessComponentProps } from './interface';
import { isPatternEqualWithoutDecimal, LocaleService } from '@univerjs/core';
import { InputNumber, Select, SelectList } from '@univerjs/design';
-import { getCurrencyFormatOptions, getCurrencyType, getDecimalFromPattern, setPatternDecimal } from '@univerjs/sheets-numfmt';
+import {
+ getCurrencyFormatOptions,
+ getCurrencyType,
+ getDecimalFromPattern,
+ setPatternDecimal,
+} from '@univerjs/sheets-numfmt';
import { useDependency } from '@univerjs/ui';
import { useContext, useLayoutEffect, useMemo, useState } from 'react';
import { UserHabitCurrencyContext } from '../../controllers/user-habit.controller';
@@ -28,7 +33,7 @@ export const isCurrencyPanel = (pattern: string) => {
return !!type && !pattern.startsWith('_(');
};
-export const CurrencyPanel: FC<IBusinessComponentProps> = (props) => {
+export function CurrencyPanel(props: IBusinessComponentProps) {
const { onActionChange, onChange: onValueChange } = props;
const localeService = useDependency(LocaleService);
const userHabitCurrency = useContext(UserHabitCurrencyContext);
@@ -76,7 +81,9 @@ export const CurrencyPanel: FC<IBusinessComponentProps> = (props) => {
<div>
<div className="univer-mt-4 univer-flex univer-justify-between">
<div className="option">
- <div className="univer-text-sm univer-text-gray-400">{localeService.t('sheets-numfmt-ui.decimalLength')}</div>
+ <div className="univer-text-sm univer-text-gray-400">
+ {localeService.t<LocaleKey>('sheets-numfmt-ui.decimalLength')}
+ </div>
<div className="univer-mt-2 univer-w-32">
<InputNumber
value={decimal}
@@ -87,7 +94,9 @@ export const CurrencyPanel: FC<IBusinessComponentProps> = (props) => {
</div>
</div>
<div className="option">
- <div className="univer-text-sm univer-text-gray-400">{localeService.t('sheets-numfmt-ui.currencyType')}</div>
+ <div className="univer-text-sm univer-text-gray-400">
+ {localeService.t<LocaleKey>('sheets-numfmt-ui.currencyType')}
+ </div>
<div className="univer-mt-2 univer-w-36">
<Select
value={suffix}
@@ -98,14 +107,16 @@ export const CurrencyPanel: FC<IBusinessComponentProps> = (props) => {
</div>
</div>
<div className="label univer-mt-4">
- {localeService.t('sheets-numfmt-ui.negType')}
+ {localeService.t<LocaleKey>('sheets-numfmt-ui.negType')}
</div>
<div className="univer-mt-2">
<SelectList value={pattern} options={negativeOptions} onChange={onChange} />
</div>
- <div className="univer-mt-4 univer-text-sm univer-text-gray-400">{localeService.t('sheets-numfmt-ui.currencyDes')}</div>
+ <div className="univer-mt-4 univer-text-sm univer-text-gray-400">
+ {localeService.t<LocaleKey>('sheets-numfmt-ui.currencyDes')}
+ </div>
</div>
);
};
diff --git a/packages/sheets-numfmt-ui/src/views/components/CustomFormat.tsx b/packages/sheets-numfmt-ui/src/views/components/CustomFormat.tsx
index 992d5e2905..1039bb3ebc 100644
--- a/packages/sheets-numfmt-ui/src/views/components/CustomFormat.tsx
+++ b/packages/sheets-numfmt-ui/src/views/components/CustomFormat.tsx
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { LocaleKey } from '../../locale/types';
import type { IBusinessComponentProps } from './interface';
import { ILocalStorageService, LocaleService } from '@univerjs/core';
import { borderClassName, clsx, Input } from '@univerjs/design';
@@ -72,16 +73,21 @@ export function CustomFormat(props: IBusinessComponentProps) {
return (
<div>
- <div className="univer-mt-4 univer-text-sm univer-text-gray-400">{localeService.t('sheets-numfmt-ui.customFormat')}</div>
+ <div className="univer-mt-4 univer-text-sm univer-text-gray-400">
+ {localeService.t<LocaleKey>('sheets-numfmt-ui.customFormat')}
+ </div>
<Input
- placeholder={localeService.t('sheets-numfmt-ui.customFormat')}
+ placeholder={localeService.t<LocaleKey>('sheets-numfmt-ui.customFormat')}
onBlur={handleBlur}
value={pattern}
onChange={setPattern}
className="univer-mt-2 univer-w-full"
/>
<div
- className={clsx('univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2', borderClassName)}
+ className={clsx(
+ 'univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2',
+ borderClassName
+ )}
>
{options.map((p) => (
<div
@@ -107,7 +113,7 @@ export function CustomFormat(props: IBusinessComponentProps) {
dark:!univer-text-gray-200
`}
>
- {localeService.t('sheets-numfmt-ui.customFormatDes')}
+ {localeService.t<LocaleKey>('sheets-numfmt-ui.customFormatDes')}
</div>
</div>
);
diff --git a/packages/sheets-numfmt-ui/src/views/components/Date.tsx b/packages/sheets-numfmt-ui/src/views/components/Date.tsx
index 97ed095788..3c1e9e7ae2 100644
--- a/packages/sheets-numfmt-ui/src/views/components/Date.tsx
+++ b/packages/sheets-numfmt-ui/src/views/components/Date.tsx
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { LocaleKey } from '../../locale/types';
import type { IBusinessComponentProps } from './interface';
import { LocaleService, numfmt } from '@univerjs/core';
import { SelectList } from '@univerjs/design';
@@ -60,7 +61,9 @@ export function DatePanel(props: IBusinessComponentProps) {
return (
<div>
- <div className="univer-mt-4 univer-text-sm univer-text-gray-400">{localeService.t('sheets-numfmt-ui.dateType')}</div>
+ <div className="univer-mt-4 univer-text-sm univer-text-gray-400">
+ {localeService.t<LocaleKey>('sheets-numfmt-ui.dateType')}
+ </div>
<div className="univer-mt-2">
<SelectList value={suffix} options={options} onChange={handleChange} />
</div>
@@ -70,7 +73,7 @@ export function DatePanel(props: IBusinessComponentProps) {
dark:!univer-text-gray-200
`}
>
- {localeService.t('sheets-numfmt-ui.dateDes')}
+ {localeService.t<LocaleKey>('sheets-numfmt-ui.dateDes')}
</div>
</div>
);
diff --git a/packages/sheets-numfmt-ui/src/views/components/General.tsx b/packages/sheets-numfmt-ui/src/views/components/General.tsx
index 82afd0a71c..62d5c12cbc 100644
--- a/packages/sheets-numfmt-ui/src/views/components/General.tsx
+++ b/packages/sheets-numfmt-ui/src/views/components/General.tsx
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { FC } from 'react';
+import type { LocaleKey } from '../../locale/types';
import type { IBusinessComponentProps } from './interface';
import { LocaleService } from '@univerjs/core';
import { useDependency } from '@univerjs/ui';
@@ -22,7 +22,7 @@ import { useLayoutEffect } from 'react';
export const isGeneralPanel = (pattern: string) => !pattern;
-export const GeneralPanel: FC<IBusinessComponentProps> = (props) => {
+export function GeneralPanel(props: IBusinessComponentProps) {
const localeService = useDependency(LocaleService);
const { onActionChange } = props;
@@ -38,8 +38,8 @@ export const GeneralPanel: FC<IBusinessComponentProps> = (props) => {
dark:!univer-text-gray-200
`}
>
- {localeService.t('sheets-numfmt-ui.generalDes')}
+ {localeService.t<LocaleKey>('sheets-numfmt-ui.generalDes')}
</div>
</div>
);
-};
+}
diff --git a/packages/sheets-numfmt-ui/src/views/components/MoreNumfmtType.tsx b/packages/sheets-numfmt-ui/src/views/components/MoreNumfmtType.tsx
index 765089fbba..ebc123ccc6 100644
--- a/packages/sheets-numfmt-ui/src/views/components/MoreNumfmtType.tsx
+++ b/packages/sheets-numfmt-ui/src/views/components/MoreNumfmtType.tsx
@@ -15,6 +15,7 @@
*/
import type { FormatType } from '@univerjs/sheets';
+import type { LocaleKey } from '../../locale/types';
import { ICommandService, LocaleService, Range } from '@univerjs/core';
import { Separator } from '@univerjs/design';
import { SheetsSelectionsService } from '@univerjs/sheets';
@@ -36,7 +37,7 @@ export const OPTIONS_KEY = 'sheets-numfmt-ui.moreNumfmtType.options';
export function MoreNumfmtType(props: { value?: string }) {
const { value } = props;
const localeService = useDependency(LocaleService);
- const text = value ?? localeService.t('sheets-numfmt-ui.general');
+ const text = value ?? localeService.t<LocaleKey>('sheets-numfmt-ui.general');
return <span className="univer-text-sm">{text}</span>;
};
@@ -106,7 +107,7 @@ export function Options() {
`}
onClick={() => handleClick(index)}
>
- <span>{localeService.t(item.label)}</span>
+ <span>{localeService.t<LocaleKey>(item.label)}</span>
<span
className={`
diff --git a/packages/sheets-numfmt-ui/src/views/components/ThousandthPercentile.tsx b/packages/sheets-numfmt-ui/src/views/components/ThousandthPercentile.tsx
index 2b3c698a63..90945f0341 100644
--- a/packages/sheets-numfmt-ui/src/views/components/ThousandthPercentile.tsx
+++ b/packages/sheets-numfmt-ui/src/views/components/ThousandthPercentile.tsx
@@ -14,10 +14,16 @@
* limitations under the License.
*/
+import type { LocaleKey } from '../../locale/types';
import type { IBusinessComponentProps } from './interface';
import { isPatternEqualWithoutDecimal, LocaleService } from '@univerjs/core';
import { InputNumber, SelectList } from '@univerjs/design';
-import { getDecimalFromPattern, getNumberFormatOptions, isPatternHasDecimal, setPatternDecimal } from '@univerjs/sheets-numfmt';
+import {
+ getDecimalFromPattern,
+ getNumberFormatOptions,
+ isPatternHasDecimal,
+ setPatternDecimal,
+} from '@univerjs/sheets-numfmt';
import { useDependency } from '@univerjs/ui';
import { useLayoutEffect, useMemo, useState } from 'react';
@@ -59,7 +65,9 @@ export function ThousandthPercentilePanel(props: IBusinessComponentProps) {
return (
<div>
- <div className="univer-mt-4 univer-text-sm univer-text-gray-400">{localeService.t('sheets-numfmt-ui.decimalLength')}</div>
+ <div className="univer-mt-4 univer-text-sm univer-text-gray-400">
+ {localeService.t<LocaleKey>('sheets-numfmt-ui.decimalLength')}
+ </div>
<div className="univer-mt-2">
<InputNumber
disabled={isInputDisable}
@@ -71,7 +79,7 @@ export function ThousandthPercentilePanel(props: IBusinessComponentProps) {
</div>
<div className="univer-mt-4 univer-text-sm univer-text-gray-400">
{' '}
- {localeService.t('sheets-numfmt-ui.negType')}
+ {localeService.t<LocaleKey>('sheets-numfmt-ui.negType')}
</div>
<div className="univer-mt-2">
<SelectList onChange={handleClick} options={options} value={suffix} />
@@ -82,7 +90,7 @@ export function ThousandthPercentilePanel(props: IBusinessComponentProps) {
dark:!univer-text-gray-200
`}
>
- {localeService.t('sheets-numfmt-ui.thousandthPercentileDes')}
+ {localeService.t<LocaleKey>('sheets-numfmt-ui.thousandthPercentileDes')}
</div>
</div>
);
diff --git a/packages/sheets-sort-ui/src/controllers/ui.controller.ts b/packages/sheets-sort-ui/src/controllers/ui.controller.ts
index 5409c2dd55..664408db6c 100644
--- a/packages/sheets-sort-ui/src/controllers/ui.controller.ts
+++ b/packages/sheets-sort-ui/src/controllers/ui.controller.ts
@@ -15,6 +15,7 @@
*/
import type { UIPartsService } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import type { ISheetSortLocation } from '../services/sheets-sort-ui.service';
import { ICommandService, Inject, Injector, LocaleService, RxDisposable } from '@univerjs/core';
import { serializeRange } from '@univerjs/engine-formula';
@@ -108,7 +109,7 @@ export class SheetsSortUIController extends RxDisposable {
id: CUSTOM_SORT_DIALOG_ID,
draggable: true,
width: CUSTOM_SORT_PANEL_WIDTH,
- title: { title: `${this._localeService.t('sheets-sort-ui.general.sort-custom')}: ${serializeRange(location.range)}` },
+ title: { title: `${this._localeService.t<LocaleKey>('sheets-sort-ui.general.sort-custom')}: ${serializeRange(location.range)}` },
children: { label: 'CustomSortPanel' },
destroyOnClose: true,
defaultPosition: getCustomSortDialogDefaultPosition(),
diff --git a/packages/sheets-sort-ui/src/locale/types.ts b/packages/sheets-sort-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-sort-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-sort-ui/src/menu/sheets-sort.menu.ts b/packages/sheets-sort-ui/src/menu/sheets-sort.menu.ts
index 6c5e0485f4..ee32ef7e36 100644
--- a/packages/sheets-sort-ui/src/menu/sheets-sort.menu.ts
+++ b/packages/sheets-sort-ui/src/menu/sheets-sort.menu.ts
@@ -16,37 +16,58 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { UniverInstanceType } from '@univerjs/core';
-import { RangeProtectionPermissionEditPoint, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSortPermission } from '@univerjs/sheets';
+import {
+ RangeProtectionPermissionEditPoint,
+ WorkbookEditablePermission,
+ WorksheetEditPermission,
+ WorksheetSortPermission,
+} from '@univerjs/sheets';
import { getCurrentExclusiveRangeInterest$, getCurrentRangeDisable$ } from '@univerjs/sheets-ui';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
-import { SortRangeAscCommand, SortRangeAscExtCommand, SortRangeAscExtInCtxMenuCommand, SortRangeAscInCtxMenuCommand, SortRangeCustomCommand, SortRangeCustomInCtxMenuCommand, SortRangeDescCommand, SortRangeDescExtCommand, SortRangeDescExtInCtxMenuCommand, SortRangeDescInCtxMenuCommand } from '../commands/commands/sheets-sort.command';
+import {
+ SortRangeAscCommand,
+ SortRangeAscExtCommand,
+ SortRangeAscExtInCtxMenuCommand,
+ SortRangeAscInCtxMenuCommand,
+ SortRangeCustomCommand,
+ SortRangeCustomInCtxMenuCommand,
+ SortRangeDescCommand,
+ SortRangeDescExtCommand,
+ SortRangeDescExtInCtxMenuCommand,
+ SortRangeDescInCtxMenuCommand,
+} from '../commands/commands/sheets-sort.command';
export const SHEETS_SORT_MENU_ID = 'sheet.menu.sheets-sort';
export const SHEETS_SORT_CTX_MENU_ID = 'sheet.menu.sheets-sort-ctx';
-export function sortRangeMenuFactory(accessor: IAccessor): IMenuItem {
+export function sortRangeMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: SHEETS_SORT_MENU_ID,
type: MenuItemType.SUBITEMS,
icon: 'AscendingIcon',
tooltip: 'sheets-sort-ui.general.sort',
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
};
}
-export function sortRangeAscMenuFactory(_accessor: IAccessor): IMenuItem {
+export function sortRangeAscMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: SortRangeAscCommand.id,
icon: 'AscendingIcon',
title: 'sheets-sort-ui.general.sort-asc-cur',
type: MenuItemType.BUTTON,
- hidden$: getCurrentExclusiveRangeInterest$(_accessor),
+ hidden$: getCurrentExclusiveRangeInterest$(accessor),
};
}
-export function sortRangeAscExtMenuFactory(_accessor: IAccessor): IMenuItem {
+export function sortRangeAscExtMenuFactory(): IMenuItem<LocaleKey> {
return {
id: SortRangeAscExtCommand.id,
title: 'sheets-sort-ui.general.sort-asc-ext',
@@ -55,7 +76,7 @@ export function sortRangeAscExtMenuFactory(_accessor: IAccessor): IMenuItem {
};
}
-export function sortRangeDescMenuFactory(_accessor: IAccessor): IMenuItem {
+export function sortRangeDescMenuFactory(): IMenuItem<LocaleKey> {
return {
id: SortRangeDescCommand.id,
title: 'sheets-sort-ui.general.sort-desc-cur',
@@ -64,7 +85,7 @@ export function sortRangeDescMenuFactory(_accessor: IAccessor): IMenuItem {
};
}
-export function sortRangeDescExtMenuFactory(_accessor: IAccessor): IMenuItem {
+export function sortRangeDescExtMenuFactory(): IMenuItem<LocaleKey> {
return {
id: SortRangeDescExtCommand.id,
title: 'sheets-sort-ui.general.sort-desc-ext',
@@ -73,7 +94,7 @@ export function sortRangeDescExtMenuFactory(_accessor: IAccessor): IMenuItem {
};
}
-export function sortRangeCustomMenuFactory(_accessor: IAccessor): IMenuItem {
+export function sortRangeCustomMenuFactory(): IMenuItem<LocaleKey> {
return {
id: SortRangeCustomCommand.id,
title: 'sheets-sort-ui.general.sort-custom',
@@ -82,7 +103,7 @@ export function sortRangeCustomMenuFactory(_accessor: IAccessor): IMenuItem {
};
}
-export function sortRangeCtxMenuFactory(accessor: IAccessor): IMenuItem {
+export function sortRangeCtxMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: SHEETS_SORT_CTX_MENU_ID,
title: 'sheets-sort-ui.general.sort',
@@ -97,52 +118,72 @@ export function sortRangeCtxMenuFactory(accessor: IAccessor): IMenuItem {
};
}
-export function sortRangeAscCtxMenuFactory(_accessor: IAccessor): IMenuItem {
+export function sortRangeAscCtxMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: SortRangeAscInCtxMenuCommand.id,
title: 'sheets-sort-ui.general.sort-asc-cur',
type: MenuItemType.BUTTON,
icon: 'AscendingIcon',
- disabled$: getCurrentRangeDisable$(_accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
};
}
-export function sortRangeAscExtCtxMenuFactory(_accessor: IAccessor): IMenuItem {
+export function sortRangeAscExtCtxMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: SortRangeAscExtInCtxMenuCommand.id,
title: 'sheets-sort-ui.general.sort-asc-ext',
type: MenuItemType.BUTTON,
icon: 'ExpandAscendingIcon',
- disabled$: getCurrentRangeDisable$(_accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
};
}
-export function sortRangeDescCtxMenuFactory(_accessor: IAccessor): IMenuItem {
+export function sortRangeDescCtxMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: SortRangeDescInCtxMenuCommand.id,
title: 'sheets-sort-ui.general.sort-desc-cur',
type: MenuItemType.BUTTON,
icon: 'DescendingIcon',
- disabled$: getCurrentRangeDisable$(_accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
};
}
-export function sortRangeDescExtCtxMenuFactory(_accessor: IAccessor): IMenuItem {
+export function sortRangeDescExtCtxMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: SortRangeDescExtInCtxMenuCommand.id,
title: 'sheets-sort-ui.general.sort-desc-ext',
type: MenuItemType.BUTTON,
icon: 'ExpandDescendingIcon',
- disabled$: getCurrentRangeDisable$(_accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
};
}
-export function sortRangeCustomCtxMenuFactory(_accessor: IAccessor): IMenuItem {
+export function sortRangeCustomCtxMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: SortRangeCustomInCtxMenuCommand.id,
title: 'sheets-sort-ui.general.sort-custom',
type: MenuItemType.BUTTON,
icon: 'CustomSortIcon',
- disabled$: getCurrentRangeDisable$(_accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetSortPermission, WorksheetEditPermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
};
}
diff --git a/packages/sheets-sort-ui/src/views/CustomSortPanel.tsx b/packages/sheets-sort-ui/src/views/CustomSortPanel.tsx
index c2ccf2db5e..ce23520295 100644
--- a/packages/sheets-sort-ui/src/views/CustomSortPanel.tsx
+++ b/packages/sheets-sort-ui/src/views/CustomSortPanel.tsx
@@ -16,9 +16,19 @@
import type { IRange, Nullable } from '@univerjs/core';
import type { IOrderRule } from '@univerjs/sheets-sort';
+import type { LocaleKey } from '../locale/types';
import type { ICustomSortState } from '../services/sheets-sort-ui.service';
import { LocaleService, throttle } from '@univerjs/core';
-import { Button, Checkbox, clsx, DraggableList, Dropdown, Radio, RadioGroup, scrollbarClassName } from '@univerjs/design';
+import {
+ Button,
+ Checkbox,
+ clsx,
+ DraggableList,
+ Dropdown,
+ Radio,
+ RadioGroup,
+ scrollbarClassName,
+} from '@univerjs/design';
import { CheckMarkIcon, DeleteEmptyIcon, GripVerticalIcon, IncreaseIcon, MoreDownIcon } from '@univerjs/icons';
import { SheetsSortService, SortType } from '@univerjs/sheets-sort';
import { useDependency, useObservable } from '@univerjs/ui';
@@ -114,7 +124,7 @@ function CustomSortPanelImpl({ state }: { state: ICustomSortState }) {
<div onMouseDown={(e) => { e.stopPropagation(); }}>
<div className="univer-mb-2 univer-flex univer-items-center univer-justify-between">
<Checkbox checked={hasTitle} onChange={(value) => setTitle(!!value)}>
- {localeService.t('sheets-sort-ui.dialog.first-row-check')}
+ {localeService.t<LocaleKey>('sheets-sort-ui.dialog.first-row-check')}
</Checkbox>
{canNew
? (
@@ -126,7 +136,7 @@ function CustomSortPanelImpl({ state }: { state: ICustomSortState }) {
onClick={newItem}
>
<IncreaseIcon />
- <span className="univer-ml-1.5">{localeService.t('sheets-sort-ui.dialog.add-condition')}</span>
+ <span className="univer-ml-1.5">{localeService.t<LocaleKey>('sheets-sort-ui.dialog.add-condition')}</span>
</div>
)
: (
@@ -139,7 +149,7 @@ function CustomSortPanelImpl({ state }: { state: ICustomSortState }) {
`}
>
<IncreaseIcon />
- <span className="univer-ml-1.5 univer-text-xs">{localeService.t('sheets-sort-ui.dialog.add-condition')}</span>
+ <span className="univer-ml-1.5 univer-text-xs">{localeService.t<LocaleKey>('sheets-sort-ui.dialog.add-condition')}</span>
</div>
)}
@@ -176,14 +186,14 @@ function CustomSortPanelImpl({ state }: { state: ICustomSortState }) {
className="univer-ml-3"
onClick={() => cancel()}
>
- {localeService.t('sheets-sort-ui.dialog.cancel')}
+ {localeService.t<LocaleKey>('sheets-sort-ui.dialog.cancel')}
</Button>
<Button
className="univer-ml-3"
variant="primary"
onClick={() => apply(list, hasTitle)}
>
- {localeService.t('sheets-sort-ui.dialog.confirm')}
+ {localeService.t<LocaleKey>('sheets-sort-ui.dialog.confirm')}
</Button>
</div>
</div>
@@ -296,8 +306,8 @@ export function SortOptionItem(props: ISortOptionItemProps) {
onChange({ ...item, type: value as SortType }, currentIndex);
}}
>
- <Radio value={SortType.ASC}>{localeService.t('sheets-sort-ui.general.sort-asc')}</Radio>
- <Radio value={SortType.DESC}>{localeService.t('sheets-sort-ui.general.sort-desc')}</Radio>
+ <Radio value={SortType.ASC}>{localeService.t<LocaleKey>('sheets-sort-ui.general.sort-asc')}</Radio>
+ <Radio value={SortType.DESC}>{localeService.t<LocaleKey>('sheets-sort-ui.general.sort-desc')}</Radio>
</RadioGroup>
<a
className={`
diff --git a/packages/sheets-sort-ui/src/views/EmbedSortBtn.tsx b/packages/sheets-sort-ui/src/views/EmbedSortBtn.tsx
index bd22666a1b..e0f6189219 100644
--- a/packages/sheets-sort-ui/src/views/EmbedSortBtn.tsx
+++ b/packages/sheets-sort-ui/src/views/EmbedSortBtn.tsx
@@ -15,6 +15,7 @@
*/
import type { IRange } from '@univerjs/core';
+import type { LocaleKey } from '../locale/types';
import { IUniverInstanceService, LocaleService } from '@univerjs/core';
import { Button, ButtonGroup } from '@univerjs/design';
import { AscendingIcon, DescendingIcon } from '@univerjs/icons';
@@ -52,11 +53,11 @@ export default function EmbedSortBtn(props: IEmbedSortBtnProps) {
<ButtonGroup className="univer-mb-3 univer-w-full univer-grid-cols-2">
<Button onClick={() => apply(true)}>
<AscendingIcon />
- {localeService.t('sheets-sort-ui.general.sort-asc')}
+ {localeService.t<LocaleKey>('sheets-sort-ui.general.sort-asc')}
</Button>
<Button onClick={() => apply(false)}>
<DescendingIcon />
- {localeService.t('sheets-sort-ui.general.sort-desc')}
+ {localeService.t<LocaleKey>('sheets-sort-ui.general.sort-desc')}
</Button>
</ButtonGroup>
);
diff --git a/packages/sheets-sort-ui/src/views/ExtendConfirm.tsx b/packages/sheets-sort-ui/src/views/ExtendConfirm.tsx
index 527cbcb0f5..18e1200ced 100644
--- a/packages/sheets-sort-ui/src/views/ExtendConfirm.tsx
+++ b/packages/sheets-sort-ui/src/views/ExtendConfirm.tsx
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { LocaleKey } from '../locale/types';
import { LocaleService } from '@univerjs/core';
import { Radio, RadioGroup } from '@univerjs/design';
import { useDependency } from '@univerjs/ui';
@@ -29,7 +30,7 @@ export const ExtendConfirm = (props: IExtendConfirmProps) => {
return (
<div className="univer-text-sm">
<div className="extend-confirm-desc">
- {localeService.t('sheets-sort-ui.dialog.sort-reminder-desc')}
+ {localeService.t<LocaleKey>('sheets-sort-ui.dialog.sort-reminder-desc')}
</div>
<RadioGroup
@@ -42,10 +43,10 @@ export const ExtendConfirm = (props: IExtendConfirmProps) => {
}}
>
<Radio value="0">
- {localeService.t('sheets-sort-ui.dialog.sort-reminder-no')}
+ {localeService.t<LocaleKey>('sheets-sort-ui.dialog.sort-reminder-no')}
</Radio>
<Radio value="1">
- {localeService.t('sheets-sort-ui.dialog.sort-reminder-ext')}
+ {localeService.t<LocaleKey>('sheets-sort-ui.dialog.sort-reminder-ext')}
</Radio>
</RadioGroup>
</div>
diff --git a/packages/sheets-table-ui/src/commands/operations/open-table-selector.operation.ts b/packages/sheets-table-ui/src/commands/operations/open-table-selector.operation.ts
index 06f9693208..64f9e60965 100644
--- a/packages/sheets-table-ui/src/commands/operations/open-table-selector.operation.ts
+++ b/packages/sheets-table-ui/src/commands/operations/open-table-selector.operation.ts
@@ -16,8 +16,14 @@
import type { IAccessor, IRange } from '@univerjs/core';
import type { IAddSheetTableCommandParams } from '@univerjs/sheets-table';
+import type { LocaleKey } from '../../locale/types';
import { CommandType, ICommandService, IUniverInstanceService, LocaleService } from '@univerjs/core';
-import { expandToContinuousRange, getSheetCommandTarget, isSingleCellSelection, SheetsSelectionsService } from '@univerjs/sheets';
+import {
+ expandToContinuousRange,
+ getSheetCommandTarget,
+ isSingleCellSelection,
+ SheetsSelectionsService,
+} from '@univerjs/sheets';
import { AddSheetTableCommand } from '@univerjs/sheets-table';
import { IDialogService } from '@univerjs/ui';
import { TABLE_SELECTOR_DIALOG } from '../../const';
@@ -88,7 +94,7 @@ export async function openRangeSelector(
};
dialogService.open({
id: TABLE_SELECTOR_DIALOG,
- title: { title: localeService.t('sheets-table-ui.selectRange') },
+ title: { title: localeService.t<LocaleKey>('sheets-table-ui.selectRange') },
draggable: true,
destroyOnClose: true,
mask: false,
diff --git a/packages/sheets-table-ui/src/controllers/sheet-table-controls-render.controller.ts b/packages/sheets-table-ui/src/controllers/sheet-table-controls-render.controller.ts
index 7989634620..7082eb56f4 100644
--- a/packages/sheets-table-ui/src/controllers/sheet-table-controls-render.controller.ts
+++ b/packages/sheets-table-ui/src/controllers/sheet-table-controls-render.controller.ts
@@ -16,16 +16,50 @@
import type { EventState, IRange, Workbook } from '@univerjs/core';
import type { IMouseEvent, IPointerEvent, IRenderContext, IRenderModule, SpreadsheetSkeleton } from '@univerjs/engine-render';
+import type { LocaleKey } from '../locale/types';
import type { ITableControlHitRegion } from '../views/widgets/table-controls-util';
-import { CommandType, Disposable, fromCallback, ICommandService, Inject, Injector, IPermissionService, LocaleService, toDisposable } from '@univerjs/core';
+import {
+ CommandType,
+ Disposable,
+ fromCallback,
+ ICommandService,
+ Inject,
+ Injector,
+ IPermissionService,
+ LocaleService,
+ toDisposable,
+} from '@univerjs/core';
import { CURSOR_TYPE } from '@univerjs/engine-render';
-import { SheetRangeThemeModel, SheetsSelectionsService, WorkbookEditablePermission, WorkbookPermissionService } from '@univerjs/sheets';
-import { DeleteSheetTableCommand, SetSheetTableCommand, SheetTableInsertColumnAtCommand, SheetTableInsertRowAtCommand, TableManager } from '@univerjs/sheets-table';
-import { getTransformCoord, ISheetSelectionRenderService, SetScrollOperation, SetZoomRatioOperation, SHEET_VIEW_KEY, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
+import {
+ SheetRangeThemeModel,
+ SheetsSelectionsService,
+ WorkbookEditablePermission,
+ WorkbookPermissionService,
+} from '@univerjs/sheets';
+import {
+ DeleteSheetTableCommand,
+ SetSheetTableCommand,
+ SheetTableInsertColumnAtCommand,
+ SheetTableInsertRowAtCommand,
+ TableManager,
+} from '@univerjs/sheets-table';
+import {
+ getTransformCoord,
+ ISheetSelectionRenderService,
+ SetScrollOperation,
+ SetZoomRatioOperation,
+ SHEET_VIEW_KEY,
+ SheetSkeletonManagerService,
+} from '@univerjs/sheets-ui';
import { IDialogService, ISidebarService } from '@univerjs/ui';
import { filter, merge } from 'rxjs';
import { openRangeSelector } from '../commands/operations/open-table-selector.operation';
-import { SHEET_TABLE_RENAME_DIALOG, SHEET_TABLE_RENAME_DIALOG_ID, SHEET_TABLE_THEME_PANEL, SHEET_TABLE_THEME_PANEL_ID } from '../const';
+import {
+ SHEET_TABLE_RENAME_DIALOG,
+ SHEET_TABLE_RENAME_DIALOG_ID,
+ SHEET_TABLE_THEME_PANEL,
+ SHEET_TABLE_THEME_PANEL_ID,
+} from '../const';
import { TABLE_CONTROL_INSERT_BUTTON_SIZE, TABLE_CONTROL_TOP_GAP_SIZE } from '../views/widgets/table-controls-util';
import { SheetTableControlsShape } from '../views/widgets/table-controls.shape';
import { SheetTableThemeUIController } from './sheet-table-theme-ui.controller';
@@ -144,10 +178,10 @@ export class SheetTableControlsRenderController extends Disposable implements IR
this._syncTopTableGap(skeleton);
this._shape.setMenuLabels({
- rename: this._localeService.t('sheets-table-ui.rename'),
- 'update-range': this._localeService.t('sheets-table-ui.updateRange'),
- 'set-theme': this._localeService.t('sheets-table-ui.setTheme'),
- delete: this._localeService.t('sheets-table-ui.removeTable'),
+ rename: this._localeService.t<LocaleKey>('sheets-table-ui.rename'),
+ 'update-range': this._localeService.t<LocaleKey>('sheets-table-ui.updateRange'),
+ 'set-theme': this._localeService.t<LocaleKey>('sheets-table-ui.setTheme'),
+ delete: this._localeService.t<LocaleKey>('sheets-table-ui.removeTable'),
});
const unitId = this._context.unit.getUnitId();
@@ -288,7 +322,7 @@ export class SheetTableControlsRenderController extends Disposable implements IR
private _openRenameDialog(unitId: string, tableId: string): void {
this._dialogService.open({
id: SHEET_TABLE_RENAME_DIALOG_ID,
- title: { title: this._localeService.t('sheets-table-ui.rename') },
+ title: { title: this._localeService.t<LocaleKey>('sheets-table-ui.rename') },
draggable: true,
destroyOnClose: true,
mask: true,
@@ -335,7 +369,7 @@ export class SheetTableControlsRenderController extends Disposable implements IR
this._sidebarService.open({
id: SHEET_TABLE_THEME_PANEL_ID,
- header: { title: this._localeService.t('sheets-table-ui.tableStyle') },
+ header: { title: this._localeService.t<LocaleKey>('sheets-table-ui.tableStyle') },
children: {
label: SHEET_TABLE_THEME_PANEL,
oldConfig: table.getTableConfig(),
diff --git a/packages/sheets-table-ui/src/locale/types.ts b/packages/sheets-table-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-table-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-table-ui/src/menu/menu.ts b/packages/sheets-table-ui/src/menu/menu.ts
index 58948c2d9b..1da819718d 100644
--- a/packages/sheets-table-ui/src/menu/menu.ts
+++ b/packages/sheets-table-ui/src/menu/menu.ts
@@ -17,9 +17,16 @@
import type { IAccessor, Workbook } from '@univerjs/core';
import type { IMenuItem, IMenuSelectorItem } from '@univerjs/ui';
import type { Observable } from 'rxjs';
+import type { LocaleKey } from '../locale/types';
import { IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { SheetsSelectionsService } from '@univerjs/sheets';
-import { SheetsTableController, SheetTableInsertColCommand, SheetTableInsertRowCommand, SheetTableRemoveColCommand, SheetTableRemoveRowCommand } from '@univerjs/sheets-table';
+import {
+ SheetsTableController,
+ SheetTableInsertColCommand,
+ SheetTableInsertRowCommand,
+ SheetTableRemoveColCommand,
+ SheetTableRemoveRowCommand,
+} from '@univerjs/sheets-table';
import { getCurrentRangeDisable$ } from '@univerjs/sheets-ui';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { of, switchMap } from 'rxjs';
@@ -28,7 +35,7 @@ import { OpenTableSelectorOperation } from '../commands/operations/open-table-se
export const SHEET_TABLE_CONTEXT_INSERT_MENU_ID = 'sheet.table.context-insert_menu-id';
export const SHEET_TABLE_CONTEXT_REMOVE_MENU_ID = 'sheet.table.context-remove_menu-id';
-export function sheetTableToolbarInsertMenuFactory(accessor: IAccessor): IMenuItem {
+export function sheetTableToolbarInsertMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: OpenTableSelectorOperation.id,
type: MenuItemType.BUTTON,
@@ -40,7 +47,7 @@ export function sheetTableToolbarInsertMenuFactory(accessor: IAccessor): IMenuIt
};
}
-export function SheetTableInsertContextMenuFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function SheetTableInsertContextMenuFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: SHEET_TABLE_CONTEXT_INSERT_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -50,7 +57,7 @@ export function SheetTableInsertContextMenuFactory(accessor: IAccessor): IMenuSe
};
}
-export function SheetTableRemoveContextMenuFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function SheetTableRemoveContextMenuFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: SHEET_TABLE_CONTEXT_REMOVE_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -69,7 +76,7 @@ export function SheetTableInsertRowMenuFactory(accessor: IAccessor) {
};
}
-export function SheetTableInsertColMenuFactory(accessor: IAccessor) {
+export function SheetTableInsertColMenuFactory() {
return {
id: SheetTableInsertColCommand.id,
title: 'sheets-table-ui.insert.col',
@@ -86,7 +93,7 @@ export function SheetTableRemoveRowMenuFactory(accessor: IAccessor) {
};
}
-export function SheetTableRemoveColMenuFactory(accessor: IAccessor) {
+export function SheetTableRemoveColMenuFactory() {
return {
id: SheetTableRemoveColCommand.id,
title: 'sheets-table-ui.remove.col',
@@ -112,7 +119,11 @@ export function getSheetTableRowColOperationHidden$(accessor: IAccessor): Observ
const range = selection.range;
const sheetsTableController = accessor.get(SheetsTableController);
- const isInTable = sheetsTableController.getContainerTableWithRange(workbook.getUnitId(), sheet.getSheetId(), range);
+ const isInTable = sheetsTableController.getContainerTableWithRange(
+ workbook.getUnitId(),
+ sheet.getSheetId(),
+ range
+ );
return of(!isInTable);
})
);
@@ -140,7 +151,11 @@ export function getSheetTableHeaderOperationHidden$(accessor: IAccessor): Observ
const range = selection.range;
const sheetsTableController = accessor.get(SheetsTableController);
- const isInTable = sheetsTableController.getContainerTableWithRange(workbook.getUnitId(), sheet.getSheetId(), range);
+ const isInTable = sheetsTableController.getContainerTableWithRange(
+ workbook.getUnitId(),
+ sheet.getSheetId(),
+ range
+ );
if (!isInTable) {
return of(true);
}
diff --git a/packages/sheets-table-ui/src/services/sheets-table-ui.service.ts b/packages/sheets-table-ui/src/services/sheets-table-ui.service.ts
index 8b289b63fe..f17c41f373 100644
--- a/packages/sheets-table-ui/src/services/sheets-table-ui.service.ts
+++ b/packages/sheets-table-ui/src/services/sheets-table-ui.service.ts
@@ -17,10 +17,27 @@
import type { Workbook } from '@univerjs/core';
import type { ISetRangeValuesMutationParams } from '@univerjs/sheets';
import type { ISetSheetTableParams, ITableFilterItem } from '@univerjs/sheets-table';
+import type { LocaleKey } from '../locale/types';
import type { IFilterByValueWithTreeItem, ITableFilterItemList } from '../types';
-import { cellToRange, Disposable, ICommandService, Inject, IUniverInstanceService, LocaleService, ObjectMatrix, Rectangle } from '@univerjs/core';
+import {
+ cellToRange,
+ Disposable,
+ ICommandService,
+ Inject,
+ IUniverInstanceService,
+ LocaleService,
+ ObjectMatrix,
+ Rectangle,
+} from '@univerjs/core';
import { SetRangeValuesMutation } from '@univerjs/sheets';
-import { isConditionFilter, isManualTableFilter, SetSheetTableFilterCommand, SheetTableService, TABLE_FILTER_EMPTY_VALUE, TableManager } from '@univerjs/sheets-table';
+import {
+ isConditionFilter,
+ isManualTableFilter,
+ SetSheetTableFilterCommand,
+ SheetTableService,
+ TABLE_FILTER_EMPTY_VALUE,
+ TableManager,
+} from '@univerjs/sheets-table';
import { FilterByEnum } from '../types';
interface ISheetTableFilterPanelProps {
@@ -104,7 +121,7 @@ export class SheetsTableUiService extends Disposable {
if (table) {
const filter = table.getTableFilterColumn(columnIndex);
if (filter && isManualTableFilter(filter)) {
- checkedItems.push(...filter.values.map((value) => value === TABLE_FILTER_EMPTY_VALUE ? this._localeService.t('sheets-table-ui.condition.empty') : value));
+ checkedItems.push(...filter.values.map((value) => value === TABLE_FILTER_EMPTY_VALUE ? this._localeService.t<LocaleKey>('sheets-table-ui.condition.empty') : value));
}
}
return checkedItems;
@@ -160,7 +177,7 @@ export class SheetsTableUiService extends Disposable {
let stringItem = this._sheetTableService.getCellValueWithConditionType(worksheet, row, column) as string;
if (stringItem == null) {
- stringItem = this._localeService.t('sheets-table-ui.condition.empty');
+ stringItem = this._localeService.t<LocaleKey>('sheets-table-ui.condition.empty');
}
if (!map.has(stringItem)) {
diff --git a/packages/sheets-table-ui/src/views/components/SheetTableFilterPanel.tsx b/packages/sheets-table-ui/src/views/components/SheetTableFilterPanel.tsx
index 1f06556974..53d24fb674 100644
--- a/packages/sheets-table-ui/src/views/components/SheetTableFilterPanel.tsx
+++ b/packages/sheets-table-ui/src/views/components/SheetTableFilterPanel.tsx
@@ -16,13 +16,28 @@
import type { ISortRangeCommandParams } from '@univerjs/sheets-sort';
import type { ITableConditionFilterItem, ITableManualFilterItem } from '@univerjs/sheets-table';
+import type { LocaleKey } from '../../locale/types';
import type { IConditionInfo } from './type';
import { ICommandService, IPermissionService, LocaleService } from '@univerjs/core';
import { Button, ButtonGroup, Segmented } from '@univerjs/design';
-import { AscendingIcon, DeleteColumnDoubleIcon, DescendingIcon, LeftInsertColumnDoubleIcon, RightInsertColumnDoubleIcon } from '@univerjs/icons';
+import {
+ AscendingIcon,
+ DeleteColumnDoubleIcon,
+ DescendingIcon,
+ LeftInsertColumnDoubleIcon,
+ RightInsertColumnDoubleIcon,
+} from '@univerjs/icons';
import { WorkbookEditablePermission } from '@univerjs/sheets';
import { SortRangeCommand, SortType } from '@univerjs/sheets-sort';
-import { SheetsTableSortStateEnum, SheetTableInsertColumnAtCommand, SheetTableRemoveColumnAtCommand, TABLE_FILTER_EMPTY_VALUE, TableColumnFilterTypeEnum, TableDateCompareTypeEnum, TableManager } from '@univerjs/sheets-table';
+import {
+ SheetsTableSortStateEnum,
+ SheetTableInsertColumnAtCommand,
+ SheetTableRemoveColumnAtCommand,
+ TABLE_FILTER_EMPTY_VALUE,
+ TableColumnFilterTypeEnum,
+ TableDateCompareTypeEnum,
+ TableManager,
+} from '@univerjs/sheets-table';
import { useDependency } from '@univerjs/ui';
import { useMemo, useState } from 'react';
import { SheetsTableComponentController } from '../../controllers/sheet-table-component.controller';
@@ -42,7 +57,12 @@ export function SheetTableFilterPanel() {
const sheetsTableComponentController = useDependency(SheetsTableComponentController);
const tableFilterPanelInfo = sheetsTableComponentController.getCurrentTableFilterInfo()!;
- const props = tableUiService.getTableFilterPanelInitProps(tableFilterPanelInfo.unitId, tableFilterPanelInfo.subUnitId, tableFilterPanelInfo.tableId, tableFilterPanelInfo.column);
+ const props = tableUiService.getTableFilterPanelInitProps(
+ tableFilterPanelInfo.unitId,
+ tableFilterPanelInfo.subUnitId,
+ tableFilterPanelInfo.tableId,
+ tableFilterPanelInfo.column
+ );
const { unitId, subUnitId, tableId, tableFilter, currentFilterBy, columnIndex } = props;
@@ -120,7 +140,7 @@ export function SheetTableFilterPanel() {
if (filterBy === FilterByEnum.Items) {
// do items
const filteredItems: string[] = [];
- const emptyLabel = localeService.t('sheets-table-ui.condition.empty');
+ const emptyLabel = localeService.t<LocaleKey>('sheets-table-ui.condition.empty');
for (const itemInfo of data) {
if (checkedItemSet.has(itemInfo.title)) {
filteredItems.push(itemInfo.title === emptyLabel ? TABLE_FILTER_EMPTY_VALUE : itemInfo.title);
@@ -203,7 +223,7 @@ export function SheetTableFilterPanel() {
onClick={() => insertColumn('left')}
>
<LeftInsertColumnDoubleIcon className="univer-size-5" extend={{ colorChannel1: 'var(--univer-primary-600)' }} />
- <span>{localeService.t('sheets-table-ui.columnMenu.insert-left')}</span>
+ <span>{localeService.t<LocaleKey>('sheets-table-ui.columnMenu.insert-left')}</span>
</button>
<button
type="button"
@@ -219,7 +239,7 @@ export function SheetTableFilterPanel() {
onClick={() => insertColumn('right')}
>
<RightInsertColumnDoubleIcon className="univer-size-5" extend={{ colorChannel1: 'var(--univer-primary-600)' }} />
- <span>{localeService.t('sheets-table-ui.columnMenu.insert-right')}</span>
+ <span>{localeService.t<LocaleKey>('sheets-table-ui.columnMenu.insert-right')}</span>
</button>
<button
type="button"
@@ -236,18 +256,18 @@ export function SheetTableFilterPanel() {
onClick={deleteColumn}
>
<DeleteColumnDoubleIcon className="univer-size-5" extend={{ colorChannel1: 'var(--univer-primary-600)' }} />
- <span>{localeService.t('sheets-table-ui.columnMenu.delete')}</span>
+ <span>{localeService.t<LocaleKey>('sheets-table-ui.columnMenu.delete')}</span>
</button>
</div>
<div className="univer-mb-3 univer-flex">
<ButtonGroup className="univer-mb-3 !univer-flex univer-w-full">
<Button className="univer-w-1/2" onClick={() => applySort(true)}>
<AscendingIcon className="univer-mr-1" />
- {localeService.t('sheets-table-ui.sort.sort-asc')}
+ {localeService.t<LocaleKey>('sheets-table-ui.sort.sort-asc')}
</Button>
<Button className="univer-w-1/2" onClick={() => applySort(false)}>
<DescendingIcon className="univer-mr-1" />
- {localeService.t('sheets-table-ui.sort.sort-desc')}
+ {localeService.t<LocaleKey>('sheets-table-ui.sort.sort-desc')}
</Button>
</ButtonGroup>
</div>
@@ -297,11 +317,11 @@ export function SheetTableFilterPanel() {
disabled={tableFilter === undefined}
onClick={onClearFilter}
>
- {localeService.t('sheets-table-ui.filter.clear-filter')}
+ {localeService.t<LocaleKey>('sheets-table-ui.filter.clear-filter')}
</Button>
<div>
- <Button className="univer-mr-2" onClick={onCancel}>{localeService.t('sheets-table-ui.filter.cancel')}</Button>
- <Button variant="primary" onClick={onApply}>{localeService.t('sheets-table-ui.filter.confirm')}</Button>
+ <Button className="univer-mr-2" onClick={onCancel}>{localeService.t<LocaleKey>('sheets-table-ui.filter.cancel')}</Button>
+ <Button variant="primary" onClick={onApply}>{localeService.t<LocaleKey>('sheets-table-ui.filter.confirm')}</Button>
</div>
</div>
</div>
@@ -311,7 +331,7 @@ export function SheetTableFilterPanel() {
function useFilterByOptions(localeService: LocaleService) {
const locale = localeService.getCurrentLocale();
return useMemo(() => [
- { label: localeService.t('sheets-table-ui.filter.by-values'), value: FilterByEnum.Items },
- { label: localeService.t('sheets-table-ui.filter.by-conditions'), value: FilterByEnum.Condition },
+ { label: localeService.t<LocaleKey>('sheets-table-ui.filter.by-values'), value: FilterByEnum.Items },
+ { label: localeService.t<LocaleKey>('sheets-table-ui.filter.by-conditions'), value: FilterByEnum.Condition },
], [locale, localeService]);
}
diff --git a/packages/sheets-table-ui/src/views/components/SheetTableItemsFilterPanel.tsx b/packages/sheets-table-ui/src/views/components/SheetTableItemsFilterPanel.tsx
index 53b42a4b3e..62b473ea27 100644
--- a/packages/sheets-table-ui/src/views/components/SheetTableItemsFilterPanel.tsx
+++ b/packages/sheets-table-ui/src/views/components/SheetTableItemsFilterPanel.tsx
@@ -16,6 +16,7 @@
import type { ITableFilterItem } from '@univerjs/sheets-table';
import type { Dispatch, SetStateAction } from 'react';
+import type { LocaleKey } from '../../locale/types';
import { LocaleService } from '@univerjs/core';
import { borderClassName, Checkbox, clsx, Input, scrollbarClassName } from '@univerjs/design';
import { useDependency } from '@univerjs/ui';
@@ -117,7 +118,7 @@ export function SheetTableItemsFilterPanel(props: ISheetTableItemsFilterPanelPro
return (
<div className="univer-flex univer-h-full univer-flex-col">
- <Input autoFocus value={searchText} placeholder={localeService.t('sheets-table-ui.filter.search-placeholder')} onChange={onSearchValueChange} />
+ <Input autoFocus value={searchText} placeholder={localeService.t<LocaleKey>('sheets-table-ui.filter.search-placeholder')} onChange={onSearchValueChange} />
<div
className={clsx(`
univer-mt-2 univer-box-border univer-flex univer-h-[180px] univer-max-h-[180px] univer-flex-grow
@@ -138,7 +139,7 @@ export function SheetTableItemsFilterPanel(props: ISheetTableItemsFilterPanelPro
onChange={onCheckAllToggled}
>
<div className="univer-flex univer-h-5 univer-flex-1 univer-items-center univer-text-sm">
- <span className="univer-flex-1 univer-truncate">{`${localeService.t('sheets-table-ui.filter.select-all')}`}</span>
+ <span className="univer-flex-1 univer-truncate">{`${localeService.t<LocaleKey>('sheets-table-ui.filter.select-all')}`}</span>
<span className="univer-ml univer-text-gray-400">{`(${checkedCount}/${searchText ? displayItems.length : allItemsCount})`}</span>
</div>
</Checkbox>
diff --git a/packages/sheets-table-ui/src/views/components/SheetTableRenameDialog.tsx b/packages/sheets-table-ui/src/views/components/SheetTableRenameDialog.tsx
index 69ef0fd36e..3ade201be0 100644
--- a/packages/sheets-table-ui/src/views/components/SheetTableRenameDialog.tsx
+++ b/packages/sheets-table-ui/src/views/components/SheetTableRenameDialog.tsx
@@ -15,10 +15,16 @@
*/
import type { IDefinedNamesService } from '@univerjs/engine-formula';
+import type { LocaleKey } from '../../locale/types';
import { ICommandService, IUniverInstanceService, LocaleService } from '@univerjs/core';
import { Button, Input } from '@univerjs/design';
import { IDefinedNamesService as IDefinedNamesServiceIdentifier } from '@univerjs/engine-formula';
-import { getExistingNamesSet, SetSheetTableCommand, TableManager, validateSheetTableName } from '@univerjs/sheets-table';
+import {
+ getExistingNamesSet,
+ SetSheetTableCommand,
+ TableManager,
+ validateSheetTableName,
+} from '@univerjs/sheets-table';
import { useDependency } from '@univerjs/ui';
import { useMemo, useState } from 'react';
@@ -63,7 +69,7 @@ export function SheetTableRenameDialog(props: ISheetTableRenameDialogProps) {
const validation = validateSheetTableName(nextName, existingNames);
if (!validation.valid) {
- setError(localeService.t('sheets-table-ui.tableNameError'));
+ setError(localeService.t<LocaleKey>('sheets-table-ui.tableNameError'));
return;
}
@@ -84,7 +90,7 @@ export function SheetTableRenameDialog(props: ISheetTableRenameDialogProps) {
<Input
size="middle"
value={value}
- placeholder={localeService.t('sheets-table-ui.renamePlaceholder')}
+ placeholder={localeService.t<LocaleKey>('sheets-table-ui.renamePlaceholder')}
onChange={(nextValue) => {
setValue(nextValue);
setError('');
@@ -98,8 +104,8 @@ export function SheetTableRenameDialog(props: ISheetTableRenameDialogProps) {
/>
{error ? <div className="-univer-mt-2 univer-text-sm univer-text-red-500">{error}</div> : null}
<div className="univer-flex univer-w-full univer-items-center univer-justify-end univer-gap-2">
- <Button className="univer-min-w-16" onClick={onClose}>{localeService.t('sheets-table-ui.cancel')}</Button>
- <Button className="univer-min-w-16" variant="primary" onClick={handleConfirm}>{localeService.t('sheets-table-ui.confirm')}</Button>
+ <Button className="univer-min-w-16" onClick={onClose}>{localeService.t<LocaleKey>('sheets-table-ui.cancel')}</Button>
+ <Button className="univer-min-w-16" variant="primary" onClick={handleConfirm}>{localeService.t<LocaleKey>('sheets-table-ui.confirm')}</Button>
</div>
</div>
);
diff --git a/packages/sheets-table-ui/src/views/components/SheetTableSelector.tsx b/packages/sheets-table-ui/src/views/components/SheetTableSelector.tsx
index 072aa4bf33..36d245ec14 100644
--- a/packages/sheets-table-ui/src/views/components/SheetTableSelector.tsx
+++ b/packages/sheets-table-ui/src/views/components/SheetTableSelector.tsx
@@ -15,6 +15,7 @@
*/
import type { ITableSelectionInfo } from '../../commands/operations/open-table-selector.operation';
+import type { LocaleKey } from '../../locale/types';
import { IUniverInstanceService, LocaleService, Rectangle } from '@univerjs/core';
import { Button } from '@univerjs/design';
import { deserializeRangeWithSheet, serializeRange } from '@univerjs/engine-formula';
@@ -57,7 +58,7 @@ export const SheetTableSelector = (props: ITableSelectionInfo & {
});
if (hasOverlapWithMerge) {
- setRangeError(localeService.t('sheets-table-ui.tableRangeWithMergeError'));
+ setRangeError(localeService.t<LocaleKey>('sheets-table-ui.tableRangeWithMergeError'));
return;
}
@@ -70,13 +71,13 @@ export const SheetTableSelector = (props: ITableSelectionInfo & {
});
if (hasOverlapWithOtherTable) {
- setRangeError(localeService.t('sheets-table-ui.tableRangeWithOtherTableError'));
+ setRangeError(localeService.t<LocaleKey>('sheets-table-ui.tableRangeWithOtherTableError'));
return;
}
const { startRow, endRow } = newRange;
const isSingleRow = startRow === endRow;
if (isSingleRow) {
- setRangeError(localeService.t('sheets-table-ui.tableRangeSingleRowError'));
+ setRangeError(localeService.t<LocaleKey>('sheets-table-ui.tableRangeSingleRowError'));
return;
}
@@ -98,7 +99,7 @@ export const SheetTableSelector = (props: ITableSelectionInfo & {
});
return;
} else {
- setRangeError(localeService.t('sheets-table-ui.updateError'));
+ setRangeError(localeService.t<LocaleKey>('sheets-table-ui.updateError'));
return;
}
}
@@ -116,7 +117,7 @@ export const SheetTableSelector = (props: ITableSelectionInfo & {
)}
<div className="univer-mt-4 univer-flex univer-justify-end">
- <Button onClick={onCancel}>{localeService.t('sheets-table-ui.cancel')}</Button>
+ <Button onClick={onCancel}>{localeService.t<LocaleKey>('sheets-table-ui.cancel')}</Button>
<Button
variant="primary"
onClick={() => {
@@ -131,7 +132,7 @@ export const SheetTableSelector = (props: ITableSelectionInfo & {
}}
className="univer-ml-2"
>
- {localeService.t('sheets-table-ui.confirm')}
+ {localeService.t<LocaleKey>('sheets-table-ui.confirm')}
</Button>
</div>
</>
diff --git a/packages/sheets-table-ui/src/views/components/SheetTableThemePanel.tsx b/packages/sheets-table-ui/src/views/components/SheetTableThemePanel.tsx
index 5bad260a2f..1f8339eb50 100644
--- a/packages/sheets-table-ui/src/views/components/SheetTableThemePanel.tsx
+++ b/packages/sheets-table-ui/src/views/components/SheetTableThemePanel.tsx
@@ -16,14 +16,28 @@
import type { IRangeThemeStyleItem, ISetRangeThemeMutationParams } from '@univerjs/sheets';
import type { IAddTableThemeCommandParams, ISetSheetTableCommandParams, ITableSetConfig } from '@univerjs/sheets-table';
+import type { LocaleKey } from '../../locale/types';
import { ColorKit, ErrorService, ICommandService, LocaleService } from '@univerjs/core';
import { borderClassName, clsx, ColorPicker, Dropdown } from '@univerjs/design';
import { DropdownIcon } from '@univerjs/icons';
import { RangeThemeStyle, SetRangeThemeMutation, SheetRangeThemeModel } from '@univerjs/sheets';
-import { AddTableThemeCommand, customEmptyThemeWithBorderStyle, processStyleWithBorderStyle, RemoveTableThemeCommand, SetSheetTableCommand, TableManager } from '@univerjs/sheets-table';
+import {
+ AddTableThemeCommand,
+ customEmptyThemeWithBorderStyle,
+ processStyleWithBorderStyle,
+ RemoveTableThemeCommand,
+ SetSheetTableCommand,
+ TableManager,
+} from '@univerjs/sheets-table';
import { useDependency, useObservable } from '@univerjs/ui';
import { useEffect, useState } from 'react';
-import { TABLE_BORDER_DEFAULT, TABLE_BORDER_NONE, TABLE_CUSTOM_NAME_PREFIX, TABLE_DEFAULT_BG_COLOR, TABLE_DEFAULT_NAME_PREFIX } from '../../const';
+import {
+ TABLE_BORDER_DEFAULT,
+ TABLE_BORDER_NONE,
+ TABLE_CUSTOM_NAME_PREFIX,
+ TABLE_DEFAULT_BG_COLOR,
+ TABLE_DEFAULT_NAME_PREFIX,
+} from '../../const';
import { SheetTableThemeUIController } from '../../controllers/sheet-table-theme-ui.controller';
export interface ISheetTableThemePanelProps {
@@ -86,7 +100,7 @@ export const SheetTableThemePanel = (props: ISheetTableThemePanelProps) => {
const handleAddCustomTheme = () => {
if (customRangeThemes.length >= 11) {
- errorService.emit(localeService.t('sheets-table-ui.customTooMore'));
+ errorService.emit(localeService.t<LocaleKey>('sheets-table-ui.customTooMore'));
return;
}
const lastCustomTheme = customRangeThemes[customRangeThemes.length - 1];
@@ -133,7 +147,7 @@ export const SheetTableThemePanel = (props: ISheetTableThemePanelProps) => {
return (
<div>
- <h5>{localeService.t('sheets-table-ui.defaultStyle')}</h5>
+ <h5>{localeService.t<LocaleKey>('sheets-table-ui.defaultStyle')}</h5>
<div className="univer-flex univer-gap-2">
{defaultRangeThemes.map((item) => {
const rangeThemeItem = rangeThemeModel.getDefaultRangeThemeStyle(item);
@@ -163,7 +177,7 @@ export const SheetTableThemePanel = (props: ISheetTableThemePanelProps) => {
})}
</div>
- <h5>{localeService.t('sheets-table-ui.customStyle')}</h5>
+ <h5>{localeService.t<LocaleKey>('sheets-table-ui.customStyle')}</h5>
<div className={clsx('univer-w-full univer-rounded-sm', borderClassName)}>
<div className="univer-flex univer-flex-wrap univer-gap-2 univer-p-2">
<div
@@ -235,7 +249,7 @@ export const SheetTableThemePanel = (props: ISheetTableThemePanelProps) => {
background: headerBg,
}}
>
- {localeService.t('sheets-table-ui.header')}
+ {localeService.t<LocaleKey>('sheets-table-ui.header')}
</div>
<Dropdown
overlay={(
@@ -289,7 +303,7 @@ export const SheetTableThemePanel = (props: ISheetTableThemePanelProps) => {
background: firstRowBg,
}}
>
- {localeService.t('sheets-table-ui.firstLine')}
+ {localeService.t<LocaleKey>('sheets-table-ui.firstLine')}
</div>
<Dropdown
overlay={(
@@ -339,7 +353,7 @@ export const SheetTableThemePanel = (props: ISheetTableThemePanelProps) => {
background: secondRowBg,
}}
>
- {localeService.t('sheets-table-ui.secondLine')}
+ {localeService.t<LocaleKey>('sheets-table-ui.secondLine')}
</div>
<Dropdown
overlay={(
@@ -387,7 +401,7 @@ export const SheetTableThemePanel = (props: ISheetTableThemePanelProps) => {
background: lastRowBg,
}}
>
- {localeService.t('sheets-table-ui.footer')}
+ {localeService.t<LocaleKey>('sheets-table-ui.footer')}
</div>
<Dropdown
overlay={(
diff --git a/packages/sheets-table-ui/src/views/components/util.ts b/packages/sheets-table-ui/src/views/components/util.ts
index 1b3030810a..9d51d64442 100644
--- a/packages/sheets-table-ui/src/views/components/util.ts
+++ b/packages/sheets-table-ui/src/views/components/util.ts
@@ -14,13 +14,17 @@
* limitations under the License.
*/
-/* eslint-disable max-lines-per-function */
-
import type { Injector } from '@univerjs/core';
import type { ITableFilterItem } from '@univerjs/sheets-table';
+import type { LocaleKey } from '../../locale/types';
import type { IConditionCompareTypeEnum } from './type';
import { LocaleService } from '@univerjs/core';
-import { TableConditionTypeEnum, TableDateCompareTypeEnum, TableNumberCompareTypeEnum, TableStringCompareTypeEnum } from '@univerjs/sheets-table';
+import {
+ TableConditionTypeEnum,
+ TableDateCompareTypeEnum,
+ TableNumberCompareTypeEnum,
+ TableStringCompareTypeEnum,
+} from '@univerjs/sheets-table';
import { ConditionSubComponentEnum } from './type';
export function getCascaderListOptions(injector: Injector) {
@@ -28,175 +32,175 @@ export function getCascaderListOptions(injector: Injector) {
return [
{
value: TableConditionTypeEnum.String,
- label: localeService.t(`sheets-table-ui.condition.${TableConditionTypeEnum.String}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.condition.${TableConditionTypeEnum.String}`),
children: [
{
value: TableStringCompareTypeEnum.Equal,
- label: localeService.t(`sheets-table-ui.string.compare.${TableStringCompareTypeEnum.Equal}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.string.compare.${TableStringCompareTypeEnum.Equal}`),
},
{
value: TableStringCompareTypeEnum.NotEqual,
- label: localeService.t(`sheets-table-ui.string.compare.${TableStringCompareTypeEnum.NotEqual}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.string.compare.${TableStringCompareTypeEnum.NotEqual}`),
},
{
value: TableStringCompareTypeEnum.Contains,
- label: localeService.t(`sheets-table-ui.string.compare.${TableStringCompareTypeEnum.Contains}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.string.compare.${TableStringCompareTypeEnum.Contains}`),
},
{
value: TableStringCompareTypeEnum.NotContains,
- label: localeService.t(`sheets-table-ui.string.compare.${TableStringCompareTypeEnum.NotContains}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.string.compare.${TableStringCompareTypeEnum.NotContains}`),
},
{
value: TableStringCompareTypeEnum.StartsWith,
- label: localeService.t(`sheets-table-ui.string.compare.${TableStringCompareTypeEnum.StartsWith}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.string.compare.${TableStringCompareTypeEnum.StartsWith}`),
},
{
value: TableStringCompareTypeEnum.EndsWith,
- label: localeService.t(`sheets-table-ui.string.compare.${TableStringCompareTypeEnum.EndsWith}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.string.compare.${TableStringCompareTypeEnum.EndsWith}`),
},
],
},
{
value: TableConditionTypeEnum.Number,
- label: localeService.t(`sheets-table-ui.condition.${TableConditionTypeEnum.Number}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.condition.${TableConditionTypeEnum.Number}`),
children: [
{
value: TableNumberCompareTypeEnum.Equal,
- label: localeService.t(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.Equal}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.Equal}`),
},
{
value: TableNumberCompareTypeEnum.NotEqual,
- label: localeService.t(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.NotEqual}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.NotEqual}`),
},
{
value: TableNumberCompareTypeEnum.GreaterThan,
- label: localeService.t(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.GreaterThan}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.GreaterThan}`),
},
{
value: TableNumberCompareTypeEnum.GreaterThanOrEqual,
- label: localeService.t(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.GreaterThanOrEqual}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.GreaterThanOrEqual}`),
},
{
value: TableNumberCompareTypeEnum.LessThan,
- label: localeService.t(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.LessThan}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.LessThan}`),
},
{
value: TableNumberCompareTypeEnum.LessThanOrEqual,
- label: localeService.t(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.LessThanOrEqual}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.LessThanOrEqual}`),
},
{
value: TableNumberCompareTypeEnum.Between,
- label: localeService.t(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.Between}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.Between}`),
},
{
value: TableNumberCompareTypeEnum.NotBetween,
- label: localeService.t(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.NotBetween}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.NotBetween}`),
},
{
value: TableNumberCompareTypeEnum.Above,
- label: localeService.t(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.Above}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.Above}`),
},
{
value: TableNumberCompareTypeEnum.Below,
- label: localeService.t(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.Below}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.Below}`),
},
// {
// value: TableNumberCompareTypeEnum.TopN,
- // label: localeService.t(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.TopN}`),
+ // label: localeService.t<LocaleKey>(`sheets-table-ui.number.compare.${TableNumberCompareTypeEnum.TopN}`),
// },
],
},
{
value: TableConditionTypeEnum.Date,
- label: localeService.t(`sheets-table-ui.condition.${TableConditionTypeEnum.Date}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.condition.${TableConditionTypeEnum.Date}`),
children: [
{
value: TableDateCompareTypeEnum.Equal,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Equal}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Equal}`),
},
{
value: TableDateCompareTypeEnum.NotEqual,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.NotEqual}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.NotEqual}`),
},
{
value: TableDateCompareTypeEnum.After,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.After}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.After}`),
},
{
value: TableDateCompareTypeEnum.AfterOrEqual,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.AfterOrEqual}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.AfterOrEqual}`),
},
{
value: TableDateCompareTypeEnum.Before,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Before}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Before}`),
},
{
value: TableDateCompareTypeEnum.BeforeOrEqual,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.BeforeOrEqual}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.BeforeOrEqual}`),
},
{
value: TableDateCompareTypeEnum.Between,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Between}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Between}`),
},
{
value: TableDateCompareTypeEnum.NotBetween,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.NotBetween}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.NotBetween}`),
},
{
value: TableDateCompareTypeEnum.Today,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Today}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Today}`),
},
{
value: TableDateCompareTypeEnum.Yesterday,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Yesterday}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Yesterday}`),
},
{
value: TableDateCompareTypeEnum.Tomorrow,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Tomorrow}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Tomorrow}`),
},
{
value: TableDateCompareTypeEnum.ThisWeek,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.ThisWeek}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.ThisWeek}`),
},
{
value: TableDateCompareTypeEnum.LastWeek,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.LastWeek}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.LastWeek}`),
},
{
value: TableDateCompareTypeEnum.NextWeek,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.NextWeek}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.NextWeek}`),
},
{
value: TableDateCompareTypeEnum.ThisMonth,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.ThisMonth}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.ThisMonth}`),
},
{
value: TableDateCompareTypeEnum.LastMonth,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.LastMonth}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.LastMonth}`),
},
{
value: TableDateCompareTypeEnum.NextMonth,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.NextMonth}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.NextMonth}`),
},
{
value: TableDateCompareTypeEnum.ThisYear,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.ThisYear}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.ThisYear}`),
},
{
value: TableDateCompareTypeEnum.LastYear,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.LastYear}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.LastYear}`),
},
{
value: TableDateCompareTypeEnum.NextYear,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.NextYear}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.NextYear}`),
},
{
value: TableDateCompareTypeEnum.Quarter,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Quarter}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Quarter}`),
},
{
value: TableDateCompareTypeEnum.Month,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Month}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Month}`),
},
],
},
@@ -213,70 +217,70 @@ export function getConditionDateSelect(injector: Injector, dateType?: TableDateC
return [
{
value: TableDateCompareTypeEnum.Q1,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Q1}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Q1}`),
},
{
value: TableDateCompareTypeEnum.Q2,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Q2}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Q2}`),
},
{
value: TableDateCompareTypeEnum.Q3,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Q3}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Q3}`),
},
{
value: TableDateCompareTypeEnum.Q4,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Q4}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.Q4}`),
},
];
case TableDateCompareTypeEnum.Month:
return [
{
value: TableDateCompareTypeEnum.M1,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M1}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M1}`),
},
{
value: TableDateCompareTypeEnum.M2,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M2}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M2}`),
},
{
value: TableDateCompareTypeEnum.M3,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M3}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M3}`),
},
{
value: TableDateCompareTypeEnum.M4,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M4}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M4}`),
},
{
value: TableDateCompareTypeEnum.M5,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M5}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M5}`),
},
{
value: TableDateCompareTypeEnum.M6,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M6}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M6}`),
},
{
value: TableDateCompareTypeEnum.M7,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M7}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M7}`),
},
{
value: TableDateCompareTypeEnum.M8,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M8}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M8}`),
},
{
value: TableDateCompareTypeEnum.M9,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M9}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M9}`),
},
{
value: TableDateCompareTypeEnum.M10,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M10}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M10}`),
},
{
value: TableDateCompareTypeEnum.M11,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M11}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M11}`),
},
{
value: TableDateCompareTypeEnum.M12,
- label: localeService.t(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M12}`),
+ label: localeService.t<LocaleKey>(`sheets-table-ui.date.compare.${TableDateCompareTypeEnum.M12}`),
},
];
default:
diff --git a/packages/sheets-table/src/commands/commands/add-sheet-table.command.ts b/packages/sheets-table/src/commands/commands/add-sheet-table.command.ts
index c287f2d363..6c04ddc586 100644
--- a/packages/sheets-table/src/commands/commands/add-sheet-table.command.ts
+++ b/packages/sheets-table/src/commands/commands/add-sheet-table.command.ts
@@ -15,8 +15,18 @@
*/
import type { ICommand, IMutationInfo, IRange } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import type { ITableOptions } from '../../types/type';
-import { CommandType, customNameCharacterCheck, generateRandomId, ICommandService, IUndoRedoService, IUniverInstanceService, LocaleService, sequenceExecute } from '@univerjs/core';
+import {
+ CommandType,
+ customNameCharacterCheck,
+ generateRandomId,
+ ICommandService,
+ IUndoRedoService,
+ IUniverInstanceService,
+ LocaleService,
+ sequenceExecute,
+} from '@univerjs/core';
import { IDefinedNamesService } from '@univerjs/engine-formula';
import { TableManager } from '../../models/table-manager';
import { getExistingNamesSet } from '../../util';
@@ -53,7 +63,7 @@ export const AddSheetTableCommand: ICommand<IAddSheetTableCommandParams> = {
let tableName = params.name;
if (!tableName || !customNameCharacterCheck(tableName.toLowerCase(), existingNamesSet)) {
- const prefix = localeService.t('sheets-table.tablePrefix');
+ const prefix = localeService.t<LocaleKey>('sheets-table.tablePrefix');
let index = tableManager.getTableList(params.unitId).length + 1;
for (const name of existingNamesSet) {
@@ -72,7 +82,7 @@ export const AddSheetTableCommand: ICommand<IAddSheetTableCommandParams> = {
const undos: IMutationInfo[] = [];
const { unitId, subUnitId, range } = params;
- const header = tableManager.getColumnHeader(unitId, subUnitId, range, localeService.t('sheets-table.columnPrefix'));
+ const header = tableManager.getColumnHeader(unitId, subUnitId, range, localeService.t<LocaleKey>('sheets-table.columnPrefix'));
redos.push({ id: AddSheetTableMutation.id, params: { ...params, tableId, name: tableName, header } });
undos.push({ id: DeleteSheetTableMutation.id, params: { tableId, unitId: params.unitId } });
diff --git a/packages/sheets-table/src/commands/commands/set-sheet-table.command.ts b/packages/sheets-table/src/commands/commands/set-sheet-table.command.ts
index 597c002fd3..0e017cb120 100644
--- a/packages/sheets-table/src/commands/commands/set-sheet-table.command.ts
+++ b/packages/sheets-table/src/commands/commands/set-sheet-table.command.ts
@@ -15,8 +15,16 @@
*/
import type { ICommand } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import type { ITableSetConfig } from '../../types/type';
-import { CommandType, ICommandService, ILogService, IUndoRedoService, IUniverInstanceService, LocaleService } from '@univerjs/core';
+import {
+ CommandType,
+ ICommandService,
+ ILogService,
+ IUndoRedoService,
+ IUniverInstanceService,
+ LocaleService,
+} from '@univerjs/core';
import { IDefinedNamesService } from '@univerjs/engine-formula';
import { SheetInterceptorService } from '@univerjs/sheets';
import { TableManager } from '../../models/table-manager';
@@ -59,7 +67,7 @@ export const SetSheetTableCommand: ICommand<ISetSheetTableCommandParams> = {
const tableNameValidation = validateSheetTableName(name, existingNamesSet);
if (!tableNameValidation.valid) {
const logService = accessor.get(ILogService);
- logService.warn(localeService.t('sheets-table.tableNameError'));
+ logService.warn(localeService.t<LocaleKey>('sheets-table.tableNameError'));
return false;
}
diff --git a/packages/sheets-table/src/controllers/sheet-table-ref-range.controller.ts b/packages/sheets-table/src/controllers/sheet-table-ref-range.controller.ts
index f589c2d1c9..784d3fffe3 100644
--- a/packages/sheets-table/src/controllers/sheet-table-ref-range.controller.ts
+++ b/packages/sheets-table/src/controllers/sheet-table-ref-range.controller.ts
@@ -14,14 +14,37 @@
* limitations under the License.
*/
-/* eslint-disable max-lines-per-function */
-/* eslint-disable complexity */
-
import type { IMutationInfo, Workbook } from '@univerjs/core';
-import type { IInsertColCommandParams, IInsertRowCommandParams, IInsertRowMutationParams, IRemoveRowColCommandParams } from '@univerjs/sheets';
+import type {
+ IInsertColCommandParams,
+ IInsertRowCommandParams,
+ IInsertRowMutationParams,
+ IRemoveRowColCommandParams,
+} from '@univerjs/sheets';
+import type { LocaleKey } from '../locale/types';
import type { ITableColumnJson, ITableJson } from '../types/type';
-import { Disposable, ICommandService, Inject, Injector, IUniverInstanceService, LocaleService, Rectangle } from '@univerjs/core';
-import { getSheetCommandTarget, InsertColCommand, InsertColMutation, InsertRowCommand, InsertRowMutation, RefRangeService, RemoveColCommand, RemoveColMutation, RemoveRowCommand, RemoveRowMutation, SheetInterceptorService } from '@univerjs/sheets';
+import {
+ Disposable,
+ ICommandService,
+ Inject,
+ Injector,
+ IUniverInstanceService,
+ LocaleService,
+ Rectangle,
+} from '@univerjs/core';
+import {
+ getSheetCommandTarget,
+ InsertColCommand,
+ InsertColMutation,
+ InsertRowCommand,
+ InsertRowMutation,
+ RefRangeService,
+ RemoveColCommand,
+ RemoveColMutation,
+ RemoveRowCommand,
+ RemoveRowMutation,
+ SheetInterceptorService,
+} from '@univerjs/sheets';
import { AddSheetTableMutation } from '../commands/mutations/add-sheet-table.mutation';
import { DeleteSheetTableMutation } from '../commands/mutations/delete-sheet-table.mutation';
import { SetSheetTableMutation } from '../commands/mutations/set-sheet-table.mutation';
@@ -350,7 +373,7 @@ export class SheetTableRefRangeController extends Disposable {
}
const header: string[] = [];
for (let i = startColumn; i <= endColumn; i++) {
- header.push(convertCellDataToString(worksheet?.getCell(startRow, i)) || getColumnName(i - startColumn + 1, this._localeService.t('sheets-table.columnPrefix')));
+ header.push(convertCellDataToString(worksheet?.getCell(startRow, i)) || getColumnName(i - startColumn + 1, this._localeService.t<LocaleKey>('sheets-table.columnPrefix')));
}
undos.push({
id: AddSheetTableMutation.id,
diff --git a/packages/sheets-table/src/facade/f-workbook.ts b/packages/sheets-table/src/facade/f-workbook.ts
index ea94689731..5f8b81bb01 100644
--- a/packages/sheets-table/src/facade/f-workbook.ts
+++ b/packages/sheets-table/src/facade/f-workbook.ts
@@ -15,9 +15,27 @@
*/
import type { Workbook } from '@univerjs/core';
-import type { IAddSheetTableCommandParams, IDeleteSheetTableParams, ISetSheetTableParams, ITableFilterItem, ITableInfo, ITableInfoWithUnitId, ITableOptions, ITableRange } from '@univerjs/sheets-table';
-import { customNameCharacterCheck, ILogService, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
-import { AddSheetTableCommand, DeleteSheetTableCommand, SetSheetTableFilterCommand, SheetTableService } from '@univerjs/sheets-table';
+import type {
+ IAddSheetTableCommandParams,
+ IDeleteSheetTableParams,
+ ISetSheetTableParams,
+ ITableFilterItem,
+ ITableInfo,
+ ITableInfoWithUnitId,
+ ITableOptions,
+ ITableRange,
+} from '@univerjs/sheets-table';
+import {
+ customNameCharacterCheck,
+ IUniverInstanceService,
+ UniverInstanceType,
+} from '@univerjs/core';
+import {
+ AddSheetTableCommand,
+ DeleteSheetTableCommand,
+ SetSheetTableFilterCommand,
+ SheetTableService,
+} from '@univerjs/sheets-table';
import { FWorkbook } from '@univerjs/sheets/facade';
/**
@@ -201,9 +219,14 @@ export class FWorkbookSheetsTableMixin extends FWorkbook implements IFWorkbookSh
return sheetTableService.getTableList(unitId);
}
- override async addTable(subUnitId: string, tableName: string, rangeInfo: ITableRange, tableId?: string, options?: ITableOptions): Promise<string | undefined> {
+ override async addTable(
+ subUnitId: string,
+ tableName: string,
+ rangeInfo: ITableRange,
+ tableId?: string,
+ options?: ITableOptions
+ ): Promise<string | undefined> {
const sheetTableService = this._injector.get(SheetTableService);
- const localeService = this._injector.get(LocaleService);
const univerInstanceService = this._injector.get(IUniverInstanceService);
const workbook = univerInstanceService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET);
@@ -215,8 +238,6 @@ export class FWorkbookSheetsTableMixin extends FWorkbook implements IFWorkbookSh
}
const isValidName = customNameCharacterCheck(tableName, sheetNameSet);
if (!isValidName) {
- const logService = this._injector.get(ILogService);
- logService.warn(localeService.t('sheets-table.tableNameError'));
return undefined;
}
diff --git a/packages/sheets-table/src/facade/f-worksheet.ts b/packages/sheets-table/src/facade/f-worksheet.ts
index 556e0e1bc5..9b49f29b20 100644
--- a/packages/sheets-table/src/facade/f-worksheet.ts
+++ b/packages/sheets-table/src/facade/f-worksheet.ts
@@ -25,7 +25,7 @@ import type {
ITableOptions,
ITableRange,
} from '@univerjs/sheets-table';
-import { cellToRange, customNameCharacterCheck, ILogService, LocaleService, Rectangle } from '@univerjs/core';
+import { cellToRange, customNameCharacterCheck, LocaleService, Rectangle } from '@univerjs/core';
import { RangeThemeStyle } from '@univerjs/sheets';
import {
AddSheetTableCommand,
@@ -369,8 +369,6 @@ export class FWorksheetTableMixin extends FWorksheet implements IFWorksheetTable
}
const isValidName = customNameCharacterCheck(tableName, sheetNameSet);
if (!isValidName) {
- const logService = this._injector.get(ILogService);
- logService.warn(localeService.t('sheets-table.tableNameError'));
return false;
}
const addTableParams: IAddSheetTableCommandParams = {
@@ -417,8 +415,6 @@ export class FWorksheetTableMixin extends FWorksheet implements IFWorksheetTable
override setTableName(tableId: string, tableName: string): Promise<boolean> | boolean {
const workbook = this.getWorkbook();
- const localeService = this._injector.get(LocaleService);
-
const sheetNameSet = new Set<string>();
if (workbook) {
workbook.getSheets().forEach((sheet) => {
@@ -427,8 +423,6 @@ export class FWorksheetTableMixin extends FWorksheet implements IFWorksheetTable
}
const isValidName = customNameCharacterCheck(tableName, sheetNameSet);
if (!isValidName) {
- const logService = this._injector.get(ILogService);
- logService.warn(localeService.t('sheets-table.tableNameError'));
return false;
}
diff --git a/packages/sheets-table/src/locale/types.ts b/packages/sheets-table/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-table/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-table/src/models/table-manager.ts b/packages/sheets-table/src/models/table-manager.ts
index a05979cb1b..c637e53beb 100644
--- a/packages/sheets-table/src/models/table-manager.ts
+++ b/packages/sheets-table/src/models/table-manager.ts
@@ -15,7 +15,25 @@
*/
import type { IRange, Workbook } from '@univerjs/core';
-import type { ITableAddedEvent, ITableDeletedEvent, ITableFilterChangedEvent, ITableFilterItem, ITableInfoWithUnitId, ITableJson, ITableNameChangedEvent, ITableOptions, ITableRange, ITableRangeChangedEvent, ITableRangeRowColOperation, ITableRangeUpdate, ITableRangeWithState, ITableResource, ITableSetConfig, ITableThemeChangedEvent } from '../types/type';
+import type { LocaleKey } from '../locale/types';
+import type {
+ ITableAddedEvent,
+ ITableDeletedEvent,
+ ITableFilterChangedEvent,
+ ITableFilterItem,
+ ITableInfoWithUnitId,
+ ITableJson,
+ ITableNameChangedEvent,
+ ITableOptions,
+ ITableRange,
+ ITableRangeChangedEvent,
+ ITableRangeRowColOperation,
+ ITableRangeUpdate,
+ ITableRangeWithState,
+ ITableResource,
+ ITableSetConfig,
+ ITableThemeChangedEvent,
+} from '../types/type';
import { Disposable, generateRandomId, Inject, IUniverInstanceService, LocaleService } from '@univerjs/core';
import { getSheetCommandTarget } from '@univerjs/sheets';
import { BehaviorSubject, Subject } from 'rxjs';
@@ -268,7 +286,7 @@ export class TableManager extends Disposable {
for (let i = 0; i < count; i++) {
// There is no need to enforce column name uniqueness.
- const columnPrefix = this._localeService.t('sheets-table.columnPrefix');
+ const columnPrefix = this._localeService.t<LocaleKey>('sheets-table.columnPrefix');
const column = new TableColumn(generateRandomId(), getColumnName(table.getColumnsCount() + 1 + i, columnPrefix));
if (columnsJson?.[i]) {
column.fromJSON(columnsJson[i]);
@@ -307,7 +325,7 @@ export class TableManager extends Disposable {
const newRange = config.newRange;
if (newRange.startColumn < oldRange.startColumn) {
const diff = oldRange.startColumn - newRange.startColumn;
- const columnPrefix = this._localeService.t('sheets-table.columnPrefix');
+ const columnPrefix = this._localeService.t<LocaleKey>('sheets-table.columnPrefix');
for (let i = 0; i < diff; i++) {
table.insertColumn(oldRange.startColumn, new TableColumn(generateRandomId(), getColumnName(table.getColumnsCount() + 1, columnPrefix)));
}
@@ -327,7 +345,7 @@ export class TableManager extends Disposable {
}
} else if (newRange.endColumn > oldRange.endColumn) {
const diff = newRange.endColumn - oldRange.endColumn;
- const columnPrefix = this._localeService.t('sheets-table.columnPrefix');
+ const columnPrefix = this._localeService.t<LocaleKey>('sheets-table.columnPrefix');
for (let i = 0; i < diff; i++) {
table.insertColumn(oldRange.endColumn, new TableColumn(generateRandomId(), getColumnName(table.getColumnsCount() + 1, columnPrefix)));
}
diff --git a/packages/sheets-thread-comment-ui/src/locale/types.ts b/packages/sheets-thread-comment-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-thread-comment-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-ui/src/commands/commands/hide-row-col-confirm.command.ts b/packages/sheets-ui/src/commands/commands/hide-row-col-confirm.command.ts
index 42412ad586..f501533488 100644
--- a/packages/sheets-ui/src/commands/commands/hide-row-col-confirm.command.ts
+++ b/packages/sheets-ui/src/commands/commands/hide-row-col-confirm.command.ts
@@ -15,9 +15,14 @@
*/
import type { IAccessor, ICommand } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import { CommandType, ICommandService, IConfirmService, IUniverInstanceService, LocaleService } from '@univerjs/core';
-import { getSheetCommandTarget, SetColHiddenCommand, SetRowHiddenCommand, SheetsSelectionsService } from '@univerjs/sheets';
-
+import {
+ getSheetCommandTarget,
+ SetColHiddenCommand,
+ SetRowHiddenCommand,
+ SheetsSelectionsService,
+} from '@univerjs/sheets';
import { isAllColumnsCovered, isAllRowsCovered } from './utils/selection-utils';
export const HideRowConfirmCommand: ICommand = {
@@ -45,11 +50,11 @@ export const HideRowConfirmCommand: ICommand = {
await confirmService.confirm({
id: 'sheet.confirm.hide-row',
title: {
- title: localeService.t('sheets-ui.info.problem'),
+ title: localeService.t<LocaleKey>('sheets-ui.info.problem'),
},
- children: { title: localeService.t('sheets-ui.rightClick.hideAllRowsAlert') },
- cancelText: localeService.t('sheets-ui.button.cancel'),
- confirmText: localeService.t('sheets-ui.button.confirm'),
+ children: { title: localeService.t<LocaleKey>('sheets-ui.rightClick.hideAllRowsAlert') },
+ cancelText: localeService.t<LocaleKey>('sheets-ui.button.cancel'),
+ confirmText: localeService.t<LocaleKey>('sheets-ui.button.confirm'),
});
return false;
@@ -87,11 +92,11 @@ export const HideColConfirmCommand: ICommand = {
await confirmService.confirm({
id: 'sheet.confirm.hide-col',
title: {
- title: localeService.t('sheets-ui.info.problem'),
+ title: localeService.t<LocaleKey>('sheets-ui.info.problem'),
},
- children: { title: localeService.t('sheets-ui.rightClick.hideAllColumnsAlert') },
- cancelText: localeService.t('sheets-ui.button.cancel'),
- confirmText: localeService.t('sheets-ui.button.confirm'),
+ children: { title: localeService.t<LocaleKey>('sheets-ui.rightClick.hideAllColumnsAlert') },
+ cancelText: localeService.t<LocaleKey>('sheets-ui.button.cancel'),
+ confirmText: localeService.t<LocaleKey>('sheets-ui.button.confirm'),
});
return false;
diff --git a/packages/sheets-ui/src/commands/commands/remove-row-col-confirm.command.ts b/packages/sheets-ui/src/commands/commands/remove-row-col-confirm.command.ts
index 1514604e18..007d907897 100644
--- a/packages/sheets-ui/src/commands/commands/remove-row-col-confirm.command.ts
+++ b/packages/sheets-ui/src/commands/commands/remove-row-col-confirm.command.ts
@@ -16,9 +16,9 @@
import type { IAccessor, ICommand } from '@univerjs/core';
import type { IRemoveRowColCommandParams } from '@univerjs/sheets';
+import type { LocaleKey } from '../../locale/types';
import { CommandType, ICommandService, IConfirmService, IUniverInstanceService, LocaleService } from '@univerjs/core';
import { getSheetCommandTarget, RemoveColCommand, RemoveRowCommand, SheetsSelectionsService } from '@univerjs/sheets';
-
import { isAllColumnsCovered, isAllRowsCovered } from './utils/selection-utils';
export const RemoveRowConfirmCommand: ICommand = {
@@ -51,11 +51,11 @@ export const RemoveRowConfirmCommand: ICommand = {
await confirmService.confirm({
id: 'sheet.confirm.remove-row',
title: {
- title: localeService.t('sheets-ui.info.problem'),
+ title: localeService.t<LocaleKey>('sheets-ui.info.problem'),
},
- children: { title: localeService.t('sheets-ui.rightClick.deleteAllRowsAlert') },
- cancelText: localeService.t('sheets-ui.button.cancel'),
- confirmText: localeService.t('sheets-ui.button.confirm'),
+ children: { title: localeService.t<LocaleKey>('sheets-ui.rightClick.deleteAllRowsAlert') },
+ cancelText: localeService.t<LocaleKey>('sheets-ui.button.cancel'),
+ confirmText: localeService.t<LocaleKey>('sheets-ui.button.confirm'),
});
return false;
@@ -96,11 +96,11 @@ export const RemoveColConfirmCommand: ICommand = {
await confirmService.confirm({
id: 'sheet.confirm.remove-col',
title: {
- title: localeService.t('sheets-ui.info.problem'),
+ title: localeService.t<LocaleKey>('sheets-ui.info.problem'),
},
- children: { title: localeService.t('sheets-ui.rightClick.deleteAllColumnsAlert') },
- cancelText: localeService.t('sheets-ui.button.cancel'),
- confirmText: localeService.t('sheets-ui.button.confirm'),
+ children: { title: localeService.t<LocaleKey>('sheets-ui.rightClick.deleteAllColumnsAlert') },
+ cancelText: localeService.t<LocaleKey>('sheets-ui.button.cancel'),
+ confirmText: localeService.t<LocaleKey>('sheets-ui.button.confirm'),
});
return false;
diff --git a/packages/sheets-ui/src/commands/commands/remove-sheet-confirm.command.ts b/packages/sheets-ui/src/commands/commands/remove-sheet-confirm.command.ts
index 9833f85481..5240e9cc0e 100644
--- a/packages/sheets-ui/src/commands/commands/remove-sheet-confirm.command.ts
+++ b/packages/sheets-ui/src/commands/commands/remove-sheet-confirm.command.ts
@@ -16,8 +16,22 @@
import type { IAccessor, ICommand } from '@univerjs/core';
import type { IUniverSheetsConfig } from '@univerjs/sheets';
-import { CommandType, ICommandService, IConfigService, IConfirmService, IUniverInstanceService, LocaleService } from '@univerjs/core';
-import { countCells, defaultLargeSheetOperationConfig, getSheetCommandTarget, RemoveSheetCommand, SHEETS_PLUGIN_CONFIG_KEY } from '@univerjs/sheets';
+import type { LocaleKey } from '../../locale/types';
+import {
+ CommandType,
+ ICommandService,
+ IConfigService,
+ IConfirmService,
+ IUniverInstanceService,
+ LocaleService,
+} from '@univerjs/core';
+import {
+ countCells,
+ defaultLargeSheetOperationConfig,
+ getSheetCommandTarget,
+ RemoveSheetCommand,
+ SHEETS_PLUGIN_CONFIG_KEY,
+} from '@univerjs/sheets';
interface IRemoveSheetConfirmCommandParams {
subUnitId: string;
@@ -51,11 +65,11 @@ export const RemoveSheetConfirmCommand: ICommand = {
const result = await confirmService.confirm({
id: 'sheet.confirm.remove-sheet',
title: {
- title: localeService.t('sheets-ui.sheetConfig.deleteSheet'),
+ title: localeService.t<LocaleKey>('sheets-ui.sheetConfig.deleteSheet'),
},
- children: { title: isLargeSheet ? localeService.t('sheets-ui.sheetConfig.deleteLargeSheetContent') : localeService.t('sheets-ui.sheetConfig.deleteSheetContent') },
- cancelText: localeService.t('sheets-ui.button.cancel'),
- confirmText: localeService.t('sheets-ui.button.confirm'),
+ children: { title: isLargeSheet ? localeService.t<LocaleKey>('sheets-ui.sheetConfig.deleteLargeSheetContent') : localeService.t<LocaleKey>('sheets-ui.sheetConfig.deleteSheetContent') },
+ cancelText: localeService.t<LocaleKey>('sheets-ui.button.cancel'),
+ confirmText: localeService.t<LocaleKey>('sheets-ui.button.confirm'),
});
if (!result) {
diff --git a/packages/sheets-ui/src/commands/operations/sidebar-defined-name.operation.ts b/packages/sheets-ui/src/commands/operations/sidebar-defined-name.operation.ts
index 8d3b5e84de..25ce86aafc 100644
--- a/packages/sheets-ui/src/commands/operations/sidebar-defined-name.operation.ts
+++ b/packages/sheets-ui/src/commands/operations/sidebar-defined-name.operation.ts
@@ -15,6 +15,7 @@
*/
import type { IAccessor, ICommand } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import { CommandType, IUniverInstanceService, LocaleService } from '@univerjs/core';
import { IEditorService } from '@univerjs/docs-ui';
import { getSheetCommandTarget } from '@univerjs/sheets';
@@ -42,7 +43,7 @@ export const SidebarDefinedNameOperation: ICommand = {
case 'open':
sidebarService.open({
id: DEFINED_NAME_CONTAINER,
- header: { title: localeService.t('sheets-ui.definedName.featureTitle') },
+ header: { title: localeService.t<LocaleKey>('sheets-ui.definedName.featureTitle') },
children: { label: DEFINED_NAME_CONTAINER },
onClose: () => {
},
diff --git a/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts b/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts
index f9e73b9ab0..3fd9528ccf 100644
--- a/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts
+++ b/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts
@@ -32,6 +32,7 @@ import type {
ISetWorksheetColWidthMutationParams,
} from '@univerjs/sheets';
import type { IUniverSheetsUIConfig } from '../../config/config';
+import type { LocaleKey } from '../../locale/types';
import type {
ICellDataWithSpanInfo,
IClipboardPropertyItem,
@@ -93,7 +94,12 @@ import {
} from '../../commands/commands/clipboard.command';
import { SetScrollOperation } from '../../commands/operations/scroll.operation';
import { SHEETS_UI_PLUGIN_CONFIG_KEY } from '../../config/config';
-import { escapeSpecialCode, ISheetClipboardService, PREDEFINED_HOOK_NAME_COPY, PREDEFINED_HOOK_NAME_PASTE } from '../../services/clipboard/clipboard.service';
+import {
+ escapeSpecialCode,
+ ISheetClipboardService,
+ PREDEFINED_HOOK_NAME_COPY,
+ PREDEFINED_HOOK_NAME_PASTE,
+} from '../../services/clipboard/clipboard.service';
import { SheetSkeletonManagerService } from '../../services/sheet-skeleton-manager.service';
import { ClipboardPopupMenu } from '../../views/clipboard/ClipboardPopupMenu';
import { whenSheetEditorFocused } from '../shortcuts/utils';
@@ -350,7 +356,7 @@ export class SheetClipboardController extends RxDisposable {
if (maxConfig && endRow * endColumn > maxConfig) {
self._messageService.show({
type: MessageType.Error,
- content: self._localService.t('sheets-ui.clipboard.paste.exceedMaxCells'),
+ content: self._localService.t<LocaleKey>('sheets-ui.clipboard.paste.exceedMaxCells'),
}); // TODO: show error info
return false;
}
diff --git a/packages/sheets-ui/src/controllers/force-string-alert-render.controller.ts b/packages/sheets-ui/src/controllers/force-string-alert-render.controller.ts
index 9d862b79b9..1d616ec896 100644
--- a/packages/sheets-ui/src/controllers/force-string-alert-render.controller.ts
+++ b/packages/sheets-ui/src/controllers/force-string-alert-render.controller.ts
@@ -17,7 +17,17 @@
import type { Workbook } from '@univerjs/core';
import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
import type { IUniverSheetsUIConfig } from '../config/config';
-import { CellValueType, Disposable, getNumfmtParseValueFilter, IConfigService, Inject, isRealNum, isTextFormat, LocaleService } from '@univerjs/core';
+import type { LocaleKey } from '../locale/types';
+import {
+ CellValueType,
+ Disposable,
+ getNumfmtParseValueFilter,
+ IConfigService,
+ Inject,
+ isRealNum,
+ isTextFormat,
+ LocaleService,
+} from '@univerjs/core';
import { SHEETS_UI_PLUGIN_CONFIG_KEY } from '../config/config';
import { CellAlertManagerService, CellAlertType } from '../services/cell-alert-manager.service';
import { HoverManagerService } from '../services/hover-manager.service';
@@ -100,8 +110,8 @@ export class ForceStringAlertRenderController extends Disposable implements IRen
this._cellAlertManagerService.showAlert({
type: CellAlertType.ERROR,
- title: this._localeService.t('sheets-ui.info.error'),
- message: this._localeService.t('sheets-ui.info.forceStringInfo'),
+ title: this._localeService.t<LocaleKey>('sheets-ui.info.error'),
+ message: this._localeService.t<LocaleKey>('sheets-ui.info.forceStringInfo'),
location,
width: 200,
height: 74,
diff --git a/packages/sheets-ui/src/controllers/permission/sheet-permission-check-ui.controller.ts b/packages/sheets-ui/src/controllers/permission/sheet-permission-check-ui.controller.ts
index d73d8fbb22..f31034cf3a 100644
--- a/packages/sheets-ui/src/controllers/permission/sheet-permission-check-ui.controller.ts
+++ b/packages/sheets-ui/src/controllers/permission/sheet-permission-check-ui.controller.ts
@@ -18,17 +18,51 @@ import type { ICommandInfo } from '@univerjs/core';
import type { IInsertTextCommandParams } from '@univerjs/docs';
import type { IIMEInputCommandParams } from '@univerjs/docs-ui';
import type { ISheetPasteParams } from '../../commands/commands/clipboard.command';
+import type { LocaleKey } from '../../locale/types';
import type { IEditorBridgeServiceVisibleParam } from '../../services/editor-bridge.service';
-import { Disposable, DisposableCollection, FOCUSING_COMMENT_EDITOR, FOCUSING_EDITOR_STANDALONE, ICommandService, IContextService, Inject, IPermissionService, IUniverInstanceService, LocaleService } from '@univerjs/core';
+import {
+ Disposable,
+ DisposableCollection,
+ FOCUSING_COMMENT_EDITOR,
+ FOCUSING_EDITOR_STANDALONE,
+ ICommandService,
+ IContextService,
+ Inject,
+ IPermissionService,
+ IUniverInstanceService,
+ LocaleService,
+} from '@univerjs/core';
import { InsertTextCommand } from '@univerjs/docs';
import { IMEInputCommand } from '@univerjs/docs-ui';
-import { getSheetCommandTarget, RangeProtectionPermissionEditPoint, RangeProtectionPermissionViewPoint, RangeProtectionRuleModel, SheetPermissionCheckController, WorkbookCopyPermission, WorkbookEditablePermission, WorksheetCopyPermission, WorksheetEditPermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission, WorksheetSetColumnStylePermission } from '@univerjs/sheets';
+import {
+ getSheetCommandTarget,
+ RangeProtectionPermissionEditPoint,
+ RangeProtectionPermissionViewPoint,
+ RangeProtectionRuleModel,
+ SheetPermissionCheckController,
+ WorkbookCopyPermission,
+ WorkbookEditablePermission,
+ WorksheetCopyPermission,
+ WorksheetEditPermission,
+ WorksheetSetCellStylePermission,
+ WorksheetSetCellValuePermission,
+ WorksheetSetColumnStylePermission,
+} from '@univerjs/sheets';
import { IDialogService } from '@univerjs/ui';
-import { SheetCopyCommand, SheetCutCommand, SheetPasteColWidthCommand, SheetPasteCommand, SheetPasteShortKeyCommand } from '../../commands/commands/clipboard.command';
+import {
+ SheetCopyCommand,
+ SheetCutCommand,
+ SheetPasteColWidthCommand,
+ SheetPasteCommand,
+ SheetPasteShortKeyCommand,
+} from '../../commands/commands/clipboard.command';
import { ApplyFormatPainterCommand } from '../../commands/commands/set-format-painter.command';
import { SetCellEditVisibleOperation } from '../../commands/operations/cell-edit.operation';
import { PREDEFINED_HOOK_NAME_PASTE } from '../../services/clipboard/clipboard.service';
-import { UNIVER_SHEET_PERMISSION_ALERT_DIALOG, UNIVER_SHEET_PERMISSION_ALERT_DIALOG_ID } from '../../views/permission/error-msg-dialog/interface';
+import {
+ UNIVER_SHEET_PERMISSION_ALERT_DIALOG,
+ UNIVER_SHEET_PERMISSION_ALERT_DIALOG_ID,
+} from '../../views/permission/error-msg-dialog/interface';
export class SheetPermissionCheckUIController extends Disposable {
disposableCollection = new DisposableCollection();
@@ -105,7 +139,7 @@ export class SheetPermissionCheckUIController extends Disposable {
worksheetTypes: [WorksheetSetCellValuePermission, WorksheetEditPermission],
rangeTypes: [RangeProtectionPermissionEditPoint],
});
- errorMsg = this._localeService.t('sheets-ui.permission.dialog.editErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets-ui.permission.dialog.editErr');
break;
case SetCellEditVisibleOperation.id:
params = commandInfo.params as IEditorBridgeServiceVisibleParam;
@@ -119,7 +153,7 @@ export class SheetPermissionCheckUIController extends Disposable {
worksheetTypes: [WorksheetSetCellValuePermission, WorksheetEditPermission],
rangeTypes: [RangeProtectionPermissionEditPoint],
});
- errorMsg = this._localeService.t('sheets-ui.permission.dialog.editErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets-ui.permission.dialog.editErr');
break;
case SheetPasteColWidthCommand.id:
permission = this._sheetPermissionCheckController.permissionCheckWithoutRange({
@@ -127,14 +161,14 @@ export class SheetPermissionCheckUIController extends Disposable {
worksheetTypes: [WorksheetEditPermission, WorksheetSetColumnStylePermission],
rangeTypes: [RangeProtectionPermissionEditPoint],
});
- errorMsg = this._localeService.t('sheets-ui.permission.dialog.pasteErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets-ui.permission.dialog.pasteErr');
break;
case SheetPasteShortKeyCommand.id:
case SheetPasteCommand.id:
params = commandInfo.params as ISheetPasteParams;
permission = this._permissionCheckByPaste(params);
- errorMsg = this._localeService.t('sheets-ui.permission.dialog.pasteErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets-ui.permission.dialog.pasteErr');
break;
case ApplyFormatPainterCommand.id:
permission = this._sheetPermissionCheckController.permissionCheckWithRanges({
@@ -142,7 +176,7 @@ export class SheetPermissionCheckUIController extends Disposable {
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetSetCellStylePermission],
rangeTypes: [RangeProtectionPermissionEditPoint],
});
- errorMsg = this._localeService.t('sheets-ui.permission.dialog.commonErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets-ui.permission.dialog.commonErr');
break;
case SheetCopyCommand.id:
permission = this._sheetPermissionCheckController.permissionCheckWithRanges({
@@ -150,7 +184,7 @@ export class SheetPermissionCheckUIController extends Disposable {
worksheetTypes: [WorksheetCopyPermission],
rangeTypes: [RangeProtectionPermissionViewPoint],
});
- errorMsg = this._localeService.t('sheets-ui.permission.dialog.copyErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets-ui.permission.dialog.copyErr');
target = getSheetCommandTarget(this._univerInstanceService);
if (
@@ -158,7 +192,7 @@ export class SheetPermissionCheckUIController extends Disposable {
target &&
!this._permissionService.getPermissionPoint(new WorkbookCopyPermission(target.unitId).id)?.value
) {
- errorMsg = this._localeService.t('sheets-ui.permission.dialog.workbookCopyErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets-ui.permission.dialog.workbookCopyErr');
}
break;
@@ -168,7 +202,7 @@ export class SheetPermissionCheckUIController extends Disposable {
worksheetTypes: [WorksheetCopyPermission, WorksheetEditPermission],
rangeTypes: [RangeProtectionPermissionViewPoint, RangeProtectionPermissionEditPoint],
});
- errorMsg = this._localeService.t('sheets-ui.permission.dialog.copyErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets-ui.permission.dialog.copyErr');
target = getSheetCommandTarget(this._univerInstanceService);
if (
@@ -176,7 +210,7 @@ export class SheetPermissionCheckUIController extends Disposable {
target &&
!this._permissionService.getPermissionPoint(new WorkbookCopyPermission(target.unitId).id)?.value
) {
- errorMsg = this._localeService.t('sheets-ui.permission.dialog.workbookCopyErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets-ui.permission.dialog.workbookCopyErr');
}
break;
diff --git a/packages/sheets-ui/src/controllers/permission/sheet-permission-interceptor-clipboard.controller.ts b/packages/sheets-ui/src/controllers/permission/sheet-permission-interceptor-clipboard.controller.ts
index 65a91a7aeb..bc7559d2c2 100644
--- a/packages/sheets-ui/src/controllers/permission/sheet-permission-interceptor-clipboard.controller.ts
+++ b/packages/sheets-ui/src/controllers/permission/sheet-permission-interceptor-clipboard.controller.ts
@@ -15,7 +15,15 @@
*/
import type { ICellDataForSheetInterceptor, IRange, Workbook } from '@univerjs/core';
-import { Disposable, DisposableCollection, Inject, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
+import {
+ Disposable,
+ DisposableCollection,
+ Inject,
+ IUniverInstanceService,
+ LocaleService,
+ UniverInstanceType,
+} from '@univerjs/core';
import { UnitAction } from '@univerjs/protocol';
import { SheetPermissionCheckController, SheetsSelectionsService } from '@univerjs/sheets';
import { ISheetClipboardService } from '../../services/clipboard/clipboard.service';
@@ -76,7 +84,9 @@ export class SheetPermissionInterceptorClipboardController extends Disposable {
}
if (!hasPermission) {
- this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localService.t('sheets-ui.permission.dialog.pasteErr'));
+ this._sheetPermissionCheckController.blockExecuteWithoutPermission(
+ this._localService.t<LocaleKey>('sheets-ui.permission.dialog.pasteErr')
+ );
}
return hasPermission;
diff --git a/packages/sheets-ui/src/locale/types.ts b/packages/sheets-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/sheets-ui/src/menu/border.menu.ts b/packages/sheets-ui/src/menu/border.menu.ts
index c096b18ffb..dd768987f2 100644
--- a/packages/sheets-ui/src/menu/border.menu.ts
+++ b/packages/sheets-ui/src/menu/border.menu.ts
@@ -17,18 +17,30 @@
import type { IAccessor } from '@univerjs/core';
import type { IBorderInfo } from '@univerjs/sheets';
import type { IMenuSelectorItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { FOCUSING_COMMON_DRAWINGS, ICommandService, IContextService, UniverInstanceType } from '@univerjs/core';
-import { BorderStyleManagerService, RangeProtectionPermissionEditPoint, SetBorderBasicCommand, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission } from '@univerjs/sheets';
+import {
+ BorderStyleManagerService,
+ RangeProtectionPermissionEditPoint,
+ SetBorderBasicCommand,
+ WorkbookEditablePermission,
+ WorksheetEditPermission,
+ WorksheetSetCellStylePermission,
+} from '@univerjs/sheets';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { combineLatest, map, Observable, startWith } from 'rxjs';
import { BORDER_LINE_CHILDREN, BORDER_PANEL_COMPONENT } from '../views/border-panel/interface';
import { getCurrentRangeDisable$ } from './menu-util';
-export function CellBorderSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<IBorderInfo, IBorderInfo> {
+export function CellBorderSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey, IBorderInfo, IBorderInfo> {
const borderStyleManagerService = accessor.get(BorderStyleManagerService);
- const disabled$ = getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] });
+ const disabled$ = getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ });
return {
id: SetBorderBasicCommand.id,
diff --git a/packages/sheets-ui/src/menu/clear.menu.ts b/packages/sheets-ui/src/menu/clear.menu.ts
index b813d6c0fd..ee94d748eb 100644
--- a/packages/sheets-ui/src/menu/clear.menu.ts
+++ b/packages/sheets-ui/src/menu/clear.menu.ts
@@ -16,6 +16,7 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { UniverInstanceType } from '@univerjs/core';
import {
ClearSelectionAllCommand,
@@ -31,7 +32,7 @@ import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { getCurrentRangeDisable$, getObservableWithExclusiveRange$ } from './menu-util';
export const CLEAR_SELECTION_MENU_ID = 'sheet.menu.clear-selection';
-export function ClearSelectionMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function ClearSelectionMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: CLEAR_SELECTION_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -41,7 +42,7 @@ export function ClearSelectionMenuItemFactory(accessor: IAccessor): IMenuSelecto
};
}
-export function ClearSelectionContentMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ClearSelectionContentMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: ClearSelectionContentCommand.id,
type: MenuItemType.BUTTON,
@@ -55,7 +56,7 @@ export function ClearSelectionContentMenuItemFactory(accessor: IAccessor): IMenu
};
}
-export function ClearSelectionFormatMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ClearSelectionFormatMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: ClearSelectionFormatCommand.id,
type: MenuItemType.BUTTON,
@@ -69,7 +70,7 @@ export function ClearSelectionFormatMenuItemFactory(accessor: IAccessor): IMenuB
};
}
-export function ClearSelectionAllToolbarMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ClearSelectionAllToolbarMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: ClearSelectionAllCommand.id,
type: MenuItemType.BUTTON,
@@ -84,7 +85,7 @@ export function ClearSelectionAllToolbarMenuItemFactory(accessor: IAccessor): IM
};
}
-export function ClearSelectionAllMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ClearSelectionAllMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: ClearSelectionAllCommand.id,
type: MenuItemType.BUTTON,
diff --git a/packages/sheets-ui/src/menu/delete.menu.ts b/packages/sheets-ui/src/menu/delete.menu.ts
index 7a7de463e0..1c284b43f3 100644
--- a/packages/sheets-ui/src/menu/delete.menu.ts
+++ b/packages/sheets-ui/src/menu/delete.menu.ts
@@ -16,8 +16,16 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
-
-import { RangeProtectionPermissionEditPoint, WorkbookDeleteColumnPermission, WorkbookDeleteRowPermission, WorkbookEditablePermission, WorksheetDeleteColumnPermission, WorksheetDeleteRowPermission, WorksheetEditPermission } from '@univerjs/sheets';
+import type { LocaleKey } from '../locale/types';
+import {
+ RangeProtectionPermissionEditPoint,
+ WorkbookDeleteColumnPermission,
+ WorkbookDeleteRowPermission,
+ WorkbookEditablePermission,
+ WorksheetDeleteColumnPermission,
+ WorksheetDeleteRowPermission,
+ WorksheetEditPermission,
+} from '@univerjs/sheets';
import { MenuItemType } from '@univerjs/ui';
import { DeleteRangeMoveLeftConfirmCommand } from '../commands/commands/delete-range-move-left-confirm.command';
import { DeleteRangeMoveUpConfirmCommand } from '../commands/commands/delete-range-move-up-confirm.command';
@@ -25,60 +33,83 @@ import {
RemoveColConfirmCommand,
RemoveRowConfirmCommand,
} from '../commands/commands/remove-row-col-confirm.command';
-import { getBaseRangeMenuHidden$, getCellMenuHidden$, getCurrentRangeDisable$, getDeleteMenuHidden$, getObservableWithExclusiveRange$ } from './menu-util';
+import {
+ getBaseRangeMenuHidden$,
+ getCellMenuHidden$,
+ getCurrentRangeDisable$,
+ getDeleteMenuHidden$,
+ getObservableWithExclusiveRange$,
+} from './menu-util';
export const DELETE_RANGE_MENU_ID = 'sheet.menu.delete';
-export function DeleteRangeMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function DeleteRangeMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: DELETE_RANGE_MENU_ID,
type: MenuItemType.SUBITEMS,
title: 'sheets-ui.rightClick.delete',
icon: 'ReduceDoubleIcon',
hidden$: getObservableWithExclusiveRange$(accessor, getBaseRangeMenuHidden$(accessor)),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetEditPermission],
+ }),
};
}
-export function RemoveColMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function RemoveColMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: RemoveColConfirmCommand.id,
type: MenuItemType.BUTTON,
icon: 'DeleteColumnDoubleIcon',
title: 'sheets-ui.rightClick.deleteSelectedColumn',
hidden$: getDeleteMenuHidden$(accessor, 'col'),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission, WorkbookDeleteColumnPermission], worksheetTypes: [WorksheetEditPermission, WorksheetDeleteColumnPermission] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission, WorkbookDeleteColumnPermission],
+ worksheetTypes: [WorksheetEditPermission, WorksheetDeleteColumnPermission],
+ }),
};
}
-export function RemoveRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function RemoveRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: RemoveRowConfirmCommand.id,
type: MenuItemType.BUTTON,
icon: 'DeleteRowDoubleIcon',
title: 'sheets-ui.rightClick.deleteSelectedRow',
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission, WorkbookDeleteRowPermission], worksheetTypes: [WorksheetEditPermission, WorksheetDeleteRowPermission] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission, WorkbookDeleteRowPermission],
+ worksheetTypes: [WorksheetEditPermission, WorksheetDeleteRowPermission],
+ }),
hidden$: getDeleteMenuHidden$(accessor, 'row'),
};
}
-export function DeleteRangeMoveLeftMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function DeleteRangeMoveLeftMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DeleteRangeMoveLeftConfirmCommand.id,
type: MenuItemType.BUTTON,
title: 'sheets-ui.rightClick.moveLeft',
icon: 'DeleteCellShiftLeftDoubleIcon',
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetEditPermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
hidden$: getCellMenuHidden$(accessor, 'col'),
};
}
-export function DeleteRangeMoveUpMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function DeleteRangeMoveUpMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DeleteRangeMoveUpConfirmCommand.id,
type: MenuItemType.BUTTON,
title: 'sheets-ui.rightClick.moveUp',
icon: 'DeleteCellShiftUpDoubleIcon',
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetEditPermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
hidden$: getCellMenuHidden$(accessor, 'row'),
};
}
diff --git a/packages/sheets-ui/src/menu/font.menu.ts b/packages/sheets-ui/src/menu/font.menu.ts
index 21e40276d4..d3d56507b1 100644
--- a/packages/sheets-ui/src/menu/font.menu.ts
+++ b/packages/sheets-ui/src/menu/font.menu.ts
@@ -16,6 +16,7 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import {
DEFAULT_STYLES,
EDITOR_ACTIVATED,
@@ -97,7 +98,7 @@ function updateFontSizeValue(accessor: IAccessor, defaultValue: number) {
}));
}
-export function FontSizeSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<number> {
+export function FontSizeSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey, number> {
const defaultValue = DEFAULT_STYLES.fs;
const disabled$ = getCurrentRangeDisable$(accessor, {
workbookTypes: [WorkbookEditablePermission],
@@ -124,7 +125,7 @@ export function FontSizeSelectorMenuItemFactory(accessor: IAccessor): IMenuSelec
};
}
-export function FontSizeIncreaseMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function FontSizeIncreaseMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const disabled$ = getCurrentRangeDisable$(accessor, {
workbookTypes: [WorkbookEditablePermission],
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
diff --git a/packages/sheets-ui/src/menu/frozen.menu.ts b/packages/sheets-ui/src/menu/frozen.menu.ts
index a0e8ac1a6f..759047026a 100644
--- a/packages/sheets-ui/src/menu/frozen.menu.ts
+++ b/packages/sheets-ui/src/menu/frozen.menu.ts
@@ -17,11 +17,18 @@
import type { IAccessor } from '@univerjs/core';
import type { ISelectionWithStyle } from '@univerjs/sheets';
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { UniverInstanceType } from '@univerjs/core';
import { CancelFrozenCommand, SheetsSelectionsService } from '@univerjs/sheets';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { combineLatest, map, Observable } from 'rxjs';
-import { SetColumnFrozenCommand, SetFirstColumnFrozenCommand, SetFirstRowFrozenCommand, SetRowFrozenCommand, SetSelectionFrozenCommand } from '../commands/commands/set-frozen.command';
+import {
+ SetColumnFrozenCommand,
+ SetFirstColumnFrozenCommand,
+ SetFirstRowFrozenCommand,
+ SetRowFrozenCommand,
+ SetSelectionFrozenCommand,
+} from '../commands/commands/set-frozen.command';
import { MENU_ITEM_FROZEN_COMPONENT } from '../views/menu-item-frozen/index';
const getMenuHiddenByCurrentSelectionChangedObservable$ = (accessor: IAccessor, type: 'row' | 'col' | 'all'): Observable<boolean> => {
@@ -65,7 +72,7 @@ const getMenuHiddenByCurrentSelectionChangedObservable$ = (accessor: IAccessor,
export const SHEET_FROZEN_MENU_ID = 'sheet.menu.sheet-frozen';
-export function SheetFrozenMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function SheetFrozenMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: SHEET_FROZEN_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -77,7 +84,7 @@ export function SheetFrozenMenuItemFactory(accessor: IAccessor): IMenuSelectorIt
export const SHEET_FROZEN_COLUMN_HEADER_MENU_ID = 'sheet.column-header-menu.sheet-frozen';
-export function SheetFrozenColumnHeaderMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function SheetFrozenColumnHeaderMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: SHEET_FROZEN_COLUMN_HEADER_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -89,7 +96,7 @@ export function SheetFrozenColumnHeaderMenuItemFactory(accessor: IAccessor): IMe
export const SHEET_FROZEN_ROW_HEADER_MENU_ID = 'sheet.row-header-menu.sheet-frozen';
-export function SheetFrozenRowHeaderMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function SheetFrozenRowHeaderMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: SHEET_FROZEN_ROW_HEADER_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -99,7 +106,7 @@ export function SheetFrozenRowHeaderMenuItemFactory(accessor: IAccessor): IMenuS
};
}
-export function FrozenMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function FrozenMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: SetSelectionFrozenCommand.id,
type: MenuItemType.BUTTON,
@@ -110,13 +117,16 @@ export function FrozenMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
type: 'all',
},
},
- hidden$: combineLatest([getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET), getMenuHiddenByCurrentSelectionChangedObservable$(accessor, 'all')]).pipe(
+ hidden$: combineLatest([
+ getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ getMenuHiddenByCurrentSelectionChangedObservable$(accessor, 'all'),
+ ]).pipe(
map(([menuHidden, selectionHidden]) => menuHidden || selectionHidden)
),
};
}
-export function FrozenRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function FrozenRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: SetRowFrozenCommand.id,
type: MenuItemType.BUTTON,
@@ -127,13 +137,16 @@ export function FrozenRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
type: 'row',
},
},
- hidden$: combineLatest([getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET), getMenuHiddenByCurrentSelectionChangedObservable$(accessor, 'row')]).pipe(
+ hidden$: combineLatest([
+ getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ getMenuHiddenByCurrentSelectionChangedObservable$(accessor, 'row'),
+ ]).pipe(
map(([menuHidden, selectionHidden]) => menuHidden || selectionHidden)
),
};
}
-export function FrozenColMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function FrozenColMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: SetColumnFrozenCommand.id,
type: MenuItemType.BUTTON,
@@ -144,13 +157,16 @@ export function FrozenColMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
type: 'col',
},
},
- hidden$: combineLatest([getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET), getMenuHiddenByCurrentSelectionChangedObservable$(accessor, 'col')]).pipe(
+ hidden$: combineLatest([
+ getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ getMenuHiddenByCurrentSelectionChangedObservable$(accessor, 'col'),
+ ]).pipe(
map(([menuHidden, selectionHidden]) => menuHidden || selectionHidden)
),
};
}
-export function FrozenFirstRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function FrozenFirstRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: SetFirstRowFrozenCommand.id,
type: MenuItemType.BUTTON,
@@ -160,7 +176,7 @@ export function FrozenFirstRowMenuItemFactory(accessor: IAccessor): IMenuButtonI
};
}
-export function FrozenFirstColMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function FrozenFirstColMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: SetFirstColumnFrozenCommand.id,
type: MenuItemType.BUTTON,
@@ -170,7 +186,7 @@ export function FrozenFirstColMenuItemFactory(accessor: IAccessor): IMenuButtonI
};
}
-export function CancelFrozenMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function CancelFrozenMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: CancelFrozenCommand.id,
type: MenuItemType.BUTTON,
diff --git a/packages/sheets-ui/src/menu/gridlines.menu.ts b/packages/sheets-ui/src/menu/gridlines.menu.ts
index 28b015d3a1..0760e57101 100644
--- a/packages/sheets-ui/src/menu/gridlines.menu.ts
+++ b/packages/sheets-ui/src/menu/gridlines.menu.ts
@@ -16,13 +16,26 @@
import type { IAccessor, Workbook } from '@univerjs/core';
import type { IMenuButtonItem } from '@univerjs/ui';
-import { BooleanNumber, DisposableCollection, ICommandService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
-import { SetWorksheetActiveOperation, ToggleGridlinesCommand, ToggleGridlinesMutation, WorkbookEditablePermission, WorksheetEditPermission } from '@univerjs/sheets';
+import type { LocaleKey } from '../locale/types';
+import {
+ BooleanNumber,
+ DisposableCollection,
+ ICommandService,
+ IUniverInstanceService,
+ UniverInstanceType,
+} from '@univerjs/core';
+import {
+ SetWorksheetActiveOperation,
+ ToggleGridlinesCommand,
+ ToggleGridlinesMutation,
+ WorkbookEditablePermission,
+ WorksheetEditPermission,
+} from '@univerjs/sheets';
import { MenuItemType } from '@univerjs/ui';
import { Observable } from 'rxjs';
import { getCurrentRangeDisable$ } from './menu-util';
-export function ToggleGridlinesMenuFactory(accessor: IAccessor): IMenuButtonItem {
+export function ToggleGridlinesMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const commandService = accessor.get(ICommandService);
const instanceService = accessor.get(IUniverInstanceService);
diff --git a/packages/sheets-ui/src/menu/insert.menu.ts b/packages/sheets-ui/src/menu/insert.menu.ts
index 8b0fa9f9c7..e8617ff4b2 100644
--- a/packages/sheets-ui/src/menu/insert.menu.ts
+++ b/packages/sheets-ui/src/menu/insert.menu.ts
@@ -16,6 +16,7 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { ICommandService, IUniverInstanceService } from '@univerjs/core';
import {
InsertColAfterCommand,
@@ -36,47 +37,65 @@ import {
WorksheetInsertColumnPermission,
WorksheetInsertRowPermission,
} from '@univerjs/sheets';
-
import { MenuItemType } from '@univerjs/ui';
import { Observable } from 'rxjs';
import { InsertRangeMoveDownConfirmCommand } from '../commands/commands/insert-range-move-down-confirm.command';
import { InsertRangeMoveRightConfirmCommand } from '../commands/commands/insert-range-move-right-confirm.command';
import { MENU_ITEM_INPUT_COMPONENT } from '../views/menu-item-input/index';
-import { deriveStateFromActiveSheet$, getBaseRangeMenuHidden$, getCellMenuHidden$, getCurrentRangeDisable$, getInsertAfterMenuHidden$, getInsertBeforeMenuHidden$, getObservableWithExclusiveRange$ } from './menu-util';
+import {
+ deriveStateFromActiveSheet$,
+ getBaseRangeMenuHidden$,
+ getCellMenuHidden$,
+ getCurrentRangeDisable$,
+ getInsertAfterMenuHidden$,
+ getInsertBeforeMenuHidden$,
+ getObservableWithExclusiveRange$,
+} from './menu-util';
export const COL_INSERT_MENU_ID = 'sheet.menu.col-insert';
-export function ColInsertMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function ColInsertMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: COL_INSERT_MENU_ID,
type: MenuItemType.SUBITEMS,
title: 'sheets-ui.rightClick.insert',
icon: 'InsertDoubleIcon',
hidden$: getBaseRangeMenuHidden$(accessor),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission, WorkbookInsertColumnPermission], worksheetTypes: [WorksheetEditPermission, WorksheetInsertColumnPermission] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission, WorkbookInsertColumnPermission],
+ worksheetTypes: [WorksheetEditPermission, WorksheetInsertColumnPermission],
+ }),
};
}
export const ROW_INSERT_MENU_ID = 'sheet.menu.row-insert';
-export function RowInsertMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function RowInsertMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: ROW_INSERT_MENU_ID,
type: MenuItemType.SUBITEMS,
title: 'sheets-ui.rightClick.insert',
icon: 'InsertDoubleIcon',
hidden$: getBaseRangeMenuHidden$(accessor),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission, WorkbookInsertRowPermission], worksheetTypes: [WorksheetInsertRowPermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission, WorkbookInsertRowPermission],
+ worksheetTypes: [WorksheetInsertRowPermission, WorksheetEditPermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
};
}
export const CELL_INSERT_MENU_ID = 'sheet.menu.cell-insert';
-export function CellInsertMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function CellInsertMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: CELL_INSERT_MENU_ID,
type: MenuItemType.SUBITEMS,
title: 'sheets-ui.rightClick.insert',
icon: 'InsertDoubleIcon',
hidden$: getObservableWithExclusiveRange$(accessor, getBaseRangeMenuHidden$(accessor)),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission, WorkbookInsertColumnPermission, WorkbookInsertRowPermission], worksheetTypes: [WorksheetInsertColumnPermission, WorksheetInsertRowPermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission, WorkbookInsertColumnPermission, WorkbookInsertRowPermission],
+ worksheetTypes: [WorksheetInsertColumnPermission, WorksheetInsertRowPermission, WorksheetEditPermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
};
}
@@ -85,7 +104,7 @@ export function CellInsertMenuItemFactory(accessor: IAccessor): IMenuSelectorIte
* @param accessor
* @returns
*/
-export function InsertRowBeforeMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function InsertRowBeforeMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: InsertRowBeforeCommand.id,
type: MenuItemType.BUTTON,
@@ -105,7 +124,7 @@ export function InsertRowBeforeMenuItemFactory(accessor: IAccessor): IMenuButton
* @param accessor
* @returns
*/
-export function InsertRowBeforeCellMenuItemFactory(accessor: IAccessor): IMenuButtonItem<number> {
+export function InsertRowBeforeCellMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey, number> {
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
const commandService = accessor.get(ICommandService);
@@ -157,7 +176,7 @@ export function InsertRowBeforeCellMenuItemFactory(accessor: IAccessor): IMenuBu
};
}
-export function InsertRowAfterMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function InsertRowAfterMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: InsertRowAfterCommand.id,
type: MenuItemType.BUTTON,
@@ -176,7 +195,7 @@ export function InsertRowAfterMenuItemFactory(accessor: IAccessor): IMenuButtonI
* context menu when right click cell
* @param accessor
*/
-export function InsertColLeftCellMenuItemFactory(accessor: IAccessor): IMenuButtonItem<number> {
+export function InsertColLeftCellMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey, number> {
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
const commandService = accessor.get(ICommandService);
@@ -228,7 +247,7 @@ export function InsertColLeftCellMenuItemFactory(accessor: IAccessor): IMenuButt
};
}
-export function InsertColBeforeMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function InsertColBeforeMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: InsertColBeforeCommand.id,
type: MenuItemType.BUTTON,
@@ -243,7 +262,7 @@ export function InsertColBeforeMenuItemFactory(accessor: IAccessor): IMenuButton
};
}
-export function InsertColAfterMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function InsertColAfterMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: InsertColAfterCommand.id,
type: MenuItemType.BUTTON,
@@ -258,7 +277,7 @@ export function InsertColAfterMenuItemFactory(accessor: IAccessor): IMenuButtonI
};
}
-export function InsertRangeMoveRightMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function InsertRangeMoveRightMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: InsertRangeMoveRightConfirmCommand.id,
type: MenuItemType.BUTTON,
@@ -277,7 +296,7 @@ export function InsertRangeMoveRightMenuItemFactory(accessor: IAccessor): IMenuB
* For insert range in cell context menu
* @param accessor
*/
-export function InsertRangeMoveDownMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function InsertRangeMoveDownMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: InsertRangeMoveDownConfirmCommand.id,
type: MenuItemType.BUTTON,
@@ -296,7 +315,7 @@ export function InsertRangeMoveDownMenuItemFactory(accessor: IAccessor): IMenuBu
* Context menu in rowheader.
* @param accessor
*/
-export function InsertMultiRowsAfterHeaderMenuItemFactory(accessor: IAccessor): IMenuButtonItem<number> {
+export function InsertMultiRowsAfterHeaderMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey, number> {
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
const commandService = accessor.get(ICommandService);
@@ -353,7 +372,7 @@ export function InsertMultiRowsAfterHeaderMenuItemFactory(accessor: IAccessor):
* Context menu in rowheader.
* @param accessor
*/
-export function InsertMultiRowsAboveHeaderMenuItemFactory(accessor: IAccessor): IMenuButtonItem<number> {
+export function InsertMultiRowsAboveHeaderMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey, number> {
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
const commandService = accessor.get(ICommandService);
@@ -409,7 +428,7 @@ export function InsertMultiRowsAboveHeaderMenuItemFactory(accessor: IAccessor):
* Context menu in rowheader.
* @param accessor
*/
-export function InsertMultiColsLeftHeaderMenuItemFactory(accessor: IAccessor): IMenuButtonItem<number> {
+export function InsertMultiColsLeftHeaderMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey, number> {
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
const commandService = accessor.get(ICommandService);
@@ -465,7 +484,7 @@ export function InsertMultiColsLeftHeaderMenuItemFactory(accessor: IAccessor): I
* Context menu in rowheader.
* @param accessor
*/
-export function InsertMultiColsRightHeaderMenuItemFactory(accessor: IAccessor): IMenuButtonItem<number> {
+export function InsertMultiColsRightHeaderMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey, number> {
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
const commandService = accessor.get(ICommandService);
diff --git a/packages/sheets-ui/src/menu/menu.ts b/packages/sheets-ui/src/menu/menu.ts
index 003371f9ed..7c01782ba7 100644
--- a/packages/sheets-ui/src/menu/menu.ts
+++ b/packages/sheets-ui/src/menu/menu.ts
@@ -16,6 +16,7 @@
import type { IAccessor, IColorStyle, Nullable, Workbook } from '@univerjs/core';
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import {
BooleanNumber,
composeStyles,
@@ -100,7 +101,10 @@ import {
SetRangeTextColorCommand,
SetRangeUnderlineCommand,
} from '../commands/commands/inline-format.command';
-import { SetInfiniteFormatPainterCommand, SetOnceFormatPainterCommand } from '../commands/commands/set-format-painter.command';
+import {
+ SetInfiniteFormatPainterCommand,
+ SetOnceFormatPainterCommand,
+} from '../commands/commands/set-format-painter.command';
import { SetWorksheetColAutoWidthCommand } from '../commands/commands/set-worksheet-auto-col-width.command';
import { ISheetClipboardService } from '../services/clipboard/clipboard.service';
import { FormatPainterStatus, IFormatPainterService } from '../services/format-painter/format-painter.service';
@@ -115,7 +119,7 @@ export enum SheetMenuPosition {
SHEET_FOOTER = 'SHEET_FOOTER',
}
-export function FormatPainterMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function FormatPainterMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const formatPainterService = accessor.get(IFormatPainterService);
return {
@@ -123,7 +127,7 @@ export function FormatPainterMenuItemFactory(accessor: IAccessor): IMenuButtonIt
subId: SetInfiniteFormatPainterCommand.id,
type: MenuItemType.BUTTON,
icon: 'BrushIcon',
- title: 'Format Painter',
+ title: 'sheets-ui.toolbar.formatPainter',
tooltip: 'sheets-ui.toolbar.formatPainter',
activated$: new Observable<boolean>((subscriber) => {
let active = false;
@@ -140,11 +144,15 @@ export function FormatPainterMenuItemFactory(accessor: IAccessor): IMenuButtonIt
};
}),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetCopyPermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }, true),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetCopyPermission, WorksheetEditPermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }, true),
};
}
-export function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const commandService = accessor.get(ICommandService);
const univerInstanceService = accessor.get(IUniverInstanceService);
const contextService = accessor.get(IContextService);
@@ -154,9 +162,13 @@ export function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
id: SetRangeBoldCommand.id,
type: MenuItemType.BUTTON,
icon: 'BoldIcon',
- title: 'Set bold',
+ title: 'sheets-ui.toolbar.bold',
tooltip: 'sheets-ui.toolbar.bold',
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] }, true),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }, true),
activated$: deriveStateFromActiveSheet$(univerInstanceService, false, ({ worksheet }) => new Observable<boolean>((subscriber) => {
const disposable = commandService.onCommandExecuted((c) => {
const id = c.id;
@@ -206,7 +218,7 @@ export function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
};
}
-export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const commandService = accessor.get(ICommandService);
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
@@ -216,7 +228,7 @@ export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
id: SetRangeItalicCommand.id,
type: MenuItemType.BUTTON,
icon: 'ItalicIcon',
- title: 'Set italic',
+ title: 'sheets-ui.toolbar.italic',
tooltip: 'sheets-ui.toolbar.italic',
disabled$: getCurrentRangeDisable$(
accessor,
@@ -268,7 +280,7 @@ export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
};
}
-export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const commandService = accessor.get(ICommandService);
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
@@ -278,7 +290,7 @@ export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
id: SetRangeUnderlineCommand.id,
type: MenuItemType.BUTTON,
icon: 'UnderlineIcon',
- title: 'Set underline',
+ title: 'sheets-ui.toolbar.underline',
tooltip: 'sheets-ui.toolbar.underline',
activated$: deriveStateFromActiveSheet$(univerInstanceService, false, ({ worksheet }) => new Observable<boolean>((subscriber) => {
const disposable = commandService.onCommandExecuted((c) => {
@@ -326,7 +338,7 @@ export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
};
}
-export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const commandService = accessor.get(ICommandService);
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
@@ -336,7 +348,7 @@ export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonIt
id: SetRangeStrickThroughCommand.id,
type: MenuItemType.BUTTON,
icon: 'StrikethroughIcon',
- title: 'Set strike through',
+ title: 'sheets-ui.toolbar.strikethrough',
tooltip: 'sheets-ui.toolbar.strikethrough',
disabled$: getCurrentRangeDisable$(accessor, {
workbookTypes: [WorkbookEditablePermission],
@@ -388,7 +400,7 @@ export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonIt
};
}
-export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey, string> {
const commandService = accessor.get(ICommandService);
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
@@ -467,7 +479,7 @@ export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSel
};
}
-export function ResetTextColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ResetTextColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: ResetRangeTextColorCommand.id,
type: MenuItemType.BUTTON,
@@ -482,7 +494,7 @@ export function ResetTextColorMenuItemFactory(accessor: IAccessor): IMenuButtonI
};
}
-export function TextColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string, string | undefined> {
+export function TextColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey, string, string | undefined> {
const commandService = accessor.get(ICommandService);
const themeService = accessor.get(ThemeService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
@@ -532,7 +544,7 @@ export function TextColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSele
};
}
-export function ResetBackgroundColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ResetBackgroundColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: ResetBackgroundColorCommand.id,
type: MenuItemType.BUTTON,
@@ -546,7 +558,7 @@ export function ResetBackgroundColorMenuItemFactory(accessor: IAccessor): IMenuB
};
}
-export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string, string | undefined> {
+export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey, string, string | undefined> {
const commandService = accessor.get(ICommandService);
const themeService = accessor.get(ThemeService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
@@ -617,7 +629,7 @@ export const HORIZONTAL_ALIGN_CHILDREN = [
},
];
-export function HorizontalAlignMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<HorizontalAlign> {
+export function HorizontalAlignMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey, HorizontalAlign> {
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
@@ -692,7 +704,7 @@ export const VERTICAL_ALIGN_CHILDREN = [
},
];
-export function VerticalAlignMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<VerticalAlign> {
+export function VerticalAlignMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey, VerticalAlign> {
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
@@ -767,7 +779,7 @@ export const TEXT_WRAP_CHILDREN = [
},
];
-export function WrapTextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<WrapStrategy> {
+export function WrapTextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey, WrapStrategy> {
const selectionManagerService = accessor.get(SheetsSelectionsService);
const univerInstanceService = accessor.get(IUniverInstanceService);
@@ -857,7 +869,7 @@ export const TEXT_ROTATE_CHILDREN = [
},
];
-export function TextRotateMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<number | string> {
+export function TextRotateMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey, number | string> {
const selectionManagerService = accessor.get(SheetsSelectionsService);
const univerInstanceService = accessor.get(IUniverInstanceService);
@@ -936,7 +948,7 @@ export function menuClipboardDisabledObservable(injector: IAccessor): Observable
});
}
-export function CopyMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function CopyMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: SheetCopyCommand.name,
commandId: SheetCopyCommand.id,
@@ -952,7 +964,7 @@ export function CopyMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
};
}
-export function CutMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function CutMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: SheetCutCommand.name,
commandId: CutCommand.id,
@@ -968,7 +980,7 @@ export function CutMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
};
}
-export function PasteMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function PasteMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: SheetPasteCommand.name,
commandId: SheetPasteCommand.id,
@@ -989,7 +1001,7 @@ export function PasteMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
// Right click menu - Copy Special
export const COPY_SPECIAL_MENU_ID = 'sheet.menu.copy-special';
-export function CopySpacialMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {
+export function CopySpacialMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: COPY_SPECIAL_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -1001,7 +1013,7 @@ export function CopySpacialMenuItemFactory(accessor: IAccessor): IMenuSelectorIt
// Right click menu - Paste Special
export const PASTE_SPECIAL_MENU_ID = 'sheet.menu.paste-special';
-export function PasteSpacialMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {
+export function PasteSpacialMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: PASTE_SPECIAL_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -1011,7 +1023,7 @@ export function PasteSpacialMenuItemFactory(accessor: IAccessor): IMenuSelectorI
};
}
-export function PasteValueMenuItemFactory(accessor: IAccessor): IMenuButtonItem<string> {
+export function PasteValueMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey, string> {
return {
id: SheetPasteValueCommand.id,
type: MenuItemType.BUTTON,
@@ -1028,7 +1040,7 @@ export function PasteValueMenuItemFactory(accessor: IAccessor): IMenuButtonItem<
};
}
-export function PasteFormatMenuItemFactory(accessor: IAccessor): IMenuButtonItem<string> {
+export function PasteFormatMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey, string> {
return {
id: SheetPasteFormatCommand.id,
type: MenuItemType.BUTTON,
@@ -1045,7 +1057,7 @@ export function PasteFormatMenuItemFactory(accessor: IAccessor): IMenuButtonItem
};
}
-export function PasteColWidthMenuItemFactory(accessor: IAccessor): IMenuButtonItem<string> {
+export function PasteColWidthMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey, string> {
return {
id: SheetPasteColWidthCommand.id,
type: MenuItemType.BUTTON,
@@ -1061,7 +1073,7 @@ export function PasteColWidthMenuItemFactory(accessor: IAccessor): IMenuButtonIt
};
}
-export function PasteBesidesBorderMenuItemFactory(accessor: IAccessor): IMenuButtonItem<string> {
+export function PasteBesidesBorderMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey, string> {
return {
id: SheetPasteBesidesBorderCommand.id,
type: MenuItemType.BUTTON,
@@ -1086,7 +1098,7 @@ export function PasteBesidesBorderMenuItemFactory(accessor: IAccessor): IMenuBut
//#endregion
-export function FitContentMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function FitContentMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: SetWorksheetRowIsAutoHeightCommand.id,
type: MenuItemType.BUTTON,
@@ -1101,7 +1113,7 @@ export function FitContentMenuItemFactory(accessor: IAccessor): IMenuButtonItem
};
}
-export function ColAutoWidthMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ColAutoWidthMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: SetWorksheetColAutoWidthCommand.id,
type: MenuItemType.BUTTON,
@@ -1116,7 +1128,7 @@ export function ColAutoWidthMenuItemFactory(accessor: IAccessor): IMenuButtonIte
};
}
-export function HideRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function HideRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: HideRowConfirmCommand.id,
type: MenuItemType.BUTTON,
@@ -1131,7 +1143,7 @@ export function HideRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
};
}
-export function HideColMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function HideColMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: HideColConfirmCommand.id,
type: MenuItemType.BUTTON,
@@ -1146,7 +1158,7 @@ export function HideColMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
};
}
-export function ShowRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ShowRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
@@ -1187,7 +1199,7 @@ export function ShowRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
};
}
-export function ShowColMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ShowColMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
const commandService = accessor.get(ICommandService);
@@ -1227,7 +1239,7 @@ export function ShowColMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
};
}
-export function SetRowHeightMenuItemFactory(accessor: IAccessor): IMenuButtonItem<number> {
+export function SetRowHeightMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey, number> {
const commandService = accessor.get(ICommandService);
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
@@ -1272,7 +1284,7 @@ export function SetRowHeightMenuItemFactory(accessor: IAccessor): IMenuButtonIte
};
}
-export function SetColWidthMenuItemFactory(accessor: IAccessor): IMenuButtonItem<number> {
+export function SetColWidthMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey, number> {
const commandService = accessor.get(ICommandService);
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SheetsSelectionsService);
diff --git a/packages/sheets-ui/src/menu/merge.menu.ts b/packages/sheets-ui/src/menu/merge.menu.ts
index 76d1a88dad..4fbeb9b603 100644
--- a/packages/sheets-ui/src/menu/merge.menu.ts
+++ b/packages/sheets-ui/src/menu/merge.menu.ts
@@ -16,6 +16,7 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { FOCUSING_COMMON_DRAWINGS, IContextService, UniverInstanceType } from '@univerjs/core';
import {
AddWorksheetMergeAllCommand,
@@ -34,8 +35,12 @@ import { combineLatest, combineLatestWith, map, startWith } from 'rxjs';
import { getSheetSelectionsDisabled$ } from '../controllers/utils/selections-tools';
import { getCurrentRangeDisable$, getObservableWithExclusiveRange$ } from './menu-util';
-export function CellMergeMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
- const editDisabled$ = getObservableWithExclusiveRange$(accessor, getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] }));
+export function CellMergeMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
+ const editDisabled$ = getObservableWithExclusiveRange$(accessor, getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetSetCellStylePermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }));
const selectionsHasCross$ = getSheetSelectionsDisabled$(accessor);
return {
@@ -55,7 +60,7 @@ export function CellMergeMenuItemFactory(accessor: IAccessor): IMenuSelectorItem
};
}
-export function CellMergeAllMenuItemFactory(accessor: IAccessor): IMenuButtonItem<string> {
+export function CellMergeAllMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: AddWorksheetMergeAllCommand.id,
type: MenuItemType.BUTTON,
@@ -65,7 +70,7 @@ export function CellMergeAllMenuItemFactory(accessor: IAccessor): IMenuButtonIte
};
}
-export function CellMergeVerticalMenuItemFactory(accessor: IAccessor): IMenuButtonItem<string> {
+export function CellMergeVerticalMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: AddWorksheetMergeVerticalCommand.id,
type: MenuItemType.BUTTON,
@@ -75,7 +80,7 @@ export function CellMergeVerticalMenuItemFactory(accessor: IAccessor): IMenuButt
};
}
-export function CellMergeHorizontalMenuItemFactory(accessor: IAccessor): IMenuButtonItem<string> {
+export function CellMergeHorizontalMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: AddWorksheetMergeHorizontalCommand.id,
type: MenuItemType.BUTTON,
@@ -85,7 +90,7 @@ export function CellMergeHorizontalMenuItemFactory(accessor: IAccessor): IMenuBu
};
}
-export function CellMergeCancelMenuItemFactory(accessor: IAccessor): IMenuButtonItem<string> {
+export function CellMergeCancelMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: RemoveWorksheetMergeCommand.id,
type: MenuItemType.BUTTON,
diff --git a/packages/sheets-ui/src/menu/permission.menu.ts b/packages/sheets-ui/src/menu/permission.menu.ts
index 199171224e..edb796b84f 100644
--- a/packages/sheets-ui/src/menu/permission.menu.ts
+++ b/packages/sheets-ui/src/menu/permission.menu.ts
@@ -16,6 +16,7 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuButtonItem, IMenuItem, IMenuSelectorItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { UniverInstanceType } from '@univerjs/core';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import {
@@ -45,7 +46,7 @@ import {
export const SHEET_PERMISSION_CONTEXT_MENU_ID = 'sheet.contextMenu.permission';
-export function sheetPermissionToolbarMenuFactory(accessor: IAccessor): IMenuItem {
+export function sheetPermissionToolbarMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: AddRangeProtectionFromToolbarCommand.id,
type: MenuItemType.BUTTON,
@@ -56,7 +57,7 @@ export function sheetPermissionToolbarMenuFactory(accessor: IAccessor): IMenuIte
};
}
-export function sheetPermissionContextMenuFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function sheetPermissionContextMenuFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: SHEET_PERMISSION_CONTEXT_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -66,7 +67,7 @@ export function sheetPermissionContextMenuFactory(accessor: IAccessor): IMenuSel
};
}
-export function sheetPermissionAddProtectContextMenuFactory(accessor: IAccessor): IMenuButtonItem {
+export function sheetPermissionAddProtectContextMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: AddRangeProtectionFromContextMenuCommand.id,
type: MenuItemType.BUTTON,
@@ -76,7 +77,7 @@ export function sheetPermissionAddProtectContextMenuFactory(accessor: IAccessor)
};
}
-export function sheetPermissionEditProtectContextMenuFactory(accessor: IAccessor): IMenuButtonItem {
+export function sheetPermissionEditProtectContextMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: SetRangeProtectionFromContextMenuCommand.id,
type: MenuItemType.BUTTON,
@@ -86,7 +87,7 @@ export function sheetPermissionEditProtectContextMenuFactory(accessor: IAccessor
};
}
-export function sheetPermissionRemoveProtectContextMenuFactory(accessor: IAccessor): IMenuButtonItem {
+export function sheetPermissionRemoveProtectContextMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DeleteRangeProtectionFromContextMenuCommand.id,
type: MenuItemType.BUTTON,
@@ -96,7 +97,7 @@ export function sheetPermissionRemoveProtectContextMenuFactory(accessor: IAccess
};
}
-export function sheetPermissionViewAllProtectRuleContextMenuFactory(accessor: IAccessor): IMenuButtonItem {
+export function sheetPermissionViewAllProtectRuleContextMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: ViewSheetPermissionFromContextMenuCommand.id,
type: MenuItemType.BUTTON,
@@ -106,7 +107,7 @@ export function sheetPermissionViewAllProtectRuleContextMenuFactory(accessor: IA
};
}
-export function sheetPermissionProtectSheetInSheetBarMenuFactory(accessor: IAccessor): IMenuButtonItem {
+export function sheetPermissionProtectSheetInSheetBarMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: AddRangeProtectionFromSheetBarCommand.id,
type: MenuItemType.BUTTON,
@@ -116,7 +117,7 @@ export function sheetPermissionProtectSheetInSheetBarMenuFactory(accessor: IAcce
};
}
-export function sheetPermissionRemoveProtectionSheetBarMenuFactory(accessor: IAccessor): IMenuButtonItem {
+export function sheetPermissionRemoveProtectionSheetBarMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: DeleteWorksheetProtectionFormSheetBarCommand.id,
type: MenuItemType.BUTTON,
@@ -126,7 +127,7 @@ export function sheetPermissionRemoveProtectionSheetBarMenuFactory(accessor: IAc
};
}
-export function sheetPermissionChangeSheetPermissionSheetBarMenuFactory(accessor: IAccessor): IMenuButtonItem {
+export function sheetPermissionChangeSheetPermissionSheetBarMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: ChangeSheetProtectionFromSheetBarCommand.id,
type: MenuItemType.BUTTON,
@@ -136,7 +137,7 @@ export function sheetPermissionChangeSheetPermissionSheetBarMenuFactory(accessor
};
}
-export function sheetPermissionViewAllProtectRuleSheetBarMenuFactory(accessor: IAccessor): IMenuButtonItem {
+export function sheetPermissionViewAllProtectRuleSheetBarMenuFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: ViewSheetPermissionFromSheetBarCommand.id,
type: MenuItemType.BUTTON,
diff --git a/packages/sheets-ui/src/menu/sheet.menu.ts b/packages/sheets-ui/src/menu/sheet.menu.ts
index 6aea8a7075..5587cde003 100644
--- a/packages/sheets-ui/src/menu/sheet.menu.ts
+++ b/packages/sheets-ui/src/menu/sheet.menu.ts
@@ -17,6 +17,7 @@
import type { IAccessor, Workbook } from '@univerjs/core';
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
import type { Subscriber } from 'rxjs';
+import type { LocaleKey } from '../locale/types';
import { BooleanNumber, ICommandService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import {
CopySheetCommand,
@@ -34,13 +35,12 @@ import {
} from '@univerjs/sheets';
import { COLOR_PICKER_COMPONENT, getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { combineLatest, combineLatestWith, map, Observable } from 'rxjs';
-
import { RemoveSheetConfirmCommand } from '../commands/commands/remove-sheet-confirm.command';
import { ShowMenuListCommand } from '../commands/commands/unhide.command';
import { RenameSheetOperation } from '../commands/operations/rename-sheet.operation';
import { getWorkbookPermissionDisable$ } from './menu-util';
-export function DeleteSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function DeleteSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const univerInstanceService = accessor.get(IUniverInstanceService);
const commandService = accessor.get(ICommandService);
const defaultDisable$ = new Observable<boolean>((subscriber) => {
@@ -60,7 +60,10 @@ export function DeleteSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem
return disposable.dispose;
});
- const permissionDisable$ = getWorkbookPermissionDisable$(accessor, [WorkbookEditablePermission, WorkbookDeleteSheetPermission]);
+ const permissionDisable$ = getWorkbookPermissionDisable$(accessor, [
+ WorkbookEditablePermission,
+ WorkbookDeleteSheetPermission,
+ ]);
return {
id: RemoveSheetConfirmCommand.id,
@@ -75,7 +78,7 @@ export function DeleteSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem
};
}
-export function CopySheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function CopySheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: CopySheetCommand.id,
type: MenuItemType.BUTTON,
@@ -85,7 +88,7 @@ export function CopySheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
};
}
-export function RenameSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function RenameSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: RenameSheetOperation.id,
type: MenuItemType.BUTTON,
@@ -95,7 +98,7 @@ export function RenameSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem
};
}
-export function ChangeColorSheetMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+export function ChangeColorSheetMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
id: SetTabColorCommand.id,
title: 'sheets-ui.sheetConfig.changeColor',
@@ -113,7 +116,7 @@ export function ChangeColorSheetMenuItemFactory(accessor: IAccessor): IMenuSelec
};
}
-export function HideSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function HideSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const univerInstanceService = accessor.get(IUniverInstanceService);
const commandService = accessor.get(ICommandService);
@@ -138,14 +141,17 @@ export function HideSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return disposable.dispose;
}).pipe(
- combineLatestWith(getWorkbookPermissionDisable$(accessor, [WorkbookEditablePermission, WorkbookHideSheetPermission])),
+ combineLatestWith(getWorkbookPermissionDisable$(accessor, [
+ WorkbookEditablePermission,
+ WorkbookHideSheetPermission,
+ ])),
map(([defaultDisabled, permissionDisabled]) => defaultDisabled || permissionDisabled)
),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
};
}
-export function UnHideSheetMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<any> {
+export function UnHideSheetMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
const univerInstanceService = accessor.get(IUniverInstanceService);
const commandService = accessor.get(ICommandService);
@@ -172,7 +178,10 @@ export function UnHideSheetMenuItemFactory(accessor: IAccessor): IMenuSelectorIt
type: MenuItemType.SELECTOR,
title: 'sheets-ui.sheetConfig.unhide',
disabled$: defaultDisable$.pipe(
- combineLatestWith(getWorkbookPermissionDisable$(accessor, [WorkbookEditablePermission, WorkbookHideSheetPermission])),
+ combineLatestWith(getWorkbookPermissionDisable$(accessor, [
+ WorkbookEditablePermission,
+ WorkbookHideSheetPermission,
+ ])),
map(([defaultDisabled, permissionDisabled]) => defaultDisabled || permissionDisabled)
),
selections: new Observable((subscriber) => {
@@ -193,7 +202,7 @@ export function UnHideSheetMenuItemFactory(accessor: IAccessor): IMenuSelectorIt
};
}
-export function ShowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function ShowMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
const univerInstanceService = accessor.get(IUniverInstanceService);
const commandService = accessor.get(ICommandService);
@@ -224,7 +233,10 @@ export function ShowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return disposable.dispose;
}).pipe(
- combineLatestWith(getWorkbookPermissionDisable$(accessor, [WorkbookEditablePermission, WorkbookHideSheetPermission])),
+ combineLatestWith(getWorkbookPermissionDisable$(accessor, [
+ WorkbookEditablePermission,
+ WorkbookHideSheetPermission,
+ ])),
map(([defaultDisabled, permissionDisabled]) => defaultDisabled || permissionDisabled)
),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
diff --git a/packages/sheets-ui/src/menu/text-to-number.menu.ts b/packages/sheets-ui/src/menu/text-to-number.menu.ts
index b318668c80..aa989ab5a2 100644
--- a/packages/sheets-ui/src/menu/text-to-number.menu.ts
+++ b/packages/sheets-ui/src/menu/text-to-number.menu.ts
@@ -17,6 +17,7 @@
import type { IAccessor, Workbook } from '@univerjs/core';
import type { ISelectionWithStyle } from '@univerjs/sheets';
import type { IMenuButtonItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { CellValueType, isRealNum, isTextFormat, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import {
RangeProtectionPermissionEditPoint,
@@ -74,7 +75,7 @@ const getMenuHiddenByCurrentSelectionChangedObservable$ = (accessor: IAccessor):
};
export const TEXT_TO_NUMBER_TOOLBAR_MENU_ID = 'sheet.toolbar.text-to-number';
-export function Text2NumberToolbarMenuItemFactory(accessor: IAccessor): IMenuButtonItem<string> {
+export function Text2NumberToolbarMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: TEXT_TO_NUMBER_TOOLBAR_MENU_ID,
commandId: TextToNumberCommand.id,
@@ -90,7 +91,7 @@ export function Text2NumberToolbarMenuItemFactory(accessor: IAccessor): IMenuBut
}
export const TEXT_TO_NUMBER_CONTEXT_MENU_ID = 'sheet.contextMenu.text-to-number';
-export function Text2NumberContextMenuItemFactory(accessor: IAccessor): IMenuButtonItem<string> {
+export function Text2NumberContextMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: TEXT_TO_NUMBER_CONTEXT_MENU_ID,
commandId: TextToNumberCommand.id,
@@ -102,7 +103,10 @@ export function Text2NumberContextMenuItemFactory(accessor: IAccessor): IMenuBut
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellValuePermission],
rangeTypes: [RangeProtectionPermissionEditPoint],
})),
- hidden$: combineLatest([getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET), getMenuHiddenByCurrentSelectionChangedObservable$(accessor)]).pipe(
+ hidden$: combineLatest([
+ getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ getMenuHiddenByCurrentSelectionChangedObservable$(accessor),
+ ]).pipe(
map(([menuHidden, selectionHidden]) => menuHidden || selectionHidden)
),
};
diff --git a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
index f9f3ef286c..a41c484e65 100644
--- a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
+++ b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts
@@ -31,6 +31,7 @@ import type {
ISetWorksheetRowAutoHeightMutationParams,
} from '@univerjs/sheets';
import type { Observable } from 'rxjs';
+import type { LocaleKey } from '../../locale/types';
import type {
ICellDataWithSpanInfo,
IClipboardPropertyItem,
@@ -337,8 +338,8 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
if (this._platformService.isWindows && htmlIsFromExcel(html)) {
this._notificationService.show({
type: 'warning',
- title: this._localeService.t('sheets-ui.clipboard.shortCutNotify.title'),
- content: this._localeService.t('sheets-ui.clipboard.shortCutNotify.useShortCutInstead'),
+ title: this._localeService.t<LocaleKey>('sheets-ui.clipboard.shortCutNotify.title'),
+ content: this._localeService.t<LocaleKey>('sheets-ui.clipboard.shortCutNotify.useShortCutInstead'),
});
// Pasting should not be allowed here.
// After the pop-up window prompts, can paste the contents of the clipboard as much as possible.
@@ -666,7 +667,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
return rangeIntersectWithDiscreteRange(m, pasteTarget.pastedRange) && !discreteRangeContainsRange(pasteTarget.pastedRange, m);
});
if (pastedRangeLapWithMergedCell) {
- this._errorService.emit(this._localeService.t('sheets-ui.clipboard.paste.overlappingMergedCells'));
+ this._errorService.emit(this._localeService.t<LocaleKey>('sheets-ui.clipboard.paste.overlappingMergedCells'));
return false;
}
}
@@ -742,7 +743,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
return rangeIntersectWithDiscreteRange(m, pasteTarget.pastedRange) && !discreteRangeContainsRange(pasteTarget.pastedRange, m);
});
if (pastedRangeLapWithMergedCell) {
- this._errorService.emit(this._localeService.t('sheets-ui.clipboard.paste.overlappingMergedCells'));
+ this._errorService.emit(this._localeService.t<LocaleKey>('sheets-ui.clipboard.paste.overlappingMergedCells'));
return false;
}
}
diff --git a/packages/sheets-ui/src/views/defined-name/DefinedNameContainer.tsx b/packages/sheets-ui/src/views/defined-name/DefinedNameContainer.tsx
index eff00f727f..62bbabb227 100644
--- a/packages/sheets-ui/src/views/defined-name/DefinedNameContainer.tsx
+++ b/packages/sheets-ui/src/views/defined-name/DefinedNameContainer.tsx
@@ -16,6 +16,7 @@
import type { Nullable, Workbook } from '@univerjs/core';
import type { IDefinedNamesServiceParam, ISetDefinedNameMutationParam } from '@univerjs/engine-formula';
+import type { LocaleKey } from '../../locale/types';
import { generateRandomId, ICommandService, IPermissionService, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
import { Button, clsx, Confirm, scrollbarClassName, Tooltip } from '@univerjs/design';
import { IDefinedNamesService, serializeRangeWithSheet } from '@univerjs/engine-formula';
@@ -173,14 +174,14 @@ export const DefinedNameContainer = () => {
const getInsertDefinedName = () => {
const count = definedNames.length + 1;
- const name = localeService.t('sheets-ui.definedName.defaultName') + count;
+ const name = localeService.t<LocaleKey>('sheets-ui.definedName.defaultName') + count;
if (definedNamesService.getValueByName(unitId, name) == null) {
return name;
}
let i = count + 1;
while (true) {
- const newName = localeService.t('sheets-ui.definedName.defaultName') + i;
+ const newName = localeService.t<LocaleKey>('sheets-ui.definedName.defaultName') + i;
if (definedNamesService.getValueByName(unitId, newName) == null) {
return newName;
}
@@ -247,7 +248,7 @@ export const DefinedNameContainer = () => {
onClick={openInsertCloseKeyEditor}
>
<IncreaseIcon />
- <span className="univer-ml-1">{localeService.t('sheets-ui.definedName.addButton')}</span>
+ <span className="univer-ml-1">{localeService.t<LocaleKey>('sheets-ui.definedName.addButton')}</span>
</Button>
{editState && (
<DefinedNameInput
@@ -322,7 +323,10 @@ export const DefinedNameContainer = () => {
dark:hover:!univer-bg-gray-600
`}
>
- <Tooltip title={localeService.t('sheets-ui.definedName.updateButton')} placement="top">
+ <Tooltip
+ title={localeService.t<LocaleKey>('sheets-ui.definedName.updateButton')}
+ placement="top"
+ >
<a
className={`
univer-rounded univer-p-1
@@ -336,7 +340,10 @@ export const DefinedNameContainer = () => {
<PenIcon />
</a>
</Tooltip>
- <Tooltip title={localeService.t('sheets-ui.definedName.deleteButton')} placement="top">
+ <Tooltip
+ title={localeService.t<LocaleKey>('sheets-ui.definedName.deleteButton')}
+ placement="top"
+ >
<a
className={`
univer-rounded univer-p-1 univer-text-red-600
@@ -359,7 +366,7 @@ export const DefinedNameContainer = () => {
onClose={handleDeleteClose}
onConfirm={() => { handleDeleteConfirm(definedName.id); }}
>
- {localeService.t('sheets-ui.definedName.deleteConfirmText')}
+ {localeService.t<LocaleKey>('sheets-ui.definedName.deleteConfirmText')}
</Confirm>
{definedName.id === editorKey && (
diff --git a/packages/sheets-ui/src/views/defined-name/DefinedNameOverlay.tsx b/packages/sheets-ui/src/views/defined-name/DefinedNameOverlay.tsx
index 4e299788a7..0b21583322 100644
--- a/packages/sheets-ui/src/views/defined-name/DefinedNameOverlay.tsx
+++ b/packages/sheets-ui/src/views/defined-name/DefinedNameOverlay.tsx
@@ -16,6 +16,7 @@
import type { Workbook } from '@univerjs/core';
import type { IDefinedNamesServiceParam } from '@univerjs/engine-formula';
+import type { LocaleKey } from '../../locale/types';
import { ICommandService, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
import { borderBottomClassName, clsx, scrollbarClassName } from '@univerjs/design';
import { IDefinedNamesService } from '@univerjs/engine-formula';
@@ -169,10 +170,10 @@ export function DefinedNameOverlay({ search, isInputEvent }: { search: string; i
dark:!univer-text-gray-200
`}
>
- {localeService.t('sheets-ui.definedName.managerTitle')}
+ {localeService.t<LocaleKey>('sheets-ui.definedName.managerTitle')}
</div>
<div className="univer-text-xs univer-text-gray-400">
- {localeService.t('sheets-ui.definedName.managerDescription')}
+ {localeService.t<LocaleKey>('sheets-ui.definedName.managerDescription')}
</div>
</div>
</div>
diff --git a/packages/sheets-ui/src/views/dropdown/DateDropdown.tsx b/packages/sheets-ui/src/views/dropdown/DateDropdown.tsx
index cc107b5c86..062baea797 100644
--- a/packages/sheets-ui/src/views/dropdown/DateDropdown.tsx
+++ b/packages/sheets-ui/src/views/dropdown/DateDropdown.tsx
@@ -16,6 +16,7 @@
import type { DateKit } from '@univerjs/core';
import type { IPopup } from '@univerjs/ui';
+import type { LocaleKey } from '../../locale/types';
import type { IBaseDropdownProps } from './type';
import { dateKit, LocaleService } from '@univerjs/core';
import { borderTopClassName, Button, Calendar, clsx, TimeInput } from '@univerjs/design';
@@ -76,7 +77,7 @@ export function DateDropdown(props: { popup: IPopup<IDateDropdownProps & IBaseDr
className={clsx('univer-mt-2 univer-flex univer-justify-end univer-pt-2', borderTopClassName)}
>
<Button size="small" variant="primary" onClick={handleSave} disabled={!date || !date.isValid()}>
- {localeService.t('sheets-ui.data-validation.alert.ok')}
+ {localeService.t<LocaleKey>('sheets-ui.data-validation.alert.ok')}
</Button>
</footer>
</div>
diff --git a/packages/sheets-ui/src/views/dropdown/ListDropDown.tsx b/packages/sheets-ui/src/views/dropdown/ListDropDown.tsx
index 20cd91f154..870a30f6c3 100644
--- a/packages/sheets-ui/src/views/dropdown/ListDropDown.tsx
+++ b/packages/sheets-ui/src/views/dropdown/ListDropDown.tsx
@@ -17,11 +17,9 @@
import type { ISheetLocation } from '@univerjs/sheets';
import type { IPopup } from '@univerjs/ui';
import type { CSSProperties } from 'react';
+import type { LocaleKey } from '../../locale/types';
import type { IBaseDropdownProps } from './type';
-import {
- ColorKit,
- LocaleService,
-} from '@univerjs/core';
+import { ColorKit, LocaleService } from '@univerjs/core';
import { borderClassName, borderTopClassName, clsx, scrollbarClassName } from '@univerjs/design';
import { CheckMarkIcon } from '@univerjs/icons';
import {
@@ -49,7 +47,18 @@ interface ISelectListProps {
}
function SelectList(props: ISelectListProps) {
- const { value, onChange, multiple, options, title, onEdit, style, location, showEdit: showEditOnDropdown, showSearch: showSearchOnDropdown } = props;
+ const {
+ value,
+ onChange,
+ multiple,
+ options,
+ title,
+ onEdit,
+ style,
+ location,
+ showEdit: showEditOnDropdown,
+ showSearch: showSearchOnDropdown,
+ } = props;
const localeService = useDependency(LocaleService);
const { row, col, unitId, subUnitId } = location;
@@ -104,12 +113,11 @@ function SelectList(props: ISelectListProps) {
<div className="univer-box-border univer-flex univer-w-full univer-px-2">
<input
ref={searchRef}
- className={`
- univer-w-full univer-rounded-md univer-border univer-border-[rgba(13,13,13,0.12)] univer-px-2
- univer-py-1 univer-text-sm
+ className={clsx(`
+ univer-w-full univer-rounded-md univer-px-2 univer-py-1 univer-text-sm
focus:univer-border-primary-500 focus:univer-outline-none
dark:!univer-bg-black dark:!univer-text-white
- `}
+ `, borderClassName)}
type="text"
value={lowerFilter}
autoFocus
@@ -173,7 +181,9 @@ function SelectList(props: ISelectListProps) {
? (
<>
<span>{item.label.substring(0, index)}</span>
- <span className="univer-font-semibold">{item.label.substring(index, index + lowerFilter.length)}</span>
+ <span className="univer-font-semibold">
+ {item.label.substring(index, index + lowerFilter.length)}
+ </span>
<span>{item.label.substring(index + lowerFilter.length)}</span>
</>
)
@@ -201,7 +211,7 @@ function SelectList(props: ISelectListProps) {
`}
onClick={onEdit}
>
- {localeService.t('sheets-ui.data-validation.list.edit')}
+ {localeService.t<LocaleKey>('sheets-ui.data-validation.list.edit')}
</a>
</div>
)}
@@ -233,7 +243,7 @@ export function ListDropDown(props: { popup: IPopup<IListDropdownProps & IBaseDr
return (
<SelectList
style={{ minWidth: cellWidth, maxWidth: Math.max(cellWidth, 200) }}
- title={multiple ? localeService.t('sheets-ui.data-validation.listMultiple.dropdown') : localeService.t('sheets-ui.data-validation.list.dropdown')}
+ title={multiple ? localeService.t<LocaleKey>('sheets-ui.data-validation.listMultiple.dropdown') : localeService.t<LocaleKey>('sheets-ui.data-validation.list.dropdown')}
value={getListDropdownValue(localValue, multiple)}
multiple={multiple}
onChange={async (newValue) => {
diff --git a/packages/sheets-ui/src/views/menu-item-frozen/MenuItemFrozen.tsx b/packages/sheets-ui/src/views/menu-item-frozen/MenuItemFrozen.tsx
index 76706bb6da..4e0d731404 100644
--- a/packages/sheets-ui/src/views/menu-item-frozen/MenuItemFrozen.tsx
+++ b/packages/sheets-ui/src/views/menu-item-frozen/MenuItemFrozen.tsx
@@ -15,6 +15,7 @@
*/
import type { ISelectionWithStyle } from '@univerjs/sheets';
+import type { LocaleKey } from '../../locale/types';
import type { IMenuItemFrozenProps } from './interface';
import { LocaleService, Tools } from '@univerjs/core';
import { SheetsSelectionsService } from '@univerjs/sheets';
@@ -61,9 +62,9 @@ export const MenuItemFrozen = (props: IMenuItemFrozenProps) => {
return (
<>
- {type === 'row' && localeService.t('sheets-ui.rightClick.freezeRow', value.row)}
- {type === 'col' && localeService.t('sheets-ui.rightClick.freezeCol', value.col)}
- {type === 'all' && localeService.t('sheets-ui.rightClick.freezeCell', value.row, value.col)}
+ {type === 'row' && localeService.t<LocaleKey>('sheets-ui.rightClick.freezeRow', value.row)}
+ {type === 'col' && localeService.t<LocaleKey>('sheets-ui.rightClick.freezeCol', value.col)}
+ {type === 'all' && localeService.t<LocaleKey>('sheets-ui.rightClick.freezeCell', value.row, value.col)}
</>
);
};
diff --git a/packages/sheets-ui/src/views/permission/AlertDialog.tsx b/packages/sheets-ui/src/views/permission/AlertDialog.tsx
index 5fcf86f344..6bd02fa55e 100644
--- a/packages/sheets-ui/src/views/permission/AlertDialog.tsx
+++ b/packages/sheets-ui/src/views/permission/AlertDialog.tsx
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { LocaleKey } from '../../locale/types';
import { LocaleService } from '@univerjs/core';
import { useDependency } from '@univerjs/ui';
@@ -23,7 +24,7 @@ export const AlertDialog = ({ errorMsg }: { errorMsg: string }) => {
return (
<div>
<p className="univer-m-0">
- {errorMsg || localeService.t('sheets-ui.permission.dialog.alertContent')}
+ {errorMsg || localeService.t<LocaleKey>('sheets-ui.permission.dialog.alertContent')}
</p>
</div>
);
diff --git a/packages/sheets-ui/src/views/permission/SheetPermissionPanelList.tsx b/packages/sheets-ui/src/views/permission/SheetPermissionPanelList.tsx
index 85a42f566d..8b62f2bf5d 100644
--- a/packages/sheets-ui/src/views/permission/SheetPermissionPanelList.tsx
+++ b/packages/sheets-ui/src/views/permission/SheetPermissionPanelList.tsx
@@ -17,13 +17,31 @@
import type { IRange, Workbook } from '@univerjs/core';
import type { IPermissionPoint } from '@univerjs/protocol';
import type { IRangeProtectionRule, IWorksheetProtectionRule } from '@univerjs/sheets';
+import type { LocaleKey } from '../../locale/types';
import type { IPermissionPanelRule } from '../../services/permission/sheet-permission-panel.model';
-import { IAuthzIoService, ICommandService, IPermissionService, IUniverInstanceService, LocaleService, Tools, UniverInstanceType, UserManagerService } from '@univerjs/core';
+import {
+ IAuthzIoService,
+ ICommandService,
+ IPermissionService,
+ IUniverInstanceService,
+ LocaleService,
+ Tools,
+ UniverInstanceType,
+ UserManagerService,
+} from '@univerjs/core';
import { Avatar, borderClassName, Button, clsx, Tooltip } from '@univerjs/design';
import { serializeRange } from '@univerjs/engine-formula';
import { DeleteIcon, WriteIcon } from '@univerjs/icons';
import { UnitAction, UnitObject } from '@univerjs/protocol';
-import { baseProtectionActions, DeleteRangeProtectionCommand, DeleteWorksheetProtectionCommand, RangeProtectionRuleModel, SetWorksheetActiveOperation, WorkbookCreateProtectPermission, WorksheetProtectionRuleModel } from '@univerjs/sheets';
+import {
+ baseProtectionActions,
+ DeleteRangeProtectionCommand,
+ DeleteWorksheetProtectionCommand,
+ RangeProtectionRuleModel,
+ SetWorksheetActiveOperation,
+ WorkbookCreateProtectPermission,
+ WorksheetProtectionRuleModel,
+} from '@univerjs/sheets';
import { ISidebarService, useDependency, useObservable } from '@univerjs/ui';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { distinctUntilChanged, merge } from 'rxjs';
@@ -215,12 +233,12 @@ export function SheetPermissionPanelList() {
<div className="univer-mr-5 univer-flex univer-cursor-pointer univer-flex-col univer-items-center" onClick={() => handleChangeHeaderType(true)}>
<div className={clsx('univer-h-6 univer-text-base univer-font-medium univer-leading-6', { 'univer-text-blue-500': isCurrentSheet })}>
{' '}
- {localeService.t('sheets-ui.permission.panel.currentSheet')}
+ {localeService.t<LocaleKey>('sheets-ui.permission.panel.currentSheet')}
</div>
<div className={clsx('univer-mt-1 univer-h-0.5 univer-w-6', { 'univer-bg-blue-500': isCurrentSheet })} />
</div>
<div className="univer-mr-5 univer-flex univer-cursor-pointer univer-flex-col univer-items-center" onClick={() => handleChangeHeaderType(false)}>
- <div className={clsx('univer-h-6 univer-text-base univer-font-medium univer-leading-6', { 'univer-text-blue-500': !isCurrentSheet })}>{localeService.t('sheets-ui.permission.panel.allSheet')}</div>
+ <div className={clsx('univer-h-6 univer-text-base univer-font-medium univer-leading-6', { 'univer-text-blue-500': !isCurrentSheet })}>{localeService.t<LocaleKey>('sheets-ui.permission.panel.allSheet')}</div>
<div className={clsx('univer-mt-1 univer-h-0.5 univer-w-6', { 'univer-bg-blue-500': !isCurrentSheet })} />
</div>
</div>
@@ -305,7 +323,7 @@ export function SheetPermissionPanelList() {
{(hasManagerPermission || hasDeletePermission) && (
<div className="univer-flex univer-items-center">
{hasManagerPermission && (
- <Tooltip title={localeService.t('sheets-ui.permission.panel.edit')}>
+ <Tooltip title={localeService.t<LocaleKey>('sheets-ui.permission.panel.edit')}>
<div
className={`
univer-box-border univer-h-6 univer-rounded-sm univer-p-1
@@ -318,7 +336,7 @@ export function SheetPermissionPanelList() {
</Tooltip>
)}
{hasDeletePermission && (
- <Tooltip title={localeService.t('sheets-ui.permission.panel.delete')}>
+ <Tooltip title={localeService.t<LocaleKey>('sheets-ui.permission.panel.delete')}>
<div
className={`
univer-box-border univer-h-6 univer-rounded-sm univer-p-1
@@ -348,7 +366,7 @@ export function SheetPermissionPanelList() {
dark:!univer-text-white
`}
>
- {localeService.t('sheets-ui.permission.panel.created')}
+ {localeService.t<LocaleKey>('sheets-ui.permission.panel.created')}
</span>
<span
className={`
@@ -356,7 +374,7 @@ export function SheetPermissionPanelList() {
dark:!univer-text-white
`}
>
- {editPermission ? `${localeService.t('sheets-ui.permission.panel.iCanEdit')}` : `${localeService.t('sheets-ui.permission.panel.iCanNotEdit')}`}
+ {editPermission ? `${localeService.t<LocaleKey>('sheets-ui.permission.panel.iCanEdit')}` : `${localeService.t<LocaleKey>('sheets-ui.permission.panel.iCanNotEdit')}`}
</span>
</div>
@@ -367,7 +385,7 @@ export function SheetPermissionPanelList() {
dark:!univer-text-white
`}
>
- {localeService.t('sheets-ui.permission.panel.viewPermission')}
+ {localeService.t<LocaleKey>('sheets-ui.permission.panel.viewPermission')}
</span>
<span
className={`
@@ -375,7 +393,7 @@ export function SheetPermissionPanelList() {
dark:!univer-text-white
`}
>
- {viewPermission ? `${localeService.t('sheets-ui.permission.panel.iCanView')}` : `${localeService.t('sheets-ui.permission.panel.iCanNotView')}`}
+ {viewPermission ? `${localeService.t<LocaleKey>('sheets-ui.permission.panel.iCanView')}` : `${localeService.t<LocaleKey>('sheets-ui.permission.panel.iCanNotView')}`}
</span>
</div>
{rule.description && (
@@ -401,7 +419,7 @@ export function SheetPermissionPanelList() {
className="univer-flex univer-flex-1 univer-flex-col univer-items-center univer-justify-center"
>
<img width={240} height={120} src={panelListEmptyBase64} alt="" draggable={false} />
- <p className="univer-w-60 univer-break-words univer-text-sm univer-text-gray-400">{localeService.t('sheets-ui.permission.dialog.listEmpty')}</p>
+ <p className="univer-w-60 univer-break-words univer-text-sm univer-text-gray-400">{localeService.t<LocaleKey>('sheets-ui.permission.dialog.listEmpty')}</p>
</div>
)}
@@ -412,7 +430,7 @@ export function SheetPermissionPanelList() {
variant="primary"
onClick={() => {
const sidebarProps = {
- header: { title: `${localeService.t('sheets-ui.permission.panel.title')}` },
+ header: { title: `${localeService.t<LocaleKey>('sheets-ui.permission.panel.title')}` },
children: {
label: UNIVER_SHEET_PERMISSION_PANEL,
showDetail: true,
@@ -423,7 +441,7 @@ export function SheetPermissionPanelList() {
}}
>
<div>+ </div>
- {localeService.t('sheets-ui.permission.button.addNewPermission')}
+ {localeService.t<LocaleKey>('sheets-ui.permission.button.addNewPermission')}
</Button>
</div>
)}
diff --git a/packages/sheets-ui/src/views/permission/SheetPermissionUserDialog.tsx b/packages/sheets-ui/src/views/permission/SheetPermissionUserDialog.tsx
index 81834a964d..8d74e50000 100644
--- a/packages/sheets-ui/src/views/permission/SheetPermissionUserDialog.tsx
+++ b/packages/sheets-ui/src/views/permission/SheetPermissionUserDialog.tsx
@@ -15,6 +15,7 @@
*/
import type { ICollaborator } from '@univerjs/protocol';
+import type { LocaleKey } from '../../locale/types';
import { IAuthzIoService, LocaleService } from '@univerjs/core';
import { Avatar, Button, clsx, Input, scrollbarClassName } from '@univerjs/design';
import { CheckMarkIcon } from '@univerjs/icons';
@@ -56,7 +57,7 @@ export const SheetPermissionUserDialog = () => {
<div>
<Input
className="univer-w-full"
- placeholder={localeService.t('sheets-ui.permission.dialog.search')}
+ placeholder={localeService.t<LocaleKey>('sheets-ui.permission.dialog.search')}
value={inputValue}
onChange={(v) => setInputValue(v)}
/>
@@ -75,7 +76,7 @@ export const SheetPermissionUserDialog = () => {
>
<Avatar src={item.subject?.avatar} size={24} />
<div className="univer-mx-1.5 univer-flex-1">{item.subject?.name}</div>
- <div className="univer-text-xs univer-text-rose-600">{localeService.t('sheets-ui.permission.dialog.ownerInherit')}</div>
+ <div className="univer-text-xs univer-text-rose-600">{localeService.t<LocaleKey>('sheets-ui.permission.dialog.ownerInherit')}</div>
</div>
);
}
@@ -92,7 +93,7 @@ export const SheetPermissionUserDialog = () => {
<Avatar src={item.subject?.avatar} size={24} />
<div className="univer-mx-1.5 univer-flex-1">{item.subject?.name}</div>
{item.role === UnitRole.Owner && (
- <div className="univer-text-xs univer-text-rose-600">{localeService.t('sheets-ui.permission.dialog.ownerWithoutInherit')}</div>
+ <div className="univer-text-xs univer-text-rose-600">{localeService.t<LocaleKey>('sheets-ui.permission.dialog.ownerWithoutInherit')}</div>
)}
{selectUserInfo?.findIndex((v) => v.subject?.userID === item.subject?.userID) !== -1 && (
<div>
@@ -113,7 +114,7 @@ export const SheetPermissionUserDialog = () => {
draggable={false}
/>
<p className="univer-text-sm univer-text-gray-400">
- {localeService.t('sheets-ui.permission.dialog.userEmpty')}
+ {localeService.t<LocaleKey>('sheets-ui.permission.dialog.userEmpty')}
</p>
</div>
)}
@@ -123,7 +124,7 @@ export const SheetPermissionUserDialog = () => {
<Button
onClick={() => dialogService.close(UNIVER_SHEET_PERMISSION_USER_DIALOG_ID)}
>
- {localeService.t('sheets-ui.permission.button.cancel')}
+ {localeService.t<LocaleKey>('sheets-ui.permission.button.cancel')}
</Button>
<Button
variant="primary"
@@ -132,7 +133,7 @@ export const SheetPermissionUserDialog = () => {
dialogService.close(UNIVER_SHEET_PERMISSION_USER_DIALOG_ID);
}}
>
- {localeService.t('sheets-ui.permission.button.confirm')}
+ {localeService.t<LocaleKey>('sheets-ui.permission.button.confirm')}
</Button>
</div>
</div>
diff --git a/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailFooterPart.tsx b/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailFooterPart.tsx
index 4e3745c330..f2a5a81eec 100644
--- a/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailFooterPart.tsx
+++ b/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailFooterPart.tsx
@@ -16,6 +16,7 @@
import type { IRange, Workbook } from '@univerjs/core';
import type { IRangeProtectionRule } from '@univerjs/sheets';
+import type { LocaleKey } from '../../../locale/types';
import type { IPermissionPanelRule } from '../../../services/permission/sheet-permission-panel.model';
import {
IAuthzIoService,
@@ -211,7 +212,7 @@ export const PermissionDetailFooterPart = (props: IPermissionDetailFooterPartPro
}
}
const sidebarProps = {
- header: { title: `${localeService.t('sheets-ui.permission.panel.title')}` },
+ header: { title: `${localeService.t<LocaleKey>('sheets-ui.permission.panel.title')}` },
children: {
label: UNIVER_SHEET_PERMISSION_PANEL,
showDetail: false,
@@ -221,7 +222,7 @@ export const PermissionDetailFooterPart = (props: IPermissionDetailFooterPartPro
sidebarService.open(sidebarProps);
}}
>
- {localeService.t('sheets-ui.permission.button.confirm')}
+ {localeService.t<LocaleKey>('sheets-ui.permission.button.confirm')}
</Button>
<Button
onClick={() => {
@@ -230,7 +231,7 @@ export const PermissionDetailFooterPart = (props: IPermissionDetailFooterPartPro
sidebarService.close();
}}
>
- {localeService.t('sheets-ui.permission.button.cancel')}
+ {localeService.t<LocaleKey>('sheets-ui.permission.button.cancel')}
</Button>
</div>
);
diff --git a/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailMainPart.tsx b/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailMainPart.tsx
index a062aa944a..730a936463 100644
--- a/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailMainPart.tsx
+++ b/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailMainPart.tsx
@@ -17,6 +17,7 @@
import type { IRange, Workbook } from '@univerjs/core';
import type { ComponentType } from 'react';
import type { IRangeSelectorProps } from '../../../basics/editor/range';
+import type { LocaleKey } from '../../../locale/types';
import { Injector, isValidRange, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
import { FormLayout, Input } from '@univerjs/design';
import { deserializeRangeWithSheet, serializeRange } from '@univerjs/engine-formula';
@@ -78,7 +79,7 @@ export const PermissionDetailMainPart = (props: IPermissionDetailMainPartProps)
<>
<FormLayout
className="univer-font-medium"
- label={localeService.t('sheets-ui.permission.panel.protectedRange')}
+ label={localeService.t<LocaleKey>('sheets-ui.permission.panel.protectedRange')}
error={rangesErrMsg}
>
{RangeSelector && (
@@ -90,11 +91,14 @@ export const PermissionDetailMainPart = (props: IPermissionDetailMainPartProps)
/>
)}
</FormLayout>
- <FormLayout className="univer-font-medium" label={localeService.t('sheets-ui.permission.panel.permissionDirection')}>
+ <FormLayout
+ className="univer-font-medium"
+ label={localeService.t<LocaleKey>('sheets-ui.permission.panel.permissionDirection')}
+ >
<Input
value={desc}
onChange={(v) => onDescChange(v)}
- placeholder={localeService.t('sheets-ui.permission.panel.permissionDirectionPlaceholder')}
+ placeholder={localeService.t<LocaleKey>('sheets-ui.permission.panel.permissionDirectionPlaceholder')}
/>
</FormLayout>
</>
diff --git a/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailUserPart.tsx b/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailUserPart.tsx
index 5824cb6a73..6fb71b9d49 100644
--- a/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailUserPart.tsx
+++ b/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailUserPart.tsx
@@ -16,7 +16,14 @@
import type { Workbook } from '@univerjs/core';
import type { ICollaborator } from '@univerjs/protocol';
-import { IAuthzIoService, IUniverInstanceService, LocaleService, UniverInstanceType, UserManagerService } from '@univerjs/core';
+import type { LocaleKey } from '../../../locale/types';
+import {
+ IAuthzIoService,
+ IUniverInstanceService,
+ LocaleService,
+ UniverInstanceType,
+ UserManagerService,
+} from '@univerjs/core';
import { Avatar, borderClassName, clsx, FormLayout, Radio, RadioGroup, Select } from '@univerjs/design';
import { UnitRole } from '@univerjs/protocol';
import { EditStateEnum, ViewStateEnum } from '@univerjs/sheets';
@@ -96,17 +103,20 @@ export const PermissionDetailUserPart = (props: IPermissionDetailUserPartProps)
return (
<>
- <FormLayout className="univer-font-medium" label={localeService.t('sheets-ui.permission.panel.editPermission')}>
+ <FormLayout
+ className="univer-font-medium"
+ label={localeService.t<LocaleKey>('sheets-ui.permission.panel.editPermission')}
+ >
<RadioGroup
value={editState}
onChange={(v) => onEditStateChange(v as EditStateEnum)}
className="univer-flex univer-flex-col"
>
<Radio value={EditStateEnum.OnlyMe}>
- <span>{localeService.t('sheets-ui.permission.panel.onlyICanEdit')}</span>
+ <span>{localeService.t<LocaleKey>('sheets-ui.permission.panel.onlyICanEdit')}</span>
</Radio>
<Radio value={EditStateEnum.DesignedUserCanEdit}>
- <span>{localeService.t('sheets-ui.permission.panel.designedUserCanEdit')}</span>
+ <span>{localeService.t<LocaleKey>('sheets-ui.permission.panel.designedUserCanEdit')}</span>
</Radio>
</RadioGroup>
</FormLayout>
@@ -118,8 +128,8 @@ export const PermissionDetailUserPart = (props: IPermissionDetailUserPartProps)
`, borderClassName)}
>
<div className="univer-flex univer-items-center univer-justify-between univer-text-sm">
- <span>{localeService.t('sheets-ui.permission.panel.designedPerson')}</span>
- <span className="univer-cursor-pointer univer-text-primary-600" onClick={handleAddPerson}>{localeService.t('sheets-ui.permission.panel.addPerson')}</span>
+ <span>{localeService.t<LocaleKey>('sheets-ui.permission.panel.designedPerson')}</span>
+ <span className="univer-cursor-pointer univer-text-primary-600" onClick={handleAddPerson}>{localeService.t<LocaleKey>('sheets-ui.permission.panel.addPerson')}</span>
</div>
<div className="univer-my-2 univer-h-px univer-bg-gray-200" />
<div className="univer-flex-1">
@@ -147,8 +157,14 @@ export const PermissionDetailUserPart = (props: IPermissionDetailUserPartProps)
borderless
value="edit"
options={[
- { label: `${localeService.t('sheets-ui.permission.panel.canEdit')}`, value: 'edit' },
- { label: `${localeService.t('sheets-ui.permission.panel.delete')}`, value: 'delete' },
+ {
+ label: `${localeService.t<LocaleKey>('sheets-ui.permission.panel.canEdit')}`,
+ value: 'edit',
+ },
+ {
+ label: `${localeService.t<LocaleKey>('sheets-ui.permission.panel.delete')}`,
+ value: 'delete',
+ },
]}
onChange={(v) => {
if (v === 'delete') {
@@ -170,7 +186,7 @@ export const PermissionDetailUserPart = (props: IPermissionDetailUserPartProps)
<p
className="univer-w-60 univer-break-words univer-text-sm univer-text-gray-400"
>
- {localeService.t('sheets-ui.permission.dialog.userEmpty')}
+ {localeService.t<LocaleKey>('sheets-ui.permission.dialog.userEmpty')}
</p>
</div>
)}
@@ -178,7 +194,7 @@ export const PermissionDetailUserPart = (props: IPermissionDetailUserPartProps)
</div>
)}
- <FormLayout className="univer-font-medium" label={localeService.t('sheets-ui.permission.panel.viewPermission')}>
+ <FormLayout className="univer-font-medium" label={localeService.t<LocaleKey>('sheets-ui.permission.panel.viewPermission')}>
<RadioGroup
value={viewState}
onChange={(v) => onViewStateChange(v as ViewStateEnum)}
@@ -188,10 +204,10 @@ export const PermissionDetailUserPart = (props: IPermissionDetailUserPartProps)
`}
>
<Radio value={ViewStateEnum.OthersCanView}>
- <span>{localeService.t('sheets-ui.permission.panel.othersCanView')}</span>
+ <span>{localeService.t<LocaleKey>('sheets-ui.permission.panel.othersCanView')}</span>
</Radio>
<Radio value={ViewStateEnum.NoOneElseCanView}>
- <span>{localeService.t('sheets-ui.permission.panel.noOneElseCanView')}</span>
+ <span>{localeService.t<LocaleKey>('sheets-ui.permission.panel.noOneElseCanView')}</span>
</Radio>
</RadioGroup>
</FormLayout>
diff --git a/packages/sheets-ui/src/views/permission/util.ts b/packages/sheets-ui/src/views/permission/util.ts
index 6499269ba7..59dbb74ada 100644
--- a/packages/sheets-ui/src/views/permission/util.ts
+++ b/packages/sheets-ui/src/views/permission/util.ts
@@ -15,6 +15,7 @@
*/
import type { Injector, IRange, Workbook, Worksheet } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import type { IPermissionPanelRule } from '../../services/permission/sheet-permission-panel.model';
import { IUniverInstanceService, LocaleService, RANGE_TYPE, Rectangle, UniverInstanceType } from '@univerjs/core';
import { UnitObject } from '@univerjs/protocol';
@@ -26,14 +27,20 @@ import {
WorksheetProtectionRuleModel,
} from '@univerjs/sheets';
-export const checkRangeValid = (injector: Injector, permissionRanges: IRange[], permissionId: string, unitId: string, subUnitId: string) => {
+export const checkRangeValid = (
+ injector: Injector,
+ permissionRanges: IRange[],
+ permissionId: string,
+ unitId: string,
+ subUnitId: string
+) => {
const localeService = injector.get(LocaleService);
const worksheetRuleModel = injector.get(WorksheetProtectionRuleModel);
const rangeProtectionRuleModel = injector.get(RangeProtectionRuleModel);
let rangeErrorString = '';
if (permissionRanges.length === 0) {
- rangeErrorString = localeService.t('sheets-ui.permission.panel.emptyRangeError');
+ rangeErrorString = localeService.t<LocaleKey>('sheets-ui.permission.panel.emptyRangeError');
} else if (permissionRanges.length > 1) {
let hasLap = false;
for (let i = 0; i < permissionRanges.length; i++) {
@@ -48,13 +55,13 @@ export const checkRangeValid = (injector: Injector, permissionRanges: IRange[],
}
}
if (hasLap) {
- rangeErrorString = localeService.t('sheets-ui.permission.panel.rangeOverlapError');
+ rangeErrorString = localeService.t<LocaleKey>('sheets-ui.permission.panel.rangeOverlapError');
}
}
if (!rangeErrorString) {
const worksheetRule = worksheetRuleModel.getRule(unitId, subUnitId);
if (worksheetRule && !permissionId) {
- rangeErrorString = localeService.t('sheets-ui.permission.panel.rangeOverlapOverPermissionError');
+ rangeErrorString = localeService.t<LocaleKey>('sheets-ui.permission.panel.rangeOverlapOverPermissionError');
return rangeErrorString;
}
const lapRule = rangeProtectionRuleModel.getSubunitRuleList(unitId, subUnitId).filter((rule) => {
@@ -68,7 +75,7 @@ export const checkRangeValid = (injector: Injector, permissionRanges: IRange[],
return permissionRanges.some((r) => Rectangle.intersects(range, r));
});
if (lapRange) {
- rangeErrorString = localeService.t('sheets-ui.permission.panel.rangeOverlapOverPermissionError');
+ rangeErrorString = localeService.t<LocaleKey>('sheets-ui.permission.panel.rangeOverlapOverPermissionError');
}
}
return rangeErrorString === '' ? undefined : rangeErrorString;
diff --git a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx
index 57b3674070..879af075e9 100644
--- a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx
+++ b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx
@@ -17,6 +17,7 @@
import type { ICommandInfo } from '@univerjs/core';
import type { IUniverUIConfig } from '@univerjs/ui';
import type { KeyboardEvent as ReactKeyboardEvent, MouseEvent as ReactMouseEvent } from 'react';
+import type { LocaleKey } from '../../../locale/types';
import type { IScrollState } from '../../../services/sheet-bar/type';
import type { IBaseSheetBarProps } from './SheetBarItem';
import {
@@ -151,10 +152,10 @@ export function SheetBarTabs() {
const openSheetNameErrorDialog = useCallback((id: string, description: string) => {
confirmService.open({
id,
- title: { title: localeService.t('sheets-ui.sheetConfig.sheetNameErrorTitle') },
+ title: { title: localeService.t<LocaleKey>('sheets-ui.sheetConfig.sheetNameErrorTitle') },
children: { title: description },
- cancelText: localeService.t('sheets-ui.button.cancel'),
- confirmText: localeService.t('sheets-ui.button.confirm'),
+ cancelText: localeService.t<LocaleKey>('sheets-ui.button.cancel'),
+ confirmText: localeService.t<LocaleKey>('sheets-ui.button.confirm'),
onClose() {
focusTabEditor();
confirmService.close(id);
@@ -171,7 +172,7 @@ export function SheetBarTabs() {
return false;
}
- openSheetNameErrorDialog('sheetNameEmptyAlert', localeService.t('sheets-ui.sheetConfig.sheetNameCannotIsEmptyError'));
+ openSheetNameErrorDialog('sheetNameEmptyAlert', localeService.t<LocaleKey>('sheets-ui.sheetConfig.sheetNameCannotIsEmptyError'));
return true;
}, [localeService, openSheetNameErrorDialog]);
@@ -180,7 +181,7 @@ export function SheetBarTabs() {
return false;
}
- openSheetNameErrorDialog('sheetNameSpecCharAlert', localeService.t('sheets-ui.sheetConfig.sheetNameSpecCharError'));
+ openSheetNameErrorDialog('sheetNameSpecCharAlert', localeService.t<LocaleKey>('sheets-ui.sheetConfig.sheetNameSpecCharError'));
return true;
}, [localeService, openSheetNameErrorDialog]);
@@ -198,10 +199,10 @@ export function SheetBarTabs() {
const id = 'sheetNameRepeatAlert';
confirmService.open({
id,
- title: { title: localeService.t('sheets-ui.sheetConfig.sheetNameErrorTitle') },
- children: { title: localeService.t('sheets-ui.sheetConfig.sheetNameAlreadyExistsError') },
- cancelText: localeService.t('sheets-ui.button.cancel'),
- confirmText: localeService.t('sheets-ui.button.confirm'),
+ title: { title: localeService.t<LocaleKey>('sheets-ui.sheetConfig.sheetNameErrorTitle') },
+ children: { title: localeService.t<LocaleKey>('sheets-ui.sheetConfig.sheetNameAlreadyExistsError') },
+ cancelText: localeService.t<LocaleKey>('sheets-ui.button.cancel'),
+ confirmText: localeService.t<LocaleKey>('sheets-ui.button.confirm'),
onClose() {
confirmService.close(id);
focusTabEditor();
diff --git a/packages/sheets/src/commands/commands/__tests__/insert-sheet.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/insert-sheet.command.spec.ts
index 4e5d7bdf14..38443ff810 100644
--- a/packages/sheets/src/commands/commands/__tests__/insert-sheet.command.spec.ts
+++ b/packages/sheets/src/commands/commands/__tests__/insert-sheet.command.spec.ts
@@ -15,6 +15,7 @@
*/
import type { Injector, Univer, Workbook } from '@univerjs/core';
+import type { LocaleKey } from '../../../locale/types';
import { ICommandService, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { InsertSheetMutation } from '../../mutations/insert-sheet.mutation';
@@ -50,7 +51,7 @@ describe('Test insert worksheet commands', () => {
it('should auto-generate incremental names when name is not provided', async () => {
const workbook = get(IUniverInstanceService).getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const localeService = get(LocaleService);
- const sheetPrefix = localeService.t('sheets.tabs.sheet');
+ const sheetPrefix = localeService.t<LocaleKey>('sheets.tabs.sheet');
expect(workbook.getSheetSize()).toBe(1);
await commandService.executeCommand(InsertSheetCommand.id, {
diff --git a/packages/sheets/src/commands/commands/add-worksheet-merge.command.ts b/packages/sheets/src/commands/commands/add-worksheet-merge.command.ts
index 0168aefa1e..9aa01873ce 100644
--- a/packages/sheets/src/commands/commands/add-worksheet-merge.command.ts
+++ b/packages/sheets/src/commands/commands/add-worksheet-merge.command.ts
@@ -14,8 +14,21 @@
* limitations under the License.
*/
-import type { IAccessor, ICellData, ICommand, IMutationInfo, Injector, IRange, Nullable, Worksheet } from '@univerjs/core';
-import type { IAddWorksheetMergeMutationParams, IRemoveWorksheetMergeMutationParams } from '../../basics/interfaces/mutation-interface';
+import type {
+ IAccessor,
+ ICellData,
+ ICommand,
+ IMutationInfo,
+ Injector,
+ IRange,
+ Nullable,
+ Worksheet,
+} from '@univerjs/core';
+import type {
+ IAddWorksheetMergeMutationParams,
+ IRemoveWorksheetMergeMutationParams,
+} from '../../basics/interfaces/mutation-interface';
+import type { LocaleKey } from '../../locale/types';
import type { ISetRangeValuesMutationParams } from '../mutations/set-range-values.mutation';
import type { ISheetCommandSharedParams } from '../utils/interface';
import {
@@ -36,9 +49,15 @@ import { getAddMergeMutationRangeByType } from '../../controllers/merge-cell.con
import { SheetsSelectionsService } from '../../services/selections/selection.service';
import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';
import { AddMergeUndoMutationFactory, AddWorksheetMergeMutation } from '../mutations/add-worksheet-merge.mutation';
-import { RemoveMergeUndoMutationFactory, RemoveWorksheetMergeMutation } from '../mutations/remove-worksheet-merge.mutation';
+import {
+ RemoveMergeUndoMutationFactory,
+ RemoveWorksheetMergeMutation,
+} from '../mutations/remove-worksheet-merge.mutation';
import { SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../mutations/set-range-values.mutation';
-import { AddMergeRedoSelectionsOperationFactory, AddMergeUndoSelectionsOperationFactory } from '../utils/handle-merge-operation';
+import {
+ AddMergeRedoSelectionsOperationFactory,
+ AddMergeUndoSelectionsOperationFactory,
+} from '../utils/handle-merge-operation';
import { RemoveWorksheetMergeCommand } from './remove-worksheet-merge.command';
import { getSheetCommandTarget } from './utils/target-util';
@@ -184,8 +203,8 @@ export const AddWorksheetMergeCommand: ICommand = {
children: {
title: 'sheets.merge.confirm.title',
},
- cancelText: localeService.t('sheets.merge.confirm.cancel'),
- confirmText: localeService.t('sheets.merge.confirm.confirm'),
+ cancelText: localeService.t<LocaleKey>('sheets.merge.confirm.cancel'),
+ confirmText: localeService.t<LocaleKey>('sheets.merge.confirm.confirm'),
});
if (!result) return false;
diff --git a/packages/sheets/src/commands/commands/copy-worksheet.command.ts b/packages/sheets/src/commands/commands/copy-worksheet.command.ts
index da0152b70f..0991eaac79 100644
--- a/packages/sheets/src/commands/commands/copy-worksheet.command.ts
+++ b/packages/sheets/src/commands/commands/copy-worksheet.command.ts
@@ -14,9 +14,21 @@
* limitations under the License.
*/
-import type { IAccessor, ICellData, ICommand, IMutationInfo, IObjectMatrixPrimitiveType, Nullable, Workbook } from '@univerjs/core';
-import type { IInsertSheetMutationParams, IRemoveSheetMutationParams } from '../../basics/interfaces/mutation-interface';
+import type {
+ IAccessor,
+ ICellData,
+ ICommand,
+ IMutationInfo,
+ IObjectMatrixPrimitiveType,
+ Nullable,
+ Workbook,
+} from '@univerjs/core';
+import type {
+ IInsertSheetMutationParams,
+ IRemoveSheetMutationParams,
+} from '../../basics/interfaces/mutation-interface';
import type { IUniverSheetsConfig } from '../../config/config';
+import type { LocaleKey } from '../../locale/types';
import type { ISetRangeValuesMutationParams } from '../mutations/set-range-values.mutation';
import {
cloneWorksheetData,
@@ -305,11 +317,11 @@ export const CopySheetCommand: ICommand = {
// If Sheet1(Copy) already exists and you copy Sheet1, you should get Sheet1(Copy2)
export function getCopyUniqueSheetName(workbook: Workbook, localeService: LocaleService, name: string): string {
- let output = `${name} ${localeService.t('sheets.tabs.sheetCopy', '')}`;
+ let output = `${name} ${localeService.t<LocaleKey>('sheets.tabs.sheetCopy', '')}`;
let count = 2;
while (workbook.checkSheetName(output)) {
- output = `${name} ${localeService.t('sheets.tabs.sheetCopy', `${count}`)}`;
+ output = `${name} ${localeService.t<LocaleKey>('sheets.tabs.sheetCopy', `${count}`)}`;
count++;
}
return output;
diff --git a/packages/sheets/src/commands/commands/insert-range-move-down.command.ts b/packages/sheets/src/commands/commands/insert-range-move-down.command.ts
index 46ff7ff90e..3c20a6404e 100644
--- a/packages/sheets/src/commands/commands/insert-range-move-down.command.ts
+++ b/packages/sheets/src/commands/commands/insert-range-move-down.command.ts
@@ -20,6 +20,7 @@ import type {
IInsertRowMutationParams,
IRemoveRowsMutationParams,
} from '../../basics/interfaces/mutation-interface';
+import type { LocaleKey } from '../../locale/types';
import {
BooleanNumber,
CommandType,
@@ -63,7 +64,7 @@ export const InsertRangeMoveDownCommand: ICommand = {
const localeService = accessor.get(LocaleService);
if (selectionManagerService.isOverlapping()) {
- errorService.emit(localeService.t('sheets.info.overlappingSelections'));
+ errorService.emit(localeService.t<LocaleKey>('sheets.info.overlappingSelections'));
return false;
}
diff --git a/packages/sheets/src/commands/commands/insert-range-move-right.command.ts b/packages/sheets/src/commands/commands/insert-range-move-right.command.ts
index 21e98619de..59f5a03618 100644
--- a/packages/sheets/src/commands/commands/insert-range-move-right.command.ts
+++ b/packages/sheets/src/commands/commands/insert-range-move-right.command.ts
@@ -20,6 +20,7 @@ import type {
IInsertRangeMutationParams,
IRemoveColMutationParams,
} from '../../basics/interfaces/mutation-interface';
+import type { LocaleKey } from '../../locale/types';
import {
BooleanNumber,
@@ -63,7 +64,7 @@ export const InsertRangeMoveRightCommand: ICommand = {
const localeService = accessor.get(LocaleService);
if (selectionManagerService.isOverlapping()) {
- errorService.emit(localeService.t('sheets.info.overlappingSelections'));
+ errorService.emit(localeService.t<LocaleKey>('sheets.info.overlappingSelections'));
return false;
}
diff --git a/packages/sheets/src/commands/commands/insert-sheet.command.ts b/packages/sheets/src/commands/commands/insert-sheet.command.ts
index 0c1a8c460a..2b7d6210e6 100644
--- a/packages/sheets/src/commands/commands/insert-sheet.command.ts
+++ b/packages/sheets/src/commands/commands/insert-sheet.command.ts
@@ -15,7 +15,11 @@
*/
import type { IAccessor, ICommand, IWorksheetData } from '@univerjs/core';
-import type { IInsertSheetMutationParams, IRemoveSheetMutationParams } from '../../basics/interfaces/mutation-interface';
+import type {
+ IInsertSheetMutationParams,
+ IRemoveSheetMutationParams,
+} from '../../basics/interfaces/mutation-interface';
+import type { LocaleKey } from '../../locale/types';
import {
CommandType,
generateRandomId,
@@ -62,10 +66,10 @@ export const InsertSheetCommand: ICommand = {
sheetConfig.id = sheetId || generateRandomId();
sheetConfig.name = sheetName
? workbook.uniqueSheetName(sheetName)
- : workbook.generateNewSheetName(`${localeService.t('sheets.tabs.sheet')}`);
+ : workbook.generateNewSheetName(`${localeService.t<LocaleKey>('sheets.tabs.sheet')}`);
} else {
sheetConfig.id = generateRandomId();
- sheetConfig.name = workbook.generateNewSheetName(`${localeService.t('sheets.tabs.sheet')}`);
+ sheetConfig.name = workbook.generateNewSheetName(`${localeService.t<LocaleKey>('sheets.tabs.sheet')}`);
}
// prepare do mutations
diff --git a/packages/sheets/src/commands/commands/move-range.command.ts b/packages/sheets/src/commands/commands/move-range.command.ts
index a3a03650f7..e61d4bcc32 100644
--- a/packages/sheets/src/commands/commands/move-range.command.ts
+++ b/packages/sheets/src/commands/commands/move-range.command.ts
@@ -24,6 +24,7 @@ import type {
Workbook,
Worksheet,
} from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import type { IMoveRangeMutationParams } from '../mutations/move-range.mutation';
import type { ISetSelectionsOperationParams } from '../operations/selection.operation';
import {
@@ -90,7 +91,7 @@ export const MoveRangeCommand: ICommand = {
const moveRangeCommandMutations = getMoveRangeCommandMutations(accessor, params);
if (!moveRangeCommandMutations) {
- errorService.emit(localeService.t('sheets.info.acrossMergedCell'));
+ errorService.emit(localeService.t<LocaleKey>('sheets.info.acrossMergedCell'));
return false;
}
diff --git a/packages/sheets/src/commands/commands/move-rows-cols.command.ts b/packages/sheets/src/commands/commands/move-rows-cols.command.ts
index e974456523..8e2be5bc1e 100644
--- a/packages/sheets/src/commands/commands/move-rows-cols.command.ts
+++ b/packages/sheets/src/commands/commands/move-rows-cols.command.ts
@@ -16,6 +16,7 @@
import type { IAccessor, ICommand, IRange, Worksheet } from '@univerjs/core';
import type { ISelectionWithStyle } from '../../basics';
+import type { LocaleKey } from '../../locale/types';
import type { IMoveColumnsMutationParams, IMoveRowsMutationParams } from '../mutations/move-rows-cols.mutation';
import type { ISetSelectionsOperationParams } from '../operations/selection.operation';
import {
@@ -106,12 +107,12 @@ export const MoveRowsCommand: ICommand<IMoveRowsCommandParams> = {
const beforePrimary = filteredSelections[0].primary;
const alignedRange = alignToMergedCellsBorders(rangeToMove, worksheet, false);
if (!Rectangle.equals(rangeToMove, alignedRange)) {
- errorService.emit(localeService.t('sheets.info.partOfCell'));
+ errorService.emit(localeService.t<LocaleKey>('sheets.info.partOfCell'));
return false;
}
if (rowAcrossMergedCell(toRow, worksheet)) {
- errorService.emit(localeService.t('sheets.info.acrossMergedCell'));
+ errorService.emit(localeService.t<LocaleKey>('sheets.info.acrossMergedCell'));
return false;
}
@@ -260,12 +261,12 @@ export const MoveColsCommand: ICommand<IMoveColsCommandParams> = {
const beforePrimary = filteredSelections[0].primary;
const alignedRange = alignToMergedCellsBorders(rangeToMove, worksheet, false);
if (!Rectangle.equals(rangeToMove, alignedRange)) {
- errorService.emit(localeService.t('sheets.info.partOfCell'));
+ errorService.emit(localeService.t<LocaleKey>('sheets.info.partOfCell'));
return false;
}
if (columnAcrossMergedCell(toCol, worksheet)) {
- errorService.emit(localeService.t('sheets.info.acrossMergedCell'));
+ errorService.emit(localeService.t<LocaleKey>('sheets.info.acrossMergedCell'));
return false;
}
diff --git a/packages/sheets/src/commands/commands/set-worksheet-hide.command.ts b/packages/sheets/src/commands/commands/set-worksheet-hide.command.ts
index 75cf323d54..331881f139 100644
--- a/packages/sheets/src/commands/commands/set-worksheet-hide.command.ts
+++ b/packages/sheets/src/commands/commands/set-worksheet-hide.command.ts
@@ -15,6 +15,7 @@
*/
import type { IAccessor, ICommand } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import type { ISetWorksheetHideMutationParams } from '../mutations/set-worksheet-hide.mutation';
import {
BooleanNumber,
@@ -60,7 +61,7 @@ export const SetWorksheetHideCommand: ICommand = {
const worksheets = workbook.getSheets();
const visibleWorksheets = worksheets.filter((sheet) => sheet.getConfig().hidden === BooleanNumber.FALSE);
if (visibleWorksheets.length === 1) {
- errorService.emit(localeService.t('sheets.info.hideSheet'));
+ errorService.emit(localeService.t<LocaleKey>('sheets.info.hideSheet'));
return false;
}
diff --git a/packages/sheets/src/controllers/permission/sheet-permission-check.controller.ts b/packages/sheets/src/controllers/permission/sheet-permission-check.controller.ts
index d831247833..9f9b2de2b7 100644
--- a/packages/sheets/src/controllers/permission/sheet-permission-check.controller.ts
+++ b/packages/sheets/src/controllers/permission/sheet-permission-check.controller.ts
@@ -14,7 +14,17 @@
* limitations under the License.
*/
-import type { ICellData, ICellDataForSheetInterceptor, ICommandInfo, IObjectMatrixPrimitiveType, IPermissionTypes, IRange, Nullable, Workbook, WorkbookPermissionPointConstructor } from '@univerjs/core';
+import type {
+ ICellData,
+ ICellDataForSheetInterceptor,
+ ICommandInfo,
+ IObjectMatrixPrimitiveType,
+ IPermissionTypes,
+ IRange,
+ Nullable,
+ Workbook,
+ WorkbookPermissionPointConstructor,
+} from '@univerjs/core';
import type { ISetDefinedNameMutationParam } from '@univerjs/engine-formula';
import type { IAutoFillCommandParams } from '../../commands/commands/auto-fill.command';
import type { IClearSelectionAllCommandParams } from '../../commands/commands/clear-selection-all.command';
@@ -27,7 +37,10 @@ import type { IInsertRangeMoveRightCommandParams } from '../../commands/commands
import type { IInsertColCommandParams, IInsertRowCommandParams } from '../../commands/commands/insert-row-col.command';
import type { IMoveRangeCommandParams } from '../../commands/commands/move-range.command';
import type { IMoveColsCommandParams, IMoveRowsCommandParams } from '../../commands/commands/move-rows-cols.command';
-import type { IRemoveColByRangeCommandParams, IRemoveRowByRangeCommandParams } from '../../commands/commands/remove-row-col.command';
+import type {
+ IRemoveColByRangeCommandParams,
+ IRemoveRowByRangeCommandParams,
+} from '../../commands/commands/remove-row-col.command';
import type { ISetBorderCommandParams } from '../../commands/commands/set-border.command';
import type { ISetSpecificColsVisibleCommandParams } from '../../commands/commands/set-col-visible.command';
import type { ISetRangeValuesCommandParams } from '../../commands/commands/set-range-values.command';
@@ -36,8 +49,12 @@ import type { ISetStyleCommandParams } from '../../commands/commands/set-style.c
import type { ISetColWidthCommandParams } from '../../commands/commands/set-worksheet-col-width.command';
import type { ISetWorksheetNameCommandParams } from '../../commands/commands/set-worksheet-name.command';
import type { ISetWorksheetOrderCommandParams } from '../../commands/commands/set-worksheet-order.command';
-import type { ISetRowHeightCommandParams, ISetWorksheetRowIsAutoHeightCommandParams } from '../../commands/commands/set-worksheet-row-height.command';
+import type {
+ ISetRowHeightCommandParams,
+ ISetWorksheetRowIsAutoHeightCommandParams,
+} from '../../commands/commands/set-worksheet-row-height.command';
import type { ISetWorksheetShowCommandParams } from '../../commands/commands/set-worksheet-show.command';
+import type { LocaleKey } from '../../locale/types';
import {
CustomCommandExecutionError,
Direction,
@@ -54,7 +71,14 @@ import {
Tools,
UniverInstanceType,
} from '@univerjs/core';
-import { deserializeRangeWithSheet, deserializeRangeWithSheetWithCache, IDefinedNamesService, LexerTreeBuilder, operatorToken, sequenceNodeType } from '@univerjs/engine-formula';
+import {
+ deserializeRangeWithSheet,
+ deserializeRangeWithSheetWithCache,
+ IDefinedNamesService,
+ LexerTreeBuilder,
+ operatorToken,
+ sequenceNodeType,
+} from '@univerjs/engine-formula';
import { UnitAction } from '@univerjs/protocol';
import { Subject } from 'rxjs';
import { AutoFillCommand } from '../../commands/commands/auto-fill.command';
@@ -72,15 +96,25 @@ import { MoveColsCommand, MoveRowsCommand } from '../../commands/commands/move-r
import { RemoveDefinedNameCommand } from '../../commands/commands/remove-defined-name.command';
import { RemoveColByRangeCommand, RemoveRowByRangeCommand } from '../../commands/commands/remove-row-col.command';
import { SetBorderCommand } from '../../commands/commands/set-border.command';
-import { SetSelectedColsVisibleCommand, SetSpecificColsVisibleCommand } from '../../commands/commands/set-col-visible.command';
+import {
+ SetSelectedColsVisibleCommand,
+ SetSpecificColsVisibleCommand,
+} from '../../commands/commands/set-col-visible.command';
import { SetDefinedNameCommand } from '../../commands/commands/set-defined-name.command';
import { SetRangeValuesCommand } from '../../commands/commands/set-range-values.command';
-import { SetSelectedRowsVisibleCommand, SetSpecificRowsVisibleCommand } from '../../commands/commands/set-row-visible.command';
+import {
+ SetSelectedRowsVisibleCommand,
+ SetSpecificRowsVisibleCommand,
+} from '../../commands/commands/set-row-visible.command';
import { SetStyleCommand } from '../../commands/commands/set-style.command';
import { DeltaColumnWidthCommand, SetColWidthCommand } from '../../commands/commands/set-worksheet-col-width.command';
import { SetWorksheetNameCommand } from '../../commands/commands/set-worksheet-name.command';
import { SetWorksheetOrderCommand } from '../../commands/commands/set-worksheet-order.command';
-import { DeltaRowHeightCommand, SetRowHeightCommand, SetWorksheetRowIsAutoHeightCommand } from '../../commands/commands/set-worksheet-row-height.command';
+import {
+ DeltaRowHeightCommand,
+ SetRowHeightCommand,
+ SetWorksheetRowIsAutoHeightCommand,
+} from '../../commands/commands/set-worksheet-row-height.command';
import { SetWorksheetShowCommand } from '../../commands/commands/set-worksheet-show.command';
import { getSheetCommandTarget } from '../../commands/commands/utils/target-util';
import { SetWorksheetNameMutation } from '../../commands/mutations/set-worksheet-name.mutation';
@@ -187,7 +221,7 @@ export class SheetPermissionCheckController extends Disposable {
if (isICellData(params.value) && params.value.f) {
permission = this._permissionCheckWithFormula(params);
- errorMsg = this._localeService.t('sheets.permission.dialog.formulaErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.formulaErr');
} else {
permission = this._permissionCheckBySetRangeValue(
{
@@ -197,7 +231,7 @@ export class SheetPermissionCheckController extends Disposable {
},
params
);
- errorMsg = this._localeService.t('sheets.permission.dialog.editErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.editErr');
}
break;
@@ -215,7 +249,7 @@ export class SheetPermissionCheckController extends Disposable {
params.unitId,
params.subUnitId
);
- errorMsg = this._localeService.t('sheets.permission.dialog.setStyleErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.setStyleErr');
break;
case SetBorderCommand.id:
params = commandInfo.params as ISetBorderCommandParams | undefined;
@@ -230,7 +264,7 @@ export class SheetPermissionCheckController extends Disposable {
params?.unitId,
params?.subUnitId
);
- errorMsg = this._localeService.t('sheets.permission.dialog.setStyleErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.setStyleErr');
break;
// clear all/content/format
@@ -247,7 +281,7 @@ export class SheetPermissionCheckController extends Disposable {
params?.unitId,
params?.subUnitId
);
- errorMsg = this._localeService.t('sheets.permission.dialog.editErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.editErr');
break;
case ClearSelectionContentCommand.id:
params = commandInfo.params as IClearSelectionContentCommandParams | undefined;
@@ -262,7 +296,7 @@ export class SheetPermissionCheckController extends Disposable {
params?.unitId,
params?.subUnitId
);
- errorMsg = this._localeService.t('sheets.permission.dialog.editErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.editErr');
break;
case ClearSelectionFormatCommand.id:
params = commandInfo.params as IClearSelectionFormatCommandParams | undefined;
@@ -277,7 +311,7 @@ export class SheetPermissionCheckController extends Disposable {
params?.unitId,
params?.subUnitId
);
- errorMsg = this._localeService.t('sheets.permission.dialog.setStyleErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.setStyleErr');
break;
// set column width
@@ -287,7 +321,7 @@ export class SheetPermissionCheckController extends Disposable {
worksheetTypes: [WorksheetSetColumnStylePermission],
}
);
- errorMsg = this._localeService.t('sheets.permission.dialog.setRowColStyleErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.setRowColStyleErr');
break;
case SetColWidthCommand.id:
params = commandInfo.params as ISetColWidthCommandParams;
@@ -299,7 +333,7 @@ export class SheetPermissionCheckController extends Disposable {
params.unitId,
params.subUnitId
);
- errorMsg = this._localeService.t('sheets.permission.dialog.setRowColStyleErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.setRowColStyleErr');
break;
// set row height
@@ -309,7 +343,7 @@ export class SheetPermissionCheckController extends Disposable {
worksheetTypes: [WorksheetSetRowStylePermission],
}
);
- errorMsg = this._localeService.t('sheets.permission.dialog.setRowColStyleErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.setRowColStyleErr');
break;
case SetRowHeightCommand.id:
case SetWorksheetRowIsAutoHeightCommand.id:
@@ -322,7 +356,7 @@ export class SheetPermissionCheckController extends Disposable {
params.unitId,
params.subUnitId
);
- errorMsg = this._localeService.t('sheets.permission.dialog.setRowColStyleErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.setRowColStyleErr');
break;
// move rows/columns/ranges
@@ -331,13 +365,13 @@ export class SheetPermissionCheckController extends Disposable {
params = commandInfo.params as IMoveRowsCommandParams | IMoveColsCommandParams;
permission = this._permissionCheckByMoveRowsColsCommand(params);
- errorMsg = this._localeService.t('sheets.permission.dialog.moveRowColErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.moveRowColErr');
break;
case MoveRangeCommand.id:
params = commandInfo.params as IMoveRangeCommandParams;
permission = this._permissionCheckByMoveRangeCommand(params);
- errorMsg = this._localeService.t('sheets.permission.dialog.moveRangeErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.moveRangeErr');
break;
// insert row/column
@@ -346,7 +380,7 @@ export class SheetPermissionCheckController extends Disposable {
params = commandInfo.params as IInsertRowCommandParams | IInsertColCommandParams;
permission = this._permissionCheckByInsertRowColCommand(params);
- errorMsg = this._localeService.t('sheets.permission.dialog.insertRowColErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.insertRowColErr');
break;
// remove row/column
@@ -363,7 +397,7 @@ export class SheetPermissionCheckController extends Disposable {
params.unitId,
params.subUnitId
);
- errorMsg = this._localeService.t('sheets.permission.dialog.removeRowColErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.removeRowColErr');
break;
case RemoveColByRangeCommand.id:
params = commandInfo.params as IRemoveRowByRangeCommandParams | IRemoveColByRangeCommandParams;
@@ -378,7 +412,7 @@ export class SheetPermissionCheckController extends Disposable {
params.unitId,
params.subUnitId
);
- errorMsg = this._localeService.t('sheets.permission.dialog.removeRowColErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.removeRowColErr');
break;
// worksheet operations
@@ -386,19 +420,19 @@ export class SheetPermissionCheckController extends Disposable {
params = commandInfo.params as ISetWorksheetOrderCommandParams;
permission = this._permissionCheckByWorksheetCommand([WorkbookEditablePermission, WorkbookMoveSheetPermission], params);
- errorMsg = this._localeService.t('sheets.permission.dialog.operatorSheetErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.operatorSheetErr');
break;
case SetWorksheetNameCommand.id:
params = commandInfo.params as ISetWorksheetNameCommandParams;
permission = this._permissionCheckByWorksheetCommand([WorkbookEditablePermission, WorkbookRenameSheetPermission], params);
- errorMsg = this._localeService.t('sheets.permission.dialog.operatorSheetErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.operatorSheetErr');
break;
case SetWorksheetShowCommand.id:
params = commandInfo.params as ISetWorksheetShowCommandParams;
permission = this._permissionCheckByWorksheetCommand([WorkbookEditablePermission, WorkbookHideSheetPermission], params);
- errorMsg = this._localeService.t('sheets.permission.dialog.operatorSheetErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.operatorSheetErr');
break;
// set row/column style
@@ -415,7 +449,7 @@ export class SheetPermissionCheckController extends Disposable {
params.unitId,
params.subUnitId
);
- errorMsg = this._localeService.t('sheets.permission.dialog.setRowColStyleErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.setRowColStyleErr');
break;
case SetSpecificRowsVisibleCommand.id:
params = commandInfo.params as ISetSpecificRowsVisibleCommandParams;
@@ -430,7 +464,7 @@ export class SheetPermissionCheckController extends Disposable {
params.unitId,
params.subUnitId
);
- errorMsg = this._localeService.t('sheets.permission.dialog.setRowColStyleErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.setRowColStyleErr');
break;
case SetSelectedColsVisibleCommand.id:
permission = this.permissionCheckWithRanges({
@@ -438,7 +472,7 @@ export class SheetPermissionCheckController extends Disposable {
worksheetTypes: [WorksheetEditPermission, WorksheetSetColumnStylePermission],
rangeTypes: [RangeProtectionPermissionEditPoint],
});
- errorMsg = this._localeService.t('sheets.permission.dialog.setRowColStyleErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.setRowColStyleErr');
break;
case SetSelectedRowsVisibleCommand.id:
permission = this.permissionCheckWithRanges({
@@ -446,7 +480,7 @@ export class SheetPermissionCheckController extends Disposable {
worksheetTypes: [WorksheetEditPermission, WorksheetSetRowStylePermission],
rangeTypes: [RangeProtectionPermissionEditPoint],
});
- errorMsg = this._localeService.t('sheets.permission.dialog.setRowColStyleErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.setRowColStyleErr');
break;
// insert/delete with move range
@@ -454,25 +488,25 @@ export class SheetPermissionCheckController extends Disposable {
params = commandInfo.params as IInsertRangeMoveRightCommandParams | undefined;
permission = this._permissionCheckWithInsertOrDeleteMoveRange('right', params);
- errorMsg = this._localeService.t('sheets.permission.dialog.insertOrDeleteMoveRangeErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.insertOrDeleteMoveRangeErr');
break;
case InsertRangeMoveDownCommand.id:
params = commandInfo.params as IInsertRangeMoveDownCommandParams | undefined;
permission = this._permissionCheckWithInsertOrDeleteMoveRange('down', params);
- errorMsg = this._localeService.t('sheets.permission.dialog.insertOrDeleteMoveRangeErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.insertOrDeleteMoveRangeErr');
break;
case DeleteRangeMoveLeftCommand.id:
params = commandInfo.params as IDeleteRangeMoveLeftCommandParams | undefined;
permission = this._permissionCheckWithInsertOrDeleteMoveRange('left', params);
- errorMsg = this._localeService.t('sheets.permission.dialog.insertOrDeleteMoveRangeErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.insertOrDeleteMoveRangeErr');
break;
case DeleteRangeMoveUpCommand.id:
params = commandInfo.params as IDeleteRangeMoveUpCommandParams | undefined;
permission = this._permissionCheckWithInsertOrDeleteMoveRange('up', params);
- errorMsg = this._localeService.t('sheets.permission.dialog.insertOrDeleteMoveRangeErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.insertOrDeleteMoveRangeErr');
break;
// auto fill
@@ -489,7 +523,7 @@ export class SheetPermissionCheckController extends Disposable {
params.unitId,
params.subUnitId
);
- errorMsg = this._localeService.t('sheets.permission.dialog.autoFillErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.autoFillErr');
break;
// defined name
@@ -515,7 +549,7 @@ export class SheetPermissionCheckController extends Disposable {
params.localSheetId
);
}
- errorMsg = this._localeService.t('sheets.permission.dialog.editErr');
+ errorMsg = this._localeService.t<LocaleKey>('sheets.permission.dialog.editErr');
break;
default:
diff --git a/packages/sheets/src/facade/f-defined-name.ts b/packages/sheets/src/facade/f-defined-name.ts
index 86779868a5..82116c5675 100644
--- a/packages/sheets/src/facade/f-defined-name.ts
+++ b/packages/sheets/src/facade/f-defined-name.ts
@@ -16,10 +16,27 @@
import type { ISetDefinedNameMutationParam } from '@univerjs/engine-formula';
import type { FWorksheet } from './f-worksheet';
-import { generateRandomId, IAuthzIoService, ICommandService, Inject, Injector, IPermissionService, IUniverInstanceService, LocaleService } from '@univerjs/core';
+import {
+ generateRandomId,
+ IAuthzIoService,
+ ICommandService,
+ Inject,
+ Injector,
+ IPermissionService,
+ IUniverInstanceService,
+ LocaleService,
+} from '@univerjs/core';
import { FBase } from '@univerjs/core/facade';
import { IDefinedNamesService, IFunctionService, ISuperTableService, serializeRange } from '@univerjs/engine-formula';
-import { RangeProtectionRuleModel, RemoveDefinedNameCommand, SCOPE_WORKBOOK_VALUE_DEFINED_NAME, SetDefinedNameCommand, validateDefinedName, WorksheetProtectionPointModel, WorksheetProtectionRuleModel } from '@univerjs/sheets';
+import {
+ RangeProtectionRuleModel,
+ RemoveDefinedNameCommand,
+ SCOPE_WORKBOOK_VALUE_DEFINED_NAME,
+ SetDefinedNameCommand,
+ validateDefinedName,
+ WorksheetProtectionPointModel,
+ WorksheetProtectionRuleModel,
+} from '@univerjs/sheets';
/**
* Get defined name field name
diff --git a/packages/sheets/src/locale/types.ts b/packages/sheets/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/sheets/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/slides-ui/src/locale/types.ts b/packages/slides-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/slides-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/slides-ui/src/menu/image.menu.ts b/packages/slides-ui/src/menu/image.menu.ts
index afa7fa05da..65a910c263 100644
--- a/packages/slides-ui/src/menu/image.menu.ts
+++ b/packages/slides-ui/src/menu/image.menu.ts
@@ -16,13 +16,14 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { UniverInstanceType } from '@univerjs/core';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { InsertSlideFloatImageCommand } from '../commands/operations/insert-image.operation';
export const SLIDES_IMAGE_MENU_ID = 'slide.menu.image';
-export function SlideImageMenuFactory(accessor: IAccessor): IMenuItem {
+export function SlideImageMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: SLIDES_IMAGE_MENU_ID,
type: MenuItemType.SUBITEMS,
@@ -32,7 +33,7 @@ export function SlideImageMenuFactory(accessor: IAccessor): IMenuItem {
};
}
-export function UploadSlideFloatImageMenuFactory(_accessor: IAccessor): IMenuItem {
+export function UploadSlideFloatImageMenuFactory(_accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: InsertSlideFloatImageCommand.id,
title: 'slides-ui.image.insert.float',
diff --git a/packages/slides-ui/src/menu/shape.menu.ts b/packages/slides-ui/src/menu/shape.menu.ts
index d22fe68065..2128cecf0d 100644
--- a/packages/slides-ui/src/menu/shape.menu.ts
+++ b/packages/slides-ui/src/menu/shape.menu.ts
@@ -16,24 +16,27 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuButtonItem, IMenuItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { UniverInstanceType } from '@univerjs/core';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
-import { InsertSlideShapeEllipseCommand, InsertSlideShapeRectangleCommand } from '../commands/operations/insert-shape.operation';
+import {
+ InsertSlideShapeEllipseCommand,
+ InsertSlideShapeRectangleCommand,
+} from '../commands/operations/insert-shape.operation';
export const SHAPE_MENU_ID = 'slide.menu.shape';
-export function SlideShapeMenuFactory(accessor: IAccessor): IMenuItem {
+export function SlideShapeMenuFactory(accessor: IAccessor): IMenuItem<LocaleKey> {
return {
id: SHAPE_MENU_ID,
type: MenuItemType.SUBITEMS,
icon: 'GraphIcon',
tooltip: 'slides-ui.shape.insert.title',
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SLIDE),
- // disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
};
}
-export function UploadSlideFloatRectangleShapeMenuFactory(_accessor: IAccessor): IMenuButtonItem {
+export function UploadSlideFloatRectangleShapeMenuFactory(_accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: InsertSlideShapeRectangleCommand.id,
title: 'slides-ui.shape.insert.rectangle',
@@ -42,7 +45,7 @@ export function UploadSlideFloatRectangleShapeMenuFactory(_accessor: IAccessor):
};
}
-export function UploadSlideFloatEllipseShapeMenuFactory(_accessor: IAccessor): IMenuButtonItem {
+export function UploadSlideFloatEllipseShapeMenuFactory(_accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: InsertSlideShapeEllipseCommand.id,
title: 'slides-ui.shape.insert.ellipse',
diff --git a/packages/slides-ui/src/menu/text.menu.ts b/packages/slides-ui/src/menu/text.menu.ts
index 73ee4eb4e1..6f586a9d91 100644
--- a/packages/slides-ui/src/menu/text.menu.ts
+++ b/packages/slides-ui/src/menu/text.menu.ts
@@ -16,11 +16,12 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuButtonItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { UniverInstanceType } from '@univerjs/core';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { SlideAddTextCommand } from '../commands/operations/insert-text.operation';
-export function SlideAddTextMenuItemFactory(_accessor: IAccessor): IMenuButtonItem {
+export function SlideAddTextMenuItemFactory(_accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: SlideAddTextCommand.id,
type: MenuItemType.BUTTON,
diff --git a/packages/slides-ui/src/views/panels/ArrangePanel.tsx b/packages/slides-ui/src/views/panels/ArrangePanel.tsx
index 92233a6582..4727bb90a4 100644
--- a/packages/slides-ui/src/views/panels/ArrangePanel.tsx
+++ b/packages/slides-ui/src/views/panels/ArrangePanel.tsx
@@ -16,6 +16,7 @@
import type { Nullable } from '@univerjs/core';
import type { Image, Rect, RichText } from '@univerjs/engine-render';
+import type { LocaleKey } from '../../locale/types';
import { ICommandService, LocaleService } from '@univerjs/core';
import { Button } from '@univerjs/design';
import { BottomIcon, MoveDownIcon, MoveUpIcon, TopmostIcon } from '@univerjs/icons';
@@ -97,7 +98,7 @@ export default function ArrangePanel(props: IProps) {
dark:!univer-text-gray-200
`}
>
- <div>{localeService.t('slides-ui.image-panel.arrange.title')}</div>
+ <div>{localeService.t<LocaleKey>('slides-ui.image-panel.arrange.title')}</div>
</div>
</div>
<div className="univer-relative univer-mt-2.5 univer-flex univer-h-full">
@@ -105,7 +106,7 @@ export default function ArrangePanel(props: IProps) {
<Button onClick={() => { onArrangeBtnClick(ArrangeTypeEnum.forward); }}>
<span className="univer-flex univer-items-center univer-gap-1">
<MoveUpIcon />
- {localeService.t('slides-ui.image-panel.arrange.forward')}
+ {localeService.t<LocaleKey>('slides-ui.image-panel.arrange.forward')}
</span>
</Button>
@@ -114,7 +115,7 @@ export default function ArrangePanel(props: IProps) {
<Button onClick={() => { onArrangeBtnClick(ArrangeTypeEnum.backward); }}>
<span className="univer-flex univer-items-center univer-gap-1">
<MoveDownIcon />
- {localeService.t('slides-ui.image-panel.arrange.backward')}
+ {localeService.t<LocaleKey>('slides-ui.image-panel.arrange.backward')}
</span>
</Button>
@@ -125,7 +126,7 @@ export default function ArrangePanel(props: IProps) {
<Button onClick={() => { onArrangeBtnClick(ArrangeTypeEnum.front); }}>
<span className="univer-flex univer-items-center univer-gap-1">
<TopmostIcon />
- {localeService.t('slides-ui.image-panel.arrange.front')}
+ {localeService.t<LocaleKey>('slides-ui.image-panel.arrange.front')}
</span>
</Button>
@@ -134,7 +135,7 @@ export default function ArrangePanel(props: IProps) {
<Button onClick={() => { onArrangeBtnClick(ArrangeTypeEnum.back); }}>
<span className="univer-flex univer-items-center univer-gap-1">
<BottomIcon />
- {localeService.t('slides-ui.image-panel.arrange.back')}
+ {localeService.t<LocaleKey>('slides-ui.image-panel.arrange.back')}
</span>
</Button>
diff --git a/packages/slides-ui/src/views/panels/FillPanel.tsx b/packages/slides-ui/src/views/panels/FillPanel.tsx
index eeb3a16497..c965efdcc8 100644
--- a/packages/slides-ui/src/views/panels/FillPanel.tsx
+++ b/packages/slides-ui/src/views/panels/FillPanel.tsx
@@ -16,6 +16,7 @@
import type { Nullable } from '@univerjs/core';
import type { Rect } from '@univerjs/engine-render';
+import type { LocaleKey } from '../../locale/types';
import { ICommandService, LocaleService } from '@univerjs/core';
import { borderTopClassName, clsx, ColorPicker, Dropdown } from '@univerjs/design';
import { MoreDownIcon, PaintBucketDoubleIcon } from '@univerjs/icons';
@@ -89,7 +90,7 @@ export default function ArrangePanel(props: IProps) {
dark:!univer-text-gray-200
`}
>
- <div>{localeService.t('slides-ui.panel.fill.title')}</div>
+ <div>{localeService.t<LocaleKey>('slides-ui.panel.fill.title')}</div>
</div>
</div>
<div className="univer-relative univer-mt-2.5 univer-flex univer-h-full">
diff --git a/packages/slides-ui/src/views/panels/TransformPanel.tsx b/packages/slides-ui/src/views/panels/TransformPanel.tsx
index 83b119fbc4..70f22025d7 100644
--- a/packages/slides-ui/src/views/panels/TransformPanel.tsx
+++ b/packages/slides-ui/src/views/panels/TransformPanel.tsx
@@ -16,6 +16,7 @@
import type { Nullable } from '@univerjs/core';
import type { BaseObject, IChangeObserverConfig, Image, Rect, RichText } from '@univerjs/engine-render';
+import type { LocaleKey } from '../../locale/types';
import { ICommandService, LocaleService } from '@univerjs/core';
import { borderTopClassName, clsx, InputNumber } from '@univerjs/design';
import { useDependency } from '@univerjs/ui';
@@ -189,7 +190,7 @@ export default function TransformPanel(props: IProps) {
dark:!univer-text-gray-200
`}
>
- <div>{localeService.t('slides-ui.image-panel.transform.title')}</div>
+ <div>{localeService.t<LocaleKey>('slides-ui.image-panel.transform.title')}</div>
</header>
<div
@@ -199,7 +200,7 @@ export default function TransformPanel(props: IProps) {
`}
>
<div>
- <span>{localeService.t('slides-ui.image-panel.transform.width')}</span>
+ <span>{localeService.t<LocaleKey>('slides-ui.image-panel.transform.width')}</span>
<InputNumber
min={1}
value={width}
@@ -207,7 +208,7 @@ export default function TransformPanel(props: IProps) {
/>
</div>
<div>
- <span>{localeService.t('slides-ui.image-panel.transform.height')}</span>
+ <span>{localeService.t<LocaleKey>('slides-ui.image-panel.transform.height')}</span>
<InputNumber
min={1}
value={height}
@@ -217,15 +218,15 @@ export default function TransformPanel(props: IProps) {
</div>
<div className="univer-relative univer-mt-2.5 univer-flex univer-h-full">
<div>
- <span>{localeService.t('slides-ui.image-panel.transform.x')}</span>
+ <span>{localeService.t<LocaleKey>('slides-ui.image-panel.transform.x')}</span>
<InputNumber min={0} precision={1} value={xPosition} onChange={(val) => { handleXChange(val); }} />
</div>
<div>
- <span>{localeService.t('slides-ui.image-panel.transform.y')}</span>
+ <span>{localeService.t<LocaleKey>('slides-ui.image-panel.transform.y')}</span>
<InputNumber min={0} precision={1} value={yPosition} onChange={(val) => { handleYChange(val); }} />
</div>
<div>
- <span>{localeService.t('slides-ui.image-panel.transform.rotate')}</span>
+ <span>{localeService.t<LocaleKey>('slides-ui.image-panel.transform.rotate')}</span>
<InputNumber
precision={1}
value={rotation}
diff --git a/packages/slides-ui/src/views/slide-bar/SlideBar.tsx b/packages/slides-ui/src/views/slide-bar/SlideBar.tsx
index c2a25aac04..28579f74ee 100644
--- a/packages/slides-ui/src/views/slide-bar/SlideBar.tsx
+++ b/packages/slides-ui/src/views/slide-bar/SlideBar.tsx
@@ -15,6 +15,7 @@
*/
import type { SlideDataModel } from '@univerjs/slides';
+import type { LocaleKey } from '../../locale/types';
import { ICommandService, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
import { borderClassName, clsx, scrollbarClassName } from '@univerjs/design';
import { IRenderManagerService } from '@univerjs/engine-render';
@@ -104,7 +105,7 @@ export function SlideSideBar() {
`, borderClassName)}
onClick={handleAppendSlide}
>
- {localeService.t('slides-ui.append')}
+ {localeService.t<LocaleKey>('slides-ui.append')}
</a>
</header>
diff --git a/packages/thread-comment-ui/src/locale/types.ts b/packages/thread-comment-ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/thread-comment-ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/thread-comment-ui/src/views/ThreadCommentEditor.tsx b/packages/thread-comment-ui/src/views/ThreadCommentEditor.tsx
index 128dcdea16..b8e75f9799 100644
--- a/packages/thread-comment-ui/src/views/ThreadCommentEditor.tsx
+++ b/packages/thread-comment-ui/src/views/ThreadCommentEditor.tsx
@@ -17,7 +17,15 @@
import type { IDocumentBody, IDocumentData, IUser } from '@univerjs/core';
import type { Editor, IKeyboardEventConfig } from '@univerjs/docs-ui';
import type { IThreadComment } from '@univerjs/thread-comment';
-import { BuildTextUtils, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, ICommandService, LocaleService, Tools, UniverInstanceType } from '@univerjs/core';
+import type { LocaleKey } from '../locale/types';
+import {
+ BuildTextUtils,
+ DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
+ ICommandService,
+ LocaleService,
+ Tools,
+ UniverInstanceType,
+} from '@univerjs/core';
import { Button, clsx } from '@univerjs/design';
import { BreakLineCommand, IEditorService, RichTextEditor } from '@univerjs/docs-ui';
import { KeyCode, useDependency } from '@univerjs/ui';
@@ -140,7 +148,7 @@ export const ThreadCommentEditor = forwardRef<IThreadCommentEditorInstance, IThr
editorId={editorId}
autoFocus={autoFocus}
keyboardEventConfig={keyboardEventConfig}
- placeholder={localeService.t('thread-comment-ui.editor.placeholder')}
+ placeholder={localeService.t<LocaleKey>('thread-comment-ui.editor.placeholder')}
initialValue={comment?.text && getSnapshot(comment.text)}
onFocusChange={(isFocus) => isFocus && setEditing(isFocus)}
isSingle={false}
@@ -168,7 +176,7 @@ export const ThreadCommentEditor = forwardRef<IThreadCommentEditorInstance, IThr
commandService.executeCommand(SetActiveCommentOperation.id);
}}
>
- {localeService.t('thread-comment-ui.editor.cancel')}
+ {localeService.t<LocaleKey>('thread-comment-ui.editor.cancel')}
</Button>
<Button
type="button"
@@ -176,7 +184,7 @@ export const ThreadCommentEditor = forwardRef<IThreadCommentEditorInstance, IThr
disabled={!canSubmit}
onClick={handleSave}
>
- {localeService.t(id ? 'thread-comment-ui.editor.save' : 'thread-comment-ui.editor.reply')}
+ {localeService.t<LocaleKey>(id ? 'thread-comment-ui.editor.save' : 'thread-comment-ui.editor.reply')}
</Button>
</div>
)
diff --git a/packages/thread-comment-ui/src/views/ThreadCommentPanel.tsx b/packages/thread-comment-ui/src/views/ThreadCommentPanel.tsx
index 7e51885a49..f164a839f5 100644
--- a/packages/thread-comment-ui/src/views/ThreadCommentPanel.tsx
+++ b/packages/thread-comment-ui/src/views/ThreadCommentPanel.tsx
@@ -17,6 +17,7 @@
import type { Nullable } from '@univerjs/core';
import type { IThreadComment } from '@univerjs/thread-comment';
import type { Observable } from 'rxjs';
+import type { LocaleKey } from '../locale/types';
import type { ThreadCommentPanelSection } from './thread-comment-panel/util';
import type { IThreadCommentTreeProps } from './ThreadCommentTree';
import { ICommandService, LocaleService, UniverInstanceType, UserManagerService } from '@univerjs/core';
@@ -207,11 +208,11 @@ export const ThreadCommentPanel = (props: IThreadCommentPanelProps) => {
options={[
{
value: 'current',
- label: localeService.t('thread-comment-ui.filter.sheet.current'),
+ label: localeService.t<LocaleKey>('thread-comment-ui.filter.sheet.current'),
},
{
value: 'all',
- label: localeService.t('thread-comment-ui.filter.sheet.all'),
+ label: localeService.t<LocaleKey>('thread-comment-ui.filter.sheet.all'),
},
]}
onChange={setUnit}
@@ -224,19 +225,19 @@ export const ThreadCommentPanel = (props: IThreadCommentPanelProps) => {
options={[
{
value: 'all',
- label: localeService.t('thread-comment-ui.filter.status.all'),
+ label: localeService.t<LocaleKey>('thread-comment-ui.filter.status.all'),
},
{
value: 'resolved',
- label: localeService.t('thread-comment-ui.filter.status.resolved'),
+ label: localeService.t<LocaleKey>('thread-comment-ui.filter.status.resolved'),
},
{
value: 'unsolved',
- label: localeService.t('thread-comment-ui.filter.status.unsolved'),
+ label: localeService.t<LocaleKey>('thread-comment-ui.filter.status.unsolved'),
},
{
value: 'concern_me',
- label: localeService.t('thread-comment-ui.filter.status.concernMe'),
+ label: localeService.t<LocaleKey>('thread-comment-ui.filter.status.concernMe'),
},
]}
onChange={setStatus}
@@ -251,12 +252,12 @@ export const ThreadCommentPanel = (props: IThreadCommentPanelProps) => {
dark:!univer-text-gray-200
`}
>
- {localeService.t('thread-comment-ui.panel.empty')}
+ {localeService.t<LocaleKey>('thread-comment-ui.panel.empty')}
{isFiltering
? (
<div className="univer-mt-2 univer-flex univer-flex-row">
<Button onClick={onReset}>
- {localeService.t('thread-comment-ui.panel.reset')}
+ {localeService.t<LocaleKey>('thread-comment-ui.panel.reset')}
</Button>
</div>
)
@@ -265,7 +266,7 @@ export const ThreadCommentPanel = (props: IThreadCommentPanelProps) => {
<div className="univer-mt-2 univer-flex univer-flex-row">
<Button onClick={onAdd}>
<IncreaseIcon className="univer-mr-1.5" />
- {localeService.t('thread-comment-ui.panel.addComment')}
+ {localeService.t<LocaleKey>('thread-comment-ui.panel.addComment')}
</Button>
</div>
)
@@ -277,7 +278,7 @@ export const ThreadCommentPanel = (props: IThreadCommentPanelProps) => {
{unSolvedComments.map(renderComment('unsolved'))}
{solvedComments.length > 0 && (
<div className="univer-text-xs">
- {localeService.t('thread-comment-ui.panel.solved')}
+ {localeService.t<LocaleKey>('thread-comment-ui.panel.solved')}
</div>
)}
{solvedComments.map(renderComment('solved'))}
diff --git a/packages/thread-comment-ui/src/views/ThreadCommentTree.tsx b/packages/thread-comment-ui/src/views/ThreadCommentTree.tsx
index 1a4b9a83b7..84fdbe396d 100644
--- a/packages/thread-comment-ui/src/views/ThreadCommentTree.tsx
+++ b/packages/thread-comment-ui/src/views/ThreadCommentTree.tsx
@@ -17,6 +17,7 @@
import type { IUser, UniverInstanceType } from '@univerjs/core';
import type { IAddCommentCommandParams, IThreadComment, IUpdateCommentCommandParams } from '@univerjs/thread-comment';
import type { IUniverUIConfig } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import type { IThreadCommentEditorInstance } from './ThreadCommentEditor';
import { generateRandomId, ICommandService, LocaleService, UserManagerService } from '@univerjs/core';
import { borderClassName, clsx, Dropdown, scrollbarClassName, Tooltip } from '@univerjs/design';
@@ -172,7 +173,7 @@ const ThreadCommentItem = (props: IThreadCommentItemProps) => {
className="hover:univer-bg-gray-200"
onClick={() => onEditingChange?.(true)}
>
- {localeService.t('thread-comment-ui.item.edit')}
+ {localeService.t<LocaleKey>('thread-comment-ui.item.edit')}
</a>
</li>
<li>
@@ -180,7 +181,7 @@ const ThreadCommentItem = (props: IThreadCommentItemProps) => {
className="hover:univer-bg-gray-200"
onClick={handleDeleteItem}
>
- {localeService.t('thread-comment-ui.item.delete')}
+ {localeService.t<LocaleKey>('thread-comment-ui.item.delete')}
</a>
</li>
</ul>
diff --git a/packages/ui/src/controllers/menus/menus.ts b/packages/ui/src/controllers/menus/menus.ts
index 6713e9712c..88f280e0e2 100644
--- a/packages/ui/src/controllers/menus/menus.ts
+++ b/packages/ui/src/controllers/menus/menus.ts
@@ -15,6 +15,7 @@
*/
import type { IAccessor } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import type { IMenuButtonItem } from '../../services/menu/menu';
import {
EDITOR_ACTIVATED,
@@ -40,23 +41,23 @@ const undoRedoDisableFactory$ = (accessor: IAccessor, isUndo: boolean) => {
}));
};
-export function UndoMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function UndoMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: UndoCommand.id,
type: MenuItemType.BUTTON,
icon: 'UndoIcon',
- title: 'Undo',
+ title: 'ui.shortcut.undo',
tooltip: 'ui.shortcut.undo',
disabled$: undoRedoDisableFactory$(accessor, true),
};
}
-export function RedoMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function RedoMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: RedoCommand.id,
type: MenuItemType.BUTTON,
icon: 'RedoIcon',
- title: 'Redo',
+ title: 'ui.shortcut.redo',
tooltip: 'ui.shortcut.redo',
disabled$: undoRedoDisableFactory$(accessor, false),
};
diff --git a/packages/ui/src/controllers/shortcut-display/menu.ts b/packages/ui/src/controllers/shortcut-display/menu.ts
index 99153642ac..e5ca9995d4 100644
--- a/packages/ui/src/controllers/shortcut-display/menu.ts
+++ b/packages/ui/src/controllers/shortcut-display/menu.ts
@@ -14,11 +14,12 @@
* limitations under the License.
*/
+import type { LocaleKey } from '../../locale/types';
import type { IMenuButtonItem } from '../../services/menu/menu';
import { ToggleShortcutPanelOperation } from '../../commands/operations/toggle-shortcut-panel.operation';
import { MenuItemType } from '../../services/menu/menu';
-export function ShortcutPanelMenuItemFactory(): IMenuButtonItem {
+export function ShortcutPanelMenuItemFactory(): IMenuButtonItem<LocaleKey> {
return {
id: ToggleShortcutPanelOperation.id,
title: 'ui.toggle-shortcut-panel',
diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.ts
index ed9af40ca3..1f7eec8ca6 100644
--- a/packages/ui/src/index.ts
+++ b/packages/ui/src/index.ts
@@ -86,6 +86,7 @@ export type {
IMenuSelectorItem,
IValueOption,
MenuConfig,
+ MenuItemConfig,
MenuItemDefaultValueType,
} from './services/menu/menu';
export { IMenuManagerService, MenuManagerService } from './services/menu/menu-manager.service';
diff --git a/packages/ui/src/locale/types.ts b/packages/ui/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/ui/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/ui/src/services/clipboard/clipboard-interface.service.ts b/packages/ui/src/services/clipboard/clipboard-interface.service.ts
index a00c9ad0b9..49942ba745 100644
--- a/packages/ui/src/services/clipboard/clipboard-interface.service.ts
+++ b/packages/ui/src/services/clipboard/clipboard-interface.service.ts
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { LocaleKey } from '../../locale/types';
import { createIdentifier, Disposable, ILogService, Inject, LocaleService, Optional } from '@univerjs/core';
import { sanitizeParsedHtml } from '../../utils/html';
import { INotificationService } from '../notification/notification.service';
@@ -324,8 +325,8 @@ export class BrowserClipboardService extends Disposable implements IClipboardInt
private _showClipboardAuthenticationNotification(): void {
this._notificationService?.show({
type: 'warning',
- title: this._localeService.t('ui.clipboard.authentication.title'),
- content: this._localeService.t('ui.clipboard.authentication.content'),
+ title: this._localeService.t<LocaleKey>('ui.clipboard.authentication.title'),
+ content: this._localeService.t<LocaleKey>('ui.clipboard.authentication.content'),
});
}
}
diff --git a/packages/ui/src/services/menu/menu.ts b/packages/ui/src/services/menu/menu.ts
index 4e98c86dda..8939b92e8f 100644
--- a/packages/ui/src/services/menu/menu.ts
+++ b/packages/ui/src/services/menu/menu.ts
@@ -30,7 +30,14 @@ export enum MenuItemType {
SUBITEMS,
}
-interface IMenuItemBase<V> {
+type MenuLabel = string | {
+ name: string;
+ hoverable?: boolean;
+ selectable?: boolean;
+ props?: Record<string, any>;
+};
+
+interface IMenuItemBase<TLocaleKey extends string, TValue> {
/** ID of the menu item. Normally it should be the same as the ID of the command that it would invoke. */
id: string;
@@ -41,53 +48,39 @@ interface IMenuItemBase<V> {
commandId?: string;
subId?: string;
- title?: string;
+ title?: TLocaleKey;
description?: string;
icon?: string | Observable<string>;
- tooltip?: string;
+ tooltip?: TLocaleKey;
slot?: boolean;
type: MenuItemType;
/**
* Custom label component id.
*/
- label?:
- | string
- | {
- name: string;
- hoverable?: boolean;
- selectable?: boolean;
- props?: Record<string, any>;
- }; // custom component, send to CustomLabel label property
+ label?: MenuLabel; // custom component, send to CustomLabel label property
hidden$?: Observable<boolean>;
disabled$?: Observable<boolean>;
params?: any | Function;
/** On observable value that should emit the value of the corresponding selection component. */
- value$?: Observable<V>;
+ value$?: Observable<TValue>;
}
-export interface IMenuButtonItem<V = undefined> extends IMenuItemBase<V> {
+export interface IMenuButtonItem<TLocaleKey extends string = string, TValue = undefined> extends IMenuItemBase<TLocaleKey, TValue> {
type: MenuItemType.BUTTON;
activated$?: Observable<boolean>;
}
-export interface IValueOption<T = undefined> {
+export interface IValueOption<TLocaleKey extends string = string, TValue = undefined> {
id?: string;
value?: string | number;
- value$?: Observable<T>;
+ value$?: Observable<TValue>;
params?: any;
slot?: boolean;
- label?:
- | string
- | {
- name: string;
- hoverable?: boolean;
- selectable?: boolean;
- props?: Record<string, string | number | Array<{ [x: string | number]: string }>>;
- }; // custom component, send to CustomLabel label property
+ label?: MenuLabel; // custom component, send to CustomLabel label property
icon?: string;
- tooltip?: string;
+ tooltip?: TLocaleKey;
style?: object;
disabled?: boolean;
commandId?: string;
@@ -98,7 +91,11 @@ export interface ICustomComponentProps<T> {
onChange: (v: T) => void;
}
-export interface IMenuSelectorItem<V = MenuItemDefaultValueType, T = undefined> extends IMenuItemBase<V> {
+export interface IMenuSelectorItem<
+ TLocaleKey extends string = string,
+ TValue = MenuItemDefaultValueType,
+ TOptionValue = undefined
+> extends IMenuItemBase<TLocaleKey, TValue> {
type: MenuItemType.SELECTOR | MenuItemType.BUTTON_SELECTOR | MenuItemType.SUBITEMS;
/**
@@ -113,32 +110,38 @@ export interface IMenuSelectorItem<V = MenuItemDefaultValueType, T = undefined>
// One is a special component, such as color picker, after selection directly use its value to trigger command
// One is another menu's id, directly rendered as another menu
/** Options or IDs of registered components. */
- selections?: Array<IValueOption<T>> | Observable<Array<IValueOption<T>>>;
+ selections?: Array<IValueOption<TLocaleKey, TOptionValue>> | Observable<Array<IValueOption<TLocaleKey, TOptionValue>>>;
/** If `type` is `MenuItemType.BUTTON_SELECTOR`, this determines if the button is activated. */
activated$?: Observable<boolean>;
}
-export function isMenuSelectorItem<T extends MenuItemDefaultValueType>(v: IMenuItem): v is IMenuSelectorItem<T> {
+export type MenuItemDefaultValueType = string | number | undefined;
+
+export type IMenuItem<TLocaleKey extends string = string> =
+ | IMenuButtonItem<TLocaleKey, MenuItemDefaultValueType>
+ | IMenuSelectorItem<TLocaleKey, MenuItemDefaultValueType, any>;
+
+export function isMenuSelectorItem<T extends MenuItemDefaultValueType, TLocaleKey extends string = string>(
+ v: IMenuItem<TLocaleKey>
+): v is IMenuSelectorItem<TLocaleKey, T, any> {
return v.type === MenuItemType.SELECTOR || v.type === MenuItemType.SUBITEMS;
}
-export function isMenuButtonSelectorItem<T extends MenuItemDefaultValueType>(v: IMenuItem): v is IMenuSelectorItem<T> {
+export function isMenuButtonSelectorItem<T extends MenuItemDefaultValueType, TLocaleKey extends string = string>(
+ v: IMenuItem<TLocaleKey>
+): v is IMenuSelectorItem<TLocaleKey, T, any> {
return v.type === MenuItemType.BUTTON_SELECTOR;
}
-export type MenuItemDefaultValueType = string | number | undefined;
-
-export type IMenuItem = IMenuButtonItem<MenuItemDefaultValueType> | IMenuSelectorItem<MenuItemDefaultValueType, any>;
-
-export type IDisplayMenuItem<T extends IMenuItem> = T & {
+export type IDisplayMenuItem<T extends IMenuItem = IMenuItem> = T & {
shortcut?: string;
};
-export type MenuItemConfig = Partial<Omit<IMenuItem, 'id' | 'subId' | 'value$' | 'hidden$' | 'disabled$' | 'activated$' | 'icon$'> & {
+export type MenuItemConfig<TLocaleKey extends string = string> = Partial<Omit<IMenuItem<TLocaleKey>, 'id' | 'subId' | 'value$' | 'hidden$' | 'disabled$' | 'activated$' | 'icon$'> & {
hidden?: boolean;
disabled?: boolean;
activated?: boolean;
}>;
-export type MenuConfig = Record<string, MenuItemConfig>;
-export type IMenuItemFactory = (accessor: IAccessor, menuConfig?: MenuConfig) => IMenuItem;
+export type MenuConfig<TLocaleKey extends string = string> = Record<string, MenuItemConfig<TLocaleKey>>;
+export type IMenuItemFactory<TLocaleKey extends string = string> = (accessor: IAccessor, menuConfig?: MenuConfig<TLocaleKey>) => IMenuItem<TLocaleKey>;
diff --git a/packages/ui/src/views/components/context-menu/MobileContextMenu.tsx b/packages/ui/src/views/components/context-menu/MobileContextMenu.tsx
index d9309ede47..92653253f5 100644
--- a/packages/ui/src/views/components/context-menu/MobileContextMenu.tsx
+++ b/packages/ui/src/views/components/context-menu/MobileContextMenu.tsx
@@ -15,6 +15,7 @@
*/
import type { IMouseEvent } from '@univerjs/engine-render';
+import type { LocaleKey } from '../../../locale/types';
import { ICommandService, LocaleService } from '@univerjs/core';
import { ConfigContext } from '@univerjs/design';
import { CloseIcon } from '@univerjs/icons';
@@ -79,9 +80,9 @@ export function MobileContextMenu() {
const sheetTitle = useMemo(() => {
switch (menuType) {
case ContextMenuPosition.ROW_HEADER:
- return localeService.t('ui.row');
+ return localeService.t<LocaleKey>('ui.row');
case ContextMenuPosition.COL_HEADER:
- return localeService.t('ui.column');
+ return localeService.t<LocaleKey>('ui.column');
default:
return '';
}
@@ -95,7 +96,7 @@ export function MobileContextMenu() {
<div dir={direction} className="univer-fixed univer-inset-0 univer-z-[1080] univer-flex univer-items-end">
<button
type="button"
- aria-label={localeService.t('ui.rangeSelector.cancel')}
+ aria-label={localeService.t<LocaleKey>('ui.rangeSelector.cancel')}
className="univer-absolute univer-inset-0 univer-bg-[rgba(15,23,42,0.32)] univer-backdrop-blur-[2px]"
onClick={handleClose}
/>
@@ -126,7 +127,7 @@ export function MobileContextMenu() {
</div>
<button
type="button"
- aria-label={localeService.t('ui.rangeSelector.cancel')}
+ aria-label={localeService.t<LocaleKey>('ui.rangeSelector.cancel')}
className="
univer-flex univer-size-8 univer-shrink-0 univer-appearance-none univer-items-center
univer-justify-center univer-rounded-full univer-border-0 univer-bg-white univer-p-0
diff --git a/packages/ui/src/views/custom-label/CustomLabel.tsx b/packages/ui/src/views/custom-label/CustomLabel.tsx
index 2896d39b3d..51afe2494e 100644
--- a/packages/ui/src/views/custom-label/CustomLabel.tsx
+++ b/packages/ui/src/views/custom-label/CustomLabel.tsx
@@ -33,7 +33,7 @@ export type ICustomLabelProps<T = undefined> = {
onChange?(v: string | number): void;
title?: ReactNode;
-} & Pick<IMenuSelectorItem<unknown>, 'label' | 'icon'>;
+} & Pick<IMenuSelectorItem<string, unknown>, 'label' | 'icon'>;
/**
* The component to render toolbar item label and menu item label.
diff --git a/packages/ui/src/views/menu/mobile/MobileMenu.tsx b/packages/ui/src/views/menu/mobile/MobileMenu.tsx
index a0eef8fa7e..ab96b56fd5 100644
--- a/packages/ui/src/views/menu/mobile/MobileMenu.tsx
+++ b/packages/ui/src/views/menu/mobile/MobileMenu.tsx
@@ -38,7 +38,7 @@ type MobileMenuView =
kind: 'options';
title?: string;
options: IValueOption[];
- menuItem: IDisplayMenuItem<IMenuSelectorItem<MenuItemDefaultValueType, any>>;
+ menuItem: IDisplayMenuItem<IMenuSelectorItem<string, MenuItemDefaultValueType, any>>;
menuKey: string;
currentValue: MenuItemDefaultValueType;
};
@@ -281,7 +281,7 @@ function MobileSchemaRow(props: {
function MobileSelectionOptionsView(props: {
options: IValueOption[];
menuKey: string;
- menuItem: IDisplayMenuItem<IMenuSelectorItem<MenuItemDefaultValueType, any>>;
+ menuItem: IDisplayMenuItem<IMenuSelectorItem<string, MenuItemDefaultValueType, any>>;
currentValue: MenuItemDefaultValueType;
onExecute?: IBaseMenuProps['onOptionSelect'];
}) {
@@ -307,7 +307,7 @@ function MobileSelectionOptionsView(props: {
function MobileSelectionOptionRow(props: {
option: IValueOption;
menuKey: string;
- menuItem: IDisplayMenuItem<IMenuSelectorItem<MenuItemDefaultValueType, any>>;
+ menuItem: IDisplayMenuItem<IMenuSelectorItem<string, MenuItemDefaultValueType, any>>;
currentValue: MenuItemDefaultValueType;
bordered: boolean;
onExecute?: IBaseMenuProps['onOptionSelect'];
@@ -365,7 +365,7 @@ function useMobileSchemaInteraction(props: {
const menuManagerService = useDependency(IMenuManagerService);
const localeService = useDependency(LocaleService);
const menuItem = schema.item as IDisplayMenuItem<IMenuItem> | undefined;
- const selectorItem = menuItem as IDisplayMenuItem<IMenuSelectorItem<MenuItemDefaultValueType, any>> | undefined;
+ const selectorItem = menuItem as IDisplayMenuItem<IMenuSelectorItem<string, MenuItemDefaultValueType, any>> | undefined;
const disabled = useObservable<boolean>(menuItem?.disabled$, false);
const hidden = useObservable<boolean>(menuItem?.hidden$, false);
const value = useObservable<MenuItemDefaultValueType>(menuItem?.value$);
@@ -436,7 +436,7 @@ function useMobileSchemaInteraction(props: {
return;
}
- const buttonItem = menuItem as IDisplayMenuItem<IMenuButtonItem<MenuItemDefaultValueType>>;
+ const buttonItem = menuItem as IDisplayMenuItem<IMenuButtonItem<string, MenuItemDefaultValueType>>;
onExecute?.({
commandId: buttonItem.commandId,
value,
diff --git a/packages/uniscript/src/locale/types.ts b/packages/uniscript/src/locale/types.ts
new file mode 100644
index 0000000000..b83cb8e9ce
--- /dev/null
+++ b/packages/uniscript/src/locale/types.ts
@@ -0,0 +1,20 @@
+/**
+ * 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 type { LocaleLeafKeys } from '@univerjs/core';
+import type enUS from './en-US';
+
+export type LocaleKey = LocaleLeafKeys<typeof enUS>;
diff --git a/packages/uniscript/src/menu/menu.ts b/packages/uniscript/src/menu/menu.ts
index 653d1aaad3..a87bce93a2 100644
--- a/packages/uniscript/src/menu/menu.ts
+++ b/packages/uniscript/src/menu/menu.ts
@@ -16,21 +16,32 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuButtonItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
import { UniverInstanceType } from '@univerjs/core';
-import { RangeProtectionPermissionEditPoint, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission } from '@univerjs/sheets';
+import {
+ RangeProtectionPermissionEditPoint,
+ WorkbookEditablePermission,
+ WorksheetEditPermission,
+ WorksheetSetCellStylePermission,
+ WorksheetSetCellValuePermission,
+} from '@univerjs/sheets';
import { getCurrentRangeDisable$ } from '@univerjs/sheets-ui';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { ToggleScriptPanelOperation } from '../commands/operations/panel.operation';
-export function UniscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+export function UniscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
return {
id: ToggleScriptPanelOperation.id,
- title: 'toggle-script-panel',
+ title: 'uniscript.title',
tooltip: 'uniscript.tooltip.menu-button',
icon: 'CodeIcon',
type: MenuItemType.BUTTON,
// FIXME hidden$ and disabled$ are not correctly in doc
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
};
}
diff --git a/packages/uniscript/src/views/components/ScriptEditorPanel.tsx b/packages/uniscript/src/views/components/ScriptEditorPanel.tsx
index 23f6c4c2cd..6c646e55c0 100644
--- a/packages/uniscript/src/views/components/ScriptEditorPanel.tsx
+++ b/packages/uniscript/src/views/components/ScriptEditorPanel.tsx
@@ -15,6 +15,7 @@
*/
import type { IDisposable, Nullable } from '@univerjs/core';
+import type { LocaleKey } from '../../locale/types';
import { DisposableCollection, LocaleService, ThemeService, toDisposable } from '@univerjs/core';
import { Button, MessageType } from '@univerjs/design';
import { IMessageService, IShortcutService, useDependency } from '@univerjs/ui';
@@ -97,7 +98,7 @@ export function ScriptEditorPanel() {
</div>
<div className="univer-mt-2.5">
<Button variant="primary" onClick={startExecution}>
- {localeService.t('uniscript.panel.execute')}
+ {localeService.t<LocaleKey>('uniscript.panel.execute')}
</Button>
</div>
</div>
@@ -116,13 +117,13 @@ function useExecution(getMonacoEditor: () => Nullable<editor.IStandaloneCodeEdit
.execute(model.getValue())
.then(() => {
messageService.show({
- content: localeService.t('uniscript.message.success'),
+ content: localeService.t<LocaleKey>('uniscript.message.success'),
type: MessageType.Success,
});
})
.catch(() => {
messageService.show({
- content: localeService.t('uniscript.message.failed'),
+ content: localeService.t<LocaleKey>('uniscript.message.failed'),
type: MessageType.Error,
});
});