@zohodesk/i18n 1.0.0-beta.3 → 1.0.0-beta.30

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 (60) hide show
  1. package/README.md +116 -2
  2. package/es/I18NContext.js +1 -2
  3. package/es/components/DateTimeDiffFormat.js +192 -200
  4. package/es/components/FormatText.js +4 -25
  5. package/es/components/HOCI18N.js +33 -45
  6. package/es/components/I18N.js +48 -63
  7. package/es/components/I18NProvider.js +59 -85
  8. package/es/components/PluralFormat.js +29 -48
  9. package/es/components/UserTimeDiffFormat.js +65 -74
  10. package/es/components/__tests__/DateTimeDiffFormat.spec.js +868 -657
  11. package/es/components/__tests__/FormatText.spec.js +20 -17
  12. package/es/components/__tests__/HOCI18N.spec.js +18 -22
  13. package/es/components/__tests__/I18N.spec.js +20 -19
  14. package/es/components/__tests__/I18NProvider.spec.js +36 -45
  15. package/es/components/__tests__/PluralFormat.spec.js +20 -17
  16. package/es/components/__tests__/UserTimeDiffFormat.spec.js +1343 -1095
  17. package/es/index.js +2 -6
  18. package/es/utils/__tests__/jsxTranslations.spec.js +174 -0
  19. package/es/utils/index.js +592 -0
  20. package/es/utils/jsxTranslations.js +193 -0
  21. package/lib/I18NContext.js +6 -6
  22. package/lib/components/DateTimeDiffFormat.js +151 -123
  23. package/lib/components/FormatText.js +32 -22
  24. package/lib/components/HOCI18N.js +47 -23
  25. package/lib/components/I18N.js +62 -36
  26. package/lib/components/I18NProvider.js +82 -70
  27. package/lib/components/PluralFormat.js +42 -32
  28. package/lib/components/UserTimeDiffFormat.js +79 -56
  29. package/lib/components/__tests__/DateTimeDiffFormat.spec.js +815 -629
  30. package/lib/components/__tests__/FormatText.spec.js +23 -25
  31. package/lib/components/__tests__/HOCI18N.spec.js +26 -34
  32. package/lib/components/__tests__/I18N.spec.js +21 -26
  33. package/lib/components/__tests__/I18NProvider.spec.js +43 -51
  34. package/lib/components/__tests__/PluralFormat.spec.js +24 -28
  35. package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1256 -1039
  36. package/lib/index.js +85 -110
  37. package/lib/utils/__tests__/jsxTranslations.spec.js +183 -0
  38. package/lib/utils/index.js +658 -0
  39. package/lib/utils/jsxTranslations.js +242 -0
  40. package/package.json +3 -2
  41. package/src/components/DateTimeDiffFormat.js +86 -55
  42. package/src/components/I18N.js +2 -0
  43. package/src/components/I18NProvider.js +34 -25
  44. package/src/components/UserTimeDiffFormat.js +24 -18
  45. package/src/index.js +7 -9
  46. package/src/utils/__tests__/jsxTranslations.spec.js +213 -0
  47. package/src/utils/index.js +632 -0
  48. package/src/utils/jsxTranslations.js +180 -0
  49. package/es/components/NewDateFormat.js +0 -50
  50. package/es/offset.js +0 -629
  51. package/es/timezones.js +0 -118
  52. package/es/utils.js +0 -621
  53. package/lib/components/NewDateFormat.js +0 -68
  54. package/lib/offset.js +0 -634
  55. package/lib/timezones.js +0 -129
  56. package/lib/utils.js +0 -651
  57. package/src/components/NewDateFormat.js +0 -60
  58. package/src/offset.js +0 -629
  59. package/src/timezones.js +0 -113
  60. package/src/utils.js +0 -648
