- Source:
Methods
getLocale(elementopt, nullable, fallbackLanguageopt, nullable) → {Object}
Evaluates the document's locale by having a look at the HTML element's lang-attribute.
Since browsers could not agree on a uniform way to return locale values yet, the returned "code" will always be "lowercaselanguage-UPPERCASECOUNTRY" (or just "lowercaselanguage", if we have no country), regardless of how the browser returns the value, while "country" and "language" will always be lower case.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
element |
HTMLElement |
<optional> <nullable> |
document.documentElement | the element holding the lang-attribute to evaluate |
fallbackLanguage |
String |
<optional> <nullable> |
null | if defined, a fallback lang value if element holds no lang information |
- Source:
- See:
Returns:
the locale as an object, having the lang value as "code", the split-up parts in "country" and "language" (if available) and "isFallback" to tell us if the fallback had to be used
- Type
- Object
Example
getLocale()
=> {
code : 'en-GB',
country : 'gb',
language : 'en',
isFallback : false
}
getLocale(document.querySelector('p'), 'en-US')
=> {
code : 'en-US',
country : 'us',
language : 'en',
isFallback : true
}