|  |  |  | 
|---|
|  |  |  | import { globalState } from '../config.js' | 
|---|
|  |  |  | import enUS from '../locales/en_US.js'; | 
|---|
|  |  |  | import zhCN from '../locales/zh_CN.js'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | export const formatMessage = (id, defaultMessage) => { | 
|---|
|  |  |  | const localesType = { | 
|---|
|  |  |  | enUS, | 
|---|
|  |  |  | zhCN, | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const message = localesType[globalState.locale] | 
|---|
|  |  |  | if(message == null) { | 
|---|
|  |  |  | return defaultMessage; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(message[id] == null || message[id] == undefined) { | 
|---|
|  |  |  | return defaultMessage; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return message[id]; | 
|---|
|  |  |  | import { globalState } from '../config.js' | 
|---|
|  |  |  | import { post } from '@/utils/request.js' | 
|---|
|  |  |  |  | 
|---|
|  |  |  | export const formatMessage = (id, defaultMessage) => { | 
|---|
|  |  |  | const message = globalState.localeData; | 
|---|
|  |  |  | if(message == null) { | 
|---|
|  |  |  | return defaultMessage; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(message[id] == null || message[id] == undefined) { | 
|---|
|  |  |  | return defaultMessage; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return message[id]; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | export const loadData = async (locale) => { | 
|---|
|  |  |  | let resp = await post('/api/language/json',{ | 
|---|
|  |  |  | locale: locale | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | let result = resp.data; | 
|---|
|  |  |  | globalState.localeData = result.data; | 
|---|
|  |  |  | } | 
|---|