@@ -0,0 +1,242 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createElement = createElement;
7
+ exports.generateChildren = generateChildren;
8
+ exports.getI18NComponent = getI18NComponent;
9
+ exports.prepareI18NFunc = prepareI18NFunc;
10
+ exports.replaceWithComponentPlaceHolder = replaceWithComponentPlaceHolder;
11
+ exports.splitMatchedExp = splitMatchedExp;
12
+
13
+ var _react = _interopRequireDefault(require("react"));
14
+
15
+ var _index = require("./index");
16
+
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
18
+
19
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
20
+
21
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
22
+
23
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
24
+
25
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
26
+
27
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
28
+
29
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
30
+
31
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
32
+
33
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
34
+
35
+ function splitMatchedExp(_ref) {
36
+ var expression = _ref.expression,
37
+ charLenToOmit = _ref.charLenToOmit,
38
+ string = _ref.string;
39
+ var splitString = string.split(new RegExp(expression, 'g'));
40
+ var matchedExpAll = string.matchAll(new RegExp(expression, 'g'));
41
+ var matchedExpKeys = [];
42
+
43
+ var _iterator = _createForOfIteratorHelper(matchedExpAll),
44
+ _step;
45
+
46
+ try {
47
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
48
+ var match = _step.value;
49
+ var value = match[0];
50
+ matchedExpKeys.push(value.substring(charLenToOmit, value.length - charLenToOmit));
51
+ }
52
+ } catch (err) {
53
+ _iterator.e(err);
54
+ } finally {
55
+ _iterator.f();
56
+ }
57
+
58
+ return {
59
+ splitString: splitString,
60
+ matchedExpKeys: matchedExpKeys
61
+ };
62
+ }
63
+
64
+ function generateChildren(_ref2) {
65
+ var children = _ref2.children,
66
+ child = _ref2.child;
67
+ var newChildren = [],
68
+ stringPlaceHolders = {};
69
+
70
+ var handleString = function handleString(string) {
71
+ if (string) {
72
+ var _splitMatchedExp = splitMatchedExp({
73
+ expression: '{[0-9]+?}',
74
+ charLenToOmit: 1,
75
+ string: string
76
+ }),
77
+ splitString = _splitMatchedExp.splitString,
78
+ matchedExpKeys = _splitMatchedExp.matchedExpKeys;
79
+
80
+ stringPlaceHolders[newChildren.length] = matchedExpKeys;
81
+ newChildren.push(splitString);
82
+ }
83
+ };
84
+
85
+ var _splitMatchedExp2 = splitMatchedExp({
86
+ expression: '<[A-Za-z0-9]+?>',
87
+ charLenToOmit: 1,
88
+ string: child
89
+ }),
90
+ splitChild = _splitMatchedExp2.splitString,
91
+ childrenKeys = _splitMatchedExp2.matchedExpKeys;
92
+
93
+ childrenKeys.forEach(function (childKey, childIndex) {
94
+ var matchedChild = splitChild[childIndex];
95
+ handleString(matchedChild);
96
+ newChildren.push(children[childKey]);
97
+ });
98
+ handleString(splitChild[childrenKeys.length]);
99
+ return {
100
+ newChildren: newChildren,
101
+ stringPlaceHolders: stringPlaceHolders
102
+ };
103
+ }
104
+
105
+ function createElement() {
106
+ var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
107
+ componentId = _ref3.componentId,
108
+ _ref3$children = _ref3.children,
109
+ children = _ref3$children === void 0 ? [] : _ref3$children,
110
+ _ref3$stringPlaceHold = _ref3.stringPlaceHolders,
111
+ stringPlaceHolders = _ref3$stringPlaceHold === void 0 ? {} : _ref3$stringPlaceHold;
112
+
113
+ return function () {
114
+ var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
115
+ _ref4$components = _ref4.components,
116
+ components = _ref4$components === void 0 ? {} : _ref4$components,
117
+ _ref4$values = _ref4.values,
118
+ values = _ref4$values === void 0 ? [] : _ref4$values;
119
+
120
+ var _ref5 = components[componentId] || {},
121
+ _ref5$type = _ref5.type,
122
+ type = _ref5$type === void 0 ? _react["default"].Fragment : _ref5$type,
123
+ props = _ref5.props;
124
+
125
+ var childElements = children.map(function (child, index) {
126
+ if (typeof child === 'function') {
127
+ return child({
128
+ components: components,
129
+ values: values
130
+ });
131
+ }
132
+
133
+ var string = '',
134
+ stringIndex = 0;
135
+ (stringPlaceHolders[index] || []).map(function (stringId, index) {
136
+ if (child[index]) {
137
+ string += child[index];
138
+ }
139
+
140
+ string += values[stringId];
141
+ stringIndex++;
142
+ });
143
+
144
+ if (child[stringIndex]) {
145
+ string += child[stringIndex];
146
+ }
147
+
148
+ return string;
149
+ });
150
+ return /*#__PURE__*/_react["default"].createElement.apply(_react["default"], [type, props].concat(_toConsumableArray(childElements)));
151
+ };
152
+ }
153
+
154
+ ;
155
+
156
+ function replaceWithComponentPlaceHolder(_ref6) {
157
+ var componentId = _ref6.componentId,
158
+ i18nKey = _ref6.i18nKey,
159
+ childrenLength = _ref6.childrenLength;
160
+ var closingTagIndex = i18nKey.indexOf("</".concat(componentId, ">"));
161
+ var childWithOpenTag = i18nKey.substring(0, closingTagIndex);
162
+ var openTagIndex = childWithOpenTag.lastIndexOf("<".concat(componentId, ">"));
163
+ return i18nKey.substring(0, openTagIndex) + "<0".concat(childrenLength).concat(componentId, ">") + i18nKey.substring(closingTagIndex + "".concat(componentId).length + 3);
164
+ }
165
+
166
+ function prepareI18NFunc() {
167
+ var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
168
+ i18nKey = _ref7.i18nKey,
169
+ _ref7$children = _ref7.children,
170
+ children = _ref7$children === void 0 ? {} : _ref7$children;
171
+
172
+ var componentIdMatch = i18nKey.match(/<\/[A-Za-z0-9]+?>/);
173
+
174
+ if (componentIdMatch) {
175
+ var componentId = componentIdMatch[0].substring(2, componentIdMatch[0].length - 1);
176
+ var childWithOpenTag = (i18nKey.match(new RegExp("(.*?)(?=</".concat(componentId, ">)"))) || [])[0] || '';
177
+ var child = childWithOpenTag.split("<".concat(componentId, ">")).pop();
178
+
179
+ var _generateChildren = generateChildren({
180
+ children: children,
181
+ child: child
182
+ }),
183
+ _newChildren = _generateChildren.newChildren,
184
+ _stringPlaceHolders = _generateChildren.stringPlaceHolders;
185
+
186
+ var childrenLength = Object.keys(children).length;
187
+ children["0".concat(childrenLength).concat(componentId)] = createElement({
188
+ componentId: componentId,
189
+ children: _newChildren,
190
+ stringPlaceHolders: _stringPlaceHolders
191
+ });
192
+ i18nKey = replaceWithComponentPlaceHolder({
193
+ componentId: componentId,
194
+ i18nKey: i18nKey,
195
+ childrenLength: childrenLength
196
+ });
197
+ return prepareI18NFunc({
198
+ i18nKey: i18nKey,
199
+ children: children
200
+ });
201
+ }
202
+
203
+ var _generateChildren2 = generateChildren({
204
+ child: i18nKey,
205
+ children: children
206
+ }),
207
+ newChildren = _generateChildren2.newChildren,
208
+ stringPlaceHolders = _generateChildren2.stringPlaceHolders;
209
+
210
+ return createElement({
211
+ componentId: -1,
212
+ children: newChildren,
213
+ stringPlaceHolders: stringPlaceHolders
214
+ });
215
+ }
216
+
217
+ function getI18NComponent(i18n) {
218
+ if (typeof i18n === 'undefined') {
219
+ return function (key) {
220
+ return key;
221
+ };
222
+ }
223
+
224
+ return function (key) {
225
+ var i18nStr = i18n[key];
226
+
227
+ if (i18nStr === undefined) {
228
+ return key;
229
+ }
230
+
231
+ if (typeof i18nStr === 'string') {
232
+ i18nStr = (0, _index.unescapeUnicode)(i18nStr);
233
+ var value = prepareI18NFunc({
234
+ i18nKey: i18nStr
235
+ });
236
+ window.loadI18nChunk && window.loadI18nChunk(_defineProperty({}, key, value));
237
+ i18nStr = value;
238
+ }
239
+
240
+ return i18nStr;
241
+ };
242
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/i18n",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.30",
4
4
  "main": "lib/index",
5
5
  "module": "es/index.js",
6
6
  "jsnext:main": "es/index.js",
@@ -15,11 +15,12 @@
15
15
  "build:dev": "npm run clean && npm run build --module:mode=dev -- -w",
16
16
  "prepublish": "npm run init && npm run build && npm run build:es ",
17
17
  "prepare": "npm run init && npm run build && npm run build:es",
18
+ "test": "react-cli test",
18
19
  "init": "npm run clean",
19
20
  "lint": "react-cli lint"
20
21
  },
