共计 841 个字符,预计需要花费 3 分钟才能阅读完成。
base.js
function getLanguage() {// 返回缓存中的 language 属性 (en / zh_CN) | |
return wx.getStorageSync('Language') || 'zh_CN' | |
}; | |
function translate(){ | |
// 返回翻译的对照信息 | |
return require('language/'+ getLanguage() + '.js').languageMap; | |
} | |
function translateTxt(desc){ | |
// 翻译 | |
return translate()[desc] || '居然没有翻译'; | |
} | |
module.exports = { | |
getLanguage: getLanguage, | |
_t: translate, | |
_: translateTxt, | |
} |
language/en.js
const languageMap = {'蓝牙搜寻':'bluetooth search',} | |
module.exports = {languageMap : languageMap} |
app.js
onLaunch() { | |
// 展现本地存储能力 | |
const logs = wx.getStorageSync('logs') || [] | |
logs.unshift(Date.now()) | |
wx.setStorageSync('logs', logs) | |
// 登录 | |
wx.login({ | |
success: res => {// 发送 res.code 到后盾换取 openId, sessionKey, unionId} | |
}) | |
if (this.globalData.base.getLanguage() == 'zh_CN') {this.globalData.language = 'English'} else {this.globalData.language = '中文'}; | |
this.globalData._t = this.globalData.base._t()}, | |
globalData: { | |
language:'中文', | |
base:require('./utils/base'), | |
} |
正文完