@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.
Files changed (70) hide show
  1. package/README.md +130 -4
  2. package/docs/murphy/01-MURPHY_OVERVIEW.md +148 -0
  3. package/docs/murphy/02-MURPHY_ARCHITECTURE.md +283 -0
  4. package/docs/murphy/03-MURPHY_BACKEND_CONFIG.md +337 -0
  5. package/docs/murphy/04-MURPHY_FRONTEND_INIT.md +437 -0
  6. package/docs/murphy/05-MURPHY_DESK_CLIENT_USAGE.md +467 -0
  7. package/docs/murphy/06-MURPHY_I18N_INTEGRATION.md +402 -0
  8. package/docs/murphy/07-MURPHY_WHY_I18N_APPROACH.md +391 -0
  9. package/es/I18NContext.js +1 -2
  10. package/es/components/DateTimeDiffFormat.js +185 -209
  11. package/es/components/FormatText.js +7 -27
  12. package/es/components/HOCI18N.js +35 -58
  13. package/es/components/I18N.js +48 -74
  14. package/es/components/I18NProvider.js +59 -93
  15. package/es/components/PluralFormat.js +28 -51
  16. package/es/components/UserTimeDiffFormat.js +66 -81
  17. package/es/components/__tests__/DateTimeDiffFormat.spec.js +810 -663
  18. package/es/components/__tests__/FormatText.spec.js +22 -19
  19. package/es/components/__tests__/HOCI18N.spec.js +19 -25
  20. package/es/components/__tests__/I18N.spec.js +23 -21
  21. package/es/components/__tests__/I18NProvider.spec.js +38 -47
  22. package/es/components/__tests__/PluralFormat.spec.js +23 -20
  23. package/es/components/__tests__/UserTimeDiffFormat.spec.js +1259 -1110
  24. package/es/index.js +13 -15
  25. package/es/utils/__tests__/jsxTranslations.spec.js +170 -0
  26. package/es/utils/errorReporter.js +41 -0
  27. package/es/utils/index.js +543 -0
  28. package/es/utils/jsxTranslations.js +185 -0
  29. package/lib/I18NContext.js +5 -10
  30. package/lib/components/DateTimeDiffFormat.js +131 -146
  31. package/lib/components/FormatText.js +29 -42
  32. package/lib/components/HOCI18N.js +34 -45
  33. package/lib/components/I18N.js +46 -57
  34. package/lib/components/I18NProvider.js +72 -95
  35. package/lib/components/PluralFormat.js +39 -55
  36. package/lib/components/UserTimeDiffFormat.js +76 -84
  37. package/lib/components/__tests__/DateTimeDiffFormat.spec.js +751 -635
  38. package/lib/components/__tests__/FormatText.spec.js +21 -30
  39. package/lib/components/__tests__/HOCI18N.spec.js +22 -41
  40. package/lib/components/__tests__/I18N.spec.js +20 -33
  41. package/lib/components/__tests__/I18NProvider.spec.js +40 -63
  42. package/lib/components/__tests__/PluralFormat.spec.js +23 -35
  43. package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1195 -1046
  44. package/lib/index.js +83 -104
  45. package/lib/utils/__tests__/jsxTranslations.spec.js +172 -0
  46. package/lib/utils/errorReporter.js +49 -0
  47. package/lib/utils/index.js +583 -0
  48. package/lib/utils/jsxTranslations.js +216 -0
  49. package/package.json +4 -3
  50. package/src/components/DateTimeDiffFormat.js +84 -55
  51. package/src/components/I18N.js +2 -0
  52. package/src/components/I18NProvider.js +44 -33
  53. package/src/components/UserTimeDiffFormat.js +22 -18
  54. package/src/index.js +12 -9
  55. package/src/utils/__tests__/jsxTranslations.spec.js +213 -0
  56. package/src/utils/errorReporter.js +48 -0
  57. package/src/utils/index.js +644 -0
  58. package/src/utils/jsxTranslations.js +199 -0
  59. package/es/components/NewDateFormat.js +0 -50
  60. package/es/offset.js +0 -629
  61. package/es/timezones.js +0 -118
  62. package/es/utils.js +0 -621
  63. package/lib/components/NewDateFormat.js +0 -68
  64. package/lib/offset.js +0 -634
  65. package/lib/timezones.js +0 -129
  66. package/lib/utils.js +0 -651
  67. package/src/components/NewDateFormat.js +0 -60
  68. package/src/offset.js +0 -629
  69. package/src/timezones.js +0 -113
  70. 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, convertUtcToUserTz } from '../utils';
