@zohodesk/i18n 1.0.0-beta.17 → 1.0.0-beta.18

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 (62) hide show
  1. package/README.md +73 -69
  2. package/es/components/HOCI18N.js +33 -30
  3. package/es/components/UserTimeDiffFormat.js +6 -5
  4. package/es/components/__tests__/DateTimeDiffFormat.spec.js +177 -136
  5. package/es/components/__tests__/FormatText.spec.js +0 -1
  6. package/es/components/__tests__/HOCI18N.spec.js +0 -1
  7. package/es/components/__tests__/I18N.spec.js +0 -2
  8. package/es/components/__tests__/I18NProvider.spec.js +0 -1
  9. package/es/components/__tests__/PluralFormat.spec.js +0 -1
  10. package/es/components/__tests__/UserTimeDiffFormat.spec.js +287 -206
  11. package/es/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
  12. package/es/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
  13. package/es/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
  14. package/es/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
  15. package/es/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
  16. package/es/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
  17. package/es/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
  18. package/es/index.js +1 -1
  19. package/es/utils.js +51 -12
  20. package/lib/components/DateTimeDiffFormat.js +3 -3
  21. package/lib/components/FormatText.js +3 -3
  22. package/lib/components/HOCI18N.js +3 -3
  23. package/lib/components/I18N.js +3 -3
  24. package/lib/components/I18NProvider.js +4 -4
  25. package/lib/components/PluralFormat.js +3 -3
  26. package/lib/components/UserTimeDiffFormat.js +3 -3
  27. package/lib/components/__tests__/I18NProvider.spec.js +1 -1
  28. package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1 -1
  29. package/lib/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
  30. package/lib/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
  31. package/lib/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
  32. package/lib/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
  33. package/lib/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
  34. package/lib/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
  35. package/lib/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
  36. package/lib/index.js +58 -52
  37. package/lib/utils.js +58 -20
  38. package/package.json +28 -28
  39. package/src/I18NContext.js +2 -2
  40. package/src/components/DateTimeDiffFormat.js +254 -254
  41. package/src/components/FormatText.js +14 -14
  42. package/src/components/HOCI18N.js +37 -37
  43. package/src/components/I18N.js +72 -72
  44. package/src/components/I18NProvider.js +106 -106
  45. package/src/components/PluralFormat.js +37 -37
  46. package/src/components/UserTimeDiffFormat.js +94 -94
  47. package/src/components/__tests__/DateTimeDiffFormat.spec.js +618 -618
  48. package/src/components/__tests__/FormatText.spec.js +26 -26
  49. package/src/components/__tests__/HOCI18N.spec.js +33 -33
  50. package/src/components/__tests__/I18N.spec.js +29 -29
  51. package/src/components/__tests__/I18NProvider.spec.js +65 -65
  52. package/src/components/__tests__/PluralFormat.spec.js +27 -27
  53. package/src/components/__tests__/UserTimeDiffFormat.spec.js +1076 -1076
  54. package/src/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
  55. package/src/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
  56. package/src/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
  57. package/src/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
  58. package/src/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
  59. package/src/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
  60. package/src/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
  61. package/src/index.js +33 -32
  62. package/src/utils.js +527 -497
package/lib/index.js CHANGED
@@ -1,88 +1,83 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
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, "formatDate", {
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 _utils.pad;
11
+ return _DateTimeDiffFormat["default"];
18
12
  }
19
13
  });
