@zohodesk/i18n 1.0.0-beta.34 → 1.0.0-beta.35-murphy
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/docs/murphy/01-MURPHY_OVERVIEW.md +148 -0
- package/docs/murphy/02-MURPHY_ARCHITECTURE.md +283 -0
- package/docs/murphy/03-MURPHY_BACKEND_CONFIG.md +337 -0
- package/docs/murphy/04-MURPHY_FRONTEND_INIT.md +437 -0
- package/docs/murphy/05-MURPHY_DESK_CLIENT_USAGE.md +467 -0
- package/docs/murphy/06-MURPHY_I18N_INTEGRATION.md +402 -0
- package/docs/murphy/07-MURPHY_WHY_I18N_APPROACH.md +391 -0
- package/es/components/DateTimeDiffFormat.js +5 -19
- package/es/components/FormatText.js +2 -2
- package/es/components/HOCI18N.js +32 -43
- package/es/components/I18N.js +2 -13
- package/es/components/I18NProvider.js +0 -9
- package/es/components/PluralFormat.js +3 -5
- package/es/components/UserTimeDiffFormat.js +5 -9
- package/es/components/__tests__/DateTimeDiffFormat.spec.js +157 -221
- package/es/components/__tests__/FormatText.spec.js +2 -2
- package/es/components/__tests__/HOCI18N.spec.js +2 -4
- package/es/components/__tests__/I18N.spec.js +6 -4
- package/es/components/__tests__/I18NProvider.spec.js +4 -4
- package/es/components/__tests__/PluralFormat.spec.js +2 -2
- package/es/components/__tests__/UserTimeDiffFormat.spec.js +249 -348
- package/es/index.js +1 -0
- package/es/utils/__tests__/jsxTranslations.spec.js +3 -7
- package/es/utils/errorReporter.js +31 -0
- package/es/utils/index.js +42 -92
- package/es/utils/jsxTranslations.js +34 -52
- package/lib/I18NContext.js +2 -7
- package/lib/components/DateTimeDiffFormat.js +46 -87
- package/lib/components/FormatText.js +18 -41
- package/lib/components/HOCI18N.js +24 -59
- package/lib/components/I18N.js +27 -64
- package/lib/components/I18NProvider.js +27 -63
- package/lib/components/PluralFormat.js +24 -50
- package/lib/components/UserTimeDiffFormat.js +43 -72
- package/lib/components/__tests__/DateTimeDiffFormat.spec.js +95 -165
- package/lib/components/__tests__/FormatText.spec.js +3 -10
- package/lib/components/__tests__/HOCI18N.spec.js +3 -14
- package/lib/components/__tests__/I18N.spec.js +4 -12
- package/lib/components/__tests__/I18NProvider.spec.js +8 -23
- package/lib/components/__tests__/PluralFormat.spec.js +3 -11
- package/lib/components/__tests__/UserTimeDiffFormat.spec.js +157 -225
- package/lib/index.js +25 -23
- package/lib/utils/__tests__/jsxTranslations.spec.js +1 -12
- package/lib/utils/errorReporter.js +39 -0
- package/lib/utils/index.js +49 -125
- package/lib/utils/jsxTranslations.js +61 -100
- package/package.json +1 -1
- package/src/index.js +5 -0
- package/src/utils/errorReporter.js +36 -0
- package/src/utils/index.js +8 -1
- package/src/utils/jsxTranslations.js +8 -1
package/es/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
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
|
+
export { reportI18NError, clearReportedKeys, I18N_ERROR_TYPES } from "./utils/errorReporter";
|
|
2
3
|
import { getI18NValue as getI18NValue1 } from "./utils";
|
|
3
4
|
export { I18NContext } from "./I18NContext";
|
|
4
5
|
export { default as I18NProvider, i18NProviderUtils } from "./components/I18NProvider";
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { splitMatchedExp, generateChildren, replaceWithComponentPlaceHolder, createElement, prepareI18NFunc, getI18NComponent } from "../jsxTranslations";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
children
|
|
7
|
-
} = _ref;
|
|
3
|
+
function Bold({
|
|
4
|
+
children
|
|
5
|
+
}) {
|
|
8
6
|
return /*#__PURE__*/React.createElement("b", null, children);
|
|
9
7
|
}
|
|
10
|
-
|
|
11
8
|
function Simple(props) {
|
|
12
9
|
return /*#__PURE__*/React.createElement("span", null, props.children);
|
|
13
10
|
}
|
|
14
|
-
|
|
15
11
|
describe('Verifying splitMatchedExp method', () => {
|
|
16
12
|
it('A string with no match test', () => {
|
|
17
13
|
const response = splitMatchedExp({
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const I18N_ERROR_TYPES = {
|
|
2
|
+
UNDEFINED_OBJECT: 'I18N_UNDEFINED_OBJECT',
|
|
3
|
+
MISSING_KEY: 'I18N_MISSING_KEY',
|
|
4
|
+
NUMERIC_FALLBACK: 'I18N_NUMERIC_FALLBACK'
|
|
5
|
+
};
|
|
6
|
+
const reportedKeys = new Set();
|
|
7
|
+
function isMurphyAvailable() {
|
|
8
|
+
return typeof murphy !== 'undefined' && typeof murphy.error === 'function';
|
|
9
|
+
}
|
|
10
|
+
export function reportI18NError(type, key) {
|
|
11
|
+
const dedupeKey = `${type}:${key}`;
|
|
12
|
+
if (reportedKeys.has(dedupeKey)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
reportedKeys.add(dedupeKey);
|
|
16
|
+
if (isMurphyAvailable()) {
|
|
17
|
+
const error = new Error(`i18n ${type}: ${key}`);
|
|
18
|
+
error.name = type;
|
|
19
|
+
murphy.error(error, undefined, {
|
|
20
|
+
customTags: {
|
|
21
|
+
errorType: type,
|
|
22
|
+
i18nKey: key,
|
|
23
|
+
category: 'i18n'
|
|
24
|
+
},
|
|
25
|
+
preventClientGrouping: true
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function clearReportedKeys() {
|
|
30
|
+
reportedKeys.clear();
|
|
31
|
+
}
|
package/es/utils/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import datetime from '@zohodesk/datetimejs';
|
|
2
2
|
import { i18NProviderUtils } from "../components/I18NProvider";
|
|
3
|
+
import { reportI18NError, I18N_ERROR_TYPES } from "./errorReporter";
|
|
3
4
|
export const dayi18n = {
|
|
4
5
|
'Sun': 'deskreact.calendar.daynameshort.sunday',
|
|
5
6
|
'Mon': 'deskreact.calendar.daynameshort.monday',
|
|
@@ -68,36 +69,29 @@ export function formatDate(dateMill, mask, dateDiffObj) {
|
|
|
68
69
|
betweenleepYears,
|
|
69
70
|
crntMonth
|
|
70
71
|
} = dateDiffObj;
|
|
71
|
-
|
|
72
72
|
if (years > 0) {
|
|
73
73
|
return `${years}y`;
|
|
74
74
|
} else if (yDays > 0) {
|
|
75
75
|
let isFeb = crntMonth === 1;
|
|
76
76
|
let isThoneMonth = [0, 2, 4, 6, 7, 9, 11].indexOf(crntMonth) != -1;
|
|
77
|
-
|
|
78
77
|
let weekCal = function (calDays) {
|
|
79
78
|
let weeks = calDays / 7;
|
|
80
79
|
return weeks < 1 ? `${calDays}d` : `${Math.trunc(weeks)}w`;
|
|
81
80
|
};
|
|
82
|
-
|
|
83
81
|
if (!isFeb) {
|
|
84
82
|
return isThoneMonth === true ? yDays === 31 ? '1m' : weekCal(yDays) : yDays === 30 ? '1m' : weekCal(yDays);
|
|
85
83
|
}
|
|
86
|
-
|
|
87
84
|
if (betweenleepYears != 0) {
|
|
88
85
|
return isFeb === true && yDays === 28 ? '1m' : weekCal(yDays);
|
|
89
86
|
}
|
|
90
|
-
|
|
91
87
|
return isFeb === true && yDays === 29 ? '1m' : weekCal(yDays);
|
|
92
88
|
} else if (hours < 24 && hours > 0) {
|
|
93
89
|
return `${hours}h`;
|
|
94
90
|
} else if (minutes < 60 && hours > 1) {
|
|
95
91
|
return `${minutes}m`;
|
|
96
92
|
}
|
|
97
|
-
|
|
98
93
|
return seconds === 0 ? 'now' : `${seconds}s`;
|
|
99
94
|
}
|
|
100
|
-
|
|
101
95
|
let date = new Date(dateMill);
|
|
102
96
|
let d = date.getDate();
|
|
103
97
|
let D = date.getDay();
|
|
@@ -143,14 +137,11 @@ export function formatDate(dateMill, mask, dateDiffObj) {
|
|
|
143
137
|
if (match in flags) {
|
|
144
138
|
return flags[match];
|
|
145
139
|
}
|
|
146
|
-
|
|
147
140
|
return match.slice(1, match.length - 1);
|
|
148
141
|
});
|
|
149
142
|
return dat;
|
|
150
143
|
}
|
|
151
|
-
export function pad(n) {
|
|
152
|
-
let width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
153
|
-
let z = arguments.length > 2 ? arguments[2] : undefined;
|
|
144
|
+
export function pad(n, width = 1, z) {
|
|
154
145
|
z = z || '0';
|
|
155
146
|
n = `${n}`;
|
|
156
147
|
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
|
|
@@ -165,15 +156,12 @@ export function replaceI18NValuesWithRegex(i18nStr, values) {
|
|
|
165
156
|
i18nStr = i18nStr.replace(new RegExp('\\{0\\}', 'g'), values);
|
|
166
157
|
}
|
|
167
158
|
}
|
|
168
|
-
|
|
169
159
|
return i18nStr;
|
|
170
160
|
}
|
|
171
161
|
export function unescapeUnicode(str) {
|
|
172
162
|
return str.replace(/\\u([a-fA-F0-9]{4})/g, (g, m1) => String.fromCharCode(parseInt(m1, 16)));
|
|
173
163
|
}
|
|
174
|
-
export function getValues() {
|
|
175
|
-
let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
176
|
-
let diff = arguments.length > 1 ? arguments[1] : undefined;
|
|
164
|
+
export function getValues(params = [], diff) {
|
|
177
165
|
return params.map(param => diff[param]);
|
|
178
166
|
}
|
|
179
167
|
export function isObject(item) {
|
|
@@ -181,26 +169,19 @@ export function isObject(item) {
|
|
|
181
169
|
}
|
|
182
170
|
let localizedData = {};
|
|
183
171
|
let localizedStringData = {};
|
|
184
|
-
|
|
185
172
|
let getMappedKey = key => key;
|
|
186
|
-
|
|
187
|
-
function setLocalizedStringData(data) {
|
|
188
|
-
let keyString = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
189
|
-
|
|
173
|
+
function setLocalizedStringData(data, keyString = '') {
|
|
190
174
|
if (typeof data === 'string') {
|
|
191
175
|
localizedStringData[keyString] = data;
|
|
192
176
|
return;
|
|
193
177
|
}
|
|
194
|
-
|
|
195
178
|
const keys = Object.keys(data);
|
|
196
|
-
|
|
197
179
|
for (let i = 0; i < keys.length; i++) {
|
|
198
180
|
const key = keys[i];
|
|
199
181
|
const newKeyString = keyString ? `${keyString}.${key}` : key;
|
|
200
182
|
setLocalizedStringData(data[key], newKeyString);
|
|
201
183
|
}
|
|
202
184
|
}
|
|
203
|
-
|
|
204
185
|
export function setLocalizedData(data) {
|
|
205
186
|
const translationData = isObject(data) ? data : {};
|
|
206
187
|
localizedData = translationData;
|
|
@@ -209,33 +190,29 @@ export function setLocalizedData(data) {
|
|
|
209
190
|
export function setI18NKeyMapping(func) {
|
|
210
191
|
getMappedKey = func;
|
|
211
192
|
}
|
|
212
|
-
export function getLocalizedValue(
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
193
|
+
export function getLocalizedValue({
|
|
194
|
+
type,
|
|
195
|
+
moduleName,
|
|
196
|
+
deptName,
|
|
197
|
+
folderName,
|
|
198
|
+
reportId,
|
|
199
|
+
reportName,
|
|
200
|
+
apiName,
|
|
201
|
+
fieldValue,
|
|
202
|
+
layoutName
|
|
203
|
+
} = {}) {
|
|
224
204
|
let localizedValue = localizedData;
|
|
225
|
-
|
|
226
205
|
switch (type) {
|
|
227
206
|
case 'field':
|
|
228
207
|
['Field', moduleName, apiName].map(key => {
|
|
229
208
|
localizedValue = localizedValue[key] || '';
|
|
230
209
|
});
|
|
231
210
|
break;
|
|
232
|
-
|
|
233
211
|
case 'picklist':
|
|
234
212
|
['PickListValue', moduleName, apiName, fieldValue].map(key => {
|
|
235
213
|
localizedValue = localizedValue[key] || '';
|
|
236
214
|
});
|
|
237
215
|
break;
|
|
238
|
-
|
|
239
216
|
case 'layout':
|
|
240
217
|
if (deptName != null) {
|
|
241
218
|
['Layout', moduleName, deptName, layoutName].map(() => {
|
|
@@ -246,48 +223,44 @@ export function getLocalizedValue() {
|
|
|
246
223
|
localizedValue = localizedValue[key] || '';
|
|
247
224
|
});
|
|
248
225
|
}
|
|
249
|
-
|
|
250
226
|
break;
|
|
251
|
-
|
|
252
227
|
case 'report':
|
|
253
228
|
['Report', deptName, folderName, reportName, reportId].map(key => {
|
|
254
229
|
localizedValue = localizedValue[key] || '';
|
|
255
230
|
});
|
|
256
|
-
|
|
257
231
|
default:
|
|
258
232
|
return null;
|
|
259
233
|
}
|
|
260
|
-
|
|
261
234
|
return localizedValue || null;
|
|
262
235
|
}
|
|
263
236
|
export function getI18NValue(i18n) {
|
|
264
237
|
if (typeof i18n === 'undefined') {
|
|
238
|
+
reportI18NError(I18N_ERROR_TYPES.UNDEFINED_OBJECT, 'i18n_object');
|
|
265
239
|
return key => key;
|
|
266
240
|
}
|
|
267
|
-
|
|
268
241
|
return (key, values, localizedProps) => {
|
|
269
242
|
const localizedValue = localizedProps ? getLocalizedValue(localizedProps) : localizedStringData[key];
|
|
270
243
|
const finalKey = getMappedKey(key);
|
|
271
244
|
let i18nStr = i18n[finalKey];
|
|
272
|
-
|
|
273
245
|
if (i18nStr === undefined) {
|
|
274
|
-
|
|
246
|
+
const isNumeric = /^\d+$/.test(finalKey);
|
|
247
|
+
reportI18NError(isNumeric ? I18N_ERROR_TYPES.NUMERIC_FALLBACK : I18N_ERROR_TYPES.MISSING_KEY, finalKey);
|
|
248
|
+
return localizedValue || getFallbackText(finalKey);
|
|
275
249
|
}
|
|
276
|
-
|
|
277
250
|
i18nStr = replaceI18NValuesWithRegex(i18nStr, values);
|
|
278
251
|
return localizedValue || unescapeUnicode(i18nStr);
|
|
279
252
|
};
|
|
280
|
-
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// function getValues(params = [], diff) {
|
|
281
256
|
// return params.map(param => {
|
|
282
257
|
// return diff[param];
|
|
283
258
|
// });
|
|
284
259
|
// }
|
|
285
|
-
|
|
286
260
|
export function getI18NInfo(toDateObj, props, diffObj) {
|
|
287
261
|
let key = null,
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
262
|
+
values,
|
|
263
|
+
text = null;
|
|
291
264
|
if (typeof props === 'function') {
|
|
292
265
|
let value = props(diffObj1);
|
|
293
266
|
key = value.key;
|
|
@@ -298,7 +271,6 @@ export function getI18NInfo(toDateObj, props, diffObj) {
|
|
|
298
271
|
} else if (typeof props === 'string') {
|
|
299
272
|
text = toDateObj.format(props);
|
|
300
273
|
}
|
|
301
|
-
|
|
302
274
|
return {
|
|
303
275
|
key,
|
|
304
276
|
values,
|
|
@@ -326,7 +298,6 @@ export function isTwoWeeksOrMore(fromDate, toDate) {
|
|
|
326
298
|
export function getDatePatternWithoutYear(datePattern) {
|
|
327
299
|
let dateObj;
|
|
328
300
|
let delemiter;
|
|
329
|
-
|
|
330
301
|
if (datePattern.indexOf('.') !== -1) {
|
|
331
302
|
dateObj = datePattern.split('.');
|
|
332
303
|
delemiter = '.';
|
|
@@ -340,26 +311,21 @@ export function getDatePatternWithoutYear(datePattern) {
|
|
|
340
311
|
dateObj = datePattern.split(' ');
|
|
341
312
|
delemiter = ' ';
|
|
342
313
|
}
|
|
343
|
-
|
|
344
314
|
return dateObj.filter(data => ['yy', 'yyyy'].indexOf(data) === -1).join(delemiter);
|
|
345
315
|
}
|
|
346
316
|
export function userDateFormat(getI18NValue, timezoneData, timeFormat, datePattern, isEnabledCurrentYear) {
|
|
347
|
-
return
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
} = _ref;
|
|
354
|
-
let isSuffixEnable = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
355
|
-
let format = arguments.length > 5 ? arguments[5] : undefined;
|
|
317
|
+
return (to, {
|
|
318
|
+
today,
|
|
319
|
+
yesterday,
|
|
320
|
+
tomorrow,
|
|
321
|
+
others
|
|
322
|
+
}, ago, later, isSuffixEnable = false, format) => {
|
|
356
323
|
let fromDateObj = datetime.toDate(datetime.tz.utcToTz(null, timezoneData));
|
|
357
324
|
let toDateObj = datetime.toDate(datetime.tz.utcToTz(to, timezoneData));
|
|
358
325
|
let diffMin = new Date(to).getTime() - new Date().getTime();
|
|
359
326
|
let from = new Date();
|
|
360
327
|
from = from.toISOString();
|
|
361
328
|
let suffix;
|
|
362
|
-
|
|
363
329
|
if (diffMin < 0) {
|
|
364
330
|
suffix = ago || '';
|
|
365
331
|
} else if (diffMin > 0) {
|
|
@@ -367,7 +333,6 @@ export function userDateFormat(getI18NValue, timezoneData, timeFormat, datePatte
|
|
|
367
333
|
} else {
|
|
368
334
|
suffix = '';
|
|
369
335
|
}
|
|
370
|
-
|
|
371
336
|
let diff = getDiffObj(diffMin);
|
|
372
337
|
let withInAWeak = diff.y === 0 && diff.yd <= 7;
|
|
373
338
|
let diffObj = {
|
|
@@ -397,9 +362,10 @@ export function userDateFormat(getI18NValue, timezoneData, timeFormat, datePatte
|
|
|
397
362
|
timeFormat: timeFormat,
|
|
398
363
|
datePattern: datePattern,
|
|
399
364
|
dateTimePattern: `${datePattern} ${timeFormat}`
|
|
400
|
-
};
|
|
401
|
-
//In else part we'll set the date format as it is
|
|
365
|
+
};
|
|
402
366
|
|
|
367
|
+
//In if condition we'll remove year and set date format if the current year is not required
|
|
368
|
+
//In else part we'll set the date format as it is
|
|
403
369
|
if (isEnabledCurrentYear === true && diffObj1.years === 0 && diffObj1.tYear === diffObj1.crntYear) {
|
|
404
370
|
let dateFormat = getDatePatternWithoutYear(datePattern);
|
|
405
371
|
diffObj1.dateFormat = dateFormat;
|
|
@@ -407,23 +373,23 @@ export function userDateFormat(getI18NValue, timezoneData, timeFormat, datePatte
|
|
|
407
373
|
} else {
|
|
408
374
|
diffObj1.dateFormat = datePattern;
|
|
409
375
|
diffObj1.dateTimeFormat = `${datePattern} ${timeFormat}`;
|
|
410
|
-
}
|
|
376
|
+
}
|
|
411
377
|
|
|
378
|
+
//var daysDiff = toDateObj.diff(fromDateObj, 'days');
|
|
412
379
|
|
|
413
380
|
let key = '';
|
|
414
381
|
let values = [];
|
|
415
382
|
let text = null;
|
|
416
|
-
|
|
417
383
|
if (format) {
|
|
418
384
|
let years, months, days, hours, minutes, seconds;
|
|
419
|
-
years = diffObj1.years > 1 ? '2' : diffObj1.years;
|
|
385
|
+
years = diffObj1.years > 1 ? '2' : diffObj1.years;
|
|
386
|
+
// months = diffObj1.months > 1 ? '2' : diffObj1.months;
|
|
420
387
|
// days = diffObj1.days > 1 ? '2' : diffObj1.days;
|
|
421
|
-
|
|
422
388
|
days = diff.yd > 1 ? '2' : diff.yd;
|
|
423
389
|
hours = diffObj1.hours > 1 ? '2' : diffObj1.hours;
|
|
424
|
-
minutes = diffObj1.minutes > 1 ? '2' : diffObj1.minutes;
|
|
390
|
+
minutes = diffObj1.minutes > 1 ? '2' : diffObj1.minutes;
|
|
391
|
+
//seconds = diffObj1.seconds > 1 ? '2' : diffObj1.seconds;
|
|
425
392
|
// let pattern = '' + years + months + days + hours + minutes + seconds;
|
|
426
|
-
|
|
427
393
|
let count = 0;
|
|
428
394
|
let pattern = [years, days, hours, minutes].reduce((res, next) => {
|
|
429
395
|
if (count === 2 || next === 0) {
|
|
@@ -434,11 +400,9 @@ export function userDateFormat(getI18NValue, timezoneData, timeFormat, datePatte
|
|
|
434
400
|
} else {
|
|
435
401
|
res = res + next;
|
|
436
402
|
}
|
|
437
|
-
|
|
438
403
|
return res;
|
|
439
404
|
}, '');
|
|
440
405
|
let value = format(diffObj1, pattern);
|
|
441
|
-
|
|
442
406
|
if (value && typeof value === 'object') {
|
|
443
407
|
key = value.key;
|
|
444
408
|
values = getValues(value.params, diffObj);
|
|
@@ -449,32 +413,28 @@ export function userDateFormat(getI18NValue, timezoneData, timeFormat, datePatte
|
|
|
449
413
|
} else {
|
|
450
414
|
let dateObj = new Date(toDateObj);
|
|
451
415
|
let curDateObj = new Date(fromDateObj);
|
|
452
|
-
let diffDayType = diffObj1.yDays;
|
|
416
|
+
let diffDayType = diffObj1.yDays;
|
|
453
417
|
|
|
418
|
+
//In this condition, to calculate different days we have copied it from live --> diffDayType
|
|
454
419
|
if (isOverdue && dateObj.getDate() < curDateObj.getDate() && diffObj1.yDays == 0) {
|
|
455
420
|
diffDayType = -1;
|
|
456
421
|
}
|
|
457
|
-
|
|
458
422
|
if (!isOverdue) {
|
|
459
423
|
let diffHr = dateObj.getHours() - curDateObj.getHours();
|
|
460
|
-
|
|
461
424
|
if (diffHr < 0) {
|
|
462
425
|
diffDayType += 1;
|
|
463
426
|
} else if (diffHr == 0) {
|
|
464
427
|
let diffMins = dateObj.getMinutes() - curDateObj.getMinutes();
|
|
465
|
-
|
|
466
428
|
if (diffMins < 0) {
|
|
467
429
|
diffDayType += 1;
|
|
468
430
|
} else if (diffMins == 0) {
|
|
469
431
|
let diffSec = dateObj.getSeconds() - curDateObj.getSeconds();
|
|
470
|
-
|
|
471
432
|
if (diffSec < 0) {
|
|
472
433
|
diffDayType += 1;
|
|
473
434
|
}
|
|
474
435
|
}
|
|
475
436
|
}
|
|
476
437
|
}
|
|
477
|
-
|
|
478
438
|
if (diff.y === 0 && (diffDayType === 0 || diffDayType === 1)) {
|
|
479
439
|
if (today && dateObj.getDate() === curDateObj.getDate()) {
|
|
480
440
|
if (typeof today === 'object') {
|
|
@@ -500,7 +460,6 @@ export function userDateFormat(getI18NValue, timezoneData, timeFormat, datePatte
|
|
|
500
460
|
}
|
|
501
461
|
} else {
|
|
502
462
|
let value = others(diffObj1);
|
|
503
|
-
|
|
504
463
|
if (typeof value === 'object') {
|
|
505
464
|
key = value.key;
|
|
506
465
|
values = getValues(value.params, diffObj);
|
|
@@ -511,7 +470,6 @@ export function userDateFormat(getI18NValue, timezoneData, timeFormat, datePatte
|
|
|
511
470
|
}
|
|
512
471
|
} else {
|
|
513
472
|
let value = others(diffObj1);
|
|
514
|
-
|
|
515
473
|
if (typeof value === 'object') {
|
|
516
474
|
key = value.key;
|
|
517
475
|
values = getValues(value.params, diffObj);
|
|
@@ -521,7 +479,6 @@ export function userDateFormat(getI18NValue, timezoneData, timeFormat, datePatte
|
|
|
521
479
|
}
|
|
522
480
|
}
|
|
523
481
|
}
|
|
524
|
-
|
|
525
482
|
let key1 = isSuffixEnable && suffix != '' ? `${key}.${suffix}` : key;
|
|
526
483
|
return text || getI18NValue(key1, values);
|
|
527
484
|
};
|
|
@@ -530,15 +487,12 @@ let oneYearInMillis = 31536000000;
|
|
|
530
487
|
let oneDayInMillis = 86400000;
|
|
531
488
|
let oneHourInMillis = 3600000;
|
|
532
489
|
let oneMinuteInMillis = 60000;
|
|
533
|
-
|
|
534
490
|
function convertAsNonExponential(number) {
|
|
535
491
|
if (number.toString().toLowerCase().indexOf('e') !== -1) {
|
|
536
492
|
return number.toFixed(20);
|
|
537
493
|
}
|
|
538
|
-
|
|
539
494
|
return number;
|
|
540
495
|
}
|
|
541
|
-
|
|
542
496
|
export function getDiffObj(diff) {
|
|
543
497
|
diff = Math.abs(diff);
|
|
544
498
|
let diffYears = diff / oneYearInMillis;
|
|
@@ -564,22 +518,19 @@ export function getDiffObj(diff) {
|
|
|
564
518
|
}
|
|
565
519
|
export function getLyears(from, to) {
|
|
566
520
|
let dFrom = new Date(from),
|
|
567
|
-
|
|
521
|
+
dTo = new Date(to);
|
|
568
522
|
let fromYear = dFrom.getFullYear();
|
|
569
523
|
let toYear = dTo.getFullYear();
|
|
570
524
|
let arrayofLeapYears = [];
|
|
571
|
-
|
|
572
525
|
for (let loopYear = fromYear; loopYear <= toYear; loopYear++) {
|
|
573
526
|
if (loopYear % 4 === 0 && loopYear % 100 !== 0 || loopYear % 100 === 0 && loopYear % 400 === 0) {
|
|
574
527
|
arrayofLeapYears.push(loopYear);
|
|
575
528
|
}
|
|
576
529
|
}
|
|
577
|
-
|
|
578
530
|
return arrayofLeapYears.length;
|
|
579
531
|
}
|
|
580
532
|
export function getSuffix(min, ago, later) {
|
|
581
533
|
let suffix;
|
|
582
|
-
|
|
583
534
|
if (min < 0) {
|
|
584
535
|
suffix = ago || '';
|
|
585
536
|
} else if (min > 0) {
|
|
@@ -587,6 +538,5 @@ export function getSuffix(min, ago, later) {
|
|
|
587
538
|
} else {
|
|
588
539
|
suffix = '';
|
|
589
540
|
}
|
|
590
|
-
|
|
591
541
|
return suffix;
|
|
592
542
|
}
|
|
@@ -1,34 +1,30 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { unescapeUnicode } from "./index";
|
|
3
3
|
import { i18NProviderUtils } from "../components/I18NProvider";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
import { reportI18NError, I18N_ERROR_TYPES } from "./errorReporter";
|
|
5
|
+
export function splitMatchedExp({
|
|
6
|
+
expression,
|
|
7
|
+
charLenToOmit,
|
|
8
|
+
string
|
|
9
|
+
}) {
|
|
10
10
|
let splitString = string.split(new RegExp(expression, 'g'));
|
|
11
11
|
let matchedExpAll = string.matchAll(new RegExp(expression, 'g'));
|
|
12
12
|
let matchedExpKeys = [];
|
|
13
|
-
|
|
14
13
|
for (let match of matchedExpAll) {
|
|
15
14
|
const value = match[0];
|
|
16
15
|
matchedExpKeys.push(value.substring(charLenToOmit, value.length - charLenToOmit));
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
return {
|
|
20
18
|
splitString,
|
|
21
19
|
matchedExpKeys
|
|
22
20
|
};
|
|
23
21
|
}
|
|
24
|
-
export function generateChildren(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} = _ref2;
|
|
22
|
+
export function generateChildren({
|
|
23
|
+
children,
|
|
24
|
+
child
|
|
25
|
+
}) {
|
|
29
26
|
let newChildren = [],
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
stringPlaceHolders = {};
|
|
32
28
|
const handleString = string => {
|
|
33
29
|
if (string) {
|
|
34
30
|
let {
|
|
@@ -43,7 +39,6 @@ export function generateChildren(_ref2) {
|
|
|
43
39
|
newChildren.push(splitString);
|
|
44
40
|
}
|
|
45
41
|
};
|
|
46
|
-
|
|
47
42
|
let {
|
|
48
43
|
splitString: splitChild,
|
|
49
44
|
matchedExpKeys: childrenKeys
|
|
@@ -63,17 +58,15 @@ export function generateChildren(_ref2) {
|
|
|
63
58
|
stringPlaceHolders
|
|
64
59
|
};
|
|
65
60
|
}
|
|
66
|
-
export function createElement(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
values = []
|
|
76
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
61
|
+
export function createElement({
|
|
62
|
+
componentId,
|
|
63
|
+
children = [],
|
|
64
|
+
stringPlaceHolders = {}
|
|
65
|
+
} = {}) {
|
|
66
|
+
return ({
|
|
67
|
+
components = {},
|
|
68
|
+
values = []
|
|
69
|
+
} = {}) => {
|
|
77
70
|
const {
|
|
78
71
|
type = React.Fragment,
|
|
79
72
|
props
|
|
@@ -85,46 +78,39 @@ export function createElement() {
|
|
|
85
78
|
values
|
|
86
79
|
});
|
|
87
80
|
}
|
|
88
|
-
|
|
89
81
|
let string = '',
|
|
90
|
-
|
|
82
|
+
stringIndex = 0;
|
|
91
83
|
(stringPlaceHolders[index] || []).map((stringId, index) => {
|
|
92
84
|
if (child[index]) {
|
|
93
85
|
string += child[index];
|
|
94
86
|
}
|
|
95
|
-
|
|
96
87
|
string += values[stringId];
|
|
97
88
|
stringIndex++;
|
|
98
89
|
});
|
|
99
|
-
|
|
100
90
|
if (child[stringIndex]) {
|
|
101
91
|
string += child[stringIndex];
|
|
102
92
|
}
|
|
103
|
-
|
|
104
93
|
return string;
|
|
105
94
|
});
|
|
106
95
|
return /*#__PURE__*/React.createElement(type, props, ...childElements);
|
|
107
96
|
};
|
|
108
97
|
}
|
|
109
98
|
;
|
|
110
|
-
export function replaceWithComponentPlaceHolder(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
} = _ref3;
|
|
99
|
+
export function replaceWithComponentPlaceHolder({
|
|
100
|
+
componentId,
|
|
101
|
+
i18nKey,
|
|
102
|
+
childrenLength
|
|
103
|
+
}) {
|
|
116
104
|
const closingTagIndex = i18nKey.indexOf(`</${componentId}>`);
|
|
117
105
|
const childWithOpenTag = i18nKey.substring(0, closingTagIndex);
|
|
118
106
|
const openTagIndex = childWithOpenTag.lastIndexOf(`<${componentId}>`);
|
|
119
107
|
return i18nKey.substring(0, openTagIndex) + `<0${childrenLength}${componentId}>` + i18nKey.substring(closingTagIndex + `${componentId}`.length + 3);
|
|
120
108
|
}
|
|
121
|
-
export function prepareI18NFunc(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
109
|
+
export function prepareI18NFunc({
|
|
110
|
+
i18nKey,
|
|
111
|
+
children = {}
|
|
112
|
+
} = {}) {
|
|
126
113
|
const componentIdMatch = i18nKey.match(/<\/[A-Za-z0-9]+?>/);
|
|
127
|
-
|
|
128
114
|
if (componentIdMatch) {
|
|
129
115
|
const componentId = componentIdMatch[0].substring(2, componentIdMatch[0].length - 1);
|
|
130
116
|
const childWithOpenTag = (i18nKey.match(new RegExp(`(.*?)(?=<\/${componentId}>)`)) || [])[0] || '';
|
|
@@ -152,7 +138,6 @@ export function prepareI18NFunc() {
|
|
|
152
138
|
children
|
|
153
139
|
});
|
|
154
140
|
}
|
|
155
|
-
|
|
156
141
|
const {
|
|
157
142
|
newChildren,
|
|
158
143
|
stringPlaceHolders
|
|
@@ -166,7 +151,6 @@ export function prepareI18NFunc() {
|
|
|
166
151
|
stringPlaceHolders
|
|
167
152
|
});
|
|
168
153
|
}
|
|
169
|
-
|
|
170
154
|
function i18nMechanismForComponents(i18nValue, key) {
|
|
171
155
|
if (typeof i18nValue === 'string') {
|
|
172
156
|
i18nValue = unescapeUnicode(i18nValue);
|
|
@@ -178,26 +162,24 @@ function i18nMechanismForComponents(i18nValue, key) {
|
|
|
178
162
|
});
|
|
179
163
|
i18nValue = value;
|
|
180
164
|
}
|
|
181
|
-
|
|
182
165
|
return i18nValue;
|
|
183
166
|
}
|
|
184
|
-
|
|
185
167
|
export function placeComponentForTags(i18nValue) {
|
|
186
168
|
const value = i18NProviderUtils.getI18NComponent(i18nValue);
|
|
187
169
|
return i18nMechanismForComponents(value, value);
|
|
188
170
|
}
|
|
189
171
|
export function getI18NComponent(i18n) {
|
|
190
172
|
if (typeof i18n === 'undefined') {
|
|
173
|
+
reportI18NError(I18N_ERROR_TYPES.UNDEFINED_OBJECT, 'i18n_object_jsx');
|
|
191
174
|
return key => key;
|
|
192
175
|
}
|
|
193
|
-
|
|
194
176
|
return key => {
|
|
195
177
|
let i18nStr = i18n[key];
|
|
196
|
-
|
|
197
178
|
if (i18nStr === undefined) {
|
|
198
|
-
|
|
179
|
+
const isNumeric = /^\d+$/.test(key);
|
|
180
|
+
reportI18NError(isNumeric ? I18N_ERROR_TYPES.NUMERIC_FALLBACK : I18N_ERROR_TYPES.MISSING_KEY, key);
|
|
181
|
+
return getFallbackText(key);
|
|
199
182
|
}
|
|
200
|
-
|
|
201
183
|
return i18nMechanismForComponents(i18nStr, key);
|
|
202
184
|
};
|
|
203
185
|
}
|
package/lib/I18NContext.js
CHANGED
|
@@ -4,11 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.I18NContext = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var I18NContext = /*#__PURE__*/_react["default"].createContext();
|
|
13
|
-
|
|
14
|
-
exports.I18NContext = I18NContext;
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
9
|
+
var I18NContext = exports.I18NContext = /*#__PURE__*/_react["default"].createContext();
|