@rpcbase/client 0.89.0 → 0.90.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/i18next.js +7 -12
- package/package.json +1 -1
package/i18next.js
CHANGED
|
@@ -4,10 +4,14 @@ import {initReactI18next} from "react-i18next"
|
|
|
4
4
|
import ChainedBackend from "i18next-chained-backend"
|
|
5
5
|
import resourcesToBackend from "i18next-resources-to-backend"
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
import getLocaleFromCode from "@rpcbase/std/get_locale_from_code"
|
|
8
|
+
|
|
9
|
+
import {RB_DEFAULT_LOCALE, RB_SUPPORTED_LOCALES} from "env"
|
|
8
10
|
|
|
9
11
|
const LOCALE_KEY = "rb.i18n_locale"
|
|
10
|
-
|
|
12
|
+
|
|
13
|
+
const DEFAULT_LOCALE = RB_DEFAULT_LOCALE || "en"
|
|
14
|
+
const SUPPORTED_LOCALES = RB_SUPPORTED_LOCALES || ["en"]
|
|
11
15
|
|
|
12
16
|
// https://github.com/i18next/i18next-browser-languageDetector
|
|
13
17
|
|
|
@@ -25,16 +29,7 @@ export default (backendFn) => {
|
|
|
25
29
|
.use(initReactI18next)
|
|
26
30
|
.init({
|
|
27
31
|
lng: locale,
|
|
28
|
-
fallbackLng: (code) =>
|
|
29
|
-
if (code.indexOf("-") > -1) {
|
|
30
|
-
const [firstPart] = code.split("-")
|
|
31
|
-
if (SUPPORTED_LOCALES.includes(firstPart)) return firstPart
|
|
32
|
-
} else if (SUPPORTED_LOCALES.includes(code)) {
|
|
33
|
-
return code
|
|
34
|
-
}
|
|
35
|
-
// no match in our locales, fallback to default
|
|
36
|
-
return DEFAULT_LOCALE
|
|
37
|
-
},
|
|
32
|
+
fallbackLng: (code) => getLocaleFromCode(code, DEFAULT_LOCALE, SUPPORTED_LOCALES),
|
|
38
33
|
defaultNS: "common",
|
|
39
34
|
backend: {
|
|
40
35
|
backends: [resourcesToBackend(backendFn)],
|