打包国际化处理,主要是引导用户的提示语,如申请权限等 https://ask.dcloud.net.cn/article/35860
uni-app全方位多语言 https://ask.dcloud.net.cn/article/35872
我的项目是直接在HBuilderX 创建的,所以需要使用npm init -y 初始化package.json文件
npm init -y
安装vue-i18n 命令如下
npm i vue-i18n
\lang.js
export default {
'en-US': {
index: {
invite: 'Invite',
game: 'Game'
}
},
'zh-CN': {
index: {
invite: '邀请',
game: '游戏'
}
}
}\main.js
import Vue from 'vue'
import App from './App'
import messages from './lang'
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
const i18n = new VueI18n({
locale: 'en-US',
messages
})
Vue.prototype._i18n = i18n
Vue.prototype.$i18nMsg = function(){
return i18n.messages[i18n.locale]
}
const app = new Vue({
i18n,
...App
})
app.$mount()
\pages\index\index.vue
<template>
<view>
<view>{{ i18n.index.invite }}</view>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello'
}
},
computed: {
i18n() {
return this.$i18nMsg()
}
},
onLoad() {
setTimeout(() => {
this.$i18n.locale = 'zh-CN'
},2000)
},
methods: {
}
}
</script>
<style rel="stylesheet/stylus">
.content-title
color #500778
</style>