Namespace: Context:getBrowserLocale

Context:getBrowserLocale

Source:

Methods

getBrowserLocale(fallbackLanguageopt, nullable) → {Object}

Evaluates the browser's locale by having a look at the preferred browser language, as reported by getBrowserLanguage.

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
fallbackLanguage String <optional>
<nullable>
null

if defined, a fallback lang value if browser reports no preferred language

Source:
See:
Returns:
the locale as an object, having the in "country" and "language" (if available) and "isFallback" to tell us if the fallback had to be used
Type
Object
Example
getBrowserLocale()
=> {
  code : 'en-GB',
  country : 'gb',
  language : 'en',
  isFallback : false
}
getBrowserLocale('en-US')
=> {
  code : 'en-US',
  country : 'us',
  language : 'en',
  isFallback : true
}