diff --git a/packages/gbeata/src/locale/index.ts b/packages/gbeata/src/locale/index.ts index 3d445267..3fb941d2 100644 --- a/packages/gbeata/src/locale/index.ts +++ b/packages/gbeata/src/locale/index.ts @@ -1,26 +1,35 @@ -import { AnyKeyProps } from '../types/AnyKeyProps' -import zhCN from './zh_CN' -import enUS from './en_US' -import jaJP from './ja_JP' -import koKr from './ko_KR' +import { AnyKeyProps } from '../types/AnyKeyProps'; +import enUS from './en_US'; +import jaJP from './ja_JP'; +import koKr from './ko_KR'; +import zhCN from './zh_CN'; -export let activeLang = localStorage.getItem('MULTIWAY_LOCALE') || 'zh_CN' +export let activeLang = localStorage.getItem('MULTIWAY_LOCALE') || 'zh_CN'; +// activeLang = JSON.parse(activeLang); let langMap: AnyKeyProps = { zh_CN: zhCN, en_US: enUS, ja_JP: jaJP, - ko_KR: koKr -} + ko_KR: koKr, +}; export const isJP = () => { - return activeLang === 'ja_JP' -} + return activeLang === 'ja_JP'; +}; /** 设置语言 */ export const setLanguage = (lang: string) => { - activeLang = lang - localStorage.setItem('MULTIWAY_LOCALE', lang) -} + activeLang = lang; + localStorage.setItem('MULTIWAY_LOCALE', lang); +}; -export default langMap[activeLang] +const handler: any = { + get(target: any, prop: any) { + return target?.[activeLang] + ? target?.[activeLang]?.[prop] + : target?.[JSON.parse(activeLang)]?.[prop] || '-'; + }, +}; + +export default new Proxy(langMap, handler);