DCloud_heavensoft
DCloud_heavensoft
  • 发布:2019-04-24 03:25
  • 更新:2024-05-24 17:52
  • 阅读:64930

uni-app国际化/多语言指南

分类:uni-app
2 关注 分享
4***@qq.com 2***@qq.com

要回复文章请先登录注册

1***@163.com

1***@163.com

回复 蒋雨洋 :
main.js里面生命一个全局变量接受i18n和语言包,如代码:
let i18n = new VueI18n({
locale: uni.getStorageSync('lang') ? JSON.parse(uni.getStorageSync('lang')).value : 'lang_en',
messages
})
Vue.prototype.$i18nObj = i18n
Vue.prototype.$lang = i18n.messages[i18n.locale]

然后页面上读取的时候,如代码:view.item-left {{ $lang.startTime }}

另外,做语言切换的时候要在组件生成之前重新获取语言包,如以下代码:
beforeCreate() {
this.$lang = this.$i18nObj.messages[JSON.parse(uni.getStorageSync('lang')).value]
},
2020-07-14 13:43
8***@qq.com

8***@qq.com

回复 1***@163.com :
请问下,怎么解决的~
2020-07-14 11:58
蒋雨洋

蒋雨洋

回复 1***@163.com :
怎么解决的 我也出现了这个问题
2020-07-09 16:03
1***@163.com

1***@163.com

回复 DCloud_heavensoft :
已经找到解决方案了,真机运行的包,不是小程序,谢谢哈
2020-07-01 21:26
DCloud_heavensoft

DCloud_heavensoft (作者)

回复 1***@163.com :
你说的移动端是app还是小程序,可能使用了dom、window等仅浏览器支持的api
2020-07-01 20:57
1***@163.com

1***@163.com

pc端国际化没问题,但是在移动端运行的时候就报错了,报错代码如下:
[Vue warn]: Error in render: "TypeError: undefined is not an object (evaluating 'i18n._t')"
20:42:19.424 (found at pages/index/index.vue:1)
20:42:19.441 TypeError: undefined is not an object (evaluating 'i18n._t')
20:42:19.474 cid unmatched at view.umd.min.js:1
20:42:19.491 TypeError: Invalid attempt to destructure non-iterable instance.
20:42:19.524 In order to be iterable, non-array objects must have a [Symbol.iterator]() method. at view.umd.min.js:1
20:42:19.541 cid unmatched at view.umd.min.js:1
20:42:19.574 TypeError: Invalid attempt to destructure non-iterable instance.
20:42:19.591 In order to be iterable, non-array objects must have a [Symbol.iterator]() method. at view.umd.min.js:1
20:42:19.609 cid unmatched at view.umd.min.js:1
20:42:19.631 TypeError: Invalid attempt to destructure non-iterable instance.
20:42:19.657 In order to be iterable, non-array objects must have a [Symbol.iterator]() method. at view.umd.min.js:1
20:42:20.382 [Vue warn]: Error in render: "TypeError: undefined is not an object (evaluating 'i18n._t')"
20:42:20.431 (found at pages/index/index.vue:1)
20:42:20.454 TypeError: undefined is not an object (evaluating 'i18n._t')


请问有解决方案吗?
2020-07-01 20:47
AlertZMK

AlertZMK

内置组件uni-ui还没实现国际化吧?
2020-06-17 10:27
b***@benzii.com

b***@benzii.com

回复 b***@benzii.com :
补充:我最终发现是用了midButton,循环调用uni.setTabBarItem的次数包括了midButton在内。。抱歉
2020-05-23 15:50
b***@benzii.com

b***@benzii.com

"底部tabbar,用uni.setTabBarItem的api动态设置文字;"
-----------
在App.vue中调用这个api,需要延时调用,否则无效;另外iOS经常遇到应用卡死,自动退出,注释这部分代码正常。
2020-05-23 15:37
叫本王宝宝

叫本王宝宝

应用启动后,在第一个展示的tabbar item 页面中对tabbar 的文字使用uni.setTabBarItem进行了修改,有明显的文字变化的过程,有办法改进嘛,或者能否在 tabbar 还没显示的时候,调用 uni.setTabBarItem?
2020-04-09 14:01