Created
August 26, 2019 18:24
-
-
Save inorganik/3dc0bc095824b1be9b40b0745ec09172 to your computer and use it in GitHub Desktop.
Angular: get user's language and locale
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getUsersLocale(defaultValue: string): string { | |
if (typeof window === 'undefined' || typeof window.navigator === 'undefined') { | |
return defaultValue; | |
} | |
const wn = window.navigator as any; | |
let lang = wn.languages ? wn.languages[0] : defaultValue; | |
lang = lang || wn.language || wn.browserLanguage || wn.userLanguage; | |
return lang; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment