首页 > 解决方案 > Ionic 4. 替代 platform.lang()

问题描述

我正在检查离子 4 的平台文档(https://ionicframework.com/docs/utilities/platform),我看到离子 3 中可用的 lang() 函数(https://ionicframework.com/docs/ v3/api/platform/Platform/)未实现。

有没有其他选择?我正在尝试将 ionic 3 项目迁移到 4,我有以下代码来检测用户的语言

const browserLanguage = navigator.language || this.platform.lang();

提前致谢!

标签: ionic-frameworkionic4

解决方案


您可以使用全球化插件

this.globalization.getPreferredLanguage()
  .then(res => console.log(res))
  .catch(e => console.log(e));

推荐阅读