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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
refactor(i18n): type static locale calls and remove drawing label helpers (#7730)
白熱360c5ccb5e40
diff --git a/packages/docs-hyper-link-ui/src/services/mobile/hyper-link-popup.service.ts b/packages/docs-hyper-link-ui/src/services/mobile/hyper-link-popup.service.tsindex 9875bc762c..cc72f12756 100644--- a/packages/docs-hyper-link-ui/src/services/mobile/hyper-link-popup.service.ts+++ b/packages/docs-hyper-link-ui/src/services/mobile/hyper-link-popup.service.ts@@ -15,6 +15,7 @@*/import type { IDisposable, ITextRangeParam } from '@univerjs/core';+import type { LocaleKey } from '../../locale/types';import type { ILinkInfo } from '../hyper-link-popup.service';import { MOBILE_DOC_ELEMENT_MENU } from '@univerjs/docs-ui';import { MobileDocHyperLinkEdit } from '../../views/MobileDocHyperLinkEdit';@@ -25,7 +26,7 @@ export class MobileDocHyperLinkPopupService extends DocHyperLinkPopupService {protected override _openEditSurface(_activeRange: ITextRangeParam, _unitId: string): IDisposable {return this._dialogService.open({id: 'doc-mobile-hyper-link-editor',- title: { title: this._localeService.t('docs-hyper-link-ui.menu.tooltip') },+ title: { title: this._localeService.t<LocaleKey>('docs-hyper-link-ui.menu.tooltip') },children: { label: MobileDocHyperLinkEdit.componentKey },maskClosable: false,onClose: () => this.hideEditPopup(),@@ -38,7 +39,7 @@ export class MobileDocHyperLinkPopupService extends DocHyperLinkPopupService {}return this._dialogService.open({id: 'doc-mobile-hyper-link-viewer',- title: { title: this._localeService.t('docs-hyper-link-ui.menu.tooltip') },+ title: { title: this._localeService.t<LocaleKey>('docs-hyper-link-ui.menu.tooltip') },children: { label: MobileDocLinkPopup.componentKey },onClose: () => this.hideInfoPopup(),});diff --git a/packages/docs-ui/src/commands/operations/paragraph-permission.operation.ts b/packages/docs-ui/src/commands/operations/paragraph-permission.operation.tsindex b82a54bae6..4d03388275 100644--- a/packages/docs-ui/src/commands/operations/paragraph-permission.operation.ts+++ b/packages/docs-ui/src/commands/operations/paragraph-permission.operation.ts@@ -15,6 +15,7 @@*/import type { DocumentDataModel, ICommand } from '@univerjs/core';+import type { LocaleKey } from '../../locale/types';import { CommandType, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';import { getDocumentParagraphPermissionObjectId, SetDocumentPermissionCommand } from '@univerjs/docs';import { IRenderManagerService } from '@univerjs/engine-render';@@ -39,7 +40,7 @@ export const OpenDocParagraphPermissionOperation: ICommand = {}return openObjectPermissionDialog(accessor, {target: { unitId, objectId: getDocumentParagraphPermissionObjectId(segmentId, paragraphId), objectType: UnitObject.DocumentParagraph },- name: accessor.get(LocaleService).t('docs-ui.objectPermission.paragraph'),+ name: accessor.get(LocaleService).t<LocaleKey>('docs-ui.objectPermission.paragraph'),commandId: SetDocumentPermissionCommand.id,exists,});diff --git a/packages/docs-ui/src/views/mobile-doc-toolbar/MobileDocToolbar.tsx b/packages/docs-ui/src/views/mobile-doc-toolbar/MobileDocToolbar.tsxindex 87491dd802..086e33d496 100644--- a/packages/docs-ui/src/views/mobile-doc-toolbar/MobileDocToolbar.tsx+++ b/packages/docs-ui/src/views/mobile-doc-toolbar/MobileDocToolbar.tsx@@ -16,6 +16,7 @@import type { IMenuSchema, IValueOption, MobileDrawerSnap } from '@univerjs/ui';import type { ReactNode } from 'react';+import type { LocaleKey } from '../../locale/types';import type { MobileDocSelectionRenderService } from '../../services/mobile/doc-selection-render.service';import { ICommandService, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';import { clsx, resetButtonClassName } from '@univerjs/design';@@ -209,7 +210,7 @@ export function MobileDocEditDoneButton() {return (<buttontype="button"- aria-label={localeService.t('docs-ui.mobile.done')}+ aria-label={localeService.t<LocaleKey>('docs-ui.mobile.done')}className={clsx(resetButtonClassName, `univer-flex univer-size-10 univer-items-center univer-justify-center univer-rounded-lguniver-text-primary-600@@ -276,7 +277,7 @@ export function MobileDocToolbar() {return (<buttontype="button"- aria-label={localeService.t('docs-ui.mobile.edit')}+ aria-label={localeService.t<LocaleKey>('docs-ui.mobile.edit')}className={clsx(resetButtonClassName, `univer-pointer-events-auto univer-absolute univer-bottom-4 univer-z-30 univer-flex univer-size-14univer-items-center univer-justify-center univer-rounded-full univer-bg-primary-600 univer-text-2xl@@ -382,37 +383,37 @@ export function MobileDocToolbar() {><MobileDocToolbarButtonactive={false}- label={localeService.t('docs-ui.mobile.insert')}+ label={localeService.t<LocaleKey>('docs-ui.mobile.insert')}icon={<QuickAddIcon />}onClick={() => openDrawer('insert')}/><MobileDocToolbarButtonactive={quickMenu === 'block'}- label={localeService.t('docs-ui.toolbar.heading.tooltip')}+ label={localeService.t<LocaleKey>('docs-ui.toolbar.heading.tooltip')}icon={<TextTypeIcon />}onClick={() => toggleQuickMenu('block')}/><MobileDocToolbarButtonactive={false}- label={localeService.t('docs-ui.mobile.format')}+ label={localeService.t<LocaleKey>('docs-ui.mobile.format')}icon={<TextIcon />}onClick={() => openDrawer('format')}/><MobileDocToolbarButtonactive={quickMenu === 'align'}- label={localeService.t('docs-ui.paragraphMenu.alignAndIndent')}+ label={localeService.t<LocaleKey>('docs-ui.paragraphMenu.alignAndIndent')}icon={<AlignTextBothIcon />}onClick={() => toggleQuickMenu('align')}/><MobileDocToolbarButtonactive={false}- label={localeService.t('docs-ui.mobile.more')}+ label={localeService.t<LocaleKey>('docs-ui.mobile.more')}icon={<MoreHorizontalIcon />}onClick={() => openDrawer('more')}/><MobileDocToolbarButtonactive={false}- label={localeService.t('docs-ui.mobile.hideKeyboard')}+ label={localeService.t<LocaleKey>('docs-ui.mobile.hideKeyboard')}icon={<CloseIcon />}onClick={hideKeyboard}/>@@ -423,8 +424,8 @@ export function MobileDocToolbar() {<MobileDrawercomponentName="mobile-doc-toolbar-drawer"snap={drawerSnap}- expandLabel={localeService.t('docs-ui.mobile.expand')}- collapseLabel={localeService.t('docs-ui.mobile.collapse')}+ expandLabel={localeService.t<LocaleKey>('docs-ui.mobile.expand')}+ collapseLabel={localeService.t<LocaleKey>('docs-ui.mobile.collapse')}onSnapChange={setDrawerSnap}onClose={closeDrawer}header={(@@ -438,7 +439,7 @@ export function MobileDocToolbar() {{navigation && (<buttontype="button"- aria-label={localeService.t('docs-ui.mobile.back')}+ aria-label={localeService.t<LocaleKey>('docs-ui.mobile.back')}className={clsx(resetButtonClassName, `univer-flex univer-size-12 univer-items-center univer-justify-centeruniver-rounded-lg univer-text-2xl univer-text-gray-700@@ -463,7 +464,7 @@ export function MobileDocToolbar() {</div><buttontype="button"- aria-label={localeService.t('docs-ui.mobile.close')}+ aria-label={localeService.t<LocaleKey>('docs-ui.mobile.close')}className={clsx(resetButtonClassName, `univer-flex univer-size-12 univer-items-center univer-justify-center univer-rounded-lguniver-text-2xl univer-text-gray-700@@ -480,7 +481,7 @@ export function MobileDocToolbar() {floatingActions={(<buttontype="button"- aria-label={localeService.t('docs-ui.mobile.keyboard')}+ aria-label={localeService.t<LocaleKey>('docs-ui.mobile.keyboard')}className={clsx(resetButtonClassName, `univer-pointer-events-auto univer-flex univer-size-12 univer-items-centeruniver-justify-center univer-rounded-full univer-bg-gray-0 univer-text-xldiff --git a/packages/drawing-ui/src/index.ts b/packages/drawing-ui/src/index.tsindex 4dbd43c375..460d9e740c 100644--- a/packages/drawing-ui/src/index.ts+++ b/packages/drawing-ui/src/index.ts@@ -76,8 +76,6 @@ export {} from './views/object-list-panel/object-list-panel-layer';export type { ObjectListPanelSectionId } from './views/object-list-panel/object-list-panel-layer';export {- getObjectListPanelLabels,- getObjectListPanelTypeName,ObjectListPanelBase,} from './views/object-list-panel/ObjectListPanelBase';export type {diff --git a/packages/drawing-ui/src/views/object-list-panel/ObjectListPanelBase.tsx b/packages/drawing-ui/src/views/object-list-panel/ObjectListPanelBase.tsxindex dc03be34b0..f5ca41f9e9 100644--- a/packages/drawing-ui/src/views/object-list-panel/ObjectListPanelBase.tsx+++ b/packages/drawing-ui/src/views/object-list-panel/ObjectListPanelBase.tsx@@ -14,7 +14,6 @@* limitations under the License.*/-import type { LocaleService } from '@univerjs/core';import type { ComponentProps, ComponentType, DragEvent, FocusEvent, KeyboardEvent, MouseEvent, ReactNode } from 'react';import { Button, clsx, Input, StateIconButton } from '@univerjs/design';import {@@ -111,46 +110,6 @@ export type ObjectListPanelTypeNameKey =| 'unit'| 'video';-export function getObjectListPanelLabels(localeService: LocaleService): IObjectListPanelLabels {- return {- title: localeService.t('drawing-ui.objectListPanel.title'),- empty: localeService.t('drawing-ui.objectListPanel.empty'),- showAll: localeService.t('drawing-ui.objectListPanel.showAll'),- hideAll: localeService.t('drawing-ui.objectListPanel.hideAll'),- lockAll: localeService.t('drawing-ui.objectListPanel.lockAll'),- unlockAll: localeService.t('drawing-ui.objectListPanel.unlockAll'),- moveForward: localeService.t('drawing-ui.objectListPanel.moveForward'),- moveBackward: localeService.t('drawing-ui.objectListPanel.moveBackward'),- close: localeService.t('drawing-ui.objectListPanel.close'),- show: localeService.t('drawing-ui.objectListPanel.show'),- hide: localeService.t('drawing-ui.objectListPanel.hide'),- lock: localeService.t('drawing-ui.objectListPanel.lock'),- unlock: localeService.t('drawing-ui.objectListPanel.unlock'),- lockHint: localeService.t('drawing-ui.objectListPanel.lockHint'),- unlockHint: localeService.t('drawing-ui.objectListPanel.unlockHint'),- name: localeService.t('drawing-ui.objectListPanel.name'),- nameInput: localeService.t('drawing-ui.objectListPanel.nameInput'),- description: localeService.t('drawing-ui.objectListPanel.description'),- descriptionPlaceholder: localeService.t('drawing-ui.objectListPanel.descriptionPlaceholder'),- details: localeService.t('drawing-ui.objectListPanel.details'),- noSelection: localeService.t('drawing-ui.objectListPanel.noSelection'),- locate: localeService.t('drawing-ui.objectListPanel.locate'),- expand: localeService.t('drawing-ui.objectListPanel.expand'),- collapse: localeService.t('drawing-ui.objectListPanel.collapse'),- dragToReorder: localeService.t('drawing-ui.objectListPanel.dragToReorder'),- search: localeService.t('drawing-ui.objectListPanel.search'),- filterAll: localeService.t('drawing-ui.objectListPanel.filterAll'),- filterHidden: localeService.t('drawing-ui.objectListPanel.filterHidden'),- filterLocked: localeService.t('drawing-ui.objectListPanel.filterLocked'),- sectionCanvas: localeService.t('drawing-ui.objectListPanel.sectionCanvas'),- sectionFloating: localeService.t('drawing-ui.objectListPanel.sectionFloating'),- };-}--export function getObjectListPanelTypeName(localeService: LocaleService, typeName: ObjectListPanelTypeNameKey): string {- return localeService.t(`drawing-ui.objectListPanel.typeNames.${typeName}`);-}-export interface IObjectListPanelBaseProps {items: IObjectListPanelItem[];selectedIds: string[];diff --git a/packages/drawing-ui/src/views/object-list-panel/__tests__/ObjectListPanelBase.spec.tsx b/packages/drawing-ui/src/views/object-list-panel/__tests__/ObjectListPanelBase.spec.tsxindex 6b4ecd0acc..d658981187 100644--- a/packages/drawing-ui/src/views/object-list-panel/__tests__/ObjectListPanelBase.spec.tsx+++ b/packages/drawing-ui/src/views/object-list-panel/__tests__/ObjectListPanelBase.spec.tsx@@ -24,7 +24,7 @@ import { createRoot } from 'react-dom/client';import { afterEach, beforeEach, describe, expect, it } from 'vitest';import enUS from '../../../locale/en-US';import { MobileObjectListPanel } from '../MobileObjectListPanel';-import { getObjectListPanelLabels, ObjectListPanelBase } from '../ObjectListPanelBase';+import { ObjectListPanelBase } from '../ObjectListPanelBase';Object.defineProperty(globalThis, 'IS_REACT_ACT_ENVIRONMENT', { value: true, configurable: true });@@ -40,6 +40,7 @@ describe.each([beforeEach(() => {univer = new Univer({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: enUS } });+ univer.__getInjector().get(LocaleService).setDirection('ltr');container = document.createElement('div');document.body.appendChild(container);root = createRoot(container);@@ -75,9 +76,9 @@ describe.each([return (<RediContext.Provider value={{ injector }}><PanelComponent+ labels={enUS['drawing-ui'].objectListPanel}items={items}selectedIds={[]}- labels={getObjectListPanelLabels(injector.get(LocaleService))}onSelect={() => {}}onCommitName={() => {}}onCommitDescription={() => {}}diff --git a/packages/ui/src/controllers/error/error.controller.ts b/packages/ui/src/controllers/error/error.controller.tsindex e3027cc7eb..affe951b55 100644--- a/packages/ui/src/controllers/error/error.controller.ts+++ b/packages/ui/src/controllers/error/error.controller.ts@@ -14,6 +14,7 @@* limitations under the License.*/+import type { LocaleKey } from '../../locale/types';import { Disposable, ErrorService, Inject, IPermissionService, LocaleService } from '@univerjs/core';import { MessageType } from '@univerjs/design';import { IMessageService } from '../../services/message/message.service';@@ -46,7 +47,7 @@ export class ErrorController extends Disposable {if (!repeated) {this._messageService.show({id: PERMISSION_MESSAGE_ID,- content: this._localeService.t('ui.objectPermission.operationDenied'),+ content: this._localeService.t<LocaleKey>('ui.objectPermission.operationDenied'),type: MessageType.Warning,duration: PERMISSION_MESSAGE_DURATION,});