@zohodesk/i18n 1.0.0-beta.4 → 1.0.0-beta.41-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/README.md +130 -4
- 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/I18NContext.js +1 -2
- package/es/components/DateTimeDiffFormat.js +185 -209
- package/es/components/FormatText.js +7 -27
- package/es/components/HOCI18N.js +35 -58
- package/es/components/I18N.js +48 -74
- package/es/components/I18NProvider.js +59 -93
- package/es/components/PluralFormat.js +28 -51
- package/es/components/UserTimeDiffFormat.js +66 -81
- package/es/components/__tests__/DateTimeDiffFormat.spec.js +810 -663
- package/es/components/__tests__/FormatText.spec.js +22 -19
- package/es/components/__tests__/HOCI18N.spec.js +19 -25
- package/es/components/__tests__/I18N.spec.js +23 -21
- package/es/components/__tests__/I18NProvider.spec.js +38 -47
- package/es/components/__tests__/PluralFormat.spec.js +23 -20
- package/es/components/__tests__/UserTimeDiffFormat.spec.js +1259 -1110
- package/es/index.js +13 -15
- package/es/utils/__tests__/jsxTranslations.spec.js +170 -0
- package/es/utils/errorReporter.js +41 -0
- package/es/utils/index.js +543 -0
- package/es/utils/jsxTranslations.js +185 -0
- package/lib/I18NContext.js +5 -10
- package/lib/components/DateTimeDiffFormat.js +131 -146
- package/lib/components/FormatText.js +29 -42
- package/lib/components/HOCI18N.js +34 -45
- package/lib/components/I18N.js +46 -57
- package/lib/components/I18NProvider.js +72 -95
- package/lib/components/PluralFormat.js +39 -55
- package/lib/components/UserTimeDiffFormat.js +76 -84
- package/lib/components/__tests__/DateTimeDiffFormat.spec.js +751 -635
- package/lib/components/__tests__/FormatText.spec.js +21 -30
- package/lib/components/__tests__/HOCI18N.spec.js +22 -41
- package/lib/components/__tests__/I18N.spec.js +20 -33
- package/lib/components/__tests__/I18NProvider.spec.js +40 -63
- package/lib/components/__tests__/PluralFormat.spec.js +23 -35
- package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1195 -1046
- package/lib/index.js +83 -104
- package/lib/utils/__tests__/jsxTranslations.spec.js +172 -0
- package/lib/utils/errorReporter.js +49 -0
- package/lib/utils/index.js +583 -0
- package/lib/utils/jsxTranslations.js +216 -0
- package/package.json +4 -3
- package/src/components/DateTimeDiffFormat.js +84 -55
- package/src/components/I18N.js +2 -0
- package/src/components/I18NProvider.js +44 -33
- package/src/components/UserTimeDiffFormat.js +22 -18
- package/src/index.js +12 -9
- package/src/utils/__tests__/jsxTranslations.spec.js +213 -0
- package/src/utils/errorReporter.js +48 -0
- package/src/utils/index.js +644 -0
- package/src/utils/jsxTranslations.js +199 -0
- package/es/components/NewDateFormat.js +0 -50
- package/es/offset.js +0 -629
- package/es/timezones.js +0 -118
- package/es/utils.js +0 -621
- package/lib/components/NewDateFormat.js +0 -68
- package/lib/offset.js +0 -634
- package/lib/timezones.js +0 -129
- package/lib/utils.js +0 -651
- package/src/components/NewDateFormat.js +0 -60
- package/src/offset.js +0 -629
- package/src/timezones.js +0 -113
- package/src/utils.js +0 -648
|
@@ -1,222 +1,197 @@
|
|
|
1
|
-
import _typeof from 'babel-runtime/helpers/typeof';
|
|
2
|
-
import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
|
|
3
|
-
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
|
4
|
-
import _createClass from 'babel-runtime/helpers/createClass';
|
|
5
|
-
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
|
6
|
-
import _inherits from 'babel-runtime/helpers/inherits';
|
|
7
1
|
import React from 'react';
|
|
8
2
|
import PropTypes from 'prop-types';
|
|
9
|
-
import { pad, getValues, getDiffObj, formatDate, getLyears,
|
|
10
|
-
import FormatText from
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
_classCallCheck(this, DateTimeDiffFormat);
|
|
17
|
-
|
|
18
|
-
var _this = _possibleConstructorReturn(this, (DateTimeDiffFormat.__proto__ || _Object$getPrototypeOf(DateTimeDiffFormat)).call(this, props));
|
|
19
|
-
|
|
20
|
-
_this.getSuffix = _this.getSuffix.bind(_this);
|
|
21
|
-
return _this;
|
|
3
|
+
import { pad, getValues, getDiffObj, formatDate, getLyears, getDatePatternWithoutYear } from "../utils";
|
|
4
|
+
import FormatText from "./FormatText";
|
|
5
|
+
import datetime from '@zohodesk/datetimejs';
|
|
6
|
+
export default class DateTimeDiffFormat extends React.Component {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
super(props);
|
|
9
|
+
this.getSuffix = this.getSuffix.bind(this);
|
|
22
10
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
suffix = this.props.later || '';
|
|
32
|
-
} else {
|
|
33
|
-
suffix = '';
|
|
34
|
-
}
|
|
35
|
-
return suffix;
|
|
11
|
+
getSuffix(min) {
|
|
12
|
+
let suffix;
|
|
13
|
+
if (this.props.ago && min < 0) {
|
|
14
|
+
suffix = this.props.ago || '';
|
|
15
|
+
} else if (this.props.later || min > 0) {
|
|
16
|
+
suffix = this.props.later || '';
|
|
17
|
+
} else {
|
|
18
|
+
suffix = '';
|
|
36
19
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
values = getValues(_value.params, diffObj);
|
|
143
|
-
if (pattern.indexOf('00000') === 0) {
|
|
144
|
-
//suffix ignore for second hook
|
|
145
|
-
isSuffixEnable = false;
|
|
146
|
-
} else {
|
|
147
|
-
isSuffixEnable = true;
|
|
148
|
-
}
|
|
149
|
-
} else if (typeof _value === 'string') {
|
|
150
|
-
text = formatDate(toDateObj, _value, diffObj1);
|
|
20
|
+
return suffix;
|
|
21
|
+
}
|
|
22
|
+
render() {
|
|
23
|
+
const {
|
|
24
|
+
type,
|
|
25
|
+
page,
|
|
26
|
+
isNeedTime,
|
|
27
|
+
from,
|
|
28
|
+
fromTzData,
|
|
29
|
+
to,
|
|
30
|
+
toTzData,
|
|
31
|
+
today,
|
|
32
|
+
yesterday,
|
|
33
|
+
tomorrow,
|
|
34
|
+
others,
|
|
35
|
+
format,
|
|
36
|
+
dataId,
|
|
37
|
+
className = null,
|
|
38
|
+
title = null,
|
|
39
|
+
isOverdue,
|
|
40
|
+
timeFormat,
|
|
41
|
+
datePattern,
|
|
42
|
+
isEnabledCurrentYear,
|
|
43
|
+
isDateField
|
|
44
|
+
} = this.props;
|
|
45
|
+
let fromDateObj = datetime.toDate(datetime.tz.utcToTz(from, fromTzData)).getTime();
|
|
46
|
+
let toDateObj = datetime.toDate(isDateField ? to : datetime.tz.utcToTz(to, toTzData)).getTime();
|
|
47
|
+
let diffMin = new Date(to).getTime() - new Date(from).getTime();
|
|
48
|
+
let suffix = this.getSuffix(diffMin);
|
|
49
|
+
let diff = getDiffObj(diffMin);
|
|
50
|
+
let withInAWeak = diff.y === 0 && diff.yd <= 7;
|
|
51
|
+
let diffObj = {
|
|
52
|
+
h: diff.h,
|
|
53
|
+
m: diff.m,
|
|
54
|
+
s: diff.s,
|
|
55
|
+
y: diff.y,
|
|
56
|
+
hh: pad(diff.h, 2),
|
|
57
|
+
mm: pad(diff.m, 2),
|
|
58
|
+
ss: pad(diff.s, 2),
|
|
59
|
+
yy: pad(diff.y, 2),
|
|
60
|
+
days: diff.yd,
|
|
61
|
+
yDays: pad(diff.yd, 2),
|
|
62
|
+
isWithInAWeek: withInAWeak,
|
|
63
|
+
suffix: suffix
|
|
64
|
+
};
|
|
65
|
+
let diffObj1 = {
|
|
66
|
+
to: to,
|
|
67
|
+
type: type,
|
|
68
|
+
page: page,
|
|
69
|
+
isNeedTime: isNeedTime,
|
|
70
|
+
hours: diff.h,
|
|
71
|
+
minutes: diff.m,
|
|
72
|
+
seconds: diff.s,
|
|
73
|
+
years: diff.y,
|
|
74
|
+
yDays: diff.yd,
|
|
75
|
+
isWithInAWeek: withInAWeak,
|
|
76
|
+
suffix: suffix,
|
|
77
|
+
crntDate: new Date(from).getDate(),
|
|
78
|
+
crntMonth: new Date(from).getMonth(),
|
|
79
|
+
crntYear: new Date(from).getFullYear(),
|
|
80
|
+
crntHours: new Date(from).getHours(),
|
|
81
|
+
crntMinutes: new Date(from).getMinutes(),
|
|
82
|
+
crntSeconds: new Date(from).getSeconds(),
|
|
83
|
+
tDate: new Date(to).getDate(),
|
|
84
|
+
tMonth: new Date(to).getMonth(),
|
|
85
|
+
tYear: new Date(to).getFullYear(),
|
|
86
|
+
tHours: new Date(to).getHours(),
|
|
87
|
+
tMinutes: new Date(to).getMinutes(),
|
|
88
|
+
tSeconds: new Date(to).getSeconds(),
|
|
89
|
+
betweenleepYears: getLyears(from, to),
|
|
90
|
+
isOverdue: isOverdue,
|
|
91
|
+
timeFormat: timeFormat,
|
|
92
|
+
datePattern: datePattern,
|
|
93
|
+
dateTimePattern: `${datePattern} ${timeFormat}`
|
|
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
|
+
}
|
|
106
|
+
let key = '';
|
|
107
|
+
let values = [];
|
|
108
|
+
let text = null;
|
|
109
|
+
let isSuffixEnable = false;
|
|
110
|
+
if (format) {
|
|
111
|
+
let years, months, days, hours, minutes, seconds;
|
|
112
|
+
years = diffObj1.years > 1 ? '2' : diffObj1.years;
|
|
113
|
+
days = diff.yd > 1 ? '2' : diff.yd;
|
|
114
|
+
hours = diffObj1.hours > 1 ? '2' : diffObj1.hours;
|
|
115
|
+
minutes = diffObj1.minutes > 1 ? '2' : diffObj1.minutes;
|
|
116
|
+
let count = 0;
|
|
117
|
+
let pattern = [years, days, hours, minutes].reduce((res, next) => {
|
|
118
|
+
if (count === 2) {
|
|
119
|
+
res = `${res}0`;
|
|
120
|
+
} else if (next !== 0) {
|
|
121
|
+
count++;
|
|
122
|
+
res = res + next;
|
|
123
|
+
} else {
|
|
124
|
+
res = res + next;
|
|
151
125
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
} else if ((typeof today === 'undefined' ? 'undefined' : _typeof(today)) === 'object') {
|
|
162
|
-
key = today.key;
|
|
163
|
-
values = getValues(today.params, diffObj);
|
|
164
|
-
isSuffixEnable = true;
|
|
165
|
-
} else if (typeof today === 'string') {
|
|
166
|
-
text = formatDate(toDateObj, today);
|
|
167
|
-
}
|
|
168
|
-
} else if (dateObj.getDate() < curDateObj.getDate()) {
|
|
169
|
-
if (typeof yesterday === 'function') {
|
|
170
|
-
var value = yesterday(diffObj1);
|
|
171
|
-
key = value.key;
|
|
172
|
-
values = getValues(value.params, diffObj);
|
|
173
|
-
} else if ((typeof yesterday === 'undefined' ? 'undefined' : _typeof(yesterday)) === 'object') {
|
|
174
|
-
key = yesterday.key;
|
|
175
|
-
values = getValues(yesterday.params, diffObj);
|
|
176
|
-
} else if (typeof yesterday === 'string') {
|
|
177
|
-
text = formatDate(toDateObj, yesterday);
|
|
178
|
-
}
|
|
179
|
-
} else if (dateObj.getDate() > curDateObj.getDate()) {
|
|
180
|
-
if (typeof tomorrow === 'function') {
|
|
181
|
-
var value = tomorrow(diffObj1);
|
|
182
|
-
key = value.key;
|
|
183
|
-
text = getValues(value.params, diffObj);
|
|
184
|
-
} else if ((typeof tomorrow === 'undefined' ? 'undefined' : _typeof(tomorrow)) === 'object') {
|
|
185
|
-
key = tomorrow.key;
|
|
186
|
-
values = getValues(tomorrow.params, diffObj);
|
|
187
|
-
} else if (typeof tomorrow === 'string') {
|
|
188
|
-
text = formatDate(toDateObj, tomorrow);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
126
|
+
return res;
|
|
127
|
+
}, '');
|
|
128
|
+
let value = format(diffObj1, pattern);
|
|
129
|
+
if (value && typeof value === 'object') {
|
|
130
|
+
key = value.key;
|
|
131
|
+
values = getValues(value.params, diffObj);
|
|
132
|
+
if (pattern.indexOf('00000') === 0) {
|
|
133
|
+
//suffix ignore for second hook
|
|
134
|
+
isSuffixEnable = false;
|
|
191
135
|
} else {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
136
|
+
isSuffixEnable = true;
|
|
137
|
+
}
|
|
138
|
+
} else if (typeof value === 'string') {
|
|
139
|
+
text = formatDate(toDateObj, value, diffObj1);
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
let dateObj = new Date(toDateObj);
|
|
143
|
+
let curDateObj = new Date(fromDateObj);
|
|
144
|
+
let diffDayType = diffObj1.yDays;
|
|
145
|
+
|
|
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
|
+
}
|
|
199
163
|
}
|
|
200
164
|
}
|
|
201
165
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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);
|
|
175
|
+
text = formatDate(toDateObj, value);
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
var value = others(diffObj1);
|
|
179
|
+
text = formatDate(toDateObj, value);
|
|
180
|
+
}
|
|
212
181
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
182
|
+
return text ? /*#__PURE__*/React.createElement("span", {
|
|
183
|
+
className: className,
|
|
184
|
+
"data-title": title,
|
|
185
|
+
"data-id": dataId,
|
|
186
|
+
"data-test-id": dataId
|
|
187
|
+
}, text) : /*#__PURE__*/React.createElement(FormatText, {
|
|
188
|
+
i18NKey: isSuffixEnable && suffix !== '' ? `${key}.${suffix}` : key,
|
|
189
|
+
values: values,
|
|
190
|
+
className: className,
|
|
191
|
+
"data-title": title
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
220
195
|
DateTimeDiffFormat.propTypes = {
|
|
221
196
|
ago: PropTypes.string,
|
|
222
197
|
className: PropTypes.string,
|
|
@@ -224,6 +199,7 @@ DateTimeDiffFormat.propTypes = {
|
|
|
224
199
|
format: PropTypes.func,
|
|
225
200
|
from: PropTypes.string,
|
|
226
201
|
fromTzData: PropTypes.object,
|
|
202
|
+
isDateField: PropTypes.bool,
|
|
227
203
|
later: PropTypes.string,
|
|
228
204
|
others: PropTypes.func,
|
|
229
205
|
title: PropTypes.string,
|
|
@@ -1,33 +1,13 @@
|
|
|
1
|
-
import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
|
|
2
|
-
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
|
3
|
-
import _createClass from 'babel-runtime/helpers/createClass';
|
|
4
|
-
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
|
5
|
-
import _inherits from 'babel-runtime/helpers/inherits';
|
|
6
1
|
import React from 'react';
|
|
7
2
|
import PropTypes from 'prop-types';
|
|
8
|
-
import I18N from
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
_classCallCheck(this, FormatText);
|
|
15
|
-
|
|
16
|
-
return _possibleConstructorReturn(this, (FormatText.__proto__ || _Object$getPrototypeOf(FormatText)).apply(this, arguments));
|
|
3
|
+
import I18N from "./I18N";
|
|
4
|
+
export default class FormatText extends React.Component {
|
|
5
|
+
render() {
|
|
6
|
+
return /*#__PURE__*/React.createElement(I18N, {
|
|
7
|
+
...this.props
|
|
8
|
+
});
|
|
17
9
|
}
|
|
18
|
-
|
|
19
|
-
_createClass(FormatText, [{
|
|
20
|
-
key: 'render',
|
|
21
|
-
value: function render() {
|
|
22
|
-
return React.createElement(I18N, this.props);
|
|
23
|
-
}
|
|
24
|
-
}]);
|
|
25
|
-
|
|
26
|
-
return FormatText;
|
|
27
|
-
}(React.Component);
|
|
28
|
-
|
|
29
|
-
export default FormatText;
|
|
30
|
-
|
|
10
|
+
}
|
|
31
11
|
FormatText.propTypes = {
|
|
32
12
|
i18NKey: PropTypes.string.isRequired,
|
|
33
13
|
isHtml: PropTypes.bool,
|
package/es/components/HOCI18N.js
CHANGED
|
@@ -1,62 +1,39 @@
|
|
|
1
|
-
import _extends from 'babel-runtime/helpers/extends';
|
|
2
|
-
import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
|
|
3
|
-
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
|
4
|
-
import _createClass from 'babel-runtime/helpers/createClass';
|
|
5
|
-
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
|
6
|
-
import _inherits from 'babel-runtime/helpers/inherits';
|
|
7
1
|
import React, { Children } from 'react';
|
|
8
2
|
import PropTypes from 'prop-types';
|
|
9
|
-
import { replaceI18NValuesWithRegex, unescapeUnicode } from
|
|
10
|
-
import { I18NContext } from
|
|
11
|
-
export default (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return _this;
|
|
3
|
+
import { replaceI18NValuesWithRegex, unescapeUnicode } from "../utils";
|
|
4
|
+
import { I18NContext } from "../I18NContext";
|
|
5
|
+
export default (i18NKeys = []) => Component => {
|
|
6
|
+
class HOCI18N extends React.Component {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
super(props);
|
|
9
|
+
this.getI18NValue = this.getI18NValue.bind(this);
|
|
10
|
+
}
|
|
11
|
+
getI18NValue(key) {
|
|
12
|
+
const {
|
|
13
|
+
i18n
|
|
14
|
+
} = this.context || {};
|
|
15
|
+
if (typeof i18n === 'undefined') {
|
|
16
|
+
return key;
|
|
24
17
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
key
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var i18nStr = i18n[key];
|
|
36
|
-
if (i18nStr === undefined) {
|
|
37
|
-
return key;
|
|
38
|
-
}
|
|
39
|
-
return unescapeUnicode(i18nStr);
|
|
40
|
-
}
|
|
41
|
-
}, {
|
|
42
|
-
key: 'render',
|
|
43
|
-
value: function render() {
|
|
44
|
-
var _this2 = this;
|
|
45
|
-
|
|
46
|
-
var i18nProps = i18NKeys.reduce(function (result, key) {
|
|
47
|
-
if (_this2.props[key]) {
|
|
48
|
-
result[key] = _this2.getI18NValue(_this2.props[key]);
|
|
49
|
-
}
|
|
50
|
-
return result;
|
|
51
|
-
}, {});
|
|
52
|
-
return React.createElement(Component, _extends({}, this.props, i18nProps));
|
|
18
|
+
let i18nStr = i18n[key];
|
|
19
|
+
if (i18nStr === undefined) {
|
|
20
|
+
return key;
|
|
21
|
+
}
|
|
22
|
+
return unescapeUnicode(i18nStr);
|
|
23
|
+
}
|
|
24
|
+
render() {
|
|
25
|
+
let i18nProps = i18NKeys.reduce((result, key) => {
|
|
26
|
+
if (this.props[key]) {
|
|
27
|
+
result[key] = this.getI18NValue(this.props[key]);
|
|
53
28
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
29
|
+
return result;
|
|
30
|
+
}, {});
|
|
31
|
+
return /*#__PURE__*/React.createElement(Component, {
|
|
32
|
+
...this.props,
|
|
33
|
+
...i18nProps
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
HOCI18N.contextType = I18NContext;
|
|
38
|
+
return HOCI18N;
|
|
39
|
+
};
|