@andre1502/react-utilities 0.9.4 → 0.9.6
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/README.md +16 -12
- package/dist/I18n/I18n.d.ts +15 -3
- package/dist/I18n/I18n.js +41 -16
- package/dist/I18n/I18n.js.map +1 -1
- package/dist/{I18n-BXs9DtEN.js → I18n-DmYkVPZM.js} +41 -18
- package/dist/I18n-DmYkVPZM.js.map +1 -0
- package/dist/{I18n-CrUfKIV0.js → I18n-zYe_O_Pr.js} +41 -18
- package/dist/I18n-zYe_O_Pr.js.map +1 -0
- package/dist/i18n.cjs +1 -1
- package/dist/i18n.mjs +1 -1
- package/dist/index-rn.cjs +1 -1
- package/dist/index-rn.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/I18n/I18n.ts +55 -28
- package/dist/I18n-BXs9DtEN.js.map +0 -1
- package/dist/I18n-CrUfKIV0.js.map +0 -1
package/dist/i18n.cjs
CHANGED
package/dist/i18n.mjs
CHANGED
package/dist/index-rn.cjs
CHANGED
@@ -29,7 +29,7 @@ require('@formatjs/intl-datetimeformat/locale-data/zh');
|
|
29
29
|
require('@formatjs/intl-datetimeformat/polyfill');
|
30
30
|
require('@formatjs/intl-datetimeformat/add-golden-tz.js');
|
31
31
|
var EnvironmentEnum = require('./EnvironmentEnum-BjXsfSRZ.js');
|
32
|
-
var I18n = require('./I18n-
|
32
|
+
var I18n = require('./I18n-zYe_O_Pr.js');
|
33
33
|
var ReactNative = require('./ReactNative-CqUrY2ZJ.js');
|
34
34
|
require('@formatjs/intl-numberformat');
|
35
35
|
require('cross-fetch');
|
package/dist/index-rn.mjs
CHANGED
@@ -27,7 +27,7 @@ import '@formatjs/intl-datetimeformat/locale-data/zh';
|
|
27
27
|
import '@formatjs/intl-datetimeformat/polyfill';
|
28
28
|
import '@formatjs/intl-datetimeformat/add-golden-tz.js';
|
29
29
|
export { E as EnvironmentEnum } from './EnvironmentEnum-UcQ6Il1O.js';
|
30
|
-
export { g as getV, i as initI18n } from './I18n-
|
30
|
+
export { g as getV, i as initI18n } from './I18n-DmYkVPZM.js';
|
31
31
|
export { i as initSentry, r as recordAdditionalSentryHttp } from './ReactNative-mNnws-b5.js';
|
32
32
|
import '@formatjs/intl-numberformat';
|
33
33
|
import 'cross-fetch';
|
package/dist/index.cjs
CHANGED
@@ -29,7 +29,7 @@ require('@formatjs/intl-datetimeformat/locale-data/zh');
|
|
29
29
|
require('@formatjs/intl-datetimeformat/polyfill');
|
30
30
|
require('@formatjs/intl-datetimeformat/add-golden-tz.js');
|
31
31
|
var EnvironmentEnum = require('./EnvironmentEnum-BjXsfSRZ.js');
|
32
|
-
var I18n = require('./I18n-
|
32
|
+
var I18n = require('./I18n-zYe_O_Pr.js');
|
33
33
|
var React = require('./React-qUl0CBmE.js');
|
34
34
|
require('@formatjs/intl-numberformat');
|
35
35
|
require('cross-fetch');
|
package/dist/index.mjs
CHANGED
@@ -27,7 +27,7 @@ import '@formatjs/intl-datetimeformat/locale-data/zh';
|
|
27
27
|
import '@formatjs/intl-datetimeformat/polyfill';
|
28
28
|
import '@formatjs/intl-datetimeformat/add-golden-tz.js';
|
29
29
|
export { E as EnvironmentEnum } from './EnvironmentEnum-UcQ6Il1O.js';
|
30
|
-
export { g as getV, i as initI18n } from './I18n-
|
30
|
+
export { g as getV, i as initI18n } from './I18n-DmYkVPZM.js';
|
31
31
|
export { i as initSentry, r as recordAdditionalSentryHttp } from './React-BaJ1KfGF.js';
|
32
32
|
import '@formatjs/intl-numberformat';
|
33
33
|
import 'cross-fetch';
|
package/package.json
CHANGED
package/src/I18n/I18n.ts
CHANGED
@@ -8,23 +8,37 @@ const getV = (divider: number): number => {
|
|
8
8
|
return Math.floor(Date.now() / divider);
|
9
9
|
};
|
10
10
|
|
11
|
-
|
12
|
-
initReactI18next: ThirdPartyModule
|
13
|
-
lang: string
|
14
|
-
fallbackLang: string
|
15
|
-
langCacheExpiredTimeMs: number
|
16
|
-
resources: { [key: string]: any }
|
17
|
-
version: string
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
export interface InitI18nProps {
|
12
|
+
initReactI18next: ThirdPartyModule;
|
13
|
+
lang: string;
|
14
|
+
fallbackLang: string;
|
15
|
+
langCacheExpiredTimeMs: number;
|
16
|
+
resources: { [key: string]: any };
|
17
|
+
version: string;
|
18
|
+
useBackend: boolean;
|
19
|
+
withLocalstorageBackend?: boolean;
|
20
|
+
cdnUrl?: string;
|
21
|
+
debug?: boolean;
|
22
|
+
}
|
23
|
+
|
24
|
+
const initI18n = ({
|
25
|
+
initReactI18next,
|
26
|
+
lang,
|
27
|
+
fallbackLang,
|
28
|
+
langCacheExpiredTimeMs,
|
29
|
+
resources,
|
30
|
+
version,
|
31
|
+
useBackend,
|
32
|
+
withLocalstorageBackend = false,
|
33
|
+
cdnUrl = '',
|
34
|
+
debug = false,
|
35
|
+
}: InitI18nProps) => {
|
22
36
|
let backends: Array<any> = [];
|
23
37
|
let backendOptions: Array<any> = [];
|
24
38
|
const langs = Object.keys(resources);
|
25
39
|
|
26
40
|
// https://www.i18next.com/how-to/backend-fallback
|
27
|
-
if (withLocalstorageBackend) {
|
41
|
+
if (useBackend && withLocalstorageBackend) {
|
28
42
|
const versions: { [key: string]: string } = {};
|
29
43
|
|
30
44
|
langs.forEach((value) => Object.assign(versions, { [value]: version }));
|
@@ -42,7 +56,7 @@ const initI18n = (
|
|
42
56
|
});
|
43
57
|
}
|
44
58
|
|
45
|
-
if (cdnUrl) {
|
59
|
+
if (useBackend && cdnUrl) {
|
46
60
|
backends.push(HttpBackend);
|
47
61
|
backendOptions.push({
|
48
62
|
// load resources from url path
|
@@ -56,7 +70,9 @@ const initI18n = (
|
|
56
70
|
});
|
57
71
|
}
|
58
72
|
|
59
|
-
|
73
|
+
if (useBackend) {
|
74
|
+
backends.push(ResourcesToBackend(resources));
|
75
|
+
}
|
60
76
|
|
61
77
|
// https://www.i18next.com/misc/creating-own-plugins#languagedetector
|
62
78
|
const languageDetector: any = {
|
@@ -71,8 +87,8 @@ const initI18n = (
|
|
71
87
|
},
|
72
88
|
};
|
73
89
|
|
74
|
-
|
75
|
-
debug: debug
|
90
|
+
let config: InitOptions = {
|
91
|
+
debug: debug,
|
76
92
|
compatibilityJSON: 'v4',
|
77
93
|
ns: ['translation'],
|
78
94
|
defaultNS: 'translation',
|
@@ -81,24 +97,35 @@ const initI18n = (
|
|
81
97
|
load: 'currentOnly',
|
82
98
|
keySeparator: false,
|
83
99
|
nonExplicitSupportedLngs: true,
|
84
|
-
backend: {
|
85
|
-
backends: backends,
|
86
|
-
backendOptions: backendOptions,
|
87
|
-
cacheHitMode: 'refreshAndUpdateStore',
|
88
|
-
reloadInterval: langCacheExpiredTimeMs,
|
89
|
-
refreshExpirationTime: langCacheExpiredTimeMs, // only after determined time it should trigger a refresh if necessary
|
90
|
-
},
|
91
|
-
react: {
|
92
|
-
bindI18nStore: 'added', // this way, when the HttpBackend delivers new translations (thanks to refreshAndUpdateStore), the UI gets updated
|
93
|
-
},
|
94
100
|
interpolation: {
|
95
101
|
escapeValue: false, // react already safes from xss
|
96
102
|
},
|
97
103
|
};
|
98
104
|
|
105
|
+
if (useBackend) {
|
106
|
+
config = {
|
107
|
+
...config,
|
108
|
+
backend: {
|
109
|
+
backends: backends,
|
110
|
+
backendOptions: backendOptions,
|
111
|
+
cacheHitMode: 'refreshAndUpdateStore',
|
112
|
+
reloadInterval: langCacheExpiredTimeMs,
|
113
|
+
refreshExpirationTime: langCacheExpiredTimeMs, // only after determined time it should trigger a refresh if necessary
|
114
|
+
},
|
115
|
+
react: {
|
116
|
+
bindI18nStore: 'added', // this way, when the HttpBackend delivers new translations (thanks to refreshAndUpdateStore), the UI gets updated
|
117
|
+
},
|
118
|
+
};
|
119
|
+
}
|
120
|
+
|
99
121
|
if (!i18next.isInitialized) {
|
100
|
-
i18next
|
101
|
-
|
122
|
+
let i18n = i18next;
|
123
|
+
|
124
|
+
if (useBackend) {
|
125
|
+
i18n = i18n.use(ChainedBackend);
|
126
|
+
}
|
127
|
+
|
128
|
+
i18n
|
102
129
|
.use(languageDetector)
|
103
130
|
.use(initReactI18next) // passes i18n down to react-i18next
|
104
131
|
.init(config, (ex, t) => {
|