@zohodesk/i18n 1.0.0-beta.40-murphy → 1.0.0-beta.42-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/es/index.js +1 -1
- package/es/utils/errorReporter.js +21 -91
- package/es/utils/index.js +0 -4
- package/es/utils/jsxTranslations.js +0 -4
- package/lib/index.js +0 -12
- package/lib/utils/errorReporter.js +21 -111
- package/lib/utils/index.js +0 -6
- package/lib/utils/jsxTranslations.js +0 -6
- package/package.json +1 -1
- package/src/index.js +0 -2
- package/src/utils/errorReporter.js +21 -103
- package/src/utils/index.js +0 -7
- package/src/utils/jsxTranslations.js +0 -4
package/es/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { formatDate, pad, replaceI18NValuesWithRegex, unescapeUnicode, getValues, getI18NInfo, isToday, isYesterday, isTomorrow, isWithinAWeek, isTwoWeeksOrMore, userDateFormat, getDiffObj, getLyears, getSuffix, getDatePatternWithoutYear, setLocalizedData, setI18NKeyMapping, dayi18n, monthi18n, timei18n } from "./utils";
|
|
2
|
-
export { reportI18NError,
|
|
2
|
+
export { reportI18NError, I18N_ERROR_TYPES } from "./utils/errorReporter";
|
|
3
3
|
import { getI18NValue as getI18NValue1 } from "./utils";
|
|
4
4
|
export { I18NContext } from "./I18NContext";
|
|
5
5
|
export { default as I18NProvider, i18NProviderUtils } from "./components/I18NProvider";
|
|
@@ -1,108 +1,38 @@
|
|
|
1
1
|
export const I18N_ERROR_TYPES = {
|
|
2
|
-
UNDEFINED_OBJECT: 'I18N_UNDEFINED_OBJECT',
|
|
3
2
|
MISSING_KEY: 'I18N_MISSING_KEY',
|
|
4
3
|
NUMERIC_FALLBACK: 'I18N_NUMERIC_FALLBACK'
|
|
5
4
|
};
|
|
6
5
|
const reportedKeys = new Set();
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
let hasLoggedFlushUse = false;
|
|
11
|
-
function getDeskCustomError() {
|
|
12
|
-
if (typeof window === 'undefined') {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
return typeof window._windowDeskCustomError === 'function' ? window._windowDeskCustomError : null;
|
|
16
|
-
}
|
|
17
|
-
function isReporterAvailable() {
|
|
18
|
-
return Boolean(getDeskCustomError());
|
|
19
|
-
}
|
|
20
|
-
function sendToDesk(type, key) {
|
|
21
|
-
const deskCustomError = getDeskCustomError();
|
|
22
|
-
if (!deskCustomError) {
|
|
23
|
-
console.log('[i18n] Murphy not available, skipping error report:', {
|
|
24
|
-
type,
|
|
25
|
-
key
|
|
26
|
-
});
|
|
6
|
+
export function reportI18NError(type, key) {
|
|
7
|
+
const dedupeKey = `${type}:${key}`;
|
|
8
|
+
if (reportedKeys.has(dedupeKey)) {
|
|
27
9
|
return;
|
|
28
10
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const envData = {
|
|
11
|
+
|
|
12
|
+
// Prefix numeric keys to prevent Murphy masking
|
|
13
|
+
const isNumeric = /^\d+$/.test(key);
|
|
14
|
+
const displayKey = isNumeric ? `key:${key}` : key;
|
|
15
|
+
const errorMessage = `i18n ${type}: ${displayKey}`;
|
|
16
|
+
const errorData = {
|
|
36
17
|
errorType: type,
|
|
37
|
-
i18nKey:
|
|
18
|
+
i18nKey: displayKey,
|
|
19
|
+
rawKey: key,
|
|
38
20
|
category: 'i18n'
|
|
39
21
|
};
|
|
40
22
|
try {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (!hasLoggedQueueUse && typeof console !== 'undefined') {
|
|
51
|
-
console.log('[i18n] queued errors while murphy not available');
|
|
52
|
-
hasLoggedQueueUse = true;
|
|
53
|
-
}
|
|
54
|
-
if (pendingErrors.size >= MAX_PENDING_ERRORS) {
|
|
55
|
-
const oldestKey = pendingErrors.keys().next().value;
|
|
56
|
-
pendingErrors.delete(oldestKey);
|
|
57
|
-
}
|
|
58
|
-
pendingErrors.set(dedupeKey, {
|
|
59
|
-
type,
|
|
60
|
-
key
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
export function flushI18NErrors() {
|
|
64
|
-
if (!isReporterAvailable()) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
if (pendingErrors.size === 0) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (!hasLoggedFlushUse && typeof console !== 'undefined') {
|
|
71
|
-
console.log('[i18n] flushing queued errors', {
|
|
72
|
-
count: pendingErrors.size
|
|
73
|
-
});
|
|
74
|
-
hasLoggedFlushUse = true;
|
|
75
|
-
}
|
|
76
|
-
for (const [dedupeKey, data] of pendingErrors) {
|
|
77
|
-
if (reportedKeys.has(dedupeKey)) {
|
|
78
|
-
pendingErrors.delete(dedupeKey);
|
|
79
|
-
continue;
|
|
23
|
+
if (typeof window._windowDeskCustomError === 'function') {
|
|
24
|
+
window._windowDeskCustomError(errorData, errorMessage, errorData);
|
|
25
|
+
} else if (window.murphy) {
|
|
26
|
+
window.murphy.addCustomTracking(errorData);
|
|
27
|
+
const error = new Error(errorMessage);
|
|
28
|
+
error.name = type;
|
|
29
|
+
window.murphy.error(error);
|
|
30
|
+
} else {
|
|
31
|
+
return;
|
|
80
32
|
}
|
|
81
|
-
|
|
82
|
-
reportedKeys.add(dedupeKey);
|
|
83
|
-
pendingErrors.delete(dedupeKey);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
export function reportI18NError(type, key) {
|
|
87
|
-
const dedupeKey = `${type}:${key}`;
|
|
88
|
-
if (reportedKeys.has(dedupeKey)) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
if (!isReporterAvailable()) {
|
|
92
|
-
queuePendingError(dedupeKey, type, key);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
flushI18NErrors();
|
|
96
|
-
if (reportedKeys.has(dedupeKey)) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
sendToDesk(type, key);
|
|
33
|
+
} catch (err) {}
|
|
100
34
|
reportedKeys.add(dedupeKey);
|
|
101
35
|
}
|
|
102
|
-
export function clearReportedKeys() {
|
|
103
|
-
reportedKeys.clear();
|
|
104
|
-
pendingErrors.clear();
|
|
105
|
-
}
|
|
106
36
|
export function getFallbackText(key) {
|
|
107
37
|
const isNumeric = /^\d+$/.test(key);
|
|
108
38
|
return isNumeric ? `text.unavailable.${key}` : key;
|
package/es/utils/index.js
CHANGED
|
@@ -234,10 +234,6 @@ export function getLocalizedValue({
|
|
|
234
234
|
return localizedValue || null;
|
|
235
235
|
}
|
|
236
236
|
export function getI18NValue(i18n) {
|
|
237
|
-
if (typeof i18n === 'undefined') {
|
|
238
|
-
reportI18NError(I18N_ERROR_TYPES.UNDEFINED_OBJECT, 'i18n_object');
|
|
239
|
-
return key => key;
|
|
240
|
-
}
|
|
241
237
|
return (key, values, localizedProps) => {
|
|
242
238
|
const localizedValue = localizedProps ? getLocalizedValue(localizedProps) : localizedStringData[key];
|
|
243
239
|
const finalKey = getMappedKey(key);
|
|
@@ -169,10 +169,6 @@ export function placeComponentForTags(i18nValue) {
|
|
|
169
169
|
return i18nMechanismForComponents(value, value);
|
|
170
170
|
}
|
|
171
171
|
export function getI18NComponent(i18n) {
|
|
172
|
-
if (typeof i18n === 'undefined') {
|
|
173
|
-
reportI18NError(I18N_ERROR_TYPES.UNDEFINED_OBJECT, 'i18n_object_jsx');
|
|
174
|
-
return key => key;
|
|
175
|
-
}
|
|
176
172
|
return key => {
|
|
177
173
|
let i18nStr = i18n[key];
|
|
178
174
|
if (i18nStr === undefined) {
|
package/lib/index.js
CHANGED
|
@@ -58,24 +58,12 @@ Object.defineProperty(exports, "UserTimeDiffFormat", {
|
|
|
58
58
|
return _UserTimeDiffFormat["default"];
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
|
-
Object.defineProperty(exports, "clearReportedKeys", {
|
|
62
|
-
enumerable: true,
|
|
63
|
-
get: function get() {
|
|
64
|
-
return _errorReporter.clearReportedKeys;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
61
|
Object.defineProperty(exports, "dayi18n", {
|
|
68
62
|
enumerable: true,
|
|
69
63
|
get: function get() {
|
|
70
64
|
return _utils.dayi18n;
|
|
71
65
|
}
|
|
72
66
|
});
|
|
73
|
-
Object.defineProperty(exports, "flushI18NErrors", {
|
|
74
|
-
enumerable: true,
|
|
75
|
-
get: function get() {
|
|
76
|
-
return _errorReporter.flushI18NErrors;
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
67
|
Object.defineProperty(exports, "formatDate", {
|
|
80
68
|
enumerable: true,
|
|
81
69
|
get: function get() {
|
|
@@ -4,133 +4,43 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.I18N_ERROR_TYPES = void 0;
|
|
7
|
-
exports.clearReportedKeys = clearReportedKeys;
|
|
8
|
-
exports.flushI18NErrors = flushI18NErrors;
|
|
9
7
|
exports.getFallbackText = getFallbackText;
|
|
10
8
|
exports.reportI18NError = reportI18NError;
|
|
11
|
-
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
12
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
14
|
-
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
15
|
-
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
16
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
17
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
18
9
|
var I18N_ERROR_TYPES = exports.I18N_ERROR_TYPES = {
|
|
19
|
-
UNDEFINED_OBJECT: 'I18N_UNDEFINED_OBJECT',
|
|
20
10
|
MISSING_KEY: 'I18N_MISSING_KEY',
|
|
21
11
|
NUMERIC_FALLBACK: 'I18N_NUMERIC_FALLBACK'
|
|
22
12
|
};
|
|
23
13
|
var reportedKeys = new Set();
|
|
24
|
-
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
var hasLoggedFlushUse = false;
|
|
28
|
-
function getDeskCustomError() {
|
|
29
|
-
if (typeof window === 'undefined') {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
return typeof window._windowDeskCustomError === 'function' ? window._windowDeskCustomError : null;
|
|
33
|
-
}
|
|
34
|
-
function isReporterAvailable() {
|
|
35
|
-
return Boolean(getDeskCustomError());
|
|
36
|
-
}
|
|
37
|
-
function sendToDesk(type, key) {
|
|
38
|
-
var deskCustomError = getDeskCustomError();
|
|
39
|
-
if (!deskCustomError) {
|
|
40
|
-
console.log('[i18n] Murphy not available, skipping error report:', {
|
|
41
|
-
type: type,
|
|
42
|
-
key: key
|
|
43
|
-
});
|
|
14
|
+
function reportI18NError(type, key) {
|
|
15
|
+
var dedupeKey = "".concat(type, ":").concat(key);
|
|
16
|
+
if (reportedKeys.has(dedupeKey)) {
|
|
44
17
|
return;
|
|
45
18
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var envData = {
|
|
19
|
+
|
|
20
|
+
// Prefix numeric keys to prevent Murphy masking
|
|
21
|
+
var isNumeric = /^\d+$/.test(key);
|
|
22
|
+
var displayKey = isNumeric ? "key:".concat(key) : key;
|
|
23
|
+
var errorMessage = "i18n ".concat(type, ": ").concat(displayKey);
|
|
24
|
+
var errorData = {
|
|
53
25
|
errorType: type,
|
|
54
|
-
i18nKey:
|
|
26
|
+
i18nKey: displayKey,
|
|
27
|
+
rawKey: key,
|
|
55
28
|
category: 'i18n'
|
|
56
29
|
};
|
|
57
30
|
try {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (!hasLoggedQueueUse && typeof console !== 'undefined') {
|
|
68
|
-
console.log('[i18n] queued errors while murphy not available');
|
|
69
|
-
hasLoggedQueueUse = true;
|
|
70
|
-
}
|
|
71
|
-
if (pendingErrors.size >= MAX_PENDING_ERRORS) {
|
|
72
|
-
var oldestKey = pendingErrors.keys().next().value;
|
|
73
|
-
pendingErrors["delete"](oldestKey);
|
|
74
|
-
}
|
|
75
|
-
pendingErrors.set(dedupeKey, {
|
|
76
|
-
type: type,
|
|
77
|
-
key: key
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
function flushI18NErrors() {
|
|
81
|
-
if (!isReporterAvailable()) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
if (pendingErrors.size === 0) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
if (!hasLoggedFlushUse && typeof console !== 'undefined') {
|
|
88
|
-
console.log('[i18n] flushing queued errors', {
|
|
89
|
-
count: pendingErrors.size
|
|
90
|
-
});
|
|
91
|
-
hasLoggedFlushUse = true;
|
|
92
|
-
}
|
|
93
|
-
var _iterator = _createForOfIteratorHelper(pendingErrors),
|
|
94
|
-
_step;
|
|
95
|
-
try {
|
|
96
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
97
|
-
var _step$value = _slicedToArray(_step.value, 2),
|
|
98
|
-
dedupeKey = _step$value[0],
|
|
99
|
-
data = _step$value[1];
|
|
100
|
-
if (reportedKeys.has(dedupeKey)) {
|
|
101
|
-
pendingErrors["delete"](dedupeKey);
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
sendToDesk(data.type, data.key);
|
|
105
|
-
reportedKeys.add(dedupeKey);
|
|
106
|
-
pendingErrors["delete"](dedupeKey);
|
|
31
|
+
if (typeof window._windowDeskCustomError === 'function') {
|
|
32
|
+
window._windowDeskCustomError(errorData, errorMessage, errorData);
|
|
33
|
+
} else if (window.murphy) {
|
|
34
|
+
window.murphy.addCustomTracking(errorData);
|
|
35
|
+
var error = new Error(errorMessage);
|
|
36
|
+
error.name = type;
|
|
37
|
+
window.murphy.error(error);
|
|
38
|
+
} else {
|
|
39
|
+
return;
|
|
107
40
|
}
|
|
108
|
-
} catch (err) {
|
|
109
|
-
_iterator.e(err);
|
|
110
|
-
} finally {
|
|
111
|
-
_iterator.f();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function reportI18NError(type, key) {
|
|
115
|
-
var dedupeKey = "".concat(type, ":").concat(key);
|
|
116
|
-
if (reportedKeys.has(dedupeKey)) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if (!isReporterAvailable()) {
|
|
120
|
-
queuePendingError(dedupeKey, type, key);
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
flushI18NErrors();
|
|
124
|
-
if (reportedKeys.has(dedupeKey)) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
sendToDesk(type, key);
|
|
41
|
+
} catch (err) {}
|
|
128
42
|
reportedKeys.add(dedupeKey);
|
|
129
43
|
}
|
|
130
|
-
function clearReportedKeys() {
|
|
131
|
-
reportedKeys.clear();
|
|
132
|
-
pendingErrors.clear();
|
|
133
|
-
}
|
|
134
44
|
function getFallbackText(key) {
|
|
135
45
|
var isNumeric = /^\d+$/.test(key);
|
|
136
46
|
return isNumeric ? "text.unavailable.".concat(key) : key;
|
package/lib/utils/index.js
CHANGED
|
@@ -269,12 +269,6 @@ function getLocalizedValue() {
|
|
|
269
269
|
return localizedValue || null;
|
|
270
270
|
}
|
|
271
271
|
function getI18NValue(i18n) {
|
|
272
|
-
if (typeof i18n === 'undefined') {
|
|
273
|
-
(0, _errorReporter.reportI18NError)(_errorReporter.I18N_ERROR_TYPES.UNDEFINED_OBJECT, 'i18n_object');
|
|
274
|
-
return function (key) {
|
|
275
|
-
return key;
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
272
|
return function (key, values, localizedProps) {
|
|
279
273
|
var localizedValue = localizedProps ? getLocalizedValue(localizedProps) : localizedStringData[key];
|
|
280
274
|
var finalKey = getMappedKey(key);
|
|
@@ -198,12 +198,6 @@ function placeComponentForTags(i18nValue) {
|
|
|
198
198
|
return i18nMechanismForComponents(value, value);
|
|
199
199
|
}
|
|
200
200
|
function getI18NComponent(i18n) {
|
|
201
|
-
if (typeof i18n === 'undefined') {
|
|
202
|
-
(0, _errorReporter.reportI18NError)(_errorReporter.I18N_ERROR_TYPES.UNDEFINED_OBJECT, 'i18n_object_jsx');
|
|
203
|
-
return function (key) {
|
|
204
|
-
return key;
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
201
|
return function (key) {
|
|
208
202
|
var i18nStr = i18n[key];
|
|
209
203
|
if (i18nStr === undefined) {
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,128 +1,46 @@
|
|
|
1
1
|
export const I18N_ERROR_TYPES = {
|
|
2
|
-
UNDEFINED_OBJECT: 'I18N_UNDEFINED_OBJECT',
|
|
3
2
|
MISSING_KEY: 'I18N_MISSING_KEY',
|
|
4
3
|
NUMERIC_FALLBACK: 'I18N_NUMERIC_FALLBACK'
|
|
5
4
|
};
|
|
6
5
|
|
|
7
6
|
const reportedKeys = new Set();
|
|
8
|
-
const pendingErrors = new Map();
|
|
9
|
-
const MAX_PENDING_ERRORS = 100;
|
|
10
|
-
let hasLoggedQueueUse = false;
|
|
11
|
-
let hasLoggedFlushUse = false;
|
|
12
7
|
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return typeof window._windowDeskCustomError === 'function'
|
|
19
|
-
? window._windowDeskCustomError
|
|
20
|
-
: null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function isReporterAvailable() {
|
|
24
|
-
return Boolean(getDeskCustomError());
|
|
25
|
-
}
|
|
8
|
+
export function reportI18NError(type, key) {
|
|
9
|
+
const dedupeKey = `${type}:${key}`;
|
|
26
10
|
|
|
27
|
-
|
|
28
|
-
const deskCustomError = getDeskCustomError();
|
|
29
|
-
if (!deskCustomError) {
|
|
30
|
-
console.log('[i18n] Murphy not available, skipping error report:', { type, key });
|
|
11
|
+
if (reportedKeys.has(dedupeKey)) {
|
|
31
12
|
return;
|
|
32
13
|
}
|
|
33
14
|
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const envData = {
|
|
15
|
+
// Prefix numeric keys to prevent Murphy masking
|
|
16
|
+
const isNumeric = /^\d+$/.test(key);
|
|
17
|
+
const displayKey = isNumeric ? `key:${key}` : key;
|
|
18
|
+
|
|
19
|
+
const errorMessage = `i18n ${type}: ${displayKey}`;
|
|
20
|
+
const errorData = {
|
|
41
21
|
errorType: type,
|
|
42
|
-
i18nKey:
|
|
22
|
+
i18nKey: displayKey,
|
|
23
|
+
rawKey: key,
|
|
43
24
|
category: 'i18n'
|
|
44
25
|
};
|
|
45
26
|
|
|
46
27
|
try {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (!hasLoggedQueueUse && typeof console !== 'undefined') {
|
|
59
|
-
console.log('[i18n] queued errors while murphy not available');
|
|
60
|
-
hasLoggedQueueUse = true;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (pendingErrors.size >= MAX_PENDING_ERRORS) {
|
|
64
|
-
const oldestKey = pendingErrors.keys().next().value;
|
|
65
|
-
pendingErrors.delete(oldestKey);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
pendingErrors.set(dedupeKey, { type, key });
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function flushI18NErrors() {
|
|
72
|
-
if (!isReporterAvailable()) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (pendingErrors.size === 0) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (!hasLoggedFlushUse && typeof console !== 'undefined') {
|
|
81
|
-
console.log('[i18n] flushing queued errors', {
|
|
82
|
-
count: pendingErrors.size
|
|
83
|
-
});
|
|
84
|
-
hasLoggedFlushUse = true;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
for (const [dedupeKey, data] of pendingErrors) {
|
|
88
|
-
if (reportedKeys.has(dedupeKey)) {
|
|
89
|
-
pendingErrors.delete(dedupeKey);
|
|
90
|
-
continue;
|
|
28
|
+
if (typeof window._windowDeskCustomError === 'function') {
|
|
29
|
+
window._windowDeskCustomError(errorData, errorMessage, errorData);
|
|
30
|
+
} else if (window.murphy) {
|
|
31
|
+
window.murphy.addCustomTracking(errorData);
|
|
32
|
+
const error = new Error(errorMessage);
|
|
33
|
+
error.name = type;
|
|
34
|
+
window.murphy.error(error);
|
|
35
|
+
} else {
|
|
36
|
+
return;
|
|
91
37
|
}
|
|
92
|
-
|
|
93
|
-
sendToDesk(data.type, data.key);
|
|
94
|
-
reportedKeys.add(dedupeKey);
|
|
95
|
-
pendingErrors.delete(dedupeKey);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function reportI18NError(type, key) {
|
|
100
|
-
const dedupeKey = `${type}:${key}`;
|
|
101
|
-
|
|
102
|
-
if (reportedKeys.has(dedupeKey)) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (!isReporterAvailable()) {
|
|
107
|
-
queuePendingError(dedupeKey, type, key);
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
flushI18NErrors();
|
|
112
|
-
|
|
113
|
-
if (reportedKeys.has(dedupeKey)) {
|
|
114
|
-
return;
|
|
38
|
+
} catch (err) {
|
|
115
39
|
}
|
|
116
40
|
|
|
117
|
-
sendToDesk(type, key);
|
|
118
41
|
reportedKeys.add(dedupeKey);
|
|
119
42
|
}
|
|
120
43
|
|
|
121
|
-
export function clearReportedKeys() {
|
|
122
|
-
reportedKeys.clear();
|
|
123
|
-
pendingErrors.clear();
|
|
124
|
-
}
|
|
125
|
-
|
|
126
44
|
export function getFallbackText(key) {
|
|
127
45
|
const isNumeric = /^\d+$/.test(key);
|
|
128
46
|
return isNumeric ? `text.unavailable.${key}` : key;
|
package/src/utils/index.js
CHANGED
|
@@ -290,24 +290,17 @@ export function getLocalizedValue({
|
|
|
290
290
|
return localizedValue || null
|
|
291
291
|
}
|
|
292
292
|
export function getI18NValue(i18n) {
|
|
293
|
-
if (typeof i18n === 'undefined') {
|
|
294
|
-
reportI18NError(I18N_ERROR_TYPES.UNDEFINED_OBJECT, 'i18n_object');
|
|
295
|
-
return (key) => key;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
293
|
return (key, values, localizedProps) => {
|
|
299
294
|
const localizedValue = localizedProps
|
|
300
295
|
? getLocalizedValue(localizedProps)
|
|
301
296
|
: localizedStringData[key];
|
|
302
297
|
const finalKey = getMappedKey(key);
|
|
303
298
|
let i18nStr = i18n[finalKey];
|
|
304
|
-
|
|
305
299
|
if (i18nStr === undefined) {
|
|
306
300
|
const isNumeric = /^\d+$/.test(finalKey);
|
|
307
301
|
const errorType = isNumeric
|
|
308
302
|
? I18N_ERROR_TYPES.NUMERIC_FALLBACK
|
|
309
303
|
: I18N_ERROR_TYPES.MISSING_KEY;
|
|
310
|
-
|
|
311
304
|
reportI18NError(errorType, finalKey);
|
|
312
305
|
return localizedValue || getFallbackText(finalKey);
|
|
313
306
|
}
|
|
@@ -180,10 +180,6 @@ export function placeComponentForTags(i18nValue) {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
export function getI18NComponent(i18n) {
|
|
183
|
-
if(typeof i18n === 'undefined') {
|
|
184
|
-
reportI18NError(I18N_ERROR_TYPES.UNDEFINED_OBJECT, 'i18n_object_jsx');
|
|
185
|
-
return (key) => key;
|
|
186
|
-
}
|
|
187
183
|
return (key) => {
|
|
188
184
|
let i18nStr = i18n[key];
|
|
189
185
|
if (i18nStr === undefined) {
|