resolve-locale - Resolve locale settings between browser default, supported locales and preferred locale
Getting started
Install resolve-locale via
npm install resolve-locale
Then add it to your browser source
const localesLoader = import"./locale/de" import"./locale/pt-pt" import"./locale/zh-Hant-CN"const availableLoaders = Objectconst storedLocale = localStorage const browserLocales = const locale = localesLoaderlocale
API
<array<string>> detectBrowserLocale([navigator])
Detect browsers locales as array sorted by preference. Locales are expanded.
["de-de","en"]
will expand to ["de-de", "de", "en"]
. navigator
is an
optional parameter reflecting browsers navigator object.
<string> resolveLocale(browserLocales, supportedLocales, [preferredLocale])
browserLocales
should be result of detectBrowserLocale()
. supportedLocales
is an array of
supported locales by your app. preferredLocale
is optional and a locale that is somehow
assigned to the user. This can be done by save locale to localStorage.
Returns best fit locale.
License
Apache License; Version 2.0, January 2004
Copyright
Copyright 2016-2018
Sebastian Software GmbH