Is it possible to switch the AngularJS internationalization language on the fly at runtime?

Is it possible to switch between i18n/angular-locale_en-us.js and i18n/angular-locale_de-de.js , for example, at runtime and update all dates, currency and numeric filters instantly? (Instantly means that after loading a new language file, of course).

Thanks.

+8
angularjs internationalization
source share
2 answers

I managed to do this with this module: https://github.com/lgalfaso/angular-dynamic-locale

Works great!

+5
source share

This is the case. If you stick to the built-in solution for i18n (which, to be honest, is somewhat broken), there is no way to switch locales. You can dynamically load the required script, but once Angular resolve all the bindings it is too late (it will not use the recently loaded script locale).

To solve this problem, you can create your own filters and use something like Globalize or iLib for formatting.

+1
source share

All Articles