uni-app setLocale在小程序端不生效

omvjsjqw  于 7个月前  发布在  uni-app
关注(0)|答案(1)|浏览(236)

release: v3.0.0-alpha-3060420220922001

调试过程如下

  1. console.log(uni.getLocale()) // zh-Hans
  2. uni.setLocale('en')
  3. console.log(uni.getLocale()) // zh-Hans

如果在manifest.json中配置 locale: en , 仍打印出zh-Hans

v8wbuo2f

v8wbuo2f1#

uni-i18n/uni-i18n.es.js 里面的一段源码

  1. function getDefaultLocale() {
  2. if (typeof uni !== 'undefined' && uni.getLocale) {
  3. return uni.getLocale();
  4. }
  5. // 小程序平台,uni 和 uni-i18n 互相引用,导致访问不到 uni,故在 global 上挂了 getLocale
  6. if (typeof global !== 'undefined' && global.getLocale) {
  7. return global.getLocale();
  8. }
  9. return LOCALE_EN;
  10. }

所以小程序平台uni.setLocale('en')无效,这个文档里也没说明,真的坑!!!!

相关问题