feat: add getLocale api #248

This commit is contained in:
Hufe921
2023-08-17 21:32:16 +08:00
parent 8f145e251b
commit fef6ddf7a8
5 changed files with 30 additions and 0 deletions
+10
View File
@@ -128,3 +128,13 @@ const {
footer: string footer: string
} = await instance.command.getText() } = await instance.command.getText()
``` ```
## getLocale
功能:Get current locale
用法:
```javascript
const locale = await instance.command.getLocale()
```
+10
View File
@@ -128,3 +128,13 @@ const {
footer: string footer: string
} = await instance.command.getText() } = await instance.command.getText()
``` ```
## getLocale
功能:获取当前语言
用法:
```javascript
const locale = await instance.command.getLocale()
```
+2
View File
@@ -86,6 +86,7 @@ export class Command {
public getRangeContext: CommandAdapt['getRangeContext'] public getRangeContext: CommandAdapt['getRangeContext']
public getPaperMargin: CommandAdapt['getPaperMargin'] public getPaperMargin: CommandAdapt['getPaperMargin']
public getSearchNavigateInfo: CommandAdapt['getSearchNavigateInfo'] public getSearchNavigateInfo: CommandAdapt['getSearchNavigateInfo']
public getLocale: CommandAdapt['getLocale']
constructor(adapt: CommandAdapt) { constructor(adapt: CommandAdapt) {
// 全局命令 // 全局命令
@@ -182,5 +183,6 @@ export class Command {
this.getCatalog = adapt.getCatalog.bind(adapt) this.getCatalog = adapt.getCatalog.bind(adapt)
this.getPaperMargin = adapt.getPaperMargin.bind(adapt) this.getPaperMargin = adapt.getPaperMargin.bind(adapt)
this.getSearchNavigateInfo = adapt.getSearchNavigateInfo.bind(adapt) this.getSearchNavigateInfo = adapt.getSearchNavigateInfo.bind(adapt)
this.getLocale = adapt.getLocale.bind(adapt)
} }
} }
+4
View File
@@ -1837,6 +1837,10 @@ export class CommandAdapt {
this.i18n.setLocale(payload) this.i18n.setLocale(payload)
} }
public getLocale(): string {
return this.i18n.getLocale()
}
public getCatalog(): Promise<ICatalog | null> { public getCatalog(): Promise<ICatalog | null> {
return this.workerManager.getCatalog() return this.workerManager.getCatalog()
} }
+4
View File
@@ -17,6 +17,10 @@ export class I18n {
this.langMap.set(locale, <ILang>mergeObject(sourceLang || zhCN, lang)) this.langMap.set(locale, <ILang>mergeObject(sourceLang || zhCN, lang))
} }
public getLocale(): string {
return this.currentLocale
}
public setLocale(locale: string) { public setLocale(locale: string) {
this.currentLocale = locale this.currentLocale = locale
} }