Can I set $locale for some application manually?
Is it possible that only way to support locals is to include localization file from angular library for current locale. What if there are multiple cultures? In that case I have to load localization files dynamically? What am I missing?
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.
One promising 3rd party library is the AngularJS localization module angular-l10n. It provides translations in directives or through filters. It uses interpolations, which allow you to insert values in strings. And it even has a locale switching feature.
Internationalization (i18n) is the process of developing products in such a way that they can be localized for languages and cultures easily. Localization (l10n), is the process of adapting applications and text to enable their usability in a particular cultural or linguistic market.
Internationalization Libraries for AngularJS angular-translate is an AngularJS module that provides filters and directives, along with the ability to load i18n data asynchronously. It supports pluralization through MessageFormat , and is designed to be highly extensible and configurable.
You can load the locale you want into localStorage
, then refresh the page. Have the script below load the i18n file you need. Changing the locale on the fly isn't supported yet.
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script>
<script>
var locale = JSON.parse(localStorage.getItem('locale'));
if (locale) {
document.write('<script src="scripts/i18n/angular-locale_'+locale+'.js"><\/script>');
}
</script>
I've built an angular module that takes care about i18n. AngularJS support for i18n is pretty primitve, if you want to have more control and also be more flexible, checkout angular-translate - http://angular-translate.github.io/
Let me know, if I can help out!
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