feat: add getLocale api #248

pr675
Hufe921 3 years ago
parent 8f145e251b
commit fef6ddf7a8

@ -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()
```

@ -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()
```

@ -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)
} }
} }

@ -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()
} }

@ -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
} }

Loading…
Cancel
Save