@zohodesk/i18n 1.0.0-beta.25 → 1.0.0-beta.27
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 +109 -101
- package/es/components/I18NProvider.js +5 -1
- package/es/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
- package/es/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
- package/es/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
- package/es/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
- package/es/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
- package/es/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
- package/es/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
- package/es/index.js +1 -1
- package/es/utils/__tests__/jsxTranslations.spec.js +174 -0
- package/es/{utils.js → utils/index.js} +59 -6
- package/es/utils/jsxTranslations.js +193 -0
- package/lib/components/I18NProvider.js +6 -1
- package/lib/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
- package/lib/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
- package/lib/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
- package/lib/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
- package/lib/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
- package/lib/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
- package/lib/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
- package/lib/index.js +6 -0
- package/lib/utils/__tests__/jsxTranslations.spec.js +183 -0
- package/lib/{utils.js → utils/index.js} +64 -6
- package/lib/utils/jsxTranslations.js +242 -0
- package/package.json +30 -29
- package/src/I18NContext.js +2 -2
- package/src/components/DateTimeDiffFormat.js +256 -256
- package/src/components/FormatText.js +14 -14
- package/src/components/HOCI18N.js +37 -37
- package/src/components/I18N.js +74 -74
- package/src/components/I18NProvider.js +116 -110
- package/src/components/PluralFormat.js +37 -37
- package/src/components/UserTimeDiffFormat.js +97 -97
- package/src/components/__tests__/DateTimeDiffFormat.spec.js +618 -618
- package/src/components/__tests__/FormatText.spec.js +26 -26
- package/src/components/__tests__/HOCI18N.spec.js +33 -33
- package/src/components/__tests__/I18N.spec.js +29 -29
- package/src/components/__tests__/I18NProvider.spec.js +65 -65
- package/src/components/__tests__/PluralFormat.spec.js +27 -27
- package/src/components/__tests__/UserTimeDiffFormat.spec.js +1076 -1076
- package/src/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
- package/src/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
- package/src/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
- package/src/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
- package/src/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
- package/src/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
- package/src/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
- package/src/index.js +37 -36
- package/src/utils/__tests__/jsxTranslations.spec.js +213 -0
- package/src/{utils.js → utils/index.js} +632 -585
- package/src/utils/jsxTranslations.js +180 -0
package/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { formatDate, pad, replaceI18NValuesWithRegex, unescapeUnicode, getValues, getI18NInfo, isToday, isYesterday, isTomorrow, isWithinAWeek, isTwoWeeksOrMore, userDateFormat, getDiffObj, getLyears, getSuffix, getDatePatternWithoutYear, setLocalizedData, dayi18n, monthi18n, timei18n } from './utils';
|
|
1
|
+
export { formatDate, pad, replaceI18NValuesWithRegex, unescapeUnicode, getValues, getI18NInfo, isToday, isYesterday, isTomorrow, isWithinAWeek, isTwoWeeksOrMore, userDateFormat, getDiffObj, getLyears, getSuffix, getDatePatternWithoutYear, setLocalizedData, setI18NKeyMapping, dayi18n, monthi18n, timei18n } from './utils';
|
|
2
2
|
import { getI18NValue as getI18NValue1 } from './utils';
|
|
3
3
|
export { I18NContext } from './I18NContext';
|
|
4
4
|
export { default as I18NProvider, i18NProviderUtils } from './components/I18NProvider';
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { splitMatchedExp, generateChildren, replaceWithComponentPlaceHolder, createElement, prepareI18NFunc, getI18NComponent } from '../jsxTranslations';
|
|
3
|
+
|
|
4
|
+
function Bold(_ref) {
|
|
5
|
+
let {
|
|
6
|
+
children
|
|
7
|
+
} = _ref;
|
|
8
|
+
return /*#__PURE__*/React.createElement("b", null, children);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function Simple(props) {
|
|
12
|
+
return /*#__PURE__*/React.createElement("span", null, props.children);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('Verifying splitMatchedExp method', () => {
|
|
16
|
+
it('A string with no match test', () => {
|
|
17
|
+
const response = splitMatchedExp({
|
|
18
|
+
expression: '{[0-9]+?}',
|
|
19
|
+
charLenToOmit: 1,
|
|
20
|
+
string: "Hello"
|
|
21
|
+
});
|
|
22
|
+
const expected = {
|
|
23
|
+
splitString: ['Hello'],
|
|
24
|
+
matchedExpKeys: []
|
|
25
|
+
};
|
|
26
|
+
expect(response).toEqual(expected);
|
|
27
|
+
});
|
|
28
|
+
it('A string with JSX Tag placeholder test', () => {
|
|
29
|
+
const response = splitMatchedExp({
|
|
30
|
+
expression: '<[A-Za-z0-9]+?>',
|
|
31
|
+
charLenToOmit: 1,
|
|
32
|
+
string: "Hi <00Good> occurs <01Strong>"
|
|
33
|
+
});
|
|
34
|
+
const expected = {
|
|
35
|
+
splitString: ["Hi ", " occurs ", ""],
|
|
36
|
+
matchedExpKeys: ['00Good', '01Strong']
|
|
37
|
+
};
|
|
38
|
+
expect(response).toEqual(expected);
|
|
39
|
+
});
|
|
40
|
+
it('A string with String placeholder test', () => {
|
|
41
|
+
const response = splitMatchedExp({
|
|
42
|
+
expression: '{[0-9]+?}',
|
|
43
|
+
charLenToOmit: 1,
|
|
44
|
+
string: "Hi {0} occurs {1}"
|
|
45
|
+
});
|
|
46
|
+
const expected = {
|
|
47
|
+
splitString: ["Hi ", " occurs ", ""],
|
|
48
|
+
matchedExpKeys: ['0', '1']
|
|
49
|
+
};
|
|
50
|
+
expect(response).toEqual(expected);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe('Verifying generateChildren Method', () => {
|
|
54
|
+
it('A string with Tag Placeholder and String placeholders', () => {
|
|
55
|
+
const children = {
|
|
56
|
+
'00Good': () => {},
|
|
57
|
+
'01Strong': () => {}
|
|
58
|
+
};
|
|
59
|
+
const response = generateChildren({
|
|
60
|
+
children,
|
|
61
|
+
child: 'Hi <00Good>{0}<01Strong>'
|
|
62
|
+
});
|
|
63
|
+
const expected = {
|
|
64
|
+
newChildren: [['Hi '], children['00Good'], ['', ''], children['01Strong']],
|
|
65
|
+
stringPlaceHolders: {
|
|
66
|
+
0: [],
|
|
67
|
+
2: ['0']
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
expect(response).toEqual(expected);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe('Verifying the replaceWithComponentPlaceHolder method', () => {
|
|
74
|
+
it('A JSX Tag with string', () => {
|
|
75
|
+
const response = replaceWithComponentPlaceHolder({
|
|
76
|
+
componentId: 'Simple',
|
|
77
|
+
i18nKey: '<Simple>Hi everyone</Simple>',
|
|
78
|
+
childrenLength: 1
|
|
79
|
+
});
|
|
80
|
+
const expected = '<01Simple>';
|
|
81
|
+
expect(response).toBe(expected);
|
|
82
|
+
});
|
|
83
|
+
it('A string with multiple JSX Tags', () => {
|
|
84
|
+
const response = replaceWithComponentPlaceHolder({
|
|
85
|
+
componentId: 'Simple',
|
|
86
|
+
i18nKey: 'Greetings <Simple>Hi everyone</Simple> for the <Simple>Day</Simple>',
|
|
87
|
+
childrenLength: 1
|
|
88
|
+
});
|
|
89
|
+
const expected = 'Greetings <01Simple> for the <Simple>Day</Simple>';
|
|
90
|
+
expect(response).toBe(expected);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
describe('Verifying the createElement method', () => {
|
|
94
|
+
it('A component Id with JSX children and Dynamic String placeholders', () => {
|
|
95
|
+
const jsxChild = createElement({
|
|
96
|
+
componentId: 'Simple',
|
|
97
|
+
children: [['Greetings']],
|
|
98
|
+
stringPlaceHolders: {
|
|
99
|
+
0: []
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
const response = createElement({
|
|
103
|
+
componentId: -1,
|
|
104
|
+
children: [['Hi ', ','], jsxChild, [' for the day']],
|
|
105
|
+
stringPlaceHolders: {
|
|
106
|
+
0: ['0'],
|
|
107
|
+
2: []
|
|
108
|
+
}
|
|
109
|
+
})({
|
|
110
|
+
components: {
|
|
111
|
+
Simple: {
|
|
112
|
+
type: Simple
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
values: ['Zoho Desk']
|
|
116
|
+
});
|
|
117
|
+
const expected = /*#__PURE__*/React.createElement(React.Fragment, null, "Hi Zoho Desk,", /*#__PURE__*/React.createElement(Simple, null, "Greetings"), " for the day");
|
|
118
|
+
expect(JSON.stringify(response)).toEqual(JSON.stringify(expected));
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
describe('Verifying the prepareI18NFunc method', () => {
|
|
122
|
+
//Hi <Bo01ld>Gigiee</Bo01ld>,<Simple> How are you</Simple><Simple>Make it simple</Simple>
|
|
123
|
+
it('A text with sibling JSX tags and alphanumeric JSX Tags', () => {
|
|
124
|
+
const response = prepareI18NFunc({
|
|
125
|
+
i18nKey: 'Hi <Bo01ld>Gigiee</Bo01ld>,<Simple>How are you</Simple><Simple>Make it simple</Simple>'
|
|
126
|
+
})({
|
|
127
|
+
components: {
|
|
128
|
+
'Bo01ld': {
|
|
129
|
+
type: Bold
|
|
130
|
+
},
|
|
131
|
+
Simple: {
|
|
132
|
+
type: Simple
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
const expected = /*#__PURE__*/React.createElement(React.Fragment, null, "Hi ", /*#__PURE__*/React.createElement(Bold, null, "Gigiee"), ",", /*#__PURE__*/React.createElement(Simple, null, "How are you"), /*#__PURE__*/React.createElement(Simple, null, "Make it simple"));
|
|
137
|
+
expect(JSON.stringify(response)).toEqual(JSON.stringify(expected));
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
describe('Verifying getI18NComponent method', () => {
|
|
141
|
+
it('An i18n key with JSX tag in its value', () => {
|
|
142
|
+
const i18n = {
|
|
143
|
+
'support.demo': 'Hi <Bo01ld>Gigiee</Bo01ld>,<Simple>How are you</Simple><Simple>Make it simple</Simple>'
|
|
144
|
+
};
|
|
145
|
+
const I18N = getI18NComponent(i18n);
|
|
146
|
+
const response = I18N('support.demo')({
|
|
147
|
+
components: {
|
|
148
|
+
'Bo01ld': {
|
|
149
|
+
type: Bold
|
|
150
|
+
},
|
|
151
|
+
Simple: {
|
|
152
|
+
type: Simple
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
const expected = /*#__PURE__*/React.createElement(React.Fragment, null, "Hi ", /*#__PURE__*/React.createElement(Bold, null, "Gigiee"), ",", /*#__PURE__*/React.createElement(Simple, null, "How are you"), /*#__PURE__*/React.createElement(Simple, null, "Make it simple"));
|
|
157
|
+
expect(JSON.stringify(response)).toEqual(JSON.stringify(expected));
|
|
158
|
+
});
|
|
159
|
+
it('Testing absence of i18n object', () => {
|
|
160
|
+
const I18N = getI18NComponent();
|
|
161
|
+
const response = I18N('support.demo');
|
|
162
|
+
const expected = 'support.demo';
|
|
163
|
+
expect(expected).toBe(response);
|
|
164
|
+
});
|
|
165
|
+
it('Testing of missing i18n key', () => {
|
|
166
|
+
const i18n = {
|
|
167
|
+
'support.demo': 'Demo'
|
|
168
|
+
};
|
|
169
|
+
const I18N = getI18NComponent(i18n);
|
|
170
|
+
const response = I18N('support.need');
|
|
171
|
+
const expected = 'support.need';
|
|
172
|
+
expect(expected).toBe(response);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import datetime from '@zohodesk/datetimejs';
|
|
2
|
-
import { i18NProviderUtils } from '
|
|
2
|
+
import { i18NProviderUtils } from '../components/I18NProvider';
|
|
3
3
|
export const dayi18n = {
|
|
4
4
|
'Sun': 'deskreact.calendar.daynameshort.sunday',
|
|
5
5
|
'Mon': 'deskreact.calendar.daynameshort.monday',
|
|
@@ -176,16 +176,50 @@ export function getValues() {
|
|
|
176
176
|
let diff = arguments.length > 1 ? arguments[1] : undefined;
|
|
177
177
|
return params.map(param => diff[param]);
|
|
178
178
|
}
|
|
179
|
+
export function isObject(item) {
|
|
180
|
+
return item && typeof item === 'object' && !Array.isArray(item);
|
|
181
|
+
}
|
|
179
182
|
let localizedData = {};
|
|
183
|
+
let localizedStringData = {};
|
|
184
|
+
|
|
185
|
+
let getMappedKey = key => key;
|
|
186
|
+
|
|
187
|
+
function setLocalizedStringData(data) {
|
|
188
|
+
let keyString = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
189
|
+
|
|
190
|
+
if (typeof data === 'string') {
|
|
191
|
+
localizedStringData[keyString] = data;
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const keys = Object.keys(data);
|
|
196
|
+
|
|
197
|
+
for (let i = 0; i < keys.length; i++) {
|
|
198
|
+
const key = keys[i];
|
|
199
|
+
const newKeyString = keyString ? `${keyString}.${key}` : key;
|
|
200
|
+
setLocalizedStringData(data[key], newKeyString);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
180
204
|
export function setLocalizedData(data) {
|
|
181
|
-
|
|
205
|
+
const translationData = isObject(data) ? data : {};
|
|
206
|
+
localizedData = translationData;
|
|
207
|
+
setLocalizedStringData(translationData);
|
|
208
|
+
}
|
|
209
|
+
export function setI18NKeyMapping(func) {
|
|
210
|
+
getMappedKey = func;
|
|
182
211
|
}
|
|
183
212
|
export function getLocalizedValue() {
|
|
184
213
|
let {
|
|
185
214
|
type,
|
|
186
215
|
moduleName,
|
|
216
|
+
deptName,
|
|
217
|
+
folderName,
|
|
218
|
+
reportId,
|
|
219
|
+
reportName,
|
|
187
220
|
apiName,
|
|
188
|
-
fieldValue
|
|
221
|
+
fieldValue,
|
|
222
|
+
layoutName
|
|
189
223
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
190
224
|
let localizedValue = localizedData;
|
|
191
225
|
|
|
@@ -202,6 +236,24 @@ export function getLocalizedValue() {
|
|
|
202
236
|
});
|
|
203
237
|
break;
|
|
204
238
|
|
|
239
|
+
case 'layout':
|
|
240
|
+
if (deptName != null) {
|
|
241
|
+
['Layout', moduleName, deptName, layoutName].map(() => {
|
|
242
|
+
localizedValue = localizedValue[key] || '';
|
|
243
|
+
});
|
|
244
|
+
} else {
|
|
245
|
+
['Layout', moduleName, layoutName].map(() => {
|
|
246
|
+
localizedValue = localizedValue[key] || '';
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
break;
|
|
251
|
+
|
|
252
|
+
case 'report':
|
|
253
|
+
['Report', deptName, folderName, reportName, reportId].map(key => {
|
|
254
|
+
localizedValue = localizedValue[key] || '';
|
|
255
|
+
});
|
|
256
|
+
|
|
205
257
|
default:
|
|
206
258
|
return null;
|
|
207
259
|
}
|
|
@@ -214,11 +266,12 @@ export function getI18NValue(i18n) {
|
|
|
214
266
|
}
|
|
215
267
|
|
|
216
268
|
return (key, values, localizedProps) => {
|
|
217
|
-
const localizedValue = localizedProps ? getLocalizedValue(localizedProps) :
|
|
218
|
-
|
|
269
|
+
const localizedValue = localizedProps ? getLocalizedValue(localizedProps) : localizedStringData[key];
|
|
270
|
+
const finalKey = getMappedKey(key);
|
|
271
|
+
let i18nStr = i18n[finalKey];
|
|
219
272
|
|
|
220
273
|
if (i18nStr === undefined) {
|
|
221
|
-
return localizedValue ||
|
|
274
|
+
return localizedValue || finalKey;
|
|
222
275
|
}
|
|
223
276
|
|
|
224
277
|
i18nStr = replaceI18NValuesWithRegex(i18nStr, values);
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { unescapeUnicode } from './index';
|
|
3
|
+
export function splitMatchedExp(_ref) {
|
|
4
|
+
let {
|
|
5
|
+
expression,
|
|
6
|
+
charLenToOmit,
|
|
7
|
+
string
|
|
8
|
+
} = _ref;
|
|
9
|
+
let splitString = string.split(new RegExp(expression, 'g'));
|
|
10
|
+
let matchedExpAll = string.matchAll(new RegExp(expression, 'g'));
|
|
11
|
+
let matchedExpKeys = [];
|
|
12
|
+
|
|
13
|
+
for (let match of matchedExpAll) {
|
|
14
|
+
const value = match[0];
|
|
15
|
+
matchedExpKeys.push(value.substring(charLenToOmit, value.length - charLenToOmit));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
splitString,
|
|
20
|
+
matchedExpKeys
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function generateChildren(_ref2) {
|
|
24
|
+
let {
|
|
25
|
+
children,
|
|
26
|
+
child
|
|
27
|
+
} = _ref2;
|
|
28
|
+
let newChildren = [],
|
|
29
|
+
stringPlaceHolders = {};
|
|
30
|
+
|
|
31
|
+
const handleString = string => {
|
|
32
|
+
if (string) {
|
|
33
|
+
let {
|
|
34
|
+
splitString,
|
|
35
|
+
matchedExpKeys
|
|
36
|
+
} = splitMatchedExp({
|
|
37
|
+
expression: '{[0-9]+?}',
|
|
38
|
+
charLenToOmit: 1,
|
|
39
|
+
string
|
|
40
|
+
});
|
|
41
|
+
stringPlaceHolders[newChildren.length] = matchedExpKeys;
|
|
42
|
+
newChildren.push(splitString);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
let {
|
|
47
|
+
splitString: splitChild,
|
|
48
|
+
matchedExpKeys: childrenKeys
|
|
49
|
+
} = splitMatchedExp({
|
|
50
|
+
expression: '<[A-Za-z0-9]+?>',
|
|
51
|
+
charLenToOmit: 1,
|
|
52
|
+
string: child
|
|
53
|
+
});
|
|
54
|
+
childrenKeys.forEach((childKey, childIndex) => {
|
|
55
|
+
const matchedChild = splitChild[childIndex];
|
|
56
|
+
handleString(matchedChild);
|
|
57
|
+
newChildren.push(children[childKey]);
|
|
58
|
+
});
|
|
59
|
+
handleString(splitChild[childrenKeys.length]);
|
|
60
|
+
return {
|
|
61
|
+
newChildren,
|
|
62
|
+
stringPlaceHolders
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export function createElement() {
|
|
66
|
+
let {
|
|
67
|
+
componentId,
|
|
68
|
+
children = [],
|
|
69
|
+
stringPlaceHolders = {}
|
|
70
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
71
|
+
return function () {
|
|
72
|
+
let {
|
|
73
|
+
components = {},
|
|
74
|
+
values = []
|
|
75
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
76
|
+
const {
|
|
77
|
+
type = React.Fragment,
|
|
78
|
+
props
|
|
79
|
+
} = components[componentId] || {};
|
|
80
|
+
const childElements = children.map((child, index) => {
|
|
81
|
+
if (typeof child === 'function') {
|
|
82
|
+
return child({
|
|
83
|
+
components,
|
|
84
|
+
values
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let string = '',
|
|
89
|
+
stringIndex = 0;
|
|
90
|
+
(stringPlaceHolders[index] || []).map((stringId, index) => {
|
|
91
|
+
if (child[index]) {
|
|
92
|
+
string += child[index];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
string += values[stringId];
|
|
96
|
+
stringIndex++;
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
if (child[stringIndex]) {
|
|
100
|
+
string += child[stringIndex];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return string;
|
|
104
|
+
});
|
|
105
|
+
return /*#__PURE__*/React.createElement(type, props, ...childElements);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
;
|
|
109
|
+
export function replaceWithComponentPlaceHolder(_ref3) {
|
|
110
|
+
let {
|
|
111
|
+
componentId,
|
|
112
|
+
i18nKey,
|
|
113
|
+
childrenLength
|
|
114
|
+
} = _ref3;
|
|
115
|
+
const closingTagIndex = i18nKey.indexOf(`</${componentId}>`);
|
|
116
|
+
const childWithOpenTag = i18nKey.substring(0, closingTagIndex);
|
|
117
|
+
const openTagIndex = childWithOpenTag.lastIndexOf(`<${componentId}>`);
|
|
118
|
+
return i18nKey.substring(0, openTagIndex) + `<0${childrenLength}${componentId}>` + i18nKey.substring(closingTagIndex + `${componentId}`.length + 3);
|
|
119
|
+
}
|
|
120
|
+
export function prepareI18NFunc() {
|
|
121
|
+
let {
|
|
122
|
+
i18nKey,
|
|
123
|
+
children = {}
|
|
124
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
125
|
+
const componentIdMatch = i18nKey.match(/<\/[A-Za-z0-9]+?>/);
|
|
126
|
+
|
|
127
|
+
if (componentIdMatch) {
|
|
128
|
+
const componentId = componentIdMatch[0].substring(2, componentIdMatch[0].length - 1);
|
|
129
|
+
const childWithOpenTag = (i18nKey.match(new RegExp(`(.*?)(?=<\/${componentId}>)`)) || [])[0] || '';
|
|
130
|
+
const child = childWithOpenTag.split(`<${componentId}>`).pop();
|
|
131
|
+
const {
|
|
132
|
+
newChildren,
|
|
133
|
+
stringPlaceHolders
|
|
134
|
+
} = generateChildren({
|
|
135
|
+
children,
|
|
136
|
+
child
|
|
137
|
+
});
|
|
138
|
+
const childrenLength = Object.keys(children).length;
|
|
139
|
+
children[`0${childrenLength}${componentId}`] = createElement({
|
|
140
|
+
componentId,
|
|
141
|
+
children: newChildren,
|
|
142
|
+
stringPlaceHolders
|
|
143
|
+
});
|
|
144
|
+
i18nKey = replaceWithComponentPlaceHolder({
|
|
145
|
+
componentId,
|
|
146
|
+
i18nKey,
|
|
147
|
+
childrenLength
|
|
148
|
+
});
|
|
149
|
+
return prepareI18NFunc({
|
|
150
|
+
i18nKey,
|
|
151
|
+
children
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const {
|
|
156
|
+
newChildren,
|
|
157
|
+
stringPlaceHolders
|
|
158
|
+
} = generateChildren({
|
|
159
|
+
child: i18nKey,
|
|
160
|
+
children
|
|
161
|
+
});
|
|
162
|
+
return createElement({
|
|
163
|
+
componentId: -1,
|
|
164
|
+
children: newChildren,
|
|
165
|
+
stringPlaceHolders
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
export function getI18NComponent(i18n) {
|
|
169
|
+
if (typeof i18n === 'undefined') {
|
|
170
|
+
return key => key;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return key => {
|
|
174
|
+
let i18nStr = i18n[key];
|
|
175
|
+
|
|
176
|
+
if (i18nStr === undefined) {
|
|
177
|
+
return key;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (typeof i18nStr === 'string') {
|
|
181
|
+
i18nStr = unescapeUnicode(i18nStr);
|
|
182
|
+
const value = prepareI18NFunc({
|
|
183
|
+
i18nKey: i18nStr
|
|
184
|
+
});
|
|
185
|
+
window.loadI18nChunk && window.loadI18nChunk({
|
|
186
|
+
[key]: value
|
|
187
|
+
});
|
|
188
|
+
i18nStr = value;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return i18nStr;
|
|
192
|
+
};
|
|
193
|
+
}
|
|
@@ -13,6 +13,8 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
13
13
|
|
|
14
14
|
var _utils = require("../utils");
|
|
15
15
|
|
|
16
|
+
var _jsxTranslations = require("../utils/jsxTranslations");
|
|
17
|
+
|
|
16
18
|
var _I18NContext = require("../I18NContext");
|
|
17
19
|
|
|
18
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
@@ -45,7 +47,8 @@ var dummy = function dummy(key, values) {
|
|
|
45
47
|
|
|
46
48
|
var i18NProviderUtils = {
|
|
47
49
|
getI18NValue: dummy,
|
|
48
|
-
userDateFormat: dummy
|
|
50
|
+
userDateFormat: dummy,
|
|
51
|
+
getI18NComponent: dummy
|
|
49
52
|
};
|
|
50
53
|
exports.i18NProviderUtils = i18NProviderUtils;
|
|
51
54
|
|
|
@@ -61,6 +64,7 @@ var I18NProvider = /*#__PURE__*/function (_React$Component) {
|
|
|
61
64
|
|
|
62
65
|
_this = _super.call(this, props, context);
|
|
63
66
|
i18NProviderUtils.getI18NValue = (0, _utils.getI18NValue)(props.i18n);
|
|
67
|
+
i18NProviderUtils.getI18NComponent = (0, _jsxTranslations.getI18NComponent)(props.i18n);
|
|
64
68
|
|
|
65
69
|
if (props.tzData) {
|
|
66
70
|
i18NProviderUtils.userDateFormat = (0, _utils.userDateFormat)(i18NProviderUtils.getI18NValue, props.tzData, props.timeFormat, props.datePattern, props.isEnabledCurrentYear);
|
|
@@ -89,6 +93,7 @@ var I18NProvider = /*#__PURE__*/function (_React$Component) {
|
|
|
89
93
|
_this2.reject = rej;
|
|
90
94
|
}).then(function () {
|
|
91
95
|
i18NProviderUtils.getI18NValue = (0, _utils.getI18NValue)(nextProps.i18n);
|
|
96
|
+
i18NProviderUtils.getI18NComponent = (0, _jsxTranslations.getI18NComponent)(nextProps.i18n);
|
|
92
97
|
|
|
93
98
|
if (props.tzData) {
|
|
94
99
|
i18NProviderUtils.userDateFormat = (0, _utils.userDateFormat)(i18NProviderUtils.getI18NValue, props.tzData, props.timeFormat, props.datePattern, _this2.props.isEnabledCurrentYear);
|