@zohodesk/i18n 1.0.0-beta.16 → 1.0.0-beta.19
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 +15 -0
- package/es/components/DateTimeDiffFormat.js +3 -2
- package/es/components/HOCI18N.js +33 -30
- package/es/components/I18NProvider.js +9 -2
- package/es/components/UserTimeDiffFormat.js +6 -5
- package/es/components/__tests__/DateTimeDiffFormat.spec.js +177 -136
- package/es/components/__tests__/FormatText.spec.js +0 -1
- package/es/components/__tests__/HOCI18N.spec.js +0 -1
- package/es/components/__tests__/I18N.spec.js +0 -2
- package/es/components/__tests__/I18NProvider.spec.js +0 -1
- package/es/components/__tests__/PluralFormat.spec.js +0 -1
- package/es/components/__tests__/UserTimeDiffFormat.spec.js +287 -206
- package/es/index.js +1 -1
- package/es/utils.js +55 -15
- package/lib/components/DateTimeDiffFormat.js +7 -6
- package/lib/components/FormatText.js +4 -4
- package/lib/components/HOCI18N.js +4 -4
- package/lib/components/I18N.js +4 -4
- package/lib/components/I18NProvider.js +15 -7
- package/lib/components/PluralFormat.js +4 -4
- package/lib/components/UserTimeDiffFormat.js +4 -4
- package/lib/components/__tests__/I18NProvider.spec.js +1 -1
- package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1 -1
- package/lib/index.js +58 -52
- package/lib/utils.js +62 -23
- package/package.json +3 -3
- package/src/components/DateTimeDiffFormat.js +3 -0
- package/src/components/I18NProvider.js +18 -14
- package/src/index.js +2 -1
- package/src/utils.js +37 -4
package/lib/index.js
CHANGED
|
@@ -1,88 +1,83 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
Object.defineProperty(exports, "
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function get() {
|
|
11
|
-
return _utils.formatDate;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
Object.defineProperty(exports, "pad", {
|
|
8
|
+
Object.defineProperty(exports, "DateTimeDiffFormat", {
|
|
15
9
|
enumerable: true,
|
|
16
10
|
get: function get() {
|
|
17
|
-
return
|
|
11
|
+
return _DateTimeDiffFormat["default"];
|
|
18
12
|
}
|
|
19
13
|
});
|
|
20
|
-
Object.defineProperty(exports, "
|
|
14
|
+
Object.defineProperty(exports, "FormatText", {
|
|
21
15
|
enumerable: true,
|
|
22
16
|
get: function get() {
|
|
23
|
-
return
|
|
17
|
+
return _FormatText["default"];
|
|
24
18
|
}
|
|
25
19
|
});
|
|
26
|
-
Object.defineProperty(exports, "
|
|
20
|
+
Object.defineProperty(exports, "HOCI18N", {
|
|
27
21
|
enumerable: true,
|
|
28
22
|
get: function get() {
|
|
29
|
-
return
|
|
23
|
+
return _HOCI18N["default"];
|
|
30
24
|
}
|
|
31
25
|
});
|
|
32
|
-
Object.defineProperty(exports, "
|
|
26
|
+
Object.defineProperty(exports, "I18N", {
|
|
33
27
|
enumerable: true,
|
|
34
28
|
get: function get() {
|
|
35
|
-
return
|
|
29
|
+
return _I18N["default"];
|
|
36
30
|
}
|
|
37
31
|
});
|
|
38
|
-
Object.defineProperty(exports, "
|
|
32
|
+
Object.defineProperty(exports, "I18NContext", {
|
|
39
33
|
enumerable: true,
|
|
40
34
|
get: function get() {
|
|
41
|
-
return
|
|
35
|
+
return _I18NContext.I18NContext;
|
|
42
36
|
}
|
|
43
37
|
});
|
|
44
|
-
Object.defineProperty(exports, "
|
|
38
|
+
Object.defineProperty(exports, "I18NProvider", {
|
|
45
39
|
enumerable: true,
|
|
46
40
|
get: function get() {
|
|
47
|
-
return
|
|
41
|
+
return _I18NProvider["default"];
|
|
48
42
|
}
|
|
49
43
|
});
|
|
50
|
-
Object.defineProperty(exports, "
|
|
44
|
+
Object.defineProperty(exports, "PluralFormat", {
|
|
51
45
|
enumerable: true,
|
|
52
46
|
get: function get() {
|
|
53
|
-
return
|
|
47
|
+
return _PluralFormat["default"];
|
|
54
48
|
}
|
|
55
49
|
});
|
|
56
|
-
Object.defineProperty(exports, "
|
|
50
|
+
Object.defineProperty(exports, "UserTimeDiffFormat", {
|
|
57
51
|
enumerable: true,
|
|
58
52
|
get: function get() {
|
|
59
|
-
return
|
|
53
|
+
return _UserTimeDiffFormat["default"];
|
|
60
54
|
}
|
|
61
55
|
});
|
|
62
|
-
Object.defineProperty(exports, "
|
|
56
|
+
Object.defineProperty(exports, "formatDate", {
|
|
63
57
|
enumerable: true,
|
|
64
58
|
get: function get() {
|
|
65
|
-
return _utils.
|
|
59
|
+
return _utils.formatDate;
|
|
66
60
|
}
|
|
67
61
|
});
|
|
68
|
-
Object.defineProperty(exports, "
|
|
62
|
+
Object.defineProperty(exports, "getDatePatternWithoutYear", {
|
|
69
63
|
enumerable: true,
|
|
70
64
|
get: function get() {
|
|
71
|
-
return _utils.
|
|
65
|
+
return _utils.getDatePatternWithoutYear;
|
|
72
66
|
}
|
|
73
67
|
});
|
|
74
|
-
Object.defineProperty(exports, "
|
|
68
|
+
Object.defineProperty(exports, "getDiffObj", {
|
|
75
69
|
enumerable: true,
|
|
76
70
|
get: function get() {
|
|
77
|
-
return _utils.
|
|
71
|
+
return _utils.getDiffObj;
|
|
78
72
|
}
|
|
79
73
|
});
|
|
80
|
-
Object.defineProperty(exports, "
|
|
74
|
+
Object.defineProperty(exports, "getI18NInfo", {
|
|
81
75
|
enumerable: true,
|
|
82
76
|
get: function get() {
|
|
83
|
-
return _utils.
|
|
77
|
+
return _utils.getI18NInfo;
|
|
84
78
|
}
|
|
85
79
|
});
|
|
80
|
+
exports.getI18NValue = void 0;
|
|
86
81
|
Object.defineProperty(exports, "getLyears", {
|
|
87
82
|
enumerable: true,
|
|
88
83
|
get: function get() {
|
|
@@ -95,67 +90,78 @@ Object.defineProperty(exports, "getSuffix", {
|
|
|
95
90
|
return _utils.getSuffix;
|
|
96
91
|
}
|
|
97
92
|
});
|
|
98
|
-
Object.defineProperty(exports, "
|
|
93
|
+
Object.defineProperty(exports, "getValues", {
|
|
99
94
|
enumerable: true,
|
|
100
95
|
get: function get() {
|
|
101
|
-
return _utils.
|
|
96
|
+
return _utils.getValues;
|
|
102
97
|
}
|
|
103
98
|
});
|
|
104
|
-
Object.defineProperty(exports, "
|
|
99
|
+
Object.defineProperty(exports, "i18NProviderUtils", {
|
|
105
100
|
enumerable: true,
|
|
106
101
|
get: function get() {
|
|
107
|
-
return
|
|
102
|
+
return _I18NProvider.i18NProviderUtils;
|
|
108
103
|
}
|
|
109
104
|
});
|
|
110
|
-
Object.defineProperty(exports, "
|
|
105
|
+
Object.defineProperty(exports, "isToday", {
|
|
111
106
|
enumerable: true,
|
|
112
107
|
get: function get() {
|
|
113
|
-
return
|
|
108
|
+
return _utils.isToday;
|
|
114
109
|
}
|
|
115
110
|
});
|
|
116
|
-
Object.defineProperty(exports, "
|
|
111
|
+
Object.defineProperty(exports, "isTomorrow", {
|
|
117
112
|
enumerable: true,
|
|
118
113
|
get: function get() {
|
|
119
|
-
return
|
|
114
|
+
return _utils.isTomorrow;
|
|
120
115
|
}
|
|
121
116
|
});
|
|
122
|
-
Object.defineProperty(exports, "
|
|
117
|
+
Object.defineProperty(exports, "isTwoWeeksOrMore", {
|
|
123
118
|
enumerable: true,
|
|
124
119
|
get: function get() {
|
|
125
|
-
return
|
|
120
|
+
return _utils.isTwoWeeksOrMore;
|
|
126
121
|
}
|
|
127
122
|
});
|
|
128
|
-
Object.defineProperty(exports, "
|
|
123
|
+
Object.defineProperty(exports, "isWithinAWeek", {
|
|
129
124
|
enumerable: true,
|
|
130
125
|
get: function get() {
|
|
131
|
-
return
|
|
126
|
+
return _utils.isWithinAWeek;
|
|
132
127
|
}
|
|
133
128
|
});
|
|
134
|
-
Object.defineProperty(exports, "
|
|
129
|
+
Object.defineProperty(exports, "isYesterday", {
|
|
135
130
|
enumerable: true,
|
|
136
131
|
get: function get() {
|
|
137
|
-
return
|
|
132
|
+
return _utils.isYesterday;
|
|
138
133
|
}
|
|
139
134
|
});
|
|
140
|
-
Object.defineProperty(exports, "
|
|
135
|
+
Object.defineProperty(exports, "pad", {
|
|
141
136
|
enumerable: true,
|
|
142
137
|
get: function get() {
|
|
143
|
-
return
|
|
138
|
+
return _utils.pad;
|
|
144
139
|
}
|
|
145
140
|
});
|
|
146
|
-
Object.defineProperty(exports, "
|
|
141
|
+
Object.defineProperty(exports, "replaceI18NValuesWithRegex", {
|
|
147
142
|
enumerable: true,
|
|
148
143
|
get: function get() {
|
|
149
|
-
return
|
|
144
|
+
return _utils.replaceI18NValuesWithRegex;
|
|
150
145
|
}
|
|
151
146
|
});
|
|
152
|
-
Object.defineProperty(exports, "
|
|
147
|
+
Object.defineProperty(exports, "setLocalizedData", {
|
|
153
148
|
enumerable: true,
|
|
154
149
|
get: function get() {
|
|
155
|
-
return
|
|
150
|
+
return _utils.setLocalizedData;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
Object.defineProperty(exports, "unescapeUnicode", {
|
|
154
|
+
enumerable: true,
|
|
155
|
+
get: function get() {
|
|
156
|
+
return _utils.unescapeUnicode;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
Object.defineProperty(exports, "userDateFormat", {
|
|
160
|
+
enumerable: true,
|
|
161
|
+
get: function get() {
|
|
162
|
+
return _utils.userDateFormat;
|
|
156
163
|
}
|
|
157
164
|
});
|
|
158
|
-
exports.getI18NValue = void 0;
|
|
159
165
|
|
|
160
166
|
var _utils = require("./utils");
|
|
161
167
|
|
package/lib/utils.js
CHANGED
|
@@ -4,28 +4,30 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.formatDate = formatDate;
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
exports.unescapeUnicode = unescapeUnicode;
|
|
10
|
-
exports.getValues = getValues;
|
|
11
|
-
exports.getI18NValue = getI18NValue;
|
|
7
|
+
exports.getDatePatternWithoutYear = getDatePatternWithoutYear;
|
|
8
|
+
exports.getDiffObj = getDiffObj;
|
|
12
9
|
exports.getI18NInfo = getI18NInfo;
|
|
10
|
+
exports.getI18NValue = getI18NValue;
|
|
11
|
+
exports.getLocalizedValue = getLocalizedValue;
|
|
12
|
+
exports.getLyears = getLyears;
|
|
13
|
+
exports.getSuffix = getSuffix;
|
|
14
|
+
exports.getValues = getValues;
|
|
13
15
|
exports.isToday = isToday;
|
|
14
|
-
exports.isYesterday = isYesterday;
|
|
15
16
|
exports.isTomorrow = isTomorrow;
|
|
16
|
-
exports.isWithinAWeek = isWithinAWeek;
|
|
17
17
|
exports.isTwoWeeksOrMore = isTwoWeeksOrMore;
|
|
18
|
-
exports.
|
|
18
|
+
exports.isWithinAWeek = isWithinAWeek;
|
|
19
|
+
exports.isYesterday = isYesterday;
|
|
20
|
+
exports.pad = pad;
|
|
21
|
+
exports.replaceI18NValuesWithRegex = replaceI18NValuesWithRegex;
|
|
22
|
+
exports.setLocalizedData = setLocalizedData;
|
|
23
|
+
exports.unescapeUnicode = unescapeUnicode;
|
|
19
24
|
exports.userDateFormat = userDateFormat;
|
|
20
|
-
exports.getDiffObj = getDiffObj;
|
|
21
|
-
exports.getLyears = getLyears;
|
|
22
|
-
exports.getSuffix = getSuffix;
|
|
23
25
|
|
|
24
26
|
var _datetimejs = _interopRequireDefault(require("@zohodesk/datetimejs"));
|
|
25
27
|
|
|
26
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
27
29
|
|
|
28
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
30
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
29
31
|
|
|
30
32
|
var dateFormat = {
|
|
31
33
|
dayNames: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
|
@@ -159,6 +161,41 @@ function getValues() {
|
|
|
159
161
|
});
|
|
160
162
|
}
|
|
161
163
|
|
|
164
|
+
var localizedData = {};
|
|
165
|
+
|
|
166
|
+
function setLocalizedData(data) {
|
|
167
|
+
localizedData = data;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function getLocalizedValue() {
|
|
171
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
172
|
+
type = _ref.type,
|
|
173
|
+
moduleName = _ref.moduleName,
|
|
174
|
+
apiName = _ref.apiName,
|
|
175
|
+
fieldValue = _ref.fieldValue;
|
|
176
|
+
|
|
177
|
+
var localizedValue = localizedData;
|
|
178
|
+
|
|
179
|
+
switch (type) {
|
|
180
|
+
case 'field':
|
|
181
|
+
['Field', moduleName, apiName].map(function (key) {
|
|
182
|
+
localizedValue = localizedValue[key] || '';
|
|
183
|
+
});
|
|
184
|
+
break;
|
|
185
|
+
|
|
186
|
+
case 'picklist':
|
|
187
|
+
['PickListValue', moduleName, apiName, fieldValue].map(function (key) {
|
|
188
|
+
localizedValue = localizedValue[key] || '';
|
|
189
|
+
});
|
|
190
|
+
break;
|
|
191
|
+
|
|
192
|
+
default:
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return localizedValue || null;
|
|
197
|
+
}
|
|
198
|
+
|
|
162
199
|
function getI18NValue(i18n) {
|
|
163
200
|
if (typeof i18n === 'undefined') {
|
|
164
201
|
return function (key) {
|
|
@@ -166,15 +203,16 @@ function getI18NValue(i18n) {
|
|
|
166
203
|
};
|
|
167
204
|
}
|
|
168
205
|
|
|
169
|
-
return function (key, values) {
|
|
206
|
+
return function (key, values, localizedProps) {
|
|
207
|
+
var localizedValue = localizedProps ? getLocalizedValue(localizedProps) : null;
|
|
170
208
|
var i18nStr = i18n[key];
|
|
171
209
|
|
|
172
210
|
if (i18nStr === undefined) {
|
|
173
|
-
return key;
|
|
211
|
+
return localizedValue || key;
|
|
174
212
|
}
|
|
175
213
|
|
|
176
214
|
i18nStr = replaceI18NValuesWithRegex(i18nStr, values);
|
|
177
|
-
return unescapeUnicode(i18nStr);
|
|
215
|
+
return localizedValue || unescapeUnicode(i18nStr);
|
|
178
216
|
};
|
|
179
217
|
} // function getValues(params = [], diff) {
|
|
180
218
|
// return params.map(param => {
|
|
@@ -248,16 +286,16 @@ function getDatePatternWithoutYear(datePattern) {
|
|
|
248
286
|
}
|
|
249
287
|
|
|
250
288
|
return dateObj.filter(function (data) {
|
|
251
|
-
return ['
|
|
289
|
+
return ['yy', 'yyyy'].indexOf(data) === -1;
|
|
252
290
|
}).join(delemiter);
|
|
253
291
|
}
|
|
254
292
|
|
|
255
293
|
function userDateFormat(getI18NValue, timezoneData, timeFormat, datePattern, isEnabledCurrentYear) {
|
|
256
|
-
return function (to,
|
|
257
|
-
var today =
|
|
258
|
-
yesterday =
|
|
259
|
-
tomorrow =
|
|
260
|
-
others =
|
|
294
|
+
return function (to, _ref2, ago, later) {
|
|
295
|
+
var today = _ref2.today,
|
|
296
|
+
yesterday = _ref2.yesterday,
|
|
297
|
+
tomorrow = _ref2.tomorrow,
|
|
298
|
+
others = _ref2.others;
|
|
261
299
|
var isSuffixEnable = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
262
300
|
var format = arguments.length > 5 ? arguments[5] : undefined;
|
|
263
301
|
|
|
@@ -307,7 +345,8 @@ function userDateFormat(getI18NValue, timezoneData, timeFormat, datePattern, isE
|
|
|
307
345
|
timeFormat: timeFormat,
|
|
308
346
|
datePattern: datePattern,
|
|
309
347
|
dateTimePattern: "".concat(datePattern, " ").concat(timeFormat)
|
|
310
|
-
};
|
|
348
|
+
}; //In if condition we'll remove year and set date format if the current year is not required
|
|
349
|
+
//In else part we'll set the date format as it is
|
|
311
350
|
|
|
312
351
|
if (isEnabledCurrentYear === true && diffObj1.years === 0 && diffObj1.tYear === diffObj1.crntYear) {
|
|
313
352
|
var _dateFormat = getDatePatternWithoutYear(datePattern);
|
|
@@ -359,7 +398,7 @@ function userDateFormat(getI18NValue, timezoneData, timeFormat, datePattern, isE
|
|
|
359
398
|
} else {
|
|
360
399
|
var dateObj = new Date(toDateObj);
|
|
361
400
|
var curDateObj = new Date(fromDateObj);
|
|
362
|
-
var diffDayType = diffObj1.yDays;
|
|
401
|
+
var diffDayType = diffObj1.yDays; //In this condition, to calculate different days we have copied it from live --> diffDayType
|
|
363
402
|
|
|
364
403
|
if (isOverdue && dateObj.getDate() < curDateObj.getDate() && diffObj1.yDays == 0) {
|
|
365
404
|
diffDayType = -1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zohodesk/i18n",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.19",
|
|
4
4
|
"main": "lib/index",
|
|
5
5
|
"module": "es/index.js",
|
|
6
6
|
"jsnext:main": "es/index.js",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
"lint": "react-cli lint"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@zoho/SecurityJS": "5.0.
|
|
22
|
+
"@zoho/SecurityJS": "5.0.2"
|
|
23
23
|
},
|
|
24
24
|
"react-cli": {
|
|
25
25
|
"docs": {
|
|
26
26
|
"componentFolder": "./src"
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
}
|
|
29
|
+
}
|
|
@@ -108,6 +108,8 @@ export default class DateTimeDiffFormat extends React.Component {
|
|
|
108
108
|
dateTimePattern: `${datePattern} ${timeFormat}`,
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
+
//In if condition we'll remove year and set date format if the current year is not required
|
|
112
|
+
//In else part we'll set the date format as it is
|
|
111
113
|
if (
|
|
112
114
|
isEnabledCurrentYear === true &&
|
|
113
115
|
diffObj1.years === 0 &&
|
|
@@ -164,6 +166,7 @@ export default class DateTimeDiffFormat extends React.Component {
|
|
|
164
166
|
let curDateObj = new Date(fromDateObj);
|
|
165
167
|
let diffDayType = diffObj1.yDays;
|
|
166
168
|
|
|
169
|
+
//In this condition, to calculate different days we have copied it from live --> diffDayType
|
|
167
170
|
if (
|
|
168
171
|
isOverdue &&
|
|
169
172
|
dateObj.getDate() < curDateObj.getDate() &&
|
|
@@ -15,13 +15,15 @@ export default class I18NProvider extends React.Component {
|
|
|
15
15
|
constructor(props, context) {
|
|
16
16
|
super(props, context);
|
|
17
17
|
i18NProviderUtils.getI18NValue = getI18NValue(props.i18n);
|
|
18
|
-
|
|
19
|
-
i18NProviderUtils.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
if(props.tzData){
|
|
19
|
+
i18NProviderUtils.userDateFormat = userDateFormat(
|
|
20
|
+
i18NProviderUtils.getI18NValue,
|
|
21
|
+
props.tzData,
|
|
22
|
+
props.timeFormat,
|
|
23
|
+
props.datePattern,
|
|
24
|
+
props.isEnabledCurrentYear
|
|
25
|
+
);
|
|
26
|
+
}
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
componentDidUpdate(next) {
|
|
@@ -48,13 +50,15 @@ export default class I18NProvider extends React.Component {
|
|
|
48
50
|
}).then(
|
|
49
51
|
() => {
|
|
50
52
|
i18NProviderUtils.getI18NValue = getI18NValue(nextProps.i18n);
|
|
51
|
-
|
|
52
|
-
i18NProviderUtils.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
if(props.tzData){
|
|
54
|
+
i18NProviderUtils.userDateFormat = userDateFormat(
|
|
55
|
+
i18NProviderUtils.getI18NValue,
|
|
56
|
+
props.tzData,
|
|
57
|
+
props.timeFormat,
|
|
58
|
+
props.datePattern,
|
|
59
|
+
this.props.isEnabledCurrentYear
|
|
60
|
+
);
|
|
61
|
+
}
|
|
58
62
|
this.promise = null;
|
|
59
63
|
},
|
|
60
64
|
() => {
|
package/src/index.js
CHANGED
|
@@ -14,7 +14,8 @@ export {
|
|
|
14
14
|
getDiffObj,
|
|
15
15
|
getLyears,
|
|
16
16
|
getSuffix,
|
|
17
|
-
getDatePatternWithoutYear
|
|
17
|
+
getDatePatternWithoutYear,
|
|
18
|
+
setLocalizedData
|
|
18
19
|
} from './utils';
|
|
19
20
|
import { getI18NValue as getI18NValue1 } from './utils';
|
|
20
21
|
export { I18NContext } from './I18NContext';
|
package/src/utils.js
CHANGED
|
@@ -155,17 +155,47 @@ export function unescapeUnicode(str) {
|
|
|
155
155
|
export function getValues(params = [], diff) {
|
|
156
156
|
return params.map((param) => diff[param]);
|
|
157
157
|
}
|
|
158
|
+
|
|
159
|
+
let localizedData = {};
|
|
160
|
+
|
|
161
|
+
export function setLocalizedData(data) {
|
|
162
|
+
localizedData = data;
|
|
163
|
+
}
|
|
164
|
+
export function getLocalizedValue({
|
|
165
|
+
type,
|
|
166
|
+
moduleName,
|
|
167
|
+
apiName,
|
|
168
|
+
fieldValue
|
|
169
|
+
} = {}) {
|
|
170
|
+
let localizedValue = localizedData;
|
|
171
|
+
switch(type) {
|
|
172
|
+
case 'field':
|
|
173
|
+
['Field', moduleName, apiName].map((key) => {
|
|
174
|
+
localizedValue = localizedValue[key] || '';
|
|
175
|
+
});
|
|
176
|
+
break;
|
|
177
|
+
case 'picklist':
|
|
178
|
+
['PickListValue', moduleName, apiName, fieldValue].map((key) => {
|
|
179
|
+
localizedValue = localizedValue[key] || '';
|
|
180
|
+
});
|
|
181
|
+
break;
|
|
182
|
+
default:
|
|
183
|
+
return null
|
|
184
|
+
}
|
|
185
|
+
return localizedValue || null
|
|
186
|
+
}
|
|
158
187
|
export function getI18NValue(i18n) {
|
|
159
188
|
if (typeof i18n === 'undefined') {
|
|
160
189
|
return (key) => key;
|
|
161
190
|
}
|
|
162
|
-
return (key, values) => {
|
|
191
|
+
return (key, values, localizedProps) => {
|
|
192
|
+
const localizedValue = localizedProps ? getLocalizedValue(localizedProps) : null;
|
|
163
193
|
let i18nStr = i18n[key];
|
|
164
194
|
if (i18nStr === undefined) {
|
|
165
|
-
return key;
|
|
195
|
+
return localizedValue || key;
|
|
166
196
|
}
|
|
167
197
|
i18nStr = replaceI18NValuesWithRegex(i18nStr, values);
|
|
168
|
-
return unescapeUnicode(i18nStr);
|
|
198
|
+
return localizedValue || unescapeUnicode(i18nStr);
|
|
169
199
|
};
|
|
170
200
|
}
|
|
171
201
|
|
|
@@ -227,7 +257,7 @@ export function getDatePatternWithoutYear(datePattern) {
|
|
|
227
257
|
delemiter = ' ';
|
|
228
258
|
}
|
|
229
259
|
return dateObj
|
|
230
|
-
.filter((data) => ['
|
|
260
|
+
.filter((data) => ['yy', 'yyyy'].indexOf(data) === -1)
|
|
231
261
|
.join(delemiter);
|
|
232
262
|
}
|
|
233
263
|
|
|
@@ -291,6 +321,8 @@ export function userDateFormat(
|
|
|
291
321
|
dateTimePattern: `${datePattern} ${timeFormat}`,
|
|
292
322
|
};
|
|
293
323
|
|
|
324
|
+
//In if condition we'll remove year and set date format if the current year is not required
|
|
325
|
+
//In else part we'll set the date format as it is
|
|
294
326
|
if (
|
|
295
327
|
isEnabledCurrentYear === true &&
|
|
296
328
|
diffObj1.years === 0 &&
|
|
@@ -345,6 +377,7 @@ export function userDateFormat(
|
|
|
345
377
|
let curDateObj = new Date(fromDateObj);
|
|
346
378
|
let diffDayType = diffObj1.yDays;
|
|
347
379
|
|
|
380
|
+
//In this condition, to calculate different days we have copied it from live --> diffDayType
|
|
348
381
|
if (
|
|
349
382
|
isOverdue &&
|
|
350
383
|
dateObj.getDate() < curDateObj.getDate() &&
|