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?
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!
For anyone looking for dynamic localization today angular-dynamic-locale does a great job.
Honestly, the $locale service in angular is pretty primitive still. It's really good, but it seems to lack flexibility in this area. The biggest issue is that even if you switch your locale by dynamically reloading the proper locale file, things like the date filter won't know you've changed it because they're registering their locale information when they're set up. So you have a couple of choices currently: 1. Reload the page with the selected locale... or 2. Write your own Locale Provider and Filters that use it.
It might be possible create a service that would dynamically load the proper script file, reinitialize all affected filters and services, then refresh the views, but I'm not really sure what all that would involve at this point.
I found something interesting. It is not angular but it is jquery so integration should be ok. I will test performances and get back with info.