20
- Object.defineProperty(exports, "replaceI18NValuesWithRegex", {
14
+ Object.defineProperty(exports, "FormatText", {
21
15
  enumerable: true,
22
16
  get: function get() {
23
- return _utils.replaceI18NValuesWithRegex;
17
+ return _FormatText["default"];
24
18
  }
25
19
  });
26
- Object.defineProperty(exports, "unescapeUnicode", {
20
+ Object.defineProperty(exports, "HOCI18N", {
27
21
  enumerable: true,
28
22
  get: function get() {
29
- return _utils.unescapeUnicode;
23
+ return _HOCI18N["default"];
30
24
  }
31
25
  });
32
- Object.defineProperty(exports, "getValues", {
26
+ Object.defineProperty(exports, "I18N", {
33
27
  enumerable: true,
34
28
  get: function get() {
35
- return _utils.getValues;
29
+ return _I18N["default"];
36
30
  }
37
31
  });
38
- Object.defineProperty(exports, "getI18NInfo", {
32
+ Object.defineProperty(exports, "I18NContext", {
39
33
  enumerable: true,
40
34
  get: function get() {
41
- return _utils.getI18NInfo;
35
+ return _I18NContext.I18NContext;
42
36
  }
43
37
  });
44
- Object.defineProperty(exports, "isToday", {
38
+ Object.defineProperty(exports, "I18NProvider", {
45
39
  enumerable: true,
46
40
  get: function get() {
47
- return _utils.isToday;
41
+ return _I18NProvider["default"];
48
42
  }
49
43
  });
50
- Object.defineProperty(exports, "isYesterday", {
44
+ Object.defineProperty(exports, "PluralFormat", {
51
45
  enumerable: true,
52
46
  get: function get() {
53
- return _utils.isYesterday;
47
+ return _PluralFormat["default"];
54
48
  }
55
49
  });
56
- Object.defineProperty(exports, "isTomorrow", {
50
+ Object.defineProperty(exports, "UserTimeDiffFormat", {
57
51
  enumerable: true,
58
52
  get: function get() {
59
- return _utils.isTomorrow;
53
+ return _UserTimeDiffFormat["default"];
60
54
  }
61
55
  });
62
- Object.defineProperty(exports, "isWithinAWeek", {
56
+ Object.defineProperty(exports, "formatDate", {
63
57
  enumerable: true,
64
58
  get: function get() {
65
- return _utils.isWithinAWeek;
59
+ return _utils.formatDate;
66
60
  }
67
61
  });
68
- Object.defineProperty(exports, "isTwoWeeksOrMore", {
62
+ Object.defineProperty(exports, "getDatePatternWithoutYear", {
69
63
  enumerable: true,
70
64
  get: function get() {
71
- return _utils.isTwoWeeksOrMore;
65
+ return _utils.getDatePatternWithoutYear;
72
66
  }
73
67
  });
74
- Object.defineProperty(exports, "userDateFormat", {
68
+ Object.defineProperty(exports, "getDiffObj", {
75
69
  enumerable: true,
76
70
  get: function get() {
77
- return _utils.userDateFormat;
71
+ return _utils.getDiffObj;
78
72
  }
79
73
  });
80
- Object.defineProperty(exports, "getDiffObj", {
74
+ Object.defineProperty(exports, "getI18NInfo", {
81
75
  enumerable: true,
82
76
  get: function get() {
83
- return _utils.getDiffObj;
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, "getDatePatternWithoutYear", {
93
+ Object.defineProperty(exports, "getValues", {
99
94
  enumerable: true,
100
95
  get: function get() {
101
- return _utils.getDatePatternWithoutYear;
96
+ return _utils.getValues;
102
97
  }
103
98
  });
104
- Object.defineProperty(exports, "I18NContext", {
99
+ Object.defineProperty(exports, "i18NProviderUtils", {
105
100
  enumerable: true,
106
101
  get: function get() {
107
- return _I18NContext.I18NContext;
102
+ return _I18NProvider.i18NProviderUtils;
108
103
  }
109
104
  });
110
- Object.defineProperty(exports, "I18NProvider", {
105
+ Object.defineProperty(exports, "isToday", {
111
106
  enumerable: true,
112
107
  get: function get() {
113
- return _I18NProvider["default"];
108
+ return _utils.isToday;
114
109
  }
115
110
  });
116
- Object.defineProperty(exports, "i18NProviderUtils", {
111
+ Object.defineProperty(exports, "isTomorrow", {
117
112
  enumerable: true,
118
113
  get: function get() {
119
- return _I18NProvider.i18NProviderUtils;
114
+ return _utils.isTomorrow;
120
115
  }
121
116
  });
122
- Object.defineProperty(exports, "I18N", {
117
+ Object.defineProperty(exports, "isTwoWeeksOrMore", {
123
118
  enumerable: true,
124
119
  get: function get() {
125
- return _I18N["default"];
120
+ return _utils.isTwoWeeksOrMore;
126
121
  }
127
122
  });
128
- Object.defineProperty(exports, "HOCI18N", {
123
+ Object.defineProperty(exports, "isWithinAWeek", {
129
124
  enumerable: true,
130
125
  get: function get() {
131
- return _HOCI18N["default"];
126
+ return _utils.isWithinAWeek;
132
127
  }
133
128
  });
134
- Object.defineProperty(exports, "FormatText", {
129
+ Object.defineProperty(exports, "isYesterday", {
135
130
  enumerable: true,
136
131
  get: function get() {
137
- return _FormatText["default"];
132
+ return _utils.isYesterday;
138
133
  }
139
134
  });
140
- Object.defineProperty(exports, "PluralFormat", {
135
+ Object.defineProperty(exports, "pad", {
141
136
  enumerable: true,
142
137
  get: function get() {
143
- return _PluralFormat["default"];
138
+ return _utils.pad;
144
139
  }
145
140
  });
146
- Object.defineProperty(exports, "DateTimeDiffFormat", {
141
+ Object.defineProperty(exports, "replaceI18NValuesWithRegex", {
147
142
  enumerable: true,
148
143
  get: function get() {
149
- return _DateTimeDiffFormat["default"];
144
+ return _utils.replaceI18NValuesWithRegex;
150
145
  }
151
146
  });
152
- Object.defineProperty(exports, "UserTimeDiffFormat", {
147
+ Object.defineProperty(exports, "setLocalizedData", {
153
148
  enumerable: true,
154
149
  get: function get() {
155
- return _UserTimeDiffFormat["default"];
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.pad = pad;
8
- exports.replaceI18NValuesWithRegex = replaceI18NValuesWithRegex;
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.getDatePatternWithoutYear = getDatePatternWithoutYear;
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"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
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 => {
@@ -253,11 +291,11 @@ function getDatePatternWithoutYear(datePattern) {
253
291
  }
254
292
 
255
293
  function userDateFormat(getI18NValue, timezoneData, timeFormat, datePattern, isEnabledCurrentYear) {
256
- return function (to, _ref, ago, later) {
257
- var today = _ref.today,
258
- yesterday = _ref.yesterday,
259
- tomorrow = _ref.tomorrow,
260
- others = _ref.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
 
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
- {
2
- "name": "@zohodesk/i18n",
3
- "version": "1.0.0-beta.17",
4
- "main": "lib/index",
5
- "module": "es/index.js",
6
- "jsnext:main": "es/index.js",
7
- "private": false,
8
- "umdVar": "i18n",
9
- "author": "",
10
- "license": "ISC",
11
- "scripts": {
12
- "clean": "react-cli clean lib es coverage",
13
- "build": "react-cli build:component:cmjs",
14
- "build:es": "react-cli build:library:es",
15
- "build:dev": "npm run clean && npm run build --module:mode=dev -- -w",
16
- "prepublish": "npm run init && npm run build && npm run build:es ",
17
- "prepare": "npm run init && npm run build && npm run build:es",
18
- "init": "npm run clean",
19
- "lint": "react-cli lint"
20
- },
21
- "dependencies": {
22
- "@zoho/SecurityJS": "5.0.2"
23
- },
24
- "react-cli": {
25
- "docs": {
26
- "componentFolder": "./src"
27
- }
28
- }
1
+ {
2
+ "name": "@zohodesk/i18n",
3
+ "version": "1.0.0-beta.18",
4
+ "main": "lib/index",
5
+ "module": "es/index.js",
6
+ "jsnext:main": "es/index.js",
7
+ "private": false,
8
+ "umdVar": "i18n",
9
+ "author": "",
10
+ "license": "ISC",
11
+ "scripts": {
12
+ "clean": "react-cli clean lib es coverage",
13
+ "build": "react-cli build:component:cmjs",
14
+ "build:es": "react-cli build:library:es",
15
+ "build:dev": "npm run clean && npm run build --module:mode=dev -- -w",
16
+ "prepublish": "npm run init && npm run build && npm run build:es ",
17
+ "prepare": "npm run init && npm run build && npm run build:es",
18
+ "init": "npm run clean",
19
+ "lint": "react-cli lint"
20
+ },
21
+ "dependencies": {
22
+ "@zoho/SecurityJS": "5.0.2"
23
+ },
24
+ "react-cli": {
25
+ "docs": {
26
+ "componentFolder": "./src"
27
+ }
28
+ }
29
29
  }
@@ -1,3 +1,3 @@
1
- import React from 'react';
2
-
1
+ import React from 'react';
2
+
3
3
  export const I18NContext = React.createContext();