0

What I want to do is described here

It allows me to have urls like domain.com/en/contacts

But additionally I want the url to have a language code when user navigates to the main page of the webpage by domain.com -> domain.com/en/

To do so I need to detect user language first and then add {locale} params to the url. Is there a good solution for it?

Community
  • 1
  • 1
user2814599
  • 1,060
  • 1
  • 13
  • 27

1 Answers1

0

I believe you can try getting the locale of the user's browser by doing something like

var locale = window.navigator.userLanguage || window.navigator.language

in the .run section of your angular app. Depending on the user language, you can then set a factory to store the locale and then use that in the router to redirect the user to the right uri.

Community
  • 1
  • 1
Ashesh
  • 2,978
  • 4
  • 27
  • 47