Get current locale of Chrome
Update:
As of Sept 2021 Chrome has pretty extensive support for the Intl
library.
function getClientLocale() { if (typeof Intl !== 'undefined') { try { return Intl.NumberFormat().resolvedOptions().locale; } catch (err) { console.error("Cannot get locale from Intl") } }}
Otherwise you can fallback to the window.navigator
object:
Firefox and Chrome have a languages
array on the navigator
object. Normally the first element in that array is the users chosen locale (normally inherited from the OS settings)
var language;if (window.navigator.languages) { language = window.navigator.languages[0];} else { language = window.navigator.userLanguage || window.navigator.language;}
The navigator.languages
array in chrome for me is ["en-GB", "en-US", "en"]
whereas navigator.language = "en-US"
, slightly different but important
In the latest versions of Chrome browser,
it var language = window.navigator.userLanguage || window.navigator.language;
returns 'fr-FR'.
If you are still facing the same issue, you can try var language = navigator.language;