10
- import FormatText from './FormatText';
11
-
12
- var DateTimeDiffFormat = function (_React$Component) {
13
- _inherits(DateTimeDiffFormat, _React$Component);
14
-
15
- function DateTimeDiffFormat(props) {
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
- _createClass(DateTimeDiffFormat, [{
25
- key: 'getSuffix',
26
- value: function getSuffix(min) {
27
- var suffix = void 0;
28
- if (this.props.ago && min < 0) {
29
- suffix = this.props.ago || '';
30
- } else if (this.props.later || min > 0) {
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
- key: 'render',
39
- value: function render() {
40
- var _props = this.props,
41
- type = _props.type,
42
- page = _props.page,
43
- from = _props.from,
44
- fromTzData = _props.fromTzData,
45
- to = _props.to,
46
- toTzData = _props.toTzData,
47
- today = _props.today,
48
- yesterday = _props.yesterday,
49
- tomorrow = _props.tomorrow,
50
- others = _props.others,
51
- format = _props.format,
52
- dataId = _props.dataId,
53
- _props$className = _props.className,
54
- className = _props$className === undefined ? null : _props$className,
55
- _props$title = _props.title,
56
- title = _props$title === undefined ? null : _props$title,
57
- isOverdue = _props.isOverdue;
58
-
59
-
60
- var fromDateObj = convertUtcToUserTz(from, fromTzData).getTime();
61
- var toDateObj = convertUtcToUserTz(to, toTzData).getTime();
62
-
63
- var diffMin = new Date(to).getTime() - new Date(from).getTime();
64
- var suffix = this.getSuffix(diffMin);
65
- var diff = getDiffObj(diffMin);
66
- var withInAWeak = diff.y === 0 && diff.yd <= 7;
67
-
68
- var diffObj = {
69
- h: diff.h,
70
- m: diff.m,
71
- s: diff.s,
72
- y: diff.y,
73
- hh: pad(diff.h, 2),
74
- mm: pad(diff.m, 2),
75
- ss: pad(diff.s, 2),
76
- yy: pad(diff.y, 2),
77
- days: diff.yd,
78
- yDays: pad(diff.yd, 2),
79
- isWithInAWeek: withInAWeak,
80
- suffix: suffix
81
- };
82
- var diffObj1 = {
83
- type: type,
84
- page: page,
85
- hours: diff.h,
86
- minutes: diff.m,
87
- seconds: diff.s,
88
- years: diff.y,
89
- yDays: diff.yd,
90
- yMonth: diff.m,
91
- isWithInAWeek: withInAWeak,
92
- suffix: suffix,
93
- crntDate: new Date(from).getDate(),
94
- crntMonth: new Date(from).getMonth(),
95
- crntYear: new Date(from).getFullYear(),
96
- crntHours: new Date(from).getHours(),
97
- crntMinutes: new Date(from).getMinutes(),
98
- crntSeconds: new Date(from).getSeconds(),
99
- tDate: new Date(to).getDate(),
100
- tMonth: new Date(to).getMonth(),
101
- tYear: new Date(to).getFullYear(),
102
- tHours: new Date(to).getHours(),
103
- tMinutes: new Date(to).getMinutes(),
104
- tSeconds: new Date(to).getSeconds(),
105
- betweenleepYears: getLyears(from, to),
106
- isOverdue: isOverdue
107
- };
108
-
109
- var key = '';
110
- var values = [];
111
- var text = null;
112
- var isSuffixEnable = false;
113
- if (format) {
114
- var years = void 0,
115
- months = void 0,
116
- days = void 0,
117
- hours = void 0,
118
- minutes = void 0,
119
- seconds = void 0;
120
- years = diffObj1.years > 1 ? '2' : diffObj1.years;
121
-
122
- days = diff.yd > 1 ? '2' : diff.yd;
123
- hours = diffObj1.hours > 1 ? '2' : diffObj1.hours;
124
- minutes = diffObj1.minutes > 1 ? '2' : diffObj1.minutes;
125
-
126
- var count = 0;
127
- var pattern = [years, days, hours, minutes].reduce(function (res, next) {
128
- if (count === 2) {
129
- res = res + '0';
130
- } else if (next !== 0) {
131
- count++;
132
- res = res + next;
133
- } else {
134
- res = res + next;
135
- }
136
- return res;
137
- }, '');
138
-
139
- var _value = format(diffObj1, pattern);
140
- if (_value && (typeof _value === 'undefined' ? 'undefined' : _typeof(_value)) === 'object') {
141
- key = _value.key;
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
- } else {
153
- if (diff.y === 0 && (diff.yd === 0 || diff.yd === 1)) {
154
- var dateObj = new Date(toDateObj);
155
- var curDateObj = new Date(fromDateObj);
156
- if (dateObj.getDate() === curDateObj.getDate()) {
157
- if (typeof today === 'function') {
158
- var value = today(diffObj1);
159
- key = value.key;
160
- values = getValues(value.params, diffObj);
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
- var value = others(diffObj1);
193
- if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
194
- key = value.key;
195
- values = getValues(value.params, diffObj);
196
- isSuffixEnable = true;
197
- } else if (typeof value === 'string') {
198
- text = formatDate(toDateObj, value);
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
- return text ? React.createElement(
203
- 'span',
204
- { className: className, 'data-title': title, 'data-id': dataId },
205
- text
206
- ) : React.createElement(FormatText, {
207
- i18NKey: isSuffixEnable && suffix !== '' ? key + '.' + suffix : key,
208
- values: values,
209
- className: className,
210
- 'data-title': title
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
- return DateTimeDiffFormat;
216
- }(React.Component);
217
-
218
- export default DateTimeDiffFormat;
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 './I18N';
9
-
10
- var FormatText = function (_React$Component) {
11
- _inherits(FormatText, _React$Component);
12
-
13
- function FormatText() {
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,
@@ -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 '../utils';
10
- import { I18NContext } from '../I18NContext';
11
- export default (function () {
12
- var i18NKeys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
13
- return function (Component) {
14
- var HOCI18N = function (_React$Component) {
15
- _inherits(HOCI18N, _React$Component);
16
-
17
- function HOCI18N(props) {
18
- _classCallCheck(this, HOCI18N);
19
-
20
- var _this = _possibleConstructorReturn(this, (HOCI18N.__proto__ || _Object$getPrototypeOf(HOCI18N)).call(this, props));
21
-
22
- _this.getI18NValue = _this.getI18NValue.bind(_this);
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
- _createClass(HOCI18N, [{
27
- key: 'getI18NValue',
28
- value: function getI18NValue(key) {
29
- var _ref = this.context || {},
30
- i18n = _ref.i18n;
31
-
32
- if (typeof i18n === 'undefined') {
33
- return key;
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 HOCI18N;
57
- }(React.Component);
58
-
59
- HOCI18N.contextType = I18NContext;
60
- return HOCI18N;
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
+ };