feat:support partial fields to set i18n lang

This commit is contained in:
Hufe921
2023-02-13 14:19:45 +08:00
parent c9125635ea
commit 7287b576e8
4 changed files with 39 additions and 4 deletions
+8 -2
View File
@@ -1,6 +1,8 @@
import { ILang } from '../../interface/i18n/I18n'
import zhCN from './lang/zh-CN.json'
import en from './lang/en.json'
import { mergeObject } from '../../utils'
import { DeepPartial } from '../../interface/Common'
export class I18n {
@@ -11,8 +13,12 @@ export class I18n {
private currentLocale = 'zhCN'
public registerLangMap(locale: string, lang: ILang) {
this.langMap.set(locale, lang)
public registerLangMap(locale: string, lang: DeepPartial<ILang>) {
const sourceLang = this.langMap.get(locale)
this.langMap.set(
locale,
<ILang>mergeObject(sourceLang || zhCN, lang)
)
}
public setLocale(locale: string) {
+2 -1
View File
@@ -4,6 +4,7 @@ import { ContextMenu } from '../contextmenu/ContextMenu'
import { Shortcut } from '../shortcut/Shortcut'
import { I18n } from '../i18n/I18n'
import { ILang } from '../../interface/i18n/I18n'
import { DeepPartial } from '../../interface/Common'
interface IRegisterPayload {
contextMenu: ContextMenu;
@@ -15,7 +16,7 @@ export class Register {
public contextMenuList: (payload: IRegisterContextMenu[]) => void
public shortcutList: (payload: IRegisterShortcut[]) => void
public langMap: (locale: string, lang: ILang) => void
public langMap: (locale: string, lang: DeepPartial<ILang>) => void
constructor(payload: IRegisterPayload) {
const { contextMenu, shortcut, i18n } = payload