2020-08-03 19:16:13 +08:00
|
|
|
import defaultLang from './lang/en'
|
2020-07-28 20:18:11 +08:00
|
|
|
|
|
|
|
let lang = defaultLang
|
|
|
|
|
2020-08-03 19:16:13 +08:00
|
|
|
export const t = (path:string): string => {
|
|
|
|
let value
|
2020-07-28 20:18:11 +08:00
|
|
|
const array = path.split('.')
|
|
|
|
let current = lang
|
|
|
|
for (let i = 0, j = array.length; i < j; i++) {
|
|
|
|
const property = array[i]
|
2020-08-25 09:58:26 +08:00
|
|
|
value = current[property]
|
2020-08-03 19:16:13 +08:00
|
|
|
if (i === j - 1) return value
|
2020-07-28 20:18:11 +08:00
|
|
|
if (!value) return ''
|
|
|
|
current = value
|
|
|
|
}
|
|
|
|
return ''
|
|
|
|
}
|
|
|
|
|
2020-08-03 19:16:13 +08:00
|
|
|
export const use = (l): void => {
|
2020-07-28 20:18:11 +08:00
|
|
|
lang = l || lang
|
|
|
|
}
|
|
|
|
|
2020-08-03 19:16:13 +08:00
|
|
|
export default { use, t }
|