我正在创建ionic 4 angular app,并使用ngx-translate来翻译一种或多种语言。通过使用ngx-translate可以很容易地在html中翻译,但是如何在alertController和mat-snackbar消息中翻译文本消息
//using below ngx-translate
import { TranslateService } from '@ngx-translate/core';
constructor(public translate:TranslateService){}
//Alert Controller
async alert_Massage() {
let alertMassage = await this.alertController.create({
message: "How are you ?",//how to translate this message.
buttons: ['Ok'],
});
await alertMassage.present();
}
//mat-snackbar //how to translate this some error message
this.snackBar.open('Some Error messages', 'Ok', {
verticalPosition: 'top',
duration: 2000,
panelClass: ['red-snackbar']
});
答案 0 :(得分:0)
您可以从服务中获得翻译:
const translations = await this.translate.get([ 'How are you?' ])}).toPromise();
let alertMassage = await this.alertController.create({
message: translations['How are you?'].
buttons: ['Ok'],
});
await alertMassage.present();