md
This commit is contained in:
parent
62a6f4d193
commit
4c5a9569ff
26
public/manifest copy.json
Normal file
26
public/manifest copy.json
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"short_name": "XDADAN",
|
||||||
|
"name": "XDADAN",
|
||||||
|
"description": "XDADAN 是一款适合多业务的云平台系统",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "favicon.png",
|
||||||
|
"sizes": "64x64 32x32 24x24 16x16",
|
||||||
|
"type": "image/png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "favicon.png",
|
||||||
|
"type": "image/png",
|
||||||
|
"sizes": "192x192"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "favicon.png",
|
||||||
|
"type": "image/png",
|
||||||
|
"sizes": "512x512"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"start_url": ".",
|
||||||
|
"display": "standalone",
|
||||||
|
"background_color": "#FFFFFF",
|
||||||
|
"orientation": "portrait"
|
||||||
|
}
|
||||||
129
src/i18n/index copy.js
Executable file
129
src/i18n/index copy.js
Executable file
@ -0,0 +1,129 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import VueI18n from 'vue-i18n'
|
||||||
|
Vue.use(VueI18n)
|
||||||
|
import ElementLocale from 'element-ui/lib/locale'
|
||||||
|
import { getI18nMessages } from "@/api/common"
|
||||||
|
import Cookies from 'js-cookie'
|
||||||
|
|
||||||
|
// 引入各个语言配置文件
|
||||||
|
import zh from './config/zh-CN'
|
||||||
|
import en from './config/en'
|
||||||
|
// 读取浏览器默认语言
|
||||||
|
const defaultLanguage = (
|
||||||
|
navigator.language || navigator.browserLanguage
|
||||||
|
)
|
||||||
|
class I18n extends VueI18n {
|
||||||
|
constructor() {
|
||||||
|
super({
|
||||||
|
// locale: '',
|
||||||
|
// message: {},
|
||||||
|
locale: localStorage.getItem('locale') || 'zh-CN', // 设置默认语言
|
||||||
|
messages: {
|
||||||
|
zh,
|
||||||
|
en
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// vue i18n init
|
||||||
|
async init() {
|
||||||
|
const sLang = this.getLang();
|
||||||
|
await this.setLocale(sLang);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
// get/update language
|
||||||
|
getLang() {
|
||||||
|
// get define language
|
||||||
|
// 需要取cookies里面的值的话就加上
|
||||||
|
sLang = Cookies.get('locale') || navigator.language || 'zh-CN';
|
||||||
|
let sLang = navigator.language || 'zh-CN';
|
||||||
|
return sLang;
|
||||||
|
}
|
||||||
|
// set locale language
|
||||||
|
async setLocale(sLang) {
|
||||||
|
// async load language message
|
||||||
|
const loadMessages = async function(sLang) {
|
||||||
|
const oMessages = {};
|
||||||
|
try {
|
||||||
|
// local language file
|
||||||
|
// const oProjectMessage = await import(`./config/${sLang}`);
|
||||||
|
// 需要 element 里面的语言包的话就加上
|
||||||
|
// const oElementMessage = await import(
|
||||||
|
// `element-ui/lib/locale/lang/${sLang}`
|
||||||
|
// );
|
||||||
|
|
||||||
|
const res=await getI18nMessages(sLang);
|
||||||
|
if(res.code == 200){
|
||||||
|
Object.assign(
|
||||||
|
oMessages,
|
||||||
|
res.data,
|
||||||
|
);
|
||||||
|
console.log(oMessages)
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sLang == 'zh-CN'){
|
||||||
|
Object.assign(
|
||||||
|
oMessages,
|
||||||
|
zh,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sLang == 'en-US'){
|
||||||
|
Object.assign(
|
||||||
|
oMessages,
|
||||||
|
en,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// assign language message
|
||||||
|
// Object.assign(
|
||||||
|
// oMessages,
|
||||||
|
// // oProjectMessage.default,
|
||||||
|
// // oElementMessage.default,
|
||||||
|
// remoteMessages,
|
||||||
|
// );
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
return oMessages;
|
||||||
|
};
|
||||||
|
const oMessages = await loadMessages(sLang);
|
||||||
|
// vue-i18n的方法
|
||||||
|
this.setLocaleMessage(sLang, oMessages);
|
||||||
|
// update lang
|
||||||
|
this.locale = sLang;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// export default new I18n();
|
||||||
|
// const i18n = new I18n().init();
|
||||||
|
|
||||||
|
// 创建vue-i18n实例i18n
|
||||||
|
const i18n = new VueI18n({
|
||||||
|
// 设置默认语言
|
||||||
|
locale: localStorage.getItem('locale') || 'zh-CN', // 设置默认语言
|
||||||
|
fallbackLocale: 'zh-CN', // 默认语言环境。如果locale中无匹配项则采用该项值
|
||||||
|
messages: {
|
||||||
|
zh,
|
||||||
|
en,
|
||||||
|
},
|
||||||
|
silentTranslationWarn: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
// i18n.loadModules = () => {
|
||||||
|
// import('@/lang/zh.js').then((messages) => {
|
||||||
|
// const newMessages = Object.assign(i18n.getLocaleMessage('zh'), messages.default)
|
||||||
|
// i18n.setLocaleMessage('zh', newMessages)
|
||||||
|
// i18n.setTitle('zh')
|
||||||
|
// })
|
||||||
|
// import('@/lang/en.js').then((messages) => {
|
||||||
|
// const newMessages = Object.assign(i18n.getLocaleMessage('en'), messages.default)
|
||||||
|
// i18n.setLocaleMessage('en', newMessages)
|
||||||
|
// i18n.setTitle('en')
|
||||||
|
// })
|
||||||
|
// Vue.locale = () => {}
|
||||||
|
// Vue.config.lang = lang
|
||||||
|
// ElementLocale.i18n((key, value) => i18n.t(key, value))
|
||||||
|
// }
|
||||||
|
|
||||||
|
ElementLocale.i18n((key, value) => i18n.t(key, value))
|
||||||
|
// 暴露i18n
|
||||||
|
export default i18n
|
||||||
Loading…
Reference in New Issue
Block a user