How to set Locale in Ionic 5

Issue

I can see the Ionic documentation where it is only mentioned that we can do only this.globalization.getPreferredLanguage()

But I want to do a reverse of this.

I want to programatically set the locale/ Language for the whole app

Solution

Ionic’s Globalization plugin allows you to get the preferred language of the device, but you cannot update it.

To define the preferred language in a Angular Ionic application, provide the LOCALE_ID (from @angular/core) in your app module.

{
      provide: LOCALE_ID,
      useFactory: (getMyLocale) // can be async
      // useValue: 'en' // if you want to hardcode it
}

Answered By – Alexis Deprez

Leave a Comment