@vxe-ui/core
Version:
Vxe UI core library
36 lines (35 loc) • 1.18 kB
JavaScript
import XEUtils from 'xe-utils';
import { VxeCore } from './core';
import { i18nConfigStore } from './i18nStore';
import { globalConfigStore } from './configStore';
let checkInstall = false;
export function getI18n(key, args) {
const { langMaps, language } = i18nConfigStore;
const { i18n } = globalConfigStore;
if (i18n) {
return `${i18n(key, args) || ''}`;
}
if (!checkInstall) {
if (!langMaps[language]) {
console.error(`[vxe core] 语言包未安装。Language not installed. https://${VxeCore.uiVersion ? 'vxeui.com' : 'vxetable.cn'}/#/start/i18n`);
}
checkInstall = true;
}
return XEUtils.toFormatString(XEUtils.get(langMaps[language], key, key), args);
}
export function setLanguage(locale) {
i18nConfigStore.language = locale || 'zh-CN';
return VxeCore;
}
export function setI18n(locale, data) {
i18nConfigStore.langMaps[locale] = Object.assign({}, data);
return VxeCore;
}
export function hasLanguage(language) {
const { langMaps } = i18nConfigStore;
return !!langMaps[language];
}
export function getLanguage() {
const { language } = i18nConfigStore;
return language;
}