UNPKG

yyzone

Version:

yyzone vue components and utils

42 lines (34 loc) 755 B
import zhs from './lang/zh-CN' import zht from './lang/zh-TW' import en from './lang/en-US' let langObject = { zhs, zht, en, 'zh-CN': zhs, 'zh-TW': zht, 'en-US': en } let langType = 'zhs' let lang = langObject[langType] export const t = function (opt) { if(typeof opt != 'string') return '' let array = opt.split('.') let value = lang array.forEach((key) => { if(typeof value !== 'undefined') { value = value[key] } }) return value != undefined ? value : opt } export const locale = function (l, source = {}) { langType = l lang = { ...(langObject[l] || langObject.zhs), ...source } } export const getLang = function () { return langType }