21
22
  "dependencies": {
22
- "@zoho/SecurityJS": "5.0.0-rc2.1"
23
+ "@zoho/SecurityJS": "6.4.2"
23
24
  },
24
25
  "react-cli": {
25
26
  "docs": {
@@ -6,9 +6,10 @@ import {
6
6
  getDiffObj,
7
7
  formatDate,
8
8
  getLyears,
9
- convertUtcToUserTz
9
+ getDatePatternWithoutYear,
10
10
  } from '../utils';
11
11
  import FormatText from './FormatText';
12
+ import datetime from '@zohodesk/datetimejs';
12
13
  export default class DateTimeDiffFormat extends React.Component {
13
14
  constructor(props) {
14
15
  super(props);
@@ -30,6 +31,8 @@ export default class DateTimeDiffFormat extends React.Component {
30
31
  render() {
31
32
  const {
32
33
  type,
34
+ page,
35
+ isNeedTime,
33
36
  from,
34
37
  fromTzData,
35
38
  to,
@@ -42,11 +45,19 @@ export default class DateTimeDiffFormat extends React.Component {
42
45
  dataId,
43
46
  className = null,
44
47
  title = null,
45
- isOverdue
48
+ isOverdue,
49
+ timeFormat,
50
+ datePattern,
51
+ isEnabledCurrentYear,
52
+ isDateField
46
53
  } = this.props;
47
54
 
48
- let fromDateObj = convertUtcToUserTz(from, fromTzData).getTime();
49
- let toDateObj = convertUtcToUserTz(to, toTzData).getTime();
55
+ let fromDateObj = datetime
56
+ .toDate(datetime.tz.utcToTz(from, fromTzData))
57
+ .getTime();
58
+ let toDateObj = datetime
59
+ .toDate(isDateField ? to : datetime.tz.utcToTz(to, toTzData))
60
+ .getTime();
50
61
 
51
62
  let diffMin = new Date(to).getTime() - new Date(from).getTime();
52
63
  let suffix = this.getSuffix(diffMin);
@@ -65,16 +76,18 @@ export default class DateTimeDiffFormat extends React.Component {
65
76
  days: diff.yd,
66
77
  yDays: pad(diff.yd, 2),
67
78
  isWithInAWeek: withInAWeak,
68
- suffix: suffix
79
+ suffix: suffix,
69
80
  };
70
81
  let diffObj1 = {
82
+ to: to,
71
83
  type: type,
84
+ page: page,
85
+ isNeedTime: isNeedTime,
72
86
  hours: diff.h,
73
87
  minutes: diff.m,
74
88
  seconds: diff.s,
75
89
  years: diff.y,
76
90
  yDays: diff.yd,
77
- yMonth: diff.m,
78
91
  isWithInAWeek: withInAWeak,
79
92
  suffix: suffix,
80
93
  crntDate: new Date(from).getDate(),
@@ -90,9 +103,27 @@ export default class DateTimeDiffFormat extends React.Component {
90
103
  tMinutes: new Date(to).getMinutes(),
91
104
  tSeconds: new Date(to).getSeconds(),
92
105
  betweenleepYears: getLyears(from, to),
93
- isOverdue: isOverdue
106
+ isOverdue: isOverdue,
107
+ timeFormat: timeFormat,
108
+ datePattern: datePattern,
109
+ dateTimePattern: `${datePattern} ${timeFormat}`,
94
110
  };
95
111
 
112
+ //In if condition we'll remove year and set date format if the current year is not required
113
+ //In else part we'll set the date format as it is
114
+ if (
115
+ isEnabledCurrentYear === true &&
116
+ diffObj1.years === 0 &&
117
+ diffObj1.tYear === diffObj1.crntYear
118
+ ) {
119
+ let dateFormat = getDatePatternWithoutYear(datePattern);
120
+ diffObj1.dateFormat = dateFormat;
121
+ diffObj1.dateTimeFormat = `${dateFormat} ${timeFormat}`;
122
+ } else {
123
+ diffObj1.dateFormat = datePattern;
124
+ diffObj1.dateTimeFormat = `${datePattern} ${timeFormat}`;
125
+ }
126
+
96
127
  let key = '';
97
128
  let values = [];
98
129
  let text = null;
@@ -132,57 +163,56 @@ export default class DateTimeDiffFormat extends React.Component {
132
163
  text = formatDate(toDateObj, value, diffObj1);
133
164
  }
134
165
  } else {
135
- if (diff.y === 0 && (diff.yd === 0 || diff.yd === 1)) {
136
- let dateObj = new Date(toDateObj);
137
- let curDateObj = new Date(fromDateObj);
138
- if (dateObj.getDate() === curDateObj.getDate()) {
139
- if (typeof today === 'function') {
140
- var value = today(diffObj1);
141
- key = value.key;
142
- values = getValues(value.params, diffObj);
143
- } else if (typeof today === 'object') {
144
- key = today.key;
145
- values = getValues(today.params, diffObj);
146
- isSuffixEnable = true;
147
- } else if (typeof today === 'string') {
148
- text = formatDate(toDateObj, today);
149
- }
150
- } else if (dateObj.getDate() < curDateObj.getDate()) {
151
- if (typeof yesterday === 'function') {
152
- var value = yesterday(diffObj1);
153
- key = value.key;
154
- values = getValues(value.params, diffObj);
155
- } else if (typeof yesterday === 'object') {
156
- key = yesterday.key;
157
- values = getValues(yesterday.params, diffObj);
158
- } else if (typeof yesterday === 'string') {
159
- text = formatDate(toDateObj, yesterday);
160
- }
161
- } else if (dateObj.getDate() > curDateObj.getDate()) {
162
- if (typeof tomorrow === 'function') {
163
- var value = tomorrow(diffObj1);
164
- key = value.key;
165
- text = getValues(value.params, diffObj);
166
- } else if (typeof tomorrow === 'object') {
167
- key = tomorrow.key;
168
- values = getValues(tomorrow.params, diffObj);
169
- } else if (typeof tomorrow === 'string') {
170
- text = formatDate(toDateObj, tomorrow);
166
+ let dateObj = new Date(toDateObj);
167
+ let curDateObj = new Date(fromDateObj);
168
+ let diffDayType = diffObj1.yDays;
169
+
170
+ //In this condition, to calculate different days we have copied it from live --> diffDayType
171
+ if (
172
+ isOverdue &&
173
+ dateObj.getDate() < curDateObj.getDate() &&
174
+ diffObj1.yDays == 0
175
+ ) {
176
+ diffDayType = -1;
177
+ }
178
+ if (!isOverdue) {
179
+ let diffHr = dateObj.getHours() - curDateObj.getHours();
180
+ if (diffHr < 0) {
181
+ diffDayType += 1;
182
+ } else if (diffHr == 0) {
183
+ let diffMins = dateObj.getMinutes() - curDateObj.getMinutes();
184
+ if (diffMins < 0) {
185
+ diffDayType += 1;
186
+ } else if (diffMins == 0) {
187
+ let diffSec = dateObj.getSeconds() - curDateObj.getSeconds();
188
+ if (diffSec < 0) {
189
+ diffDayType += 1;
190
+ }
171
191
  }
172
192
  }
173
- } else {
174
- var value = others(diffObj1);
175
- if (typeof value === 'object') {
176
- key = value.key;
177
- values = getValues(value.params, diffObj);
178
- isSuffixEnable = true;
179
- } else if (typeof value === 'string') {
193
+ }
194
+ if (diff.y === 0 && (diffDayType === 0 || diffDayType === 1)) {
195
+ if (dateObj.getDate() === curDateObj.getDate()) {
196
+ var value = (today && today(diffObj1)) || others(diffObj1);
197
+ text = formatDate(toDateObj, value);
198
+ } else if (
199
+ (dateObj.getMonth() === curDateObj.getMonth() &&
200
+ dateObj.getDate() < curDateObj.getDate()) ||
201
+ dateObj.getMonth() < curDateObj.getMonth()
202
+ ) {
203
+ var value = (yesterday && yesterday(diffObj1)) || others(diffObj1);
204
+ text = formatDate(toDateObj, value);
205
+ } else if (!isOverdue && diff.y === 0 && diffDayType === 1) {
206
+ var value = (tomorrow && tomorrow(diffObj1)) || others(diffObj1);
180
207
  text = formatDate(toDateObj, value);
181
208
  }
209
+ } else {
210
+ var value = others(diffObj1);
211
+ text = formatDate(toDateObj, value);
182
212
  }
183
213
  }
184
214
  return text ? (
185
- <span className={className} data-title={title} data-id={dataId}>
215
+ <span className={className} data-title={title} data-id={dataId} data-test-id={dataId}>
186
216
  {text}
187
217
  </span>
188
218
  ) : (
@@ -202,6 +232,7 @@ DateTimeDiffFormat.propTypes = {
202
232
  format: PropTypes.func,
203
233
  from: PropTypes.string,
204
234
  fromTzData: PropTypes.object,
235
+ isDateField: PropTypes.bool,
205
236
  later: PropTypes.string,
206
237
  others: PropTypes.func,
207
238
  title: PropTypes.string,
@@ -210,16 +241,16 @@ DateTimeDiffFormat.propTypes = {
210
241
  today: PropTypes.oneOfType([
211
242
  PropTypes.string,
212
243
  PropTypes.object,
213
- PropTypes.func
244
+ PropTypes.func,
214
245
  ]),
215
246
  tomorrow: PropTypes.oneOfType([
216
247
  PropTypes.string,
217
248
  PropTypes.object,
218
- PropTypes.func
249
+ PropTypes.func,
219
250
  ]),
220
251
  yesterday: PropTypes.oneOfType([
221
252
  PropTypes.string,
222
253
  PropTypes.object,
223
- PropTypes.func
224
- ])
254
+ PropTypes.func,
255
+ ]),
225
256
  };
@@ -41,6 +41,7 @@ export default class I18N extends React.Component {
41
41
  //const child=this.getI18NValue();
42
42
  if (this.props.dataId) {
43
43
  props['data-id'] = this.props.dataId;
44
+ props['data-test-id'] = this.props.dataId;
44
45
  }
45
46
  if (this.props.isHtml) {
46
47
  let dangerouslySetInnerHTML = {
@@ -63,6 +64,7 @@ I18N.propTypes = {
63
64
  i18NKey: PropTypes.string.isRequired,
64
65
  isHtml: PropTypes.bool,
65
66
  tag: PropTypes.string,
67
+ dataId: PropTypes.string,
66
68
  values: PropTypes.oneOfType([PropTypes.string, PropTypes.array])
67
69
  };
68
70
  I18N.defaultProps = {
@@ -1,29 +1,34 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { getI18NValue, userDateFormat } from '../utils';
4
- import { unpack } from '../timezones';
5
- import { createSelector } from 'reselect';
4
+ import {
5
+ getI18NComponent
6
+ } from '../utils/jsxTranslations';
6
7
  import { I18NContext } from '../I18NContext';
7
8
 
8
9
  const emptyObj = {};
9
10
  const dummy = (key, values) => key;
10
- const getTzData = createSelector(
11
- [tzStr => tzStr],
12
- tzStr => unpack(tzStr)
13
- );
11
+
14
12
  export const i18NProviderUtils = {
15
13
  getI18NValue: dummy,
16
- userDateFormat: dummy
14
+ userDateFormat: dummy,
15
+ getI18NComponent: dummy
17
16
  };
18
17
 
19
18
  export default class I18NProvider extends React.Component {
20
19
  constructor(props, context) {
21
20
  super(props, context);
22
21
  i18NProviderUtils.getI18NValue = getI18NValue(props.i18n);
23
- i18NProviderUtils.userDateFormat = userDateFormat(
24
- i18NProviderUtils.getI18NValue,
25
- unpack(props.tzData)
26
- );
22
+ i18NProviderUtils.getI18NComponent = getI18NComponent(props.i18n);
23
+ if(props.tzData){
24
+ i18NProviderUtils.userDateFormat = userDateFormat(
25
+ i18NProviderUtils.getI18NValue,
26
+ props.tzData,
27
+ props.timeFormat,
28
+ props.datePattern,
29
+ props.isEnabledCurrentYear
30
+ );
31
+ }
27
32
  }
28
33
 
29
34
  componentDidUpdate(next) {
@@ -32,17 +37,15 @@ export default class I18NProvider extends React.Component {
32
37
  timeZone,
33
38
  datePattern,
34
39
  timeFormat,
35
- dateTimeFormat,
36
40
  direction,
37
41
  onChange,
38
- tzData
42
+ tzData,
39
43
  } = this.props;
40
44
  if (
41
45
  i18n !== next.i18n ||
42
46
  timeZone !== next.timeZone ||
43
47
  datePattern !== next.datePattern ||
44
48
  timeFormat !== next.timeFormat ||
45
- dateTimeFormat !== next.dateTimeFormat ||
46
49
  direction !== next.direction ||
47
50
  tzData !== next.tzData
48
51
  ) {
@@ -52,10 +55,16 @@ export default class I18NProvider extends React.Component {
52
55
  }).then(
53
56
  () => {
54
57
  i18NProviderUtils.getI18NValue = getI18NValue(nextProps.i18n);
55
- i18NProviderUtils.userDateFormat = userDateFormat(
56
- i18NProviderUtils.getI18NValue,
57
- unpack(tzData)
58
- );
58
+ i18NProviderUtils.getI18NComponent = getI18NComponent(nextProps.i18n);
59
+ if(props.tzData){
60
+ i18NProviderUtils.userDateFormat = userDateFormat(
61
+ i18NProviderUtils.getI18NValue,
62
+ props.tzData,
63
+ props.timeFormat,
64
+ props.datePattern,
65
+ this.props.isEnabledCurrentYear
66
+ );
67
+ }
59
68
  this.promise = null;
60
69
  },
61
70
  () => {
@@ -73,10 +82,10 @@ export default class I18NProvider extends React.Component {
73
82
  i18n: this.props.i18n,
74
83
  direction: this.props.direction,
75
84
  timeZone: this.props.timeZone,
76
- tzData: getTzData(this.props.tzData),
77
85
  datePattern: this.props.datePattern,
78
86
  timeFormat: this.props.timeFormat,
79
- dateTimeFormat: this.props.dateTimeFormat
87
+ isEnabledCurrentYear: this.props.isEnabledCurrentYear,
88
+ tzData: this.props.tzData,
80
89
  }}
81
90
  >
82
91
  {this.props.children}
@@ -90,18 +99,18 @@ I18NProvider.defaultProps = {
90
99
  timeZone: '',
91
100
  datePattern: '',
92
101
  timeFormat: '',
93
- dateTimeFormat: '',
94
- direction: 'ltr'
102
+ isEnabledCurrentYear: '',
103
+ direction: 'ltr',
95
104
  };
96
105
 
97
106
  I18NProvider.propTypes = {
98
107
  children: PropTypes.element.isRequired,
99
108
  datePattern: PropTypes.string,
100
- dateTimeFormat: PropTypes.string,
109
+ isEnabledCurrentYear: PropTypes.string,
101
110
  direction: PropTypes.string,
102
111
  i18n: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
103
112
  onChange: PropTypes.func,
104
113
  timeFormat: PropTypes.string,
105
114
  timeZone: PropTypes.string,
106
- tzData: PropTypes.string
107
- };
115
+ tzData: PropTypes.object,
116
+ };