Is it possible to switch between i18n/angular-locale_en-us.js
and i18n/angular-locale_de-de.js
, for example, at runtime and have all date, currency and number filters update instantly? (Instantly means after the new locale file loaded of course).
Thank you.
AngularJS supports inbuilt internationalization for three types of filters currency, date and numbers. We only need to incorporate corresponding js according to locale of the country. By default it handles the locale of the browser.
To internationalize them, you will have to replace both string literals with tokens that AngularJS can then replace with the actual translated strings, based on the user's preference, while rendering the page. AngularJS can do this by using your tokens to perform a lookup in translation tables that you provide.
I managed to do this using this module: https://github.com/lgalfaso/angular-dynamic-locale
Works perfectly!
It is and it is not. If you stick with built-in solution for i18n (which to be honest is somewhat broken), there is no way to switch locales. You may dynamically load the desired script, but once Angular resolve all bindings it is already too late (it won't use newly loaded locale script).
To overcome this problem, you may want to create your own filters and use something like Globalize or iLib to do the formatting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With