diff --git a/docs/en/guide/command-get.md b/docs/en/guide/command-get.md index eab021d..cd74701 100644 --- a/docs/en/guide/command-get.md +++ b/docs/en/guide/command-get.md @@ -128,3 +128,13 @@ const { footer: string } = await instance.command.getText() ``` + +## getLocale + +功能:Get current locale + +用法: + +```javascript +const locale = await instance.command.getLocale() +``` \ No newline at end of file diff --git a/docs/guide/command-get.md b/docs/guide/command-get.md index 967bd65..2fb800b 100644 --- a/docs/guide/command-get.md +++ b/docs/guide/command-get.md @@ -128,3 +128,13 @@ const { footer: string } = await instance.command.getText() ``` + +## getLocale + +功能:获取当前语言 + +用法: + +```javascript +const locale = await instance.command.getLocale() +``` diff --git a/src/editor/core/command/Command.ts b/src/editor/core/command/Command.ts index c386fe4..c66e786 100644 --- a/src/editor/core/command/Command.ts +++ b/src/editor/core/command/Command.ts @@ -86,6 +86,7 @@ export class Command { public getRangeContext: CommandAdapt['getRangeContext'] public getPaperMargin: CommandAdapt['getPaperMargin'] public getSearchNavigateInfo: CommandAdapt['getSearchNavigateInfo'] + public getLocale: CommandAdapt['getLocale'] constructor(adapt: CommandAdapt) { // 全局命令 @@ -182,5 +183,6 @@ export class Command { this.getCatalog = adapt.getCatalog.bind(adapt) this.getPaperMargin = adapt.getPaperMargin.bind(adapt) this.getSearchNavigateInfo = adapt.getSearchNavigateInfo.bind(adapt) + this.getLocale = adapt.getLocale.bind(adapt) } } diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index ad76899..1a10d1f 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -1837,6 +1837,10 @@ export class CommandAdapt { this.i18n.setLocale(payload) } + public getLocale(): string { + return this.i18n.getLocale() + } + public getCatalog(): Promise { return this.workerManager.getCatalog() } diff --git a/src/editor/core/i18n/I18n.ts b/src/editor/core/i18n/I18n.ts index 5ba4f28..486005a 100644 --- a/src/editor/core/i18n/I18n.ts +++ b/src/editor/core/i18n/I18n.ts @@ -17,6 +17,10 @@ export class I18n { this.langMap.set(locale, mergeObject(sourceLang || zhCN, lang)) } + public getLocale(): string { + return this.currentLocale + } + public setLocale(locale: string) { this.currentLocale = locale }