Ionic 4. platform.lang() 的替代方案

Ionic 4. Alternative for platform.lang()

我正在检查平台文档 (https://ionicframework.com/docs/utilities/platform) for ionic 4, i see that the lang() function which was available in ionic 3 (https://ionicframework.com/docs/v3/api/platform/Platform/) 是否未实现。

有什么替代方案吗?我正在尝试将 ionic 3 项目迁移到 4,其中我有以下代码来检测用户的语言

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

提前致谢!

您可以使用 Globalization Plugin

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