初始化
This commit is contained in:
15
common/i18n/lang/en.js
Normal file
15
common/i18n/lang/en.js
Normal file
@@ -0,0 +1,15 @@
|
||||
export default {
|
||||
"首页": "Home",
|
||||
"扫码": "QR Scan",
|
||||
"设置": "Settings",
|
||||
"语言": "Language",
|
||||
"扫一扫": "Scan",
|
||||
"将扫码框对准二维码,即自动扫描": "Scan the code box at the QR code, that is, automatic scanning",
|
||||
"轻触关灯": "Turn off the light",
|
||||
"轻触照亮": "Touch your light",
|
||||
"点击登录": "Login",
|
||||
"请输入账号": "Please enter your username",
|
||||
"请输入密码": "Please enter your password",
|
||||
"登录": "Login",
|
||||
"退出登录": "Logout"
|
||||
}
|
165
common/i18n/lang/index.js
Normal file
165
common/i18n/lang/index.js
Normal file
@@ -0,0 +1,165 @@
|
||||
import Vue from 'vue'
|
||||
// 引入语言包,注意路径
|
||||
import enMessage from './en.js';
|
||||
import jpMessage from './jp.js';
|
||||
import koMessage from './ko.js';
|
||||
// VueI18n
|
||||
import VueI18n from '@/common/i18n/vue-i18n.min.js'
|
||||
import Request from '@/common/http/luch-request/index'
|
||||
import config from "@/common/config"
|
||||
const http = new Request()
|
||||
http.setConfig((conf) => {
|
||||
/* 设置全局配置 */
|
||||
conf.baseURL = config.baseUrl
|
||||
conf.header = {
|
||||
...conf.header,
|
||||
}
|
||||
return conf
|
||||
})
|
||||
// VueI18n
|
||||
Vue.use(VueI18n)
|
||||
// 网络加载国际化译文
|
||||
// 系统支持的语言
|
||||
const supportLans = [{
|
||||
value: 'zh',
|
||||
label: '中文'
|
||||
},
|
||||
{
|
||||
value: 'en',
|
||||
label: 'English'
|
||||
},
|
||||
{
|
||||
value: 'ja',
|
||||
label: '日本語'
|
||||
},
|
||||
{
|
||||
value: 'ko',
|
||||
label: '한국어'
|
||||
},
|
||||
{
|
||||
value: 'zh_tw',
|
||||
label: '繁體中文'
|
||||
}
|
||||
]
|
||||
|
||||
// 语言包
|
||||
const messages = {
|
||||
zh: {
|
||||
// 'APP概要':'APP概要'
|
||||
},
|
||||
en: {},
|
||||
ja: {},
|
||||
ko: {}
|
||||
}
|
||||
|
||||
// 获取租户支持的语言
|
||||
export function getSupportLanOptions() {
|
||||
const cookieSupportLans = uni.getStorageSync('language_info').value
|
||||
if (cookieSupportLans && cookieSupportLans.length > 0) {
|
||||
const supportLanOptions = []
|
||||
for (let i = 0; i < supportLans.length; i++) {
|
||||
if (cookieSupportLans.indexOf(supportLans[i].value) !== -1) {
|
||||
supportLanOptions.push(supportLans[i])
|
||||
}
|
||||
}
|
||||
return supportLanOptions
|
||||
}
|
||||
return supportLans
|
||||
}
|
||||
|
||||
// 获取默认语言
|
||||
export function getDefaultLan() {
|
||||
const cookieDefaultLan = uni.getStorageSync('language_info').value
|
||||
if (cookieDefaultLan) return cookieDefaultLan
|
||||
return 'zh'
|
||||
}
|
||||
|
||||
// 获取当前用户选择的语言
|
||||
export function getLanguage() {
|
||||
const chooseLanguage = uni.getStorageSync('language_info').value
|
||||
if (chooseLanguage) return chooseLanguage
|
||||
// if has not choose language
|
||||
// const language = (navigator.language || navigator.browserLanguage).toLowerCase()
|
||||
// const locales = Object.keys(messages)
|
||||
// for (const locale of locales) {
|
||||
// if (language.indexOf(locale) > -1) {
|
||||
// return locale
|
||||
// }
|
||||
// }
|
||||
return 'zh'
|
||||
}
|
||||
|
||||
// 重新加载国际化
|
||||
export async function reloadMessage() {
|
||||
const dict = await loadDict()
|
||||
uni.setStorageSync('dict', dict)
|
||||
for (var lanObj of supportLans) {
|
||||
if(lanObj.value === 'zh') {
|
||||
regMessage(lanObj.value, dict.en)
|
||||
}else {
|
||||
regMessage(lanObj.value, dict[lanObj.value])
|
||||
}
|
||||
|
||||
}
|
||||
return messages
|
||||
}
|
||||
|
||||
// 注册语言包
|
||||
export async function regMessage(lan, lanDict) {
|
||||
if (!lan || !lanDict) {
|
||||
return
|
||||
}
|
||||
if (lan === 'zh') {
|
||||
for(var key in lanDict) {
|
||||
messages['zh'][key] = key
|
||||
}
|
||||
// messages['zh'] = {
|
||||
// ...lanDict
|
||||
// }
|
||||
} else if (lan === 'en') {
|
||||
messages['en'] = {
|
||||
...lanDict
|
||||
}
|
||||
} else if (lan === 'ja') {
|
||||
messages['ja'] = {
|
||||
...lanDict
|
||||
}
|
||||
} else if (lan === 'ko') {
|
||||
messages['ko'] = {
|
||||
...lanDict
|
||||
}
|
||||
}else if (lan === 'ko') {
|
||||
messages['ko'] = {
|
||||
...lanDict
|
||||
}
|
||||
}else if (lan === 'zh_tw') {
|
||||
messages['zh_tw'] = {
|
||||
...lanDict
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 网络加载国际化译文
|
||||
export async function loadDict() {
|
||||
uni.removeStorageSync('dict')
|
||||
const url = `customer/lans`
|
||||
try {
|
||||
return http.get(url).then(res => res.data)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return {}
|
||||
}
|
||||
}
|
||||
reloadMessage()
|
||||
const i18n = new VueI18n({
|
||||
// set locale
|
||||
// options: en | zh | ja
|
||||
locale: getLanguage(),
|
||||
// locale: 'zh',
|
||||
// set locale messages
|
||||
messages,
|
||||
// 屏蔽console的warn
|
||||
silentTranslationWarn: true
|
||||
})
|
||||
|
||||
export default i18n
|
15
common/i18n/lang/jp.js
Normal file
15
common/i18n/lang/jp.js
Normal file
@@ -0,0 +1,15 @@
|
||||
export default {
|
||||
"首页": "Home",
|
||||
"扫码": "QR Scan",
|
||||
"设置": "Settings",
|
||||
"语言": "Language",
|
||||
"扫一扫": "Scan",
|
||||
"将扫码框对准二维码,即自动扫描": "Scan the code box at the QR code, that is, automatic scanning",
|
||||
"轻触关灯": "Turn off the light",
|
||||
"轻触照亮": "Touch your light",
|
||||
"点击登录": "Login",
|
||||
"请输入账号": "Please enter your username",
|
||||
"请输入密码": "Please enter your password",
|
||||
"登录": "Login",
|
||||
"退出登录": "Logout"
|
||||
}
|
15
common/i18n/lang/ko.js
Normal file
15
common/i18n/lang/ko.js
Normal file
@@ -0,0 +1,15 @@
|
||||
export default {
|
||||
"首页": "Home",
|
||||
"扫码": "QR Scan",
|
||||
"设置": "Settings",
|
||||
"语言": "Language",
|
||||
"扫一扫": "Scan",
|
||||
"将扫码框对准二维码,即自动扫描": "Scan the code box at the QR code, that is, automatic scanning",
|
||||
"轻触关灯": "Turn off the light",
|
||||
"轻触照亮": "Touch your light",
|
||||
"点击登录": "Login",
|
||||
"请输入账号": "Please enter your username",
|
||||
"请输入密码": "Please enter your password",
|
||||
"登录": "Login",
|
||||
"退出登录": "Logout"
|
||||
}
|
Reference in New Issue
Block a user