[英]Get current language of the Ionic App
我正在使用 rest API 开发基于 WooCommerce 数据库的 Ionic 3 应用程序。
我使用 Polylang Plugin 来翻译我的 WordPress 网站,由于该插件不支持 rest API,我决定在查询类别时使用“include”参数,以便以一种语言获取它们。
前任:
this.http.get(this.config.setUrl('GET', '/wp-json/wc/v2/products/categories?', {
per_page: 120, include: '151,152,929'
})
有没有办法检查应用程序的当前语言,并基于它来查询某些类别?
就像是:
if ( currentLang = 'en' ){
this.http.get(this.config.setUrl('GET', '/wp-json/wc/v2/products/categories?', {
per_page: 120, include: '151,152,929'
}else ...
先感谢您!
您必须使用Ionic 本地全球化插件来获取当前语言,
import { Globalization } from '@ionic-native/globalization';
this.globalization.getPreferredLanguage()
.then(res => console.log(res))
.catch(e => console.log(e));
谢谢你。
你可以使用ngx-translate
import { TranslateService } from '@ngx-translate/core';
constructor(private translate: TranslateService) {
console.log(this.translate.getBrowserLang());
}
暗示:
离子原生全球化插件已被弃用
https://github.com/apache/cordova-plugin-globalization#deprecation-notice
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.