Reputation: 3121
I am looking at way to set window.navigator.language programmatically. I was wondering if there was a way to do this using angularjs ?
Currently, I am using localization service to switch get my localization with i18n.
Upvotes: 0
Views: 716
Reputation: 610
Quick answer: No
Locale should be set by the browser and is typically read only.
There may be ways to mess with the browser to change this, but if this could be done with just JavaScript that would potentially be a security vulnerability.
Upvotes: 1
Reputation: 6791
If your intention is to change the user's browser language then I think you're doomed due to all the security things... However, if your intention is to change the language for the Accept-Language header in web requests you have a better case.
For the latter - check out Angulars $httpProvider.interceptors
.
$httpProvider.interceptors.push(function($q) {
return {
'request': function(config) {
config.headers['Accept-Language'] = 'some locale';
return config;
}
};
});
Good luck :)
Upvotes: 0