Hello,
I have 2 differents problems when i have to use the translation module in my ts files :
First one :
This work fine :
lockAlert() {
this.translate.get(['PROMPT.LOCK_ALERT.TITLE']).subscribe(res => {
this.lockAlertTranslatePrompt_1 = res;
});
this.translate.get('PROMPT.LOCK_ALERT.SUBTITLE').subscribe(res => {
this.lockAlertTranslatePrompt_2 = res;
});
this.translate.get('PROMPT.LOCK_ALERT.BUTTON').subscribe(res => {
this.lockAlertTranslatePrompt_3 = res;
});
let alert = this.alertCtrl.create({
title: this.lockAlertTranslatePrompt_1,
subTitle: this.lockAlertTranslatePrompt_2,
buttons: [this.lockAlertTranslatePrompt_3]
});
alert.present();
}
But with “better” code :
I don’t know how to read a json array…
lockAlert() {
this.translate.get(['TEST','PROMPT.LOCK_ALERT.SUBTITLE','PROMPT.LOCK_ALERT.BUTTON']).subscribe(
res => {
let alert = this.alertCtrl.create({
title: res.TEST,
subTitle: res.PROMPT.LOCK_ALERT.SUBTITLE,
buttons: ['test']
});
alert.present();
});
}
I can get TEST, but i don’t know how access to my JSON array. : res.PROMPT.LOCK_ALERT.SUBTITLE get me an error.
The json file :
"TEST": "testeee",
"PROMPT":{
"LOCK_ALERT" : {
"TITLE": "Commande impossible",
"SUBTITLE": "Déverrouiller au préalable la porte pour la commander",
"BUTTON": "Ok"
},
"CONNECTION" : {
"TITLE": "Connection"
}
}
}
Second problem :
With a confirm alert, so an alert with buttons… My strings are not translated, i have no idea why.
This alert is launched directly on the first page, and at this time strings are not translated. But if i go on an other page and go back on this one, my strings are translated…
I detect the langage in app.component.ts constructor and put translate.setDefaultLang and translate.reloadLang in this constructor according to the langage detected…
It’s like it’s no charged at the beginning, but i thought that the properties are updated when we get the observable
here the code :
presentConfirmPerms(havePerms) {
let trans: any = {};
this.translate.get(['TEST']).subscribe(
res => {
let alert = this.alertCtrl.create({
title: res.TEST,
message: res.TEST,
buttons: [
{
text: res.TEST,
role: res.TEST,
handler: () => {
console.log('clicked Cancel');
}
},
{
text: res.TEST,
handler: () => {
console.log('clicked go for android Perms'),
this.androidPermissions.requestPermissions([this.androidPermissions.PERMISSION.ACCESS_COARSE_LOCATION,this.androidPermissions.PERMISSION.ACCESS_FINE_LOCATION, this.androidPermissions.PERMISSION.ACCESS_LOCATION_EXTRA_COMMANDS])
}
}
]
});
alert.present();
});
Thanks in advance for you answers.