@rpcbase/client 0.42.0 → 0.44.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.
Files changed (2) hide show
  1. package/i18next.js +46 -0
  2. package/package.json +7 -3
package/i18next.js ADDED
@@ -0,0 +1,46 @@
1
+ /* @flow */
2
+ import i18n from "i18next"
3
+ import {initReactI18next} from "react-i18next"
4
+ import ChainedBackend from "i18next-chained-backend"
5
+ import resourcesToBackend from "i18next-resources-to-backend"
6
+
7
+ export const SUPPORTED_LOCALES = ["en", "fr", "es", "pt", "de"]
8
+
9
+ const LOCALE_KEY = "rb.i18n_locale"
10
+ const DEFAULT_LOCALE = "en"
11
+
12
+ // https://github.com/i18next/i18next-browser-languageDetector
13
+
14
+ // get stored locale or fallback to navigator
15
+ let locale = localStorage.getItem(LOCALE_KEY)
16
+ if (!locale) {
17
+ locale = navigator.language
18
+ }
19
+
20
+ // Do not call this code directly, it is injected from babel-plugin-i18next-client by the bundler
21
+ export default (backendFn) => {
22
+
23
+ i18n
24
+ .use(ChainedBackend)
25
+ .use(initReactI18next)
26
+ .init({
27
+ 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
+ },
38
+ defaultNS: "common",
39
+ backend: {
40
+ backends: [resourcesToBackend(backendFn)],
41
+ },
42
+ interpolation: {
43
+ escapeValue: false,
44
+ },
45
+ })
46
+ }
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@rpcbase/client",
3
- "version": "0.42.0",
3
+ "version": "0.44.0",
4
4
  "scripts": {
5
5
  "test": "echo \"Error: no test specified\" && exit 0"
6
6
  },
7
7
  "dependencies": {
8
- "axios": "0.27.2",
9
- "lodash": "4.17.21"
8
+ "axios": "1.4.0",
9
+ "i18next": "23.2.11",
10
+ "i18next-chained-backend": "4.4.0",
11
+ "i18next-resources-to-backend": "1.1.4",
12
+ "lodash": "4.17.21",
13
+ "react-i18next": "13.0.1"
10
14
  }
11
15
  }