Ionic 4 ngx translation

Hi all,

How can I change my variables which are in page.module.ts file to another language? I tried using translate.instant(‘key’) it is translating but when changing the language again, it is not changing.

My advice is to switch to the translate pipe. If keeps your ts code clean and is the easiest to understand.

<ion-input type="password" placeholder="{{ 'LOGIN.PASSWORD' | translate }}" formControlName="password"> </ion-input>

the thing is these data comes from an array

Have your tried to subscribe to the translation?

As terranmarine suggested, you can use something like this:

  value => {
    // value is our translated string
    let alertTitle = value;
1 Like

my problem is how should i translate a value in an array like this

{ imgurl: ‘…/…/assets/preg_slider/image1.png’, imgid: 1, imgNum: this.translate.instant(‘Home’), imgName: this.translate.instant(‘Meau’) },

Do you use the array in HTML file? Because you can use *ngFor and pipe translate, if you have translation texts in a file:

<ion-item *ngFor="let item of array">
  <ion-label>{{item.imgNum | translate}}</ion-label>
  <ion-label>{{item.imgName | translate}}</ion-label>

the thing is I’m not displaying elements as an array. its a slider. so the values are changing according to the slider index

Can you put your code here? If you put your code, I can see it and try to help you :smiley: