UNPKG

1.23 kBJavaScriptView Raw
1/* global __KOOT_SSR__:false, __KOOT_SSR_STATE__:false */
2const __devLocales = {}
3
4/**
5 * 根据当前环境,返回语言包对象的引用
6 * - 客户端: 当前语种的语言包对象 (仅当多语言类型为 `redux` 时)
7 * - 服务器端: 所有语种语言包合集对象
8 * @returns {Object}
9 */
10const getLocalesObject = () => {
11 if (__SERVER__) {
12 if (__DEV__) {
13 return __devLocales
14 } else if (typeof __KOOT_SSR__ === 'object')
15 return __KOOT_SSR__.locales
16 }
17 if (__CLIENT__) {
18 if (typeof __KOOT_SSR_STATE__ === 'object') {
19 return __KOOT_SSR_STATE__.locales
20 }
21 }
22 return false
23}
24
25/**
26 * @type {Object}
27 * 语言包对象
28 * - 客户端: 当前语种的语言包对象 (仅当多语言类型为 `redux` 时)
29 * - 服务器端: 所有语种语言包合集对象
30 */
31export const locales = (() => getLocalesObject() || {})()
32
33export const setLocales = (newLocales = {}) => {
34 // const obj = getLocalesObject()
35 if (locales) Object.assign(locales, newLocales)
36 // console.log({ newLocales, obj, locales, 'global.__KOOT_SSR__': global.__KOOT_SSR__ })
37 return locales
38}
39
40export default locales