How to save the translated language setting in the app?

Iam using Ngx Translation to translate my app from EN to HI (hindi) everything works gr8 but when i close the app and restart it the app is translated back to English. Is their any way i can keep my changed language setting or any way to keep it stored as per the setting chose by the current user logged in?

My current code below:
Settings.html

<ion-item>
                    <ion-label>Change Language</ion-label>
                    <ion-select [(ngModel)]="language" (ionChange)="changeLanguage()" name="language" placeholder="Select Language">
                       <ion-option value="en" selected="true">English</ion-option>
                       <ion-option value="hi">Hindi</ion-option>
                    </ion-select>
                </ion-item>

settings.ts

changeLanguage()
{
   
   this.translateService.use(this.language);
}

I use LocalStorage to save the chosen language.

Use this to save:

changeLanguage()
{
   
   this.translateService.use(this.language);
   localStorage.setItem("myConfig", this.language);
}

And this to load (app.component.ts, first method or constructor):

this.platform.ready().then(() => {
     this.translateService.use(localStorage["myConfig"]);
});
1 Like

thnx this works for me perfectly :slight_smile:

1 Like