@zohodesk/i18n 1.0.0-beta.33 → 1.0.0-beta.35-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 +4 -0
- 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/components/DateTimeDiffFormat.js +5 -19
- package/es/components/FormatText.js +2 -2
- package/es/components/HOCI18N.js +32 -43
- package/es/components/I18N.js +2 -13
- package/es/components/I18NProvider.js +0 -9
- package/es/components/PluralFormat.js +3 -5
- package/es/components/UserTimeDiffFormat.js +5 -9
- package/es/components/__tests__/DateTimeDiffFormat.spec.js +157 -221
- package/es/components/__tests__/FormatText.spec.js +2 -2
- package/es/components/__tests__/HOCI18N.spec.js +2 -4
- package/es/components/__tests__/I18N.spec.js +6 -4
- package/es/components/__tests__/I18NProvider.spec.js +4 -4
- package/es/components/__tests__/PluralFormat.spec.js +2 -2
- package/es/components/__tests__/UserTimeDiffFormat.spec.js +249 -348
- package/es/index.js +2 -0
- package/es/utils/__tests__/jsxTranslations.spec.js +3 -7
- package/es/utils/errorReporter.js +31 -0
- package/es/utils/index.js +42 -92
- package/es/utils/jsxTranslations.js +53 -61
- package/lib/I18NContext.js +2 -7
- package/lib/components/DateTimeDiffFormat.js +46 -87
- package/lib/components/FormatText.js +18 -41
- package/lib/components/HOCI18N.js +24 -59
- package/lib/components/I18N.js +27 -64
- package/lib/components/I18NProvider.js +27 -63
- package/lib/components/PluralFormat.js +24 -50
- package/lib/components/UserTimeDiffFormat.js +43 -72
- package/lib/components/__tests__/DateTimeDiffFormat.spec.js +95 -165
- package/lib/components/__tests__/FormatText.spec.js +3 -10
- package/lib/components/__tests__/HOCI18N.spec.js +3 -14
- package/lib/components/__tests__/I18N.spec.js +4 -12
- package/lib/components/__tests__/I18NProvider.spec.js +8 -23
- package/lib/components/__tests__/PluralFormat.spec.js +3 -11
- package/lib/components/__tests__/UserTimeDiffFormat.spec.js +157 -225
- package/lib/index.js +32 -22
- package/lib/utils/__tests__/jsxTranslations.spec.js +1 -12
- package/lib/utils/errorReporter.js +39 -0
- package/lib/utils/index.js +49 -125
- package/lib/utils/jsxTranslations.js +79 -105
- package/package.json +1 -1
- package/src/index.js +6 -0
- package/src/utils/errorReporter.js +36 -0
- package/src/utils/index.js +8 -1
- package/src/utils/jsxTranslations.js +31 -12
package/lib/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(
|
|
4
|
-
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -41,6 +40,12 @@ Object.defineProperty(exports, "I18NProvider", {
|
|
|
41
40
|
return _I18NProvider["default"];
|
|
42
41
|
}
|
|
43
42
|
});
|
|
43
|
+
Object.defineProperty(exports, "I18N_ERROR_TYPES", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function get() {
|
|
46
|
+
return _errorReporter.I18N_ERROR_TYPES;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
44
49
|
Object.defineProperty(exports, "PluralFormat", {
|
|
45
50
|
enumerable: true,
|
|
46
51
|
get: function get() {
|
|
@@ -53,6 +58,12 @@ Object.defineProperty(exports, "UserTimeDiffFormat", {
|
|
|
53
58
|
return _UserTimeDiffFormat["default"];
|
|
54
59
|
}
|
|
55
60
|
});
|
|
61
|
+
Object.defineProperty(exports, "clearReportedKeys", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function get() {
|
|
64
|
+
return _errorReporter.clearReportedKeys;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
56
67
|
Object.defineProperty(exports, "dayi18n", {
|
|
57
68
|
enumerable: true,
|
|
58
69
|
get: function get() {
|
|
@@ -150,12 +161,24 @@ Object.defineProperty(exports, "pad", {
|
|
|
150
161
|
return _utils.pad;
|
|
151
162
|
}
|
|
152
163
|
});
|
|
164
|
+
Object.defineProperty(exports, "placeComponentForTags", {
|
|
165
|
+
enumerable: true,
|
|
166
|
+
get: function get() {
|
|
167
|
+
return _jsxTranslations.placeComponentForTags;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
153
170
|
Object.defineProperty(exports, "replaceI18NValuesWithRegex", {
|
|
154
171
|
enumerable: true,
|
|
155
172
|
get: function get() {
|
|
156
173
|
return _utils.replaceI18NValuesWithRegex;
|
|
157
174
|
}
|
|
158
175
|
});
|
|
176
|
+
Object.defineProperty(exports, "reportI18NError", {
|
|
177
|
+
enumerable: true,
|
|
178
|
+
get: function get() {
|
|
179
|
+
return _errorReporter.reportI18NError;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
159
182
|
Object.defineProperty(exports, "setI18NKeyMapping", {
|
|
160
183
|
enumerable: true,
|
|
161
184
|
get: function get() {
|
|
@@ -186,33 +209,20 @@ Object.defineProperty(exports, "userDateFormat", {
|
|
|
186
209
|
return _utils.userDateFormat;
|
|
187
210
|
}
|
|
188
211
|
});
|
|
189
|
-
|
|
190
212
|
var _utils = require("./utils");
|
|
191
|
-
|
|
213
|
+
var _errorReporter = require("./utils/errorReporter");
|
|
192
214
|
var _I18NContext = require("./I18NContext");
|
|
193
|
-
|
|
194
215
|
var _I18NProvider = _interopRequireWildcard(require("./components/I18NProvider"));
|
|
195
|
-
|
|
196
216
|
var _I18N = _interopRequireDefault(require("./components/I18N"));
|
|
197
|
-
|
|
198
217
|
var _HOCI18N = _interopRequireDefault(require("./components/HOCI18N"));
|
|
199
|
-
|
|
200
218
|
var _FormatText = _interopRequireDefault(require("./components/FormatText"));
|
|
201
|
-
|
|
202
219
|
var _PluralFormat = _interopRequireDefault(require("./components/PluralFormat"));
|
|
203
|
-
|
|
204
220
|
var _DateTimeDiffFormat = _interopRequireDefault(require("./components/DateTimeDiffFormat"));
|
|
205
|
-
|
|
206
221
|
var _UserTimeDiffFormat = _interopRequireDefault(require("./components/UserTimeDiffFormat"));
|
|
207
|
-
|
|
208
|
-
function _interopRequireDefault(
|
|
209
|
-
|
|
210
|
-
function
|
|
211
|
-
|
|
212
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
213
|
-
|
|
214
|
-
var getI18NValue = function getI18NValue(i18n, key, values) {
|
|
222
|
+
var _jsxTranslations = require("./utils/jsxTranslations");
|
|
223
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
224
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
225
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
226
|
+
var getI18NValue = exports.getI18NValue = function getI18NValue(i18n, key, values) {
|
|
215
227
|
return (0, _utils.getI18NValue)(i18n)(key, values);
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
exports.getI18NValue = getI18NValue;
|
|
228
|
+
};
|
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _react = _interopRequireDefault(require("react"));
|
|
4
|
-
|
|
5
4
|
var _jsxTranslations = require("../jsxTranslations");
|
|
6
|
-
|
|
7
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
8
|
-
|
|
5
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
9
6
|
function Bold(_ref) {
|
|
10
7
|
var children = _ref.children;
|
|
11
8
|
return /*#__PURE__*/_react["default"].createElement("b", null, children);
|
|
12
9
|
}
|
|
13
|
-
|
|
14
10
|
function Simple(props) {
|
|
15
11
|
return /*#__PURE__*/_react["default"].createElement("span", null, props.children);
|
|
16
12
|
}
|
|
17
|
-
|
|
18
13
|
describe('Verifying splitMatchedExp method', function () {
|
|
19
14
|
it('A string with no match test', function () {
|
|
20
15
|
var response = (0, _jsxTranslations.splitMatchedExp)({
|
|
@@ -117,9 +112,7 @@ describe('Verifying the createElement method', function () {
|
|
|
117
112
|
},
|
|
118
113
|
values: ['Zoho Desk']
|
|
119
114
|
});
|
|
120
|
-
|
|
121
115
|
var expected = /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, "Hi Zoho Desk,", /*#__PURE__*/_react["default"].createElement(Simple, null, "Greetings"), " for the day");
|
|
122
|
-
|
|
123
116
|
expect(JSON.stringify(response)).toEqual(JSON.stringify(expected));
|
|
124
117
|
});
|
|
125
118
|
});
|
|
@@ -138,9 +131,7 @@ describe('Verifying the prepareI18NFunc method', function () {
|
|
|
138
131
|
}
|
|
139
132
|
}
|
|
140
133
|
});
|
|
141
|
-
|
|
142
134
|
var expected = /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, "Hi ", /*#__PURE__*/_react["default"].createElement(Bold, null, "Gigiee"), ",", /*#__PURE__*/_react["default"].createElement(Simple, null, "How are you"), /*#__PURE__*/_react["default"].createElement(Simple, null, "Make it simple"));
|
|
143
|
-
|
|
144
135
|
expect(JSON.stringify(response)).toEqual(JSON.stringify(expected));
|
|
145
136
|
});
|
|
146
137
|
});
|
|
@@ -160,9 +151,7 @@ describe('Verifying getI18NComponent method', function () {
|
|
|
160
151
|
}
|
|
161
152
|
}
|
|
162
153
|
});
|
|
163
|
-
|
|
164
154
|
var expected = /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, "Hi ", /*#__PURE__*/_react["default"].createElement(Bold, null, "Gigiee"), ",", /*#__PURE__*/_react["default"].createElement(Simple, null, "How are you"), /*#__PURE__*/_react["default"].createElement(Simple, null, "Make it simple"));
|
|
165
|
-
|
|
166
155
|
expect(JSON.stringify(response)).toEqual(JSON.stringify(expected));
|
|
167
156
|
});
|
|
168
157
|
it('Testing absence of i18n object', function () {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.I18N_ERROR_TYPES = void 0;
|
|
7
|
+
exports.clearReportedKeys = clearReportedKeys;
|
|
8
|
+
exports.reportI18NError = reportI18NError;
|
|
9
|
+
var I18N_ERROR_TYPES = exports.I18N_ERROR_TYPES = {
|
|
10
|
+
UNDEFINED_OBJECT: 'I18N_UNDEFINED_OBJECT',
|
|
11
|
+
MISSING_KEY: 'I18N_MISSING_KEY',
|
|
12
|
+
NUMERIC_FALLBACK: 'I18N_NUMERIC_FALLBACK'
|
|
13
|
+
};
|
|
14
|
+
var reportedKeys = new Set();
|
|
15
|
+
function isMurphyAvailable() {
|
|
16
|
+
return typeof murphy !== 'undefined' && typeof murphy.error === 'function';
|
|
17
|
+
}
|
|
18
|
+
function reportI18NError(type, key) {
|
|
19
|
+
var dedupeKey = "".concat(type, ":").concat(key);
|
|
20
|
+
if (reportedKeys.has(dedupeKey)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
reportedKeys.add(dedupeKey);
|
|
24
|
+
if (isMurphyAvailable()) {
|
|
25
|
+
var error = new Error("i18n ".concat(type, ": ").concat(key));
|
|
26
|
+
error.name = type;
|
|
27
|
+
murphy.error(error, undefined, {
|
|
28
|
+
customTags: {
|
|
29
|
+
errorType: type,
|
|
30
|
+
i18nKey: key,
|
|
31
|
+
category: 'i18n'
|
|
32
|
+
},
|
|
33
|
+
preventClientGrouping: true
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function clearReportedKeys() {
|
|
38
|
+
reportedKeys.clear();
|
|
39
|
+
}
|