@zohodesk/i18n 1.0.0-exp.3 → 1.0.0-exp.4
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 +139 -25
- package/es/components/DateTimeDiffFormat.js +60 -61
- package/es/components/FormatText.js +4 -3
- package/es/components/HOCI18N.js +36 -41
- package/es/components/I18N.js +6 -16
- package/es/components/I18NProvider.js +21 -19
- package/es/components/PluralFormat.js +5 -9
- package/es/components/UserTimeDiffFormat.js +19 -11
- package/es/components/__tests__/DateTimeDiffFormat.spec.js +180 -182
- package/es/components/__tests__/FormatText.spec.js +4 -5
- package/es/components/__tests__/HOCI18N.spec.js +4 -7
- package/es/components/__tests__/I18N.spec.js +10 -11
- package/es/components/__tests__/I18NProvider.spec.js +6 -7
- package/es/components/__tests__/PluralFormat.spec.js +5 -6
- package/es/components/__tests__/UserTimeDiffFormat.spec.js +323 -269
- 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 +12 -12
- package/es/utils/__tests__/jsxTranslations.spec.js +171 -0
- package/es/utils/errorReporter.js +33 -0
- package/es/utils/index.js +549 -0
- package/es/utils/jsxTranslations.js +186 -0
- package/lib/I18NContext.js +1 -5
- package/lib/components/DateTimeDiffFormat.js +89 -114
- package/lib/components/FormatText.js +14 -34
- package/lib/components/HOCI18N.js +17 -50
- package/lib/components/I18N.js +22 -55
- package/lib/components/I18NProvider.js +40 -59
- package/lib/components/PluralFormat.js +20 -43
- package/lib/components/UserTimeDiffFormat.js +47 -67
- package/lib/components/__tests__/DateTimeDiffFormat.spec.js +119 -189
- 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 +7 -23
- package/lib/components/__tests__/PluralFormat.spec.js +3 -11
- package/lib/components/__tests__/UserTimeDiffFormat.spec.js +202 -271
- 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 +83 -70
- package/lib/utils/__tests__/jsxTranslations.spec.js +172 -0
- package/lib/utils/errorReporter.js +42 -0
- package/lib/utils/index.js +582 -0
- package/lib/utils/jsxTranslations.js +209 -0
- package/package.json +30 -29
- package/src/I18NContext.js +2 -2
- package/src/components/DateTimeDiffFormat.js +256 -229
- package/src/components/FormatText.js +14 -14
- package/src/components/HOCI18N.js +37 -37
- package/src/components/I18N.js +74 -72
- package/src/components/I18NProvider.js +118 -102
- package/src/components/PluralFormat.js +37 -37
- package/src/components/UserTimeDiffFormat.js +97 -93
- 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 +38 -33
- package/src/utils/__tests__/jsxTranslations.spec.js +213 -0
- package/src/utils/errorReporter.js +39 -0
- package/src/{utils.js → utils/index.js} +636 -595
- package/src/utils/jsxTranslations.js +191 -0
- package/es/components/NewDateFormat.js +0 -54
- package/es/utils.js +0 -557
- package/lib/components/NewDateFormat.js +0 -60
- package/lib/utils.js +0 -645
- package/src/components/NewDateFormat.js +0 -60
package/README.md
CHANGED
|
@@ -1,25 +1,139 @@
|
|
|
1
|
-
# i18n
|
|
2
|
-
|
|
3
|
-
# 1.0.0-beta.
|
|
4
|
-
|
|
5
|
-
-
|
|
6
|
-
|
|
7
|
-
# 1.0.0-beta.
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
# 1.0.0-beta.
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
# 1.0.0-beta.
|
|
16
|
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
# 1.0.0-beta.
|
|
20
|
-
|
|
21
|
-
-
|
|
22
|
-
|
|
23
|
-
# 1.0.0-beta.
|
|
24
|
-
|
|
25
|
-
-
|
|
1
|
+
# i18n
|
|
2
|
+
|
|
3
|
+
# 1.0.0-beta.34
|
|
4
|
+
|
|
5
|
+
- Tagholder Replacement with React Component
|
|
6
|
+
|
|
7
|
+
# 1.0.0-beta.33
|
|
8
|
+
|
|
9
|
+
- Upgrading @zoho/SecurityJS package to 7.2.4
|
|
10
|
+
|
|
11
|
+
# 1.0.0-beta.32
|
|
12
|
+
|
|
13
|
+
- Upgrading @zoho/SecurityJS package to 7.2.0
|
|
14
|
+
|
|
15
|
+
# 1.0.0-beta.31
|
|
16
|
+
|
|
17
|
+
- Syntax correction in Update Flow
|
|
18
|
+
|
|
19
|
+
# 1.0.0-beta.30
|
|
20
|
+
|
|
21
|
+
- Upgrading @zoho/SecurityJS package to 6.4.2
|
|
22
|
+
|
|
23
|
+
# 1.0.0-beta.29
|
|
24
|
+
|
|
25
|
+
- Downgrading @zoho/SecurityJS package to 6.3.0
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# 1.0.0-beta.28
|
|
29
|
+
|
|
30
|
+
- Updating @zoho/SecurityJS package to 7.0.2
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# 1.0.0-beta.27
|
|
34
|
+
|
|
35
|
+
- JSX support within a text
|
|
36
|
+
|
|
37
|
+
# 1.0.0-beta.26
|
|
38
|
+
|
|
39
|
+
- Localization feature enhancement in i18n method.
|
|
40
|
+
|
|
41
|
+
# 1.0.0-beta.25
|
|
42
|
+
|
|
43
|
+
- July i18n key correction
|
|
44
|
+
|
|
45
|
+
# 1.0.0-beta.24
|
|
46
|
+
|
|
47
|
+
- I18N support for Days, Months and 12-hour time variables.
|
|
48
|
+
|
|
49
|
+
# 1.0.0-beta.23
|
|
50
|
+
|
|
51
|
+
- Zoho security version updated.
|
|
52
|
+
|
|
53
|
+
# 1.0.0-beta.22
|
|
54
|
+
|
|
55
|
+
- Data test id added for I18N.js
|
|
56
|
+
|
|
57
|
+
# 1.0.0-beta.21
|
|
58
|
+
|
|
59
|
+
- Data test id added for dateTimedifformat.js
|
|
60
|
+
|
|
61
|
+
# 1.0.0-beta.20
|
|
62
|
+
|
|
63
|
+
- Date field issue fixed in UserTimeDiffFormat component
|
|
64
|
+
|
|
65
|
+
# 1.0.0-beta.19
|
|
66
|
+
|
|
67
|
+
- In this version we have made changes in i18n provider to call user date format function only if the time zone data is available.
|
|
68
|
+
|
|
69
|
+
# 1.0.0-beta.18
|
|
70
|
+
|
|
71
|
+
- Localization feature added and incorporated into getI18NValue Method.
|
|
72
|
+
|
|
73
|
+
# 1.0.0-beta.17
|
|
74
|
+
|
|
75
|
+
- There was some i18n changes done in live before moving the date format build to live. Since we need these changes we have published it as new version.
|
|
76
|
+
|
|
77
|
+
# 1.0.0-beta.16
|
|
78
|
+
|
|
79
|
+
- DatePattern and dateTimePattern key has been changed for the date format build.
|
|
80
|
+
|
|
81
|
+
# 1.0.0-beta.15.1
|
|
82
|
+
|
|
83
|
+
- Zoho security version updated.
|
|
84
|
+
|
|
85
|
+
# 1.0.0-beta.15
|
|
86
|
+
|
|
87
|
+
- When working on date format build we have published I18n. Also, before moving date format build to master we had a emergency fix that need to be sent, so when publishing I18n we have published the date format changes with the next version.
|
|
88
|
+
|
|
89
|
+
# 1.0.0-beta.14
|
|
90
|
+
|
|
91
|
+
- Issue fixed in enable current year.
|
|
92
|
+
|
|
93
|
+
# 1.0.0-beta.13
|
|
94
|
+
|
|
95
|
+
- Issue fixed in due date.
|
|
96
|
+
|
|
97
|
+
# 1.0.0-beta.12
|
|
98
|
+
|
|
99
|
+
- Issue fixed in date Format Pattern.
|
|
100
|
+
|
|
101
|
+
# 1.0.0-beta.11
|
|
102
|
+
|
|
103
|
+
- Date Format Changes
|
|
104
|
+
|
|
105
|
+
# 1.0.0-beta.10
|
|
106
|
+
|
|
107
|
+
- Date Format Issue Fixes
|
|
108
|
+
|
|
109
|
+
# 1.0.0-beta.9
|
|
110
|
+
|
|
111
|
+
- Date Format Changes
|
|
112
|
+
|
|
113
|
+
# 1.0.0-beta.8
|
|
114
|
+
|
|
115
|
+
- ES Module Support Changes
|
|
116
|
+
|
|
117
|
+
# 1.0.0-beta.7
|
|
118
|
+
|
|
119
|
+
- 'userDateFormat' util method - 'others' function fix
|
|
120
|
+
|
|
121
|
+
# 1.0.0-beta.6
|
|
122
|
+
|
|
123
|
+
- Added new prop 'isNeedTime' for DateTimeDiffFormat Component
|
|
124
|
+
|
|
125
|
+
# 1.0.0-beta.5
|
|
126
|
+
|
|
127
|
+
- Timezone logic moved to @zohodesk/datetimejs
|
|
128
|
+
|
|
129
|
+
# 1.0.0-beta.4
|
|
130
|
+
|
|
131
|
+
- Added new prop 'page' for DateTimeDiffFormat Component
|
|
132
|
+
|
|
133
|
+
# 1.0.0-beta.3
|
|
134
|
+
|
|
135
|
+
- Added support for exact times along with relative times in format() function
|
|
136
|
+
|
|
137
|
+
# 1.0.0-beta.0
|
|
138
|
+
|
|
139
|
+
- Test Publish
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { pad, getValues, getDiffObj, formatDate, getLyears } from
|
|
4
|
-
import FormatText from
|
|
3
|
+
import { pad, getValues, getDiffObj, formatDate, getLyears, getDatePatternWithoutYear } from "../utils";
|
|
4
|
+
import FormatText from "./FormatText";
|
|
5
5
|
import datetime from '@zohodesk/datetimejs';
|
|
6
6
|
export default class DateTimeDiffFormat extends React.Component {
|
|
7
7
|
constructor(props) {
|
|
8
8
|
super(props);
|
|
9
9
|
this.getSuffix = this.getSuffix.bind(this);
|
|
10
10
|
}
|
|
11
|
-
|
|
12
11
|
getSuffix(min) {
|
|
13
12
|
let suffix;
|
|
14
|
-
|
|
15
13
|
if (this.props.ago && min < 0) {
|
|
16
14
|
suffix = this.props.ago || '';
|
|
17
15
|
} else if (this.props.later || min > 0) {
|
|
@@ -19,10 +17,8 @@ export default class DateTimeDiffFormat extends React.Component {
|
|
|
19
17
|
} else {
|
|
20
18
|
suffix = '';
|
|
21
19
|
}
|
|
22
|
-
|
|
23
20
|
return suffix;
|
|
24
21
|
}
|
|
25
|
-
|
|
26
22
|
render() {
|
|
27
23
|
const {
|
|
28
24
|
type,
|
|
@@ -40,10 +36,14 @@ export default class DateTimeDiffFormat extends React.Component {
|
|
|
40
36
|
dataId,
|
|
41
37
|
className = null,
|
|
42
38
|
title = null,
|
|
43
|
-
isOverdue
|
|
39
|
+
isOverdue,
|
|
40
|
+
timeFormat,
|
|
41
|
+
datePattern,
|
|
42
|
+
isEnabledCurrentYear,
|
|
43
|
+
isDateField
|
|
44
44
|
} = this.props;
|
|
45
45
|
let fromDateObj = datetime.toDate(datetime.tz.utcToTz(from, fromTzData)).getTime();
|
|
46
|
-
let toDateObj = datetime.toDate(datetime.tz.utcToTz(to, toTzData)).getTime();
|
|
46
|
+
let toDateObj = datetime.toDate(isDateField ? to : datetime.tz.utcToTz(to, toTzData)).getTime();
|
|
47
47
|
let diffMin = new Date(to).getTime() - new Date(from).getTime();
|
|
48
48
|
let suffix = this.getSuffix(diffMin);
|
|
49
49
|
let diff = getDiffObj(diffMin);
|
|
@@ -63,6 +63,7 @@ export default class DateTimeDiffFormat extends React.Component {
|
|
|
63
63
|
suffix: suffix
|
|
64
64
|
};
|
|
65
65
|
let diffObj1 = {
|
|
66
|
+
to: to,
|
|
66
67
|
type: type,
|
|
67
68
|
page: page,
|
|
68
69
|
isNeedTime: isNeedTime,
|
|
@@ -71,7 +72,6 @@ export default class DateTimeDiffFormat extends React.Component {
|
|
|
71
72
|
seconds: diff.s,
|
|
72
73
|
years: diff.y,
|
|
73
74
|
yDays: diff.yd,
|
|
74
|
-
yMonth: diff.m,
|
|
75
75
|
isWithInAWeek: withInAWeak,
|
|
76
76
|
suffix: suffix,
|
|
77
77
|
crntDate: new Date(from).getDate(),
|
|
@@ -87,13 +87,26 @@ export default class DateTimeDiffFormat extends React.Component {
|
|
|
87
87
|
tMinutes: new Date(to).getMinutes(),
|
|
88
88
|
tSeconds: new Date(to).getSeconds(),
|
|
89
89
|
betweenleepYears: getLyears(from, to),
|
|
90
|
-
isOverdue: isOverdue
|
|
90
|
+
isOverdue: isOverdue,
|
|
91
|
+
timeFormat: timeFormat,
|
|
92
|
+
datePattern: datePattern,
|
|
93
|
+
dateTimePattern: `${datePattern} ${timeFormat}`
|
|
91
94
|
};
|
|
95
|
+
|
|
96
|
+
//In if condition we'll remove year and set date format if the current year is not required
|
|
97
|
+
//In else part we'll set the date format as it is
|
|
98
|
+
if (isEnabledCurrentYear === true && diffObj1.years === 0 && diffObj1.tYear === diffObj1.crntYear) {
|
|
99
|
+
let dateFormat = getDatePatternWithoutYear(datePattern);
|
|
100
|
+
diffObj1.dateFormat = dateFormat;
|
|
101
|
+
diffObj1.dateTimeFormat = `${dateFormat} ${timeFormat}`;
|
|
102
|
+
} else {
|
|
103
|
+
diffObj1.dateFormat = datePattern;
|
|
104
|
+
diffObj1.dateTimeFormat = `${datePattern} ${timeFormat}`;
|
|
105
|
+
}
|
|
92
106
|
let key = '';
|
|
93
107
|
let values = [];
|
|
94
108
|
let text = null;
|
|
95
109
|
let isSuffixEnable = false;
|
|
96
|
-
|
|
97
110
|
if (format) {
|
|
98
111
|
let years, months, days, hours, minutes, seconds;
|
|
99
112
|
years = diffObj1.years > 1 ? '2' : diffObj1.years;
|
|
@@ -110,15 +123,12 @@ export default class DateTimeDiffFormat extends React.Component {
|
|
|
110
123
|
} else {
|
|
111
124
|
res = res + next;
|
|
112
125
|
}
|
|
113
|
-
|
|
114
126
|
return res;
|
|
115
127
|
}, '');
|
|
116
128
|
let value = format(diffObj1, pattern);
|
|
117
|
-
|
|
118
129
|
if (value && typeof value === 'object') {
|
|
119
130
|
key = value.key;
|
|
120
131
|
values = getValues(value.params, diffObj);
|
|
121
|
-
|
|
122
132
|
if (pattern.indexOf('00000') === 0) {
|
|
123
133
|
//suffix ignore for second hook
|
|
124
134
|
isSuffixEnable = false;
|
|
@@ -129,62 +139,51 @@ export default class DateTimeDiffFormat extends React.Component {
|
|
|
129
139
|
text = formatDate(toDateObj, value, diffObj1);
|
|
130
140
|
}
|
|
131
141
|
} else {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
142
|
+
let dateObj = new Date(toDateObj);
|
|
143
|
+
let curDateObj = new Date(fromDateObj);
|
|
144
|
+
let diffDayType = diffObj1.yDays;
|
|
135
145
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
} else if (typeof yesterday === 'object') {
|
|
154
|
-
key = yesterday.key;
|
|
155
|
-
values = getValues(yesterday.params, diffObj);
|
|
156
|
-
} else if (typeof yesterday === 'string') {
|
|
157
|
-
text = formatDate(toDateObj, yesterday);
|
|
158
|
-
}
|
|
159
|
-
} else if (dateObj.getDate() > curDateObj.getDate()) {
|
|
160
|
-
if (typeof tomorrow === 'function') {
|
|
161
|
-
var value = tomorrow(diffObj1);
|
|
162
|
-
key = value.key;
|
|
163
|
-
text = getValues(value.params, diffObj);
|
|
164
|
-
} else if (typeof tomorrow === 'object') {
|
|
165
|
-
key = tomorrow.key;
|
|
166
|
-
values = getValues(tomorrow.params, diffObj);
|
|
167
|
-
} else if (typeof tomorrow === 'string') {
|
|
168
|
-
text = formatDate(toDateObj, tomorrow);
|
|
146
|
+
//In this condition, to calculate different days we have copied it from live --> diffDayType
|
|
147
|
+
if (isOverdue && dateObj.getDate() < curDateObj.getDate() && diffObj1.yDays == 0) {
|
|
148
|
+
diffDayType = -1;
|
|
149
|
+
}
|
|
150
|
+
if (!isOverdue) {
|
|
151
|
+
let diffHr = dateObj.getHours() - curDateObj.getHours();
|
|
152
|
+
if (diffHr < 0) {
|
|
153
|
+
diffDayType += 1;
|
|
154
|
+
} else if (diffHr == 0) {
|
|
155
|
+
let diffMins = dateObj.getMinutes() - curDateObj.getMinutes();
|
|
156
|
+
if (diffMins < 0) {
|
|
157
|
+
diffDayType += 1;
|
|
158
|
+
} else if (diffMins == 0) {
|
|
159
|
+
let diffSec = dateObj.getSeconds() - curDateObj.getSeconds();
|
|
160
|
+
if (diffSec < 0) {
|
|
161
|
+
diffDayType += 1;
|
|
162
|
+
}
|
|
169
163
|
}
|
|
170
164
|
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
165
|
+
}
|
|
166
|
+
if (diff.y === 0 && (diffDayType === 0 || diffDayType === 1)) {
|
|
167
|
+
if (dateObj.getDate() === curDateObj.getDate()) {
|
|
168
|
+
var value = today && today(diffObj1) || others(diffObj1);
|
|
169
|
+
text = formatDate(toDateObj, value);
|
|
170
|
+
} else if (dateObj.getMonth() === curDateObj.getMonth() && dateObj.getDate() < curDateObj.getDate() || dateObj.getMonth() < curDateObj.getMonth()) {
|
|
171
|
+
var value = yesterday && yesterday(diffObj1) || others(diffObj1);
|
|
172
|
+
text = formatDate(toDateObj, value);
|
|
173
|
+
} else if (!isOverdue && diff.y === 0 && diffDayType === 1) {
|
|
174
|
+
var value = tomorrow && tomorrow(diffObj1) || others(diffObj1);
|
|
179
175
|
text = formatDate(toDateObj, value);
|
|
180
176
|
}
|
|
177
|
+
} else {
|
|
178
|
+
var value = others(diffObj1);
|
|
179
|
+
text = formatDate(toDateObj, value);
|
|
181
180
|
}
|
|
182
181
|
}
|
|
183
|
-
|
|
184
182
|
return text ? /*#__PURE__*/React.createElement("span", {
|
|
185
183
|
className: className,
|
|
186
184
|
"data-title": title,
|
|
187
|
-
"data-id": dataId
|
|
185
|
+
"data-id": dataId,
|
|
186
|
+
"data-test-id": dataId
|
|
188
187
|
}, text) : /*#__PURE__*/React.createElement(FormatText, {
|
|
189
188
|
i18NKey: isSuffixEnable && suffix !== '' ? `${key}.${suffix}` : key,
|
|
190
189
|
values: values,
|
|
@@ -192,7 +191,6 @@ export default class DateTimeDiffFormat extends React.Component {
|
|
|
192
191
|
"data-title": title
|
|
193
192
|
});
|
|
194
193
|
}
|
|
195
|
-
|
|
196
194
|
}
|
|
197
195
|
DateTimeDiffFormat.propTypes = {
|
|
198
196
|
ago: PropTypes.string,
|
|
@@ -201,6 +199,7 @@ DateTimeDiffFormat.propTypes = {
|
|
|
201
199
|
format: PropTypes.func,
|
|
202
200
|
from: PropTypes.string,
|
|
203
201
|
fromTzData: PropTypes.object,
|
|
202
|
+
isDateField: PropTypes.bool,
|
|
204
203
|
later: PropTypes.string,
|
|
205
204
|
others: PropTypes.func,
|
|
206
205
|
title: PropTypes.string,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import I18N from
|
|
3
|
+
import I18N from "./I18N";
|
|
4
4
|
export default class FormatText extends React.Component {
|
|
5
5
|
render() {
|
|
6
|
-
return /*#__PURE__*/React.createElement(I18N,
|
|
6
|
+
return /*#__PURE__*/React.createElement(I18N, {
|
|
7
|
+
...this.props
|
|
8
|
+
});
|
|
7
9
|
}
|
|
8
|
-
|
|
9
10
|
}
|
|
10
11
|
FormatText.propTypes = {
|
|
11
12
|
i18NKey: PropTypes.string.isRequired,
|
package/es/components/HOCI18N.js
CHANGED
|
@@ -1,47 +1,42 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
-
|
|
3
1
|
import React, { Children } from 'react';
|
|
4
2
|
import PropTypes from 'prop-types';
|
|
5
|
-
import { replaceI18NValuesWithRegex, unescapeUnicode } from
|
|
6
|
-
import { I18NContext } from
|
|
7
|
-
export default ((
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
getI18NValue(key) {
|
|
15
|
-
const {
|
|
16
|
-
i18n
|
|
17
|
-
} = this.context || {};
|
|
18
|
-
|
|
19
|
-
if (typeof i18n === 'undefined') {
|
|
20
|
-
return key;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let i18nStr = i18n[key];
|
|
24
|
-
|
|
25
|
-
if (i18nStr === undefined) {
|
|
26
|
-
return key;
|
|
3
|
+
import { replaceI18NValuesWithRegex, unescapeUnicode } from "../utils";
|
|
4
|
+
import { I18NContext } from "../I18NContext";
|
|
5
|
+
export default (function () {
|
|
6
|
+
let i18NKeys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
7
|
+
return Component => {
|
|
8
|
+
class HOCI18N extends React.Component {
|
|
9
|
+
constructor(props) {
|
|
10
|
+
super(props);
|
|
11
|
+
this.getI18NValue = this.getI18NValue.bind(this);
|
|
27
12
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (this.props[key]) {
|
|
35
|
-
result[key] = this.getI18NValue(this.props[key]);
|
|
13
|
+
getI18NValue(key) {
|
|
14
|
+
const {
|
|
15
|
+
i18n
|
|
16
|
+
} = this.context || {};
|
|
17
|
+
if (typeof i18n === 'undefined') {
|
|
18
|
+
return key;
|
|
36
19
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
20
|
+
let i18nStr = i18n[key];
|
|
21
|
+
if (i18nStr === undefined) {
|
|
22
|
+
return key;
|
|
23
|
+
}
|
|
24
|
+
return unescapeUnicode(i18nStr);
|
|
25
|
+
}
|
|
26
|
+
render() {
|
|
27
|
+
let i18nProps = i18NKeys.reduce((result, key) => {
|
|
28
|
+
if (this.props[key]) {
|
|
29
|
+
result[key] = this.getI18NValue(this.props[key]);
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}, {});
|
|
33
|
+
return /*#__PURE__*/React.createElement(Component, {
|
|
34
|
+
...this.props,
|
|
35
|
+
...i18nProps
|
|
36
|
+
});
|
|
37
|
+
}
|
|
41
38
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
HOCI18N.contextType = I18NContext;
|
|
46
|
-
return HOCI18N;
|
|
39
|
+
HOCI18N.contextType = I18NContext;
|
|
40
|
+
return HOCI18N;
|
|
41
|
+
};
|
|
47
42
|
});
|
package/es/components/I18N.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import "core-js/modules/web.dom-collections.iterator";
|
|
2
1
|
import React, { Children } from 'react';
|
|
3
2
|
import PropTypes from 'prop-types';
|
|
4
|
-
import { replaceI18NValuesWithRegex, unescapeUnicode } from
|
|
3
|
+
import { replaceI18NValuesWithRegex, unescapeUnicode } from "../utils";
|
|
5
4
|
import { HTMLPurifier } from '@zoho/SecurityJS';
|
|
6
|
-
import { I18NContext } from
|
|
5
|
+
import { I18NContext } from "../I18NContext";
|
|
7
6
|
export default class I18N extends React.Component {
|
|
8
7
|
constructor(props) {
|
|
9
8
|
super(props);
|
|
10
9
|
this.getI18NValue = this.getI18NValue.bind(this);
|
|
11
10
|
this.createElement = this.createElement.bind(this);
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
getI18NValue() {
|
|
15
13
|
const {
|
|
16
14
|
i18NKey: key,
|
|
@@ -19,34 +17,28 @@ export default class I18N extends React.Component {
|
|
|
19
17
|
const {
|
|
20
18
|
i18n
|
|
21
19
|
} = this.context || {};
|
|
22
|
-
|
|
23
20
|
if (typeof i18n === 'undefined') {
|
|
24
21
|
return key;
|
|
25
22
|
}
|
|
26
|
-
|
|
27
23
|
let i18nStr = i18n[key];
|
|
28
|
-
|
|
29
24
|
if (i18nStr === undefined) {
|
|
30
25
|
return key;
|
|
31
26
|
}
|
|
32
|
-
|
|
33
27
|
i18nStr = replaceI18NValuesWithRegex(i18nStr, values);
|
|
34
28
|
return unescapeUnicode(i18nStr);
|
|
35
29
|
}
|
|
36
|
-
|
|
37
30
|
createElement() {
|
|
38
31
|
const props = Object.keys(this.props).reduce((result, nextKey) => {
|
|
39
32
|
if (nextKey != 'i18NKey' && nextKey != 'tag' && nextKey != 'values' && nextKey != 'isHtml' && nextKey != 'dataId') {
|
|
40
33
|
result[nextKey] = this.props[nextKey];
|
|
41
34
|
}
|
|
42
|
-
|
|
43
35
|
return result;
|
|
44
|
-
}, {});
|
|
45
|
-
|
|
36
|
+
}, {});
|
|
37
|
+
//const child=this.getI18NValue();
|
|
46
38
|
if (this.props.dataId) {
|
|
47
39
|
props['data-id'] = this.props.dataId;
|
|
40
|
+
props['data-test-id'] = this.props.dataId;
|
|
48
41
|
}
|
|
49
|
-
|
|
50
42
|
if (this.props.isHtml) {
|
|
51
43
|
let dangerouslySetInnerHTML = {
|
|
52
44
|
__html: HTMLPurifier.sanitize(this.getI18NValue())
|
|
@@ -55,19 +47,17 @@ export default class I18N extends React.Component {
|
|
|
55
47
|
dangerouslySetInnerHTML
|
|
56
48
|
}));
|
|
57
49
|
}
|
|
58
|
-
|
|
59
50
|
return /*#__PURE__*/React.createElement(this.props.tag, props, this.getI18NValue());
|
|
60
51
|
}
|
|
61
|
-
|
|
62
52
|
render() {
|
|
63
53
|
return this.createElement();
|
|
64
54
|
}
|
|
65
|
-
|
|
66
55
|
}
|
|
67
56
|
I18N.propTypes = {
|
|
68
57
|
i18NKey: PropTypes.string.isRequired,
|
|
69
58
|
isHtml: PropTypes.bool,
|
|
70
59
|
tag: PropTypes.string,
|
|
60
|
+
dataId: PropTypes.string,
|
|
71
61
|
values: PropTypes.oneOfType([PropTypes.string, PropTypes.array])
|
|
72
62
|
};
|
|
73
63
|
I18N.defaultProps = {
|
|
@@ -1,41 +1,45 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { getI18NValue, userDateFormat } from
|
|
4
|
-
import {
|
|
3
|
+
import { getI18NValue, userDateFormat } from "../utils";
|
|
4
|
+
import { getI18NComponent } from "../utils/jsxTranslations";
|
|
5
|
+
import { I18NContext } from "../I18NContext";
|
|
5
6
|
const emptyObj = {};
|
|
6
|
-
|
|
7
7
|
const dummy = (key, values) => key;
|
|
8
|
-
|
|
9
8
|
export const i18NProviderUtils = {
|
|
10
9
|
getI18NValue: dummy,
|
|
11
|
-
userDateFormat: dummy
|
|
10
|
+
userDateFormat: dummy,
|
|
11
|
+
getI18NComponent: dummy
|
|
12
12
|
};
|
|
13
13
|
export default class I18NProvider extends React.Component {
|
|
14
14
|
constructor(props, context) {
|
|
15
15
|
super(props, context);
|
|
16
16
|
i18NProviderUtils.getI18NValue = getI18NValue(props.i18n);
|
|
17
|
-
i18NProviderUtils.
|
|
17
|
+
i18NProviderUtils.getI18NComponent = getI18NComponent(props.i18n);
|
|
18
|
+
if (props.tzData) {
|
|
19
|
+
i18NProviderUtils.userDateFormat = userDateFormat(i18NProviderUtils.getI18NValue, props.tzData, props.timeFormat, props.datePattern, props.isEnabledCurrentYear);
|
|
20
|
+
}
|
|
18
21
|
}
|
|
19
|
-
|
|
20
|
-
componentDidUpdate(next) {
|
|
22
|
+
componentDidUpdate(prevProps) {
|
|
21
23
|
let {
|
|
22
24
|
i18n,
|
|
23
25
|
timeZone,
|
|
24
26
|
datePattern,
|
|
25
27
|
timeFormat,
|
|
26
|
-
dateTimeFormat,
|
|
27
28
|
direction,
|
|
28
29
|
onChange,
|
|
29
|
-
tzData
|
|
30
|
+
tzData,
|
|
31
|
+
isEnabledCurrentYear
|
|
30
32
|
} = this.props;
|
|
31
|
-
|
|
32
|
-
if (i18n !== next.i18n || timeZone !== next.timeZone || datePattern !== next.datePattern || timeFormat !== next.timeFormat || dateTimeFormat !== next.dateTimeFormat || direction !== next.direction || tzData !== next.tzData) {
|
|
33
|
+
if (i18n !== prevProps.i18n || timeZone !== prevProps.timeZone || datePattern !== prevProps.datePattern || timeFormat !== prevProps.timeFormat || direction !== prevProps.direction || tzData !== prevProps.tzData || isEnabledCurrentYear !== prevProps.isEnabledCurrentYear) {
|
|
33
34
|
this.promise = new Promise((res, rej) => {
|
|
34
35
|
this.resolve = res;
|
|
35
36
|
this.reject = rej;
|
|
36
37
|
}).then(() => {
|
|
37
|
-
i18NProviderUtils.getI18NValue = getI18NValue(
|
|
38
|
-
i18NProviderUtils.
|
|
38
|
+
i18NProviderUtils.getI18NValue = getI18NValue(this.props.i18n);
|
|
39
|
+
i18NProviderUtils.getI18NComponent = getI18NComponent(this.props.i18n);
|
|
40
|
+
if (this.props.tzData) {
|
|
41
|
+
i18NProviderUtils.userDateFormat = userDateFormat(i18NProviderUtils.getI18NValue, this.props.tzData, this.props.timeFormat, this.props.datePattern, this.props.isEnabledCurrentYear);
|
|
42
|
+
}
|
|
39
43
|
this.promise = null;
|
|
40
44
|
}, () => {
|
|
41
45
|
this.promise = null;
|
|
@@ -43,7 +47,6 @@ export default class I18NProvider extends React.Component {
|
|
|
43
47
|
onChange && onChange(this.resolve, this.reject);
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
|
-
|
|
47
50
|
render() {
|
|
48
51
|
return /*#__PURE__*/React.createElement(I18NContext.Provider, {
|
|
49
52
|
value: {
|
|
@@ -52,25 +55,24 @@ export default class I18NProvider extends React.Component {
|
|
|
52
55
|
timeZone: this.props.timeZone,
|
|
53
56
|
datePattern: this.props.datePattern,
|
|
54
57
|
timeFormat: this.props.timeFormat,
|
|
55
|
-
|
|
58
|
+
isEnabledCurrentYear: this.props.isEnabledCurrentYear,
|
|
56
59
|
tzData: this.props.tzData
|
|
57
60
|
}
|
|
58
61
|
}, this.props.children);
|
|
59
62
|
}
|
|
60
|
-
|
|
61
63
|
}
|
|
62
64
|
I18NProvider.defaultProps = {
|
|
63
65
|
i18n: emptyObj,
|
|
64
66
|
timeZone: '',
|
|
65
67
|
datePattern: '',
|
|
66
68
|
timeFormat: '',
|
|
67
|
-
|
|
69
|
+
isEnabledCurrentYear: '',
|
|
68
70
|
direction: 'ltr'
|
|
69
71
|
};
|
|
70
72
|
I18NProvider.propTypes = {
|
|
71
73
|
children: PropTypes.element.isRequired,
|
|
72
74
|
datePattern: PropTypes.string,
|
|
73
|
-
|
|
75
|
+
isEnabledCurrentYear: PropTypes.string,
|
|
74
76
|
direction: PropTypes.string,
|
|
75
77
|
i18n: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
|
76
78
|
onChange: PropTypes.func,
|