diff options
Diffstat (limited to 'src/helpers')
-rw-r--r-- | src/helpers/i18n-helpers.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/helpers/i18n-helpers.js b/src/helpers/i18n-helpers.js new file mode 100644 index 000000000..afd28cab4 --- /dev/null +++ b/src/helpers/i18n-helpers.js | |||
@@ -0,0 +1,27 @@ | |||
1 | export function getLocale({ locale, locales, defaultLocale, fallbackLocale }) { | ||
2 | let localeStr = locale; | ||
3 | if (locales[locale] === undefined) { | ||
4 | let localeFuzzy; | ||
5 | Object.keys(locales).forEach((localStr) => { | ||
6 | if (locales && Object.hasOwnProperty.call(locales, localStr)) { | ||
7 | if (locale.substring(0, 2) === localStr.substring(0, 2)) { | ||
8 | localeFuzzy = localStr; | ||
9 | } | ||
10 | } | ||
11 | }); | ||
12 | |||
13 | if (localeFuzzy !== undefined) { | ||
14 | localeStr = localeFuzzy; | ||
15 | } | ||
16 | } | ||
17 | |||
18 | if (locales[localeStr] === undefined) { | ||
19 | localeStr = defaultLocale; | ||
20 | } | ||
21 | |||
22 | if (!localeStr) { | ||
23 | localeStr = fallbackLocale; | ||
24 | } | ||
25 | |||
26 | return localeStr; | ||
27 | } | ||