angular 5 change locale dynamically for i18n

Discussão em 'Angular' iniciado por j0w, Abril 28, 2025.

  1. j0w

    j0w Guest

    I am trying to change locale dynamically to change i18n language. I have two files, the one with english values and the other one with french values.

    What I've tried for now is something like that :

    ngOnInit() {
    const localeName = localStorage.getItem('locale') || 'fr';
    import(`@angular/common/locales/${localeName}.js`).then(locale => {
    registerLocaleData(locale.default);
    });
    }


    but it gave me the following error :

    error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules.


    Any ideas on how I can switch from english to french dynamically? :/

    Continue reading...

Compartilhe esta Página