@bigbinary/neeto-webhooks-frontend 1.6.0 → 1.6.2
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/app/javascript/src/translations/en.json +81 -0
- package/app/javascript/src/translations/index.js +1 -0
- package/dist/index.cjs.js +111 -3042
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +63 -2994
- package/dist/index.js.map +1 -1
- package/package.json +10 -4
package/dist/index.cjs.js
CHANGED
|
@@ -4,2987 +4,53 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var reactRouterDom = require('react-router-dom');
|
|
7
|
-
var
|
|
7
|
+
var neetoCist = require('@bigbinary/neeto-cist');
|
|
8
|
+
var constants = require('@bigbinary/neeto-commons-frontend/constants');
|
|
8
9
|
var Container = require('@bigbinary/neeto-molecules/Container');
|
|
9
10
|
var Header$2 = require('@bigbinary/neeto-molecules/Header');
|
|
10
11
|
var PageLoader = require('@bigbinary/neeto-molecules/PageLoader');
|
|
11
12
|
var TableWrapper = require('@bigbinary/neeto-molecules/TableWrapper');
|
|
12
13
|
var neetoui = require('@bigbinary/neetoui');
|
|
14
|
+
var reactI18next = require('react-i18next');
|
|
13
15
|
var reactQuery = require('react-query');
|
|
14
|
-
var devtools = require('react-query/devtools');
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var ramda = require('ramda');
|
|
19
|
-
var neetoIcons = require('@bigbinary/neeto-icons');
|
|
20
|
-
var formik = require('@bigbinary/neetoui/formik');
|
|
21
|
-
var utils = require('@bigbinary/neeto-commons-frontend/utils');
|
|
22
|
-
var yup = require('yup');
|
|
23
|
-
|
|
24
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
25
|
-
|
|
26
|
-
function _interopNamespace(e) {
|
|
27
|
-
if (e && e.__esModule) return e;
|
|
28
|
-
var n = Object.create(null);
|
|
29
|
-
if (e) {
|
|
30
|
-
Object.keys(e).forEach(function (k) {
|
|
31
|
-
if (k !== 'default') {
|
|
32
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
33
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
get: function () { return e[k]; }
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
n["default"] = e;
|
|
41
|
-
return Object.freeze(n);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
45
|
-
var Container__default = /*#__PURE__*/_interopDefaultLegacy(Container);
|
|
46
|
-
var Header__default = /*#__PURE__*/_interopDefaultLegacy(Header$2);
|
|
47
|
-
var PageLoader__default = /*#__PURE__*/_interopDefaultLegacy(PageLoader);
|
|
48
|
-
var TableWrapper__default = /*#__PURE__*/_interopDefaultLegacy(TableWrapper);
|
|
49
|
-
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
50
|
-
var DateFormat__default = /*#__PURE__*/_interopDefaultLegacy(DateFormat);
|
|
51
|
-
var yup__namespace = /*#__PURE__*/_interopNamespace(yup);
|
|
52
|
-
|
|
53
|
-
const consoleLogger = {
|
|
54
|
-
type: 'logger',
|
|
55
|
-
log(args) {
|
|
56
|
-
this.output('log', args);
|
|
57
|
-
},
|
|
58
|
-
warn(args) {
|
|
59
|
-
this.output('warn', args);
|
|
60
|
-
},
|
|
61
|
-
error(args) {
|
|
62
|
-
this.output('error', args);
|
|
63
|
-
},
|
|
64
|
-
output(type, args) {
|
|
65
|
-
if (console && console[type]) console[type].apply(console, args);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
class Logger {
|
|
69
|
-
constructor(concreteLogger) {
|
|
70
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
71
|
-
this.init(concreteLogger, options);
|
|
72
|
-
}
|
|
73
|
-
init(concreteLogger) {
|
|
74
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
75
|
-
this.prefix = options.prefix || 'i18next:';
|
|
76
|
-
this.logger = concreteLogger || consoleLogger;
|
|
77
|
-
this.options = options;
|
|
78
|
-
this.debug = options.debug;
|
|
79
|
-
}
|
|
80
|
-
log() {
|
|
81
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
82
|
-
args[_key] = arguments[_key];
|
|
83
|
-
}
|
|
84
|
-
return this.forward(args, 'log', '', true);
|
|
85
|
-
}
|
|
86
|
-
warn() {
|
|
87
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
88
|
-
args[_key2] = arguments[_key2];
|
|
89
|
-
}
|
|
90
|
-
return this.forward(args, 'warn', '', true);
|
|
91
|
-
}
|
|
92
|
-
error() {
|
|
93
|
-
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
94
|
-
args[_key3] = arguments[_key3];
|
|
95
|
-
}
|
|
96
|
-
return this.forward(args, 'error', '');
|
|
97
|
-
}
|
|
98
|
-
deprecate() {
|
|
99
|
-
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
100
|
-
args[_key4] = arguments[_key4];
|
|
101
|
-
}
|
|
102
|
-
return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
|
|
103
|
-
}
|
|
104
|
-
forward(args, lvl, prefix, debugOnly) {
|
|
105
|
-
if (debugOnly && !this.debug) return null;
|
|
106
|
-
if (typeof args[0] === 'string') args[0] = `${prefix}${this.prefix} ${args[0]}`;
|
|
107
|
-
return this.logger[lvl](args);
|
|
108
|
-
}
|
|
109
|
-
create(moduleName) {
|
|
110
|
-
return new Logger(this.logger, {
|
|
111
|
-
...{
|
|
112
|
-
prefix: `${this.prefix}:${moduleName}:`
|
|
113
|
-
},
|
|
114
|
-
...this.options
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
clone(options) {
|
|
118
|
-
options = options || this.options;
|
|
119
|
-
options.prefix = options.prefix || this.prefix;
|
|
120
|
-
return new Logger(this.logger, options);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
var baseLogger = new Logger();
|
|
124
|
-
|
|
125
|
-
class EventEmitter {
|
|
126
|
-
constructor() {
|
|
127
|
-
this.observers = {};
|
|
128
|
-
}
|
|
129
|
-
on(events, listener) {
|
|
130
|
-
events.split(' ').forEach(event => {
|
|
131
|
-
this.observers[event] = this.observers[event] || [];
|
|
132
|
-
this.observers[event].push(listener);
|
|
133
|
-
});
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
136
|
-
off(event, listener) {
|
|
137
|
-
if (!this.observers[event]) return;
|
|
138
|
-
if (!listener) {
|
|
139
|
-
delete this.observers[event];
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
this.observers[event] = this.observers[event].filter(l => l !== listener);
|
|
143
|
-
}
|
|
144
|
-
emit(event) {
|
|
145
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
146
|
-
args[_key - 1] = arguments[_key];
|
|
147
|
-
}
|
|
148
|
-
if (this.observers[event]) {
|
|
149
|
-
const cloned = [].concat(this.observers[event]);
|
|
150
|
-
cloned.forEach(observer => {
|
|
151
|
-
observer(...args);
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
if (this.observers['*']) {
|
|
155
|
-
const cloned = [].concat(this.observers['*']);
|
|
156
|
-
cloned.forEach(observer => {
|
|
157
|
-
observer.apply(observer, [event, ...args]);
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function defer() {
|
|
164
|
-
let res;
|
|
165
|
-
let rej;
|
|
166
|
-
const promise = new Promise((resolve, reject) => {
|
|
167
|
-
res = resolve;
|
|
168
|
-
rej = reject;
|
|
169
|
-
});
|
|
170
|
-
promise.resolve = res;
|
|
171
|
-
promise.reject = rej;
|
|
172
|
-
return promise;
|
|
173
|
-
}
|
|
174
|
-
function makeString(object) {
|
|
175
|
-
if (object == null) return '';
|
|
176
|
-
return '' + object;
|
|
177
|
-
}
|
|
178
|
-
function copy(a, s, t) {
|
|
179
|
-
a.forEach(m => {
|
|
180
|
-
if (s[m]) t[m] = s[m];
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
function getLastOfPath(object, path, Empty) {
|
|
184
|
-
function cleanKey(key) {
|
|
185
|
-
return key && key.indexOf('###') > -1 ? key.replace(/###/g, '.') : key;
|
|
186
|
-
}
|
|
187
|
-
function canNotTraverseDeeper() {
|
|
188
|
-
return !object || typeof object === 'string';
|
|
189
|
-
}
|
|
190
|
-
const stack = typeof path !== 'string' ? [].concat(path) : path.split('.');
|
|
191
|
-
while (stack.length > 1) {
|
|
192
|
-
if (canNotTraverseDeeper()) return {};
|
|
193
|
-
const key = cleanKey(stack.shift());
|
|
194
|
-
if (!object[key] && Empty) object[key] = new Empty();
|
|
195
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
196
|
-
object = object[key];
|
|
197
|
-
} else {
|
|
198
|
-
object = {};
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
if (canNotTraverseDeeper()) return {};
|
|
202
|
-
return {
|
|
203
|
-
obj: object,
|
|
204
|
-
k: cleanKey(stack.shift())
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
function setPath(object, path, newValue) {
|
|
208
|
-
const {
|
|
209
|
-
obj,
|
|
210
|
-
k
|
|
211
|
-
} = getLastOfPath(object, path, Object);
|
|
212
|
-
obj[k] = newValue;
|
|
213
|
-
}
|
|
214
|
-
function pushPath(object, path, newValue, concat) {
|
|
215
|
-
const {
|
|
216
|
-
obj,
|
|
217
|
-
k
|
|
218
|
-
} = getLastOfPath(object, path, Object);
|
|
219
|
-
obj[k] = obj[k] || [];
|
|
220
|
-
if (concat) obj[k] = obj[k].concat(newValue);
|
|
221
|
-
if (!concat) obj[k].push(newValue);
|
|
222
|
-
}
|
|
223
|
-
function getPath(object, path) {
|
|
224
|
-
const {
|
|
225
|
-
obj,
|
|
226
|
-
k
|
|
227
|
-
} = getLastOfPath(object, path);
|
|
228
|
-
if (!obj) return undefined;
|
|
229
|
-
return obj[k];
|
|
230
|
-
}
|
|
231
|
-
function getPathWithDefaults(data, defaultData, key) {
|
|
232
|
-
const value = getPath(data, key);
|
|
233
|
-
if (value !== undefined) {
|
|
234
|
-
return value;
|
|
235
|
-
}
|
|
236
|
-
return getPath(defaultData, key);
|
|
237
|
-
}
|
|
238
|
-
function deepExtend(target, source, overwrite) {
|
|
239
|
-
for (const prop in source) {
|
|
240
|
-
if (prop !== '__proto__' && prop !== 'constructor') {
|
|
241
|
-
if (prop in target) {
|
|
242
|
-
if (typeof target[prop] === 'string' || target[prop] instanceof String || typeof source[prop] === 'string' || source[prop] instanceof String) {
|
|
243
|
-
if (overwrite) target[prop] = source[prop];
|
|
244
|
-
} else {
|
|
245
|
-
deepExtend(target[prop], source[prop], overwrite);
|
|
246
|
-
}
|
|
247
|
-
} else {
|
|
248
|
-
target[prop] = source[prop];
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return target;
|
|
253
|
-
}
|
|
254
|
-
function regexEscape(str) {
|
|
255
|
-
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
|
|
256
|
-
}
|
|
257
|
-
var _entityMap = {
|
|
258
|
-
'&': '&',
|
|
259
|
-
'<': '<',
|
|
260
|
-
'>': '>',
|
|
261
|
-
'"': '"',
|
|
262
|
-
"'": ''',
|
|
263
|
-
'/': '/'
|
|
264
|
-
};
|
|
265
|
-
function escape(data) {
|
|
266
|
-
if (typeof data === 'string') {
|
|
267
|
-
return data.replace(/[&<>"'\/]/g, s => _entityMap[s]);
|
|
268
|
-
}
|
|
269
|
-
return data;
|
|
270
|
-
}
|
|
271
|
-
const chars = [' ', ',', '?', '!', ';'];
|
|
272
|
-
function looksLikeObjectPath(key, nsSeparator, keySeparator) {
|
|
273
|
-
nsSeparator = nsSeparator || '';
|
|
274
|
-
keySeparator = keySeparator || '';
|
|
275
|
-
const possibleChars = chars.filter(c => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
|
|
276
|
-
if (possibleChars.length === 0) return true;
|
|
277
|
-
const r = new RegExp(`(${possibleChars.map(c => c === '?' ? '\\?' : c).join('|')})`);
|
|
278
|
-
let matched = !r.test(key);
|
|
279
|
-
if (!matched) {
|
|
280
|
-
const ki = key.indexOf(keySeparator);
|
|
281
|
-
if (ki > 0 && !r.test(key.substring(0, ki))) {
|
|
282
|
-
matched = true;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
return matched;
|
|
286
|
-
}
|
|
287
|
-
function deepFind(obj, path) {
|
|
288
|
-
let keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
|
|
289
|
-
if (!obj) return undefined;
|
|
290
|
-
if (obj[path]) return obj[path];
|
|
291
|
-
const paths = path.split(keySeparator);
|
|
292
|
-
let current = obj;
|
|
293
|
-
for (let i = 0; i < paths.length; ++i) {
|
|
294
|
-
if (!current) return undefined;
|
|
295
|
-
if (typeof current[paths[i]] === 'string' && i + 1 < paths.length) {
|
|
296
|
-
return undefined;
|
|
297
|
-
}
|
|
298
|
-
if (current[paths[i]] === undefined) {
|
|
299
|
-
let j = 2;
|
|
300
|
-
let p = paths.slice(i, i + j).join(keySeparator);
|
|
301
|
-
let mix = current[p];
|
|
302
|
-
while (mix === undefined && paths.length > i + j) {
|
|
303
|
-
j++;
|
|
304
|
-
p = paths.slice(i, i + j).join(keySeparator);
|
|
305
|
-
mix = current[p];
|
|
306
|
-
}
|
|
307
|
-
if (mix === undefined) return undefined;
|
|
308
|
-
if (mix === null) return null;
|
|
309
|
-
if (path.endsWith(p)) {
|
|
310
|
-
if (typeof mix === 'string') return mix;
|
|
311
|
-
if (p && typeof mix[p] === 'string') return mix[p];
|
|
312
|
-
}
|
|
313
|
-
const joinedPath = paths.slice(i + j).join(keySeparator);
|
|
314
|
-
if (joinedPath) return deepFind(mix, joinedPath, keySeparator);
|
|
315
|
-
return undefined;
|
|
316
|
-
}
|
|
317
|
-
current = current[paths[i]];
|
|
318
|
-
}
|
|
319
|
-
return current;
|
|
320
|
-
}
|
|
321
|
-
function getCleanedCode(code) {
|
|
322
|
-
if (code && code.indexOf('_') > 0) return code.replace('_', '-');
|
|
323
|
-
return code;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
class ResourceStore extends EventEmitter {
|
|
327
|
-
constructor(data) {
|
|
328
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
329
|
-
ns: ['translation'],
|
|
330
|
-
defaultNS: 'translation'
|
|
331
|
-
};
|
|
332
|
-
super();
|
|
333
|
-
this.data = data || {};
|
|
334
|
-
this.options = options;
|
|
335
|
-
if (this.options.keySeparator === undefined) {
|
|
336
|
-
this.options.keySeparator = '.';
|
|
337
|
-
}
|
|
338
|
-
if (this.options.ignoreJSONStructure === undefined) {
|
|
339
|
-
this.options.ignoreJSONStructure = true;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
addNamespaces(ns) {
|
|
343
|
-
if (this.options.ns.indexOf(ns) < 0) {
|
|
344
|
-
this.options.ns.push(ns);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
removeNamespaces(ns) {
|
|
348
|
-
const index = this.options.ns.indexOf(ns);
|
|
349
|
-
if (index > -1) {
|
|
350
|
-
this.options.ns.splice(index, 1);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
getResource(lng, ns, key) {
|
|
354
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
355
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
356
|
-
const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
357
|
-
let path = [lng, ns];
|
|
358
|
-
if (key && typeof key !== 'string') path = path.concat(key);
|
|
359
|
-
if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
360
|
-
if (lng.indexOf('.') > -1) {
|
|
361
|
-
path = lng.split('.');
|
|
362
|
-
}
|
|
363
|
-
const result = getPath(this.data, path);
|
|
364
|
-
if (result || !ignoreJSONStructure || typeof key !== 'string') return result;
|
|
365
|
-
return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
|
|
366
|
-
}
|
|
367
|
-
addResource(lng, ns, key, value) {
|
|
368
|
-
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
369
|
-
silent: false
|
|
370
|
-
};
|
|
371
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
372
|
-
let path = [lng, ns];
|
|
373
|
-
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
374
|
-
if (lng.indexOf('.') > -1) {
|
|
375
|
-
path = lng.split('.');
|
|
376
|
-
value = ns;
|
|
377
|
-
ns = path[1];
|
|
378
|
-
}
|
|
379
|
-
this.addNamespaces(ns);
|
|
380
|
-
setPath(this.data, path, value);
|
|
381
|
-
if (!options.silent) this.emit('added', lng, ns, key, value);
|
|
382
|
-
}
|
|
383
|
-
addResources(lng, ns, resources) {
|
|
384
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
385
|
-
silent: false
|
|
386
|
-
};
|
|
387
|
-
for (const m in resources) {
|
|
388
|
-
if (typeof resources[m] === 'string' || Object.prototype.toString.apply(resources[m]) === '[object Array]') this.addResource(lng, ns, m, resources[m], {
|
|
389
|
-
silent: true
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
393
|
-
}
|
|
394
|
-
addResourceBundle(lng, ns, resources, deep, overwrite) {
|
|
395
|
-
let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
|
|
396
|
-
silent: false
|
|
397
|
-
};
|
|
398
|
-
let path = [lng, ns];
|
|
399
|
-
if (lng.indexOf('.') > -1) {
|
|
400
|
-
path = lng.split('.');
|
|
401
|
-
deep = resources;
|
|
402
|
-
resources = ns;
|
|
403
|
-
ns = path[1];
|
|
404
|
-
}
|
|
405
|
-
this.addNamespaces(ns);
|
|
406
|
-
let pack = getPath(this.data, path) || {};
|
|
407
|
-
if (deep) {
|
|
408
|
-
deepExtend(pack, resources, overwrite);
|
|
409
|
-
} else {
|
|
410
|
-
pack = {
|
|
411
|
-
...pack,
|
|
412
|
-
...resources
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
setPath(this.data, path, pack);
|
|
416
|
-
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
417
|
-
}
|
|
418
|
-
removeResourceBundle(lng, ns) {
|
|
419
|
-
if (this.hasResourceBundle(lng, ns)) {
|
|
420
|
-
delete this.data[lng][ns];
|
|
421
|
-
}
|
|
422
|
-
this.removeNamespaces(ns);
|
|
423
|
-
this.emit('removed', lng, ns);
|
|
424
|
-
}
|
|
425
|
-
hasResourceBundle(lng, ns) {
|
|
426
|
-
return this.getResource(lng, ns) !== undefined;
|
|
427
|
-
}
|
|
428
|
-
getResourceBundle(lng, ns) {
|
|
429
|
-
if (!ns) ns = this.options.defaultNS;
|
|
430
|
-
if (this.options.compatibilityAPI === 'v1') return {
|
|
431
|
-
...{},
|
|
432
|
-
...this.getResource(lng, ns)
|
|
433
|
-
};
|
|
434
|
-
return this.getResource(lng, ns);
|
|
435
|
-
}
|
|
436
|
-
getDataByLanguage(lng) {
|
|
437
|
-
return this.data[lng];
|
|
438
|
-
}
|
|
439
|
-
hasLanguageSomeTranslations(lng) {
|
|
440
|
-
const data = this.getDataByLanguage(lng);
|
|
441
|
-
const n = data && Object.keys(data) || [];
|
|
442
|
-
return !!n.find(v => data[v] && Object.keys(data[v]).length > 0);
|
|
443
|
-
}
|
|
444
|
-
toJSON() {
|
|
445
|
-
return this.data;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
var postProcessor = {
|
|
450
|
-
processors: {},
|
|
451
|
-
addPostProcessor(module) {
|
|
452
|
-
this.processors[module.name] = module;
|
|
453
|
-
},
|
|
454
|
-
handle(processors, value, key, options, translator) {
|
|
455
|
-
processors.forEach(processor => {
|
|
456
|
-
if (this.processors[processor]) value = this.processors[processor].process(value, key, options, translator);
|
|
457
|
-
});
|
|
458
|
-
return value;
|
|
459
|
-
}
|
|
460
|
-
};
|
|
461
|
-
|
|
462
|
-
const checkedLoadedFor = {};
|
|
463
|
-
class Translator extends EventEmitter {
|
|
464
|
-
constructor(services) {
|
|
465
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
466
|
-
super();
|
|
467
|
-
copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, this);
|
|
468
|
-
this.options = options;
|
|
469
|
-
if (this.options.keySeparator === undefined) {
|
|
470
|
-
this.options.keySeparator = '.';
|
|
471
|
-
}
|
|
472
|
-
this.logger = baseLogger.create('translator');
|
|
473
|
-
}
|
|
474
|
-
changeLanguage(lng) {
|
|
475
|
-
if (lng) this.language = lng;
|
|
476
|
-
}
|
|
477
|
-
exists(key) {
|
|
478
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
479
|
-
interpolation: {}
|
|
480
|
-
};
|
|
481
|
-
if (key === undefined || key === null) {
|
|
482
|
-
return false;
|
|
483
|
-
}
|
|
484
|
-
const resolved = this.resolve(key, options);
|
|
485
|
-
return resolved && resolved.res !== undefined;
|
|
486
|
-
}
|
|
487
|
-
extractFromKey(key, options) {
|
|
488
|
-
let nsSeparator = options.nsSeparator !== undefined ? options.nsSeparator : this.options.nsSeparator;
|
|
489
|
-
if (nsSeparator === undefined) nsSeparator = ':';
|
|
490
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
491
|
-
let namespaces = options.ns || this.options.defaultNS || [];
|
|
492
|
-
const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
493
|
-
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
494
|
-
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
495
|
-
const m = key.match(this.interpolator.nestingRegexp);
|
|
496
|
-
if (m && m.length > 0) {
|
|
497
|
-
return {
|
|
498
|
-
key,
|
|
499
|
-
namespaces
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
const parts = key.split(nsSeparator);
|
|
503
|
-
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
|
|
504
|
-
key = parts.join(keySeparator);
|
|
505
|
-
}
|
|
506
|
-
if (typeof namespaces === 'string') namespaces = [namespaces];
|
|
507
|
-
return {
|
|
508
|
-
key,
|
|
509
|
-
namespaces
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
translate(keys, options, lastKey) {
|
|
513
|
-
if (typeof options !== 'object' && this.options.overloadTranslationOptionHandler) {
|
|
514
|
-
options = this.options.overloadTranslationOptionHandler(arguments);
|
|
515
|
-
}
|
|
516
|
-
if (typeof options === 'object') options = {
|
|
517
|
-
...options
|
|
518
|
-
};
|
|
519
|
-
if (!options) options = {};
|
|
520
|
-
if (keys === undefined || keys === null) return '';
|
|
521
|
-
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
522
|
-
const returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
|
|
523
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
524
|
-
const {
|
|
525
|
-
key,
|
|
526
|
-
namespaces
|
|
527
|
-
} = this.extractFromKey(keys[keys.length - 1], options);
|
|
528
|
-
const namespace = namespaces[namespaces.length - 1];
|
|
529
|
-
const lng = options.lng || this.language;
|
|
530
|
-
const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
531
|
-
if (lng && lng.toLowerCase() === 'cimode') {
|
|
532
|
-
if (appendNamespaceToCIMode) {
|
|
533
|
-
const nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
534
|
-
if (returnDetails) {
|
|
535
|
-
return {
|
|
536
|
-
res: `${namespace}${nsSeparator}${key}`,
|
|
537
|
-
usedKey: key,
|
|
538
|
-
exactUsedKey: key,
|
|
539
|
-
usedLng: lng,
|
|
540
|
-
usedNS: namespace
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
return `${namespace}${nsSeparator}${key}`;
|
|
544
|
-
}
|
|
545
|
-
if (returnDetails) {
|
|
546
|
-
return {
|
|
547
|
-
res: key,
|
|
548
|
-
usedKey: key,
|
|
549
|
-
exactUsedKey: key,
|
|
550
|
-
usedLng: lng,
|
|
551
|
-
usedNS: namespace
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
return key;
|
|
555
|
-
}
|
|
556
|
-
const resolved = this.resolve(keys, options);
|
|
557
|
-
let res = resolved && resolved.res;
|
|
558
|
-
const resUsedKey = resolved && resolved.usedKey || key;
|
|
559
|
-
const resExactUsedKey = resolved && resolved.exactUsedKey || key;
|
|
560
|
-
const resType = Object.prototype.toString.apply(res);
|
|
561
|
-
const noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
|
|
562
|
-
const joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
|
|
563
|
-
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
564
|
-
const handleAsObject = typeof res !== 'string' && typeof res !== 'boolean' && typeof res !== 'number';
|
|
565
|
-
if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === 'string' && resType === '[object Array]')) {
|
|
566
|
-
if (!options.returnObjects && !this.options.returnObjects) {
|
|
567
|
-
if (!this.options.returnedObjectHandler) {
|
|
568
|
-
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
569
|
-
}
|
|
570
|
-
const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, {
|
|
571
|
-
...options,
|
|
572
|
-
ns: namespaces
|
|
573
|
-
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
574
|
-
if (returnDetails) {
|
|
575
|
-
resolved.res = r;
|
|
576
|
-
return resolved;
|
|
577
|
-
}
|
|
578
|
-
return r;
|
|
579
|
-
}
|
|
580
|
-
if (keySeparator) {
|
|
581
|
-
const resTypeIsArray = resType === '[object Array]';
|
|
582
|
-
const copy = resTypeIsArray ? [] : {};
|
|
583
|
-
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
584
|
-
for (const m in res) {
|
|
585
|
-
if (Object.prototype.hasOwnProperty.call(res, m)) {
|
|
586
|
-
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
587
|
-
copy[m] = this.translate(deepKey, {
|
|
588
|
-
...options,
|
|
589
|
-
...{
|
|
590
|
-
joinArrays: false,
|
|
591
|
-
ns: namespaces
|
|
592
|
-
}
|
|
593
|
-
});
|
|
594
|
-
if (copy[m] === deepKey) copy[m] = res[m];
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
res = copy;
|
|
598
|
-
}
|
|
599
|
-
} else if (handleAsObjectInI18nFormat && typeof joinArrays === 'string' && resType === '[object Array]') {
|
|
600
|
-
res = res.join(joinArrays);
|
|
601
|
-
if (res) res = this.extendTranslation(res, keys, options, lastKey);
|
|
602
|
-
} else {
|
|
603
|
-
let usedDefault = false;
|
|
604
|
-
let usedKey = false;
|
|
605
|
-
const needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
|
|
606
|
-
const hasDefaultValue = Translator.hasDefaultValue(options);
|
|
607
|
-
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : '';
|
|
608
|
-
const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
|
|
609
|
-
ordinal: false
|
|
610
|
-
}) : '';
|
|
611
|
-
const defaultValue = options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
|
|
612
|
-
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
613
|
-
usedDefault = true;
|
|
614
|
-
res = defaultValue;
|
|
615
|
-
}
|
|
616
|
-
if (!this.isValidLookup(res)) {
|
|
617
|
-
usedKey = true;
|
|
618
|
-
res = key;
|
|
619
|
-
}
|
|
620
|
-
const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
621
|
-
const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
|
|
622
|
-
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
623
|
-
if (usedKey || usedDefault || updateMissing) {
|
|
624
|
-
this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
|
|
625
|
-
if (keySeparator) {
|
|
626
|
-
const fk = this.resolve(key, {
|
|
627
|
-
...options,
|
|
628
|
-
keySeparator: false
|
|
629
|
-
});
|
|
630
|
-
if (fk && fk.res) this.logger.warn('Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.');
|
|
631
|
-
}
|
|
632
|
-
let lngs = [];
|
|
633
|
-
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
|
|
634
|
-
if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
|
|
635
|
-
for (let i = 0; i < fallbackLngs.length; i++) {
|
|
636
|
-
lngs.push(fallbackLngs[i]);
|
|
637
|
-
}
|
|
638
|
-
} else if (this.options.saveMissingTo === 'all') {
|
|
639
|
-
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
|
|
640
|
-
} else {
|
|
641
|
-
lngs.push(options.lng || this.language);
|
|
642
|
-
}
|
|
643
|
-
const send = (l, k, specificDefaultValue) => {
|
|
644
|
-
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
645
|
-
if (this.options.missingKeyHandler) {
|
|
646
|
-
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
647
|
-
} else if (this.backendConnector && this.backendConnector.saveMissing) {
|
|
648
|
-
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
649
|
-
}
|
|
650
|
-
this.emit('missingKey', l, namespace, k, res);
|
|
651
|
-
};
|
|
652
|
-
if (this.options.saveMissing) {
|
|
653
|
-
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
654
|
-
lngs.forEach(language => {
|
|
655
|
-
this.pluralResolver.getSuffixes(language, options).forEach(suffix => {
|
|
656
|
-
send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
|
|
657
|
-
});
|
|
658
|
-
});
|
|
659
|
-
} else {
|
|
660
|
-
send(lngs, key, defaultValue);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
res = this.extendTranslation(res, keys, options, resolved, lastKey);
|
|
665
|
-
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
|
|
666
|
-
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
667
|
-
if (this.options.compatibilityAPI !== 'v1') {
|
|
668
|
-
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : undefined);
|
|
669
|
-
} else {
|
|
670
|
-
res = this.options.parseMissingKeyHandler(res);
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
if (returnDetails) {
|
|
675
|
-
resolved.res = res;
|
|
676
|
-
return resolved;
|
|
677
|
-
}
|
|
678
|
-
return res;
|
|
679
|
-
}
|
|
680
|
-
extendTranslation(res, key, options, resolved, lastKey) {
|
|
681
|
-
var _this = this;
|
|
682
|
-
if (this.i18nFormat && this.i18nFormat.parse) {
|
|
683
|
-
res = this.i18nFormat.parse(res, {
|
|
684
|
-
...this.options.interpolation.defaultVariables,
|
|
685
|
-
...options
|
|
686
|
-
}, resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
687
|
-
resolved
|
|
688
|
-
});
|
|
689
|
-
} else if (!options.skipInterpolation) {
|
|
690
|
-
if (options.interpolation) this.interpolator.init({
|
|
691
|
-
...options,
|
|
692
|
-
...{
|
|
693
|
-
interpolation: {
|
|
694
|
-
...this.options.interpolation,
|
|
695
|
-
...options.interpolation
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
});
|
|
699
|
-
const skipOnVariables = typeof res === 'string' && (options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
700
|
-
let nestBef;
|
|
701
|
-
if (skipOnVariables) {
|
|
702
|
-
const nb = res.match(this.interpolator.nestingRegexp);
|
|
703
|
-
nestBef = nb && nb.length;
|
|
704
|
-
}
|
|
705
|
-
let data = options.replace && typeof options.replace !== 'string' ? options.replace : options;
|
|
706
|
-
if (this.options.interpolation.defaultVariables) data = {
|
|
707
|
-
...this.options.interpolation.defaultVariables,
|
|
708
|
-
...data
|
|
709
|
-
};
|
|
710
|
-
res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
|
|
711
|
-
if (skipOnVariables) {
|
|
712
|
-
const na = res.match(this.interpolator.nestingRegexp);
|
|
713
|
-
const nestAft = na && na.length;
|
|
714
|
-
if (nestBef < nestAft) options.nest = false;
|
|
715
|
-
}
|
|
716
|
-
if (!options.lng && this.options.compatibilityAPI !== 'v1' && resolved && resolved.res) options.lng = resolved.usedLng;
|
|
717
|
-
if (options.nest !== false) res = this.interpolator.nest(res, function () {
|
|
718
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
719
|
-
args[_key] = arguments[_key];
|
|
720
|
-
}
|
|
721
|
-
if (lastKey && lastKey[0] === args[0] && !options.context) {
|
|
722
|
-
_this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
723
|
-
return null;
|
|
724
|
-
}
|
|
725
|
-
return _this.translate(...args, key);
|
|
726
|
-
}, options);
|
|
727
|
-
if (options.interpolation) this.interpolator.reset();
|
|
728
|
-
}
|
|
729
|
-
const postProcess = options.postProcess || this.options.postProcess;
|
|
730
|
-
const postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess;
|
|
731
|
-
if (res !== undefined && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
|
|
732
|
-
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
733
|
-
i18nResolved: resolved,
|
|
734
|
-
...options
|
|
735
|
-
} : options, this);
|
|
736
|
-
}
|
|
737
|
-
return res;
|
|
738
|
-
}
|
|
739
|
-
resolve(keys) {
|
|
740
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
741
|
-
let found;
|
|
742
|
-
let usedKey;
|
|
743
|
-
let exactUsedKey;
|
|
744
|
-
let usedLng;
|
|
745
|
-
let usedNS;
|
|
746
|
-
if (typeof keys === 'string') keys = [keys];
|
|
747
|
-
keys.forEach(k => {
|
|
748
|
-
if (this.isValidLookup(found)) return;
|
|
749
|
-
const extracted = this.extractFromKey(k, options);
|
|
750
|
-
const key = extracted.key;
|
|
751
|
-
usedKey = key;
|
|
752
|
-
let namespaces = extracted.namespaces;
|
|
753
|
-
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
754
|
-
const needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
|
|
755
|
-
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
|
|
756
|
-
const needsContextHandling = options.context !== undefined && (typeof options.context === 'string' || typeof options.context === 'number') && options.context !== '';
|
|
757
|
-
const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
|
|
758
|
-
namespaces.forEach(ns => {
|
|
759
|
-
if (this.isValidLookup(found)) return;
|
|
760
|
-
usedNS = ns;
|
|
761
|
-
if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils && this.utils.hasLoadedNamespace && !this.utils.hasLoadedNamespace(usedNS)) {
|
|
762
|
-
checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
763
|
-
this.logger.warn(`key "${usedKey}" for languages "${codes.join(', ')}" won't get resolved as namespace "${usedNS}" was not yet loaded`, 'This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!');
|
|
764
|
-
}
|
|
765
|
-
codes.forEach(code => {
|
|
766
|
-
if (this.isValidLookup(found)) return;
|
|
767
|
-
usedLng = code;
|
|
768
|
-
const finalKeys = [key];
|
|
769
|
-
if (this.i18nFormat && this.i18nFormat.addLookupKeys) {
|
|
770
|
-
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
|
|
771
|
-
} else {
|
|
772
|
-
let pluralSuffix;
|
|
773
|
-
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
|
|
774
|
-
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
775
|
-
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
776
|
-
if (needsPluralHandling) {
|
|
777
|
-
finalKeys.push(key + pluralSuffix);
|
|
778
|
-
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
779
|
-
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
780
|
-
}
|
|
781
|
-
if (needsZeroSuffixLookup) {
|
|
782
|
-
finalKeys.push(key + zeroSuffix);
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
if (needsContextHandling) {
|
|
786
|
-
const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
|
|
787
|
-
finalKeys.push(contextKey);
|
|
788
|
-
if (needsPluralHandling) {
|
|
789
|
-
finalKeys.push(contextKey + pluralSuffix);
|
|
790
|
-
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
791
|
-
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
792
|
-
}
|
|
793
|
-
if (needsZeroSuffixLookup) {
|
|
794
|
-
finalKeys.push(contextKey + zeroSuffix);
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
let possibleKey;
|
|
800
|
-
while (possibleKey = finalKeys.pop()) {
|
|
801
|
-
if (!this.isValidLookup(found)) {
|
|
802
|
-
exactUsedKey = possibleKey;
|
|
803
|
-
found = this.getResource(code, ns, possibleKey, options);
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
});
|
|
807
|
-
});
|
|
808
|
-
});
|
|
809
|
-
return {
|
|
810
|
-
res: found,
|
|
811
|
-
usedKey,
|
|
812
|
-
exactUsedKey,
|
|
813
|
-
usedLng,
|
|
814
|
-
usedNS
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
isValidLookup(res) {
|
|
818
|
-
return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
|
|
819
|
-
}
|
|
820
|
-
getResource(code, ns, key) {
|
|
821
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
822
|
-
if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
823
|
-
return this.resourceStore.getResource(code, ns, key, options);
|
|
824
|
-
}
|
|
825
|
-
static hasDefaultValue(options) {
|
|
826
|
-
const prefix = 'defaultValue';
|
|
827
|
-
for (const option in options) {
|
|
828
|
-
if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
|
|
829
|
-
return true;
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
return false;
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
function capitalize(string) {
|
|
837
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
838
|
-
}
|
|
839
|
-
class LanguageUtil {
|
|
840
|
-
constructor(options) {
|
|
841
|
-
this.options = options;
|
|
842
|
-
this.supportedLngs = this.options.supportedLngs || false;
|
|
843
|
-
this.logger = baseLogger.create('languageUtils');
|
|
844
|
-
}
|
|
845
|
-
getScriptPartFromCode(code) {
|
|
846
|
-
code = getCleanedCode(code);
|
|
847
|
-
if (!code || code.indexOf('-') < 0) return null;
|
|
848
|
-
const p = code.split('-');
|
|
849
|
-
if (p.length === 2) return null;
|
|
850
|
-
p.pop();
|
|
851
|
-
if (p[p.length - 1].toLowerCase() === 'x') return null;
|
|
852
|
-
return this.formatLanguageCode(p.join('-'));
|
|
853
|
-
}
|
|
854
|
-
getLanguagePartFromCode(code) {
|
|
855
|
-
code = getCleanedCode(code);
|
|
856
|
-
if (!code || code.indexOf('-') < 0) return code;
|
|
857
|
-
const p = code.split('-');
|
|
858
|
-
return this.formatLanguageCode(p[0]);
|
|
859
|
-
}
|
|
860
|
-
formatLanguageCode(code) {
|
|
861
|
-
if (typeof code === 'string' && code.indexOf('-') > -1) {
|
|
862
|
-
const specialCases = ['hans', 'hant', 'latn', 'cyrl', 'cans', 'mong', 'arab'];
|
|
863
|
-
let p = code.split('-');
|
|
864
|
-
if (this.options.lowerCaseLng) {
|
|
865
|
-
p = p.map(part => part.toLowerCase());
|
|
866
|
-
} else if (p.length === 2) {
|
|
867
|
-
p[0] = p[0].toLowerCase();
|
|
868
|
-
p[1] = p[1].toUpperCase();
|
|
869
|
-
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
|
|
870
|
-
} else if (p.length === 3) {
|
|
871
|
-
p[0] = p[0].toLowerCase();
|
|
872
|
-
if (p[1].length === 2) p[1] = p[1].toUpperCase();
|
|
873
|
-
if (p[0] !== 'sgn' && p[2].length === 2) p[2] = p[2].toUpperCase();
|
|
874
|
-
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
|
|
875
|
-
if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
|
|
876
|
-
}
|
|
877
|
-
return p.join('-');
|
|
878
|
-
}
|
|
879
|
-
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
880
|
-
}
|
|
881
|
-
isSupportedCode(code) {
|
|
882
|
-
if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
|
|
883
|
-
code = this.getLanguagePartFromCode(code);
|
|
884
|
-
}
|
|
885
|
-
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
886
|
-
}
|
|
887
|
-
getBestMatchFromCodes(codes) {
|
|
888
|
-
if (!codes) return null;
|
|
889
|
-
let found;
|
|
890
|
-
codes.forEach(code => {
|
|
891
|
-
if (found) return;
|
|
892
|
-
const cleanedLng = this.formatLanguageCode(code);
|
|
893
|
-
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
894
|
-
});
|
|
895
|
-
if (!found && this.options.supportedLngs) {
|
|
896
|
-
codes.forEach(code => {
|
|
897
|
-
if (found) return;
|
|
898
|
-
const lngOnly = this.getLanguagePartFromCode(code);
|
|
899
|
-
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
900
|
-
found = this.options.supportedLngs.find(supportedLng => {
|
|
901
|
-
if (supportedLng === lngOnly) return supportedLng;
|
|
902
|
-
if (supportedLng.indexOf('-') < 0 && lngOnly.indexOf('-') < 0) return;
|
|
903
|
-
if (supportedLng.indexOf(lngOnly) === 0) return supportedLng;
|
|
904
|
-
});
|
|
905
|
-
});
|
|
906
|
-
}
|
|
907
|
-
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
908
|
-
return found;
|
|
909
|
-
}
|
|
910
|
-
getFallbackCodes(fallbacks, code) {
|
|
911
|
-
if (!fallbacks) return [];
|
|
912
|
-
if (typeof fallbacks === 'function') fallbacks = fallbacks(code);
|
|
913
|
-
if (typeof fallbacks === 'string') fallbacks = [fallbacks];
|
|
914
|
-
if (Object.prototype.toString.apply(fallbacks) === '[object Array]') return fallbacks;
|
|
915
|
-
if (!code) return fallbacks.default || [];
|
|
916
|
-
let found = fallbacks[code];
|
|
917
|
-
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
918
|
-
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
919
|
-
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
920
|
-
if (!found) found = fallbacks.default;
|
|
921
|
-
return found || [];
|
|
922
|
-
}
|
|
923
|
-
toResolveHierarchy(code, fallbackCode) {
|
|
924
|
-
const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
925
|
-
const codes = [];
|
|
926
|
-
const addCode = c => {
|
|
927
|
-
if (!c) return;
|
|
928
|
-
if (this.isSupportedCode(c)) {
|
|
929
|
-
codes.push(c);
|
|
930
|
-
} else {
|
|
931
|
-
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
932
|
-
}
|
|
933
|
-
};
|
|
934
|
-
if (typeof code === 'string' && (code.indexOf('-') > -1 || code.indexOf('_') > -1)) {
|
|
935
|
-
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
|
|
936
|
-
if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
|
|
937
|
-
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
|
|
938
|
-
} else if (typeof code === 'string') {
|
|
939
|
-
addCode(this.formatLanguageCode(code));
|
|
940
|
-
}
|
|
941
|
-
fallbackCodes.forEach(fc => {
|
|
942
|
-
if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
|
|
943
|
-
});
|
|
944
|
-
return codes;
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
let sets = [{
|
|
949
|
-
lngs: ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'gun', 'ln', 'mfe', 'mg', 'mi', 'oc', 'pt', 'pt-BR', 'tg', 'tl', 'ti', 'tr', 'uz', 'wa'],
|
|
950
|
-
nr: [1, 2],
|
|
951
|
-
fc: 1
|
|
952
|
-
}, {
|
|
953
|
-
lngs: ['af', 'an', 'ast', 'az', 'bg', 'bn', 'ca', 'da', 'de', 'dev', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fi', 'fo', 'fur', 'fy', 'gl', 'gu', 'ha', 'hi', 'hu', 'hy', 'ia', 'it', 'kk', 'kn', 'ku', 'lb', 'mai', 'ml', 'mn', 'mr', 'nah', 'nap', 'nb', 'ne', 'nl', 'nn', 'no', 'nso', 'pa', 'pap', 'pms', 'ps', 'pt-PT', 'rm', 'sco', 'se', 'si', 'so', 'son', 'sq', 'sv', 'sw', 'ta', 'te', 'tk', 'ur', 'yo'],
|
|
954
|
-
nr: [1, 2],
|
|
955
|
-
fc: 2
|
|
956
|
-
}, {
|
|
957
|
-
lngs: ['ay', 'bo', 'cgg', 'fa', 'ht', 'id', 'ja', 'jbo', 'ka', 'km', 'ko', 'ky', 'lo', 'ms', 'sah', 'su', 'th', 'tt', 'ug', 'vi', 'wo', 'zh'],
|
|
958
|
-
nr: [1],
|
|
959
|
-
fc: 3
|
|
960
|
-
}, {
|
|
961
|
-
lngs: ['be', 'bs', 'cnr', 'dz', 'hr', 'ru', 'sr', 'uk'],
|
|
962
|
-
nr: [1, 2, 5],
|
|
963
|
-
fc: 4
|
|
964
|
-
}, {
|
|
965
|
-
lngs: ['ar'],
|
|
966
|
-
nr: [0, 1, 2, 3, 11, 100],
|
|
967
|
-
fc: 5
|
|
968
|
-
}, {
|
|
969
|
-
lngs: ['cs', 'sk'],
|
|
970
|
-
nr: [1, 2, 5],
|
|
971
|
-
fc: 6
|
|
972
|
-
}, {
|
|
973
|
-
lngs: ['csb', 'pl'],
|
|
974
|
-
nr: [1, 2, 5],
|
|
975
|
-
fc: 7
|
|
976
|
-
}, {
|
|
977
|
-
lngs: ['cy'],
|
|
978
|
-
nr: [1, 2, 3, 8],
|
|
979
|
-
fc: 8
|
|
980
|
-
}, {
|
|
981
|
-
lngs: ['fr'],
|
|
982
|
-
nr: [1, 2],
|
|
983
|
-
fc: 9
|
|
984
|
-
}, {
|
|
985
|
-
lngs: ['ga'],
|
|
986
|
-
nr: [1, 2, 3, 7, 11],
|
|
987
|
-
fc: 10
|
|
988
|
-
}, {
|
|
989
|
-
lngs: ['gd'],
|
|
990
|
-
nr: [1, 2, 3, 20],
|
|
991
|
-
fc: 11
|
|
992
|
-
}, {
|
|
993
|
-
lngs: ['is'],
|
|
994
|
-
nr: [1, 2],
|
|
995
|
-
fc: 12
|
|
996
|
-
}, {
|
|
997
|
-
lngs: ['jv'],
|
|
998
|
-
nr: [0, 1],
|
|
999
|
-
fc: 13
|
|
1000
|
-
}, {
|
|
1001
|
-
lngs: ['kw'],
|
|
1002
|
-
nr: [1, 2, 3, 4],
|
|
1003
|
-
fc: 14
|
|
1004
|
-
}, {
|
|
1005
|
-
lngs: ['lt'],
|
|
1006
|
-
nr: [1, 2, 10],
|
|
1007
|
-
fc: 15
|
|
1008
|
-
}, {
|
|
1009
|
-
lngs: ['lv'],
|
|
1010
|
-
nr: [1, 2, 0],
|
|
1011
|
-
fc: 16
|
|
1012
|
-
}, {
|
|
1013
|
-
lngs: ['mk'],
|
|
1014
|
-
nr: [1, 2],
|
|
1015
|
-
fc: 17
|
|
1016
|
-
}, {
|
|
1017
|
-
lngs: ['mnk'],
|
|
1018
|
-
nr: [0, 1, 2],
|
|
1019
|
-
fc: 18
|
|
1020
|
-
}, {
|
|
1021
|
-
lngs: ['mt'],
|
|
1022
|
-
nr: [1, 2, 11, 20],
|
|
1023
|
-
fc: 19
|
|
1024
|
-
}, {
|
|
1025
|
-
lngs: ['or'],
|
|
1026
|
-
nr: [2, 1],
|
|
1027
|
-
fc: 2
|
|
1028
|
-
}, {
|
|
1029
|
-
lngs: ['ro'],
|
|
1030
|
-
nr: [1, 2, 20],
|
|
1031
|
-
fc: 20
|
|
1032
|
-
}, {
|
|
1033
|
-
lngs: ['sl'],
|
|
1034
|
-
nr: [5, 1, 2, 3],
|
|
1035
|
-
fc: 21
|
|
1036
|
-
}, {
|
|
1037
|
-
lngs: ['he', 'iw'],
|
|
1038
|
-
nr: [1, 2, 20, 21],
|
|
1039
|
-
fc: 22
|
|
1040
|
-
}];
|
|
1041
|
-
let _rulesPluralsTypes = {
|
|
1042
|
-
1: function (n) {
|
|
1043
|
-
return Number(n > 1);
|
|
1044
|
-
},
|
|
1045
|
-
2: function (n) {
|
|
1046
|
-
return Number(n != 1);
|
|
1047
|
-
},
|
|
1048
|
-
3: function (n) {
|
|
1049
|
-
return 0;
|
|
1050
|
-
},
|
|
1051
|
-
4: function (n) {
|
|
1052
|
-
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1053
|
-
},
|
|
1054
|
-
5: function (n) {
|
|
1055
|
-
return Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5);
|
|
1056
|
-
},
|
|
1057
|
-
6: function (n) {
|
|
1058
|
-
return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2);
|
|
1059
|
-
},
|
|
1060
|
-
7: function (n) {
|
|
1061
|
-
return Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1062
|
-
},
|
|
1063
|
-
8: function (n) {
|
|
1064
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3);
|
|
1065
|
-
},
|
|
1066
|
-
9: function (n) {
|
|
1067
|
-
return Number(n >= 2);
|
|
1068
|
-
},
|
|
1069
|
-
10: function (n) {
|
|
1070
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4);
|
|
1071
|
-
},
|
|
1072
|
-
11: function (n) {
|
|
1073
|
-
return Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3);
|
|
1074
|
-
},
|
|
1075
|
-
12: function (n) {
|
|
1076
|
-
return Number(n % 10 != 1 || n % 100 == 11);
|
|
1077
|
-
},
|
|
1078
|
-
13: function (n) {
|
|
1079
|
-
return Number(n !== 0);
|
|
1080
|
-
},
|
|
1081
|
-
14: function (n) {
|
|
1082
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3);
|
|
1083
|
-
},
|
|
1084
|
-
15: function (n) {
|
|
1085
|
-
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1086
|
-
},
|
|
1087
|
-
16: function (n) {
|
|
1088
|
-
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2);
|
|
1089
|
-
},
|
|
1090
|
-
17: function (n) {
|
|
1091
|
-
return Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1);
|
|
1092
|
-
},
|
|
1093
|
-
18: function (n) {
|
|
1094
|
-
return Number(n == 0 ? 0 : n == 1 ? 1 : 2);
|
|
1095
|
-
},
|
|
1096
|
-
19: function (n) {
|
|
1097
|
-
return Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3);
|
|
1098
|
-
},
|
|
1099
|
-
20: function (n) {
|
|
1100
|
-
return Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2);
|
|
1101
|
-
},
|
|
1102
|
-
21: function (n) {
|
|
1103
|
-
return Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0);
|
|
1104
|
-
},
|
|
1105
|
-
22: function (n) {
|
|
1106
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3);
|
|
1107
|
-
}
|
|
1108
|
-
};
|
|
1109
|
-
const nonIntlVersions = ['v1', 'v2', 'v3'];
|
|
1110
|
-
const intlVersions = ['v4'];
|
|
1111
|
-
const suffixesOrder = {
|
|
1112
|
-
zero: 0,
|
|
1113
|
-
one: 1,
|
|
1114
|
-
two: 2,
|
|
1115
|
-
few: 3,
|
|
1116
|
-
many: 4,
|
|
1117
|
-
other: 5
|
|
1118
|
-
};
|
|
1119
|
-
function createRules() {
|
|
1120
|
-
const rules = {};
|
|
1121
|
-
sets.forEach(set => {
|
|
1122
|
-
set.lngs.forEach(l => {
|
|
1123
|
-
rules[l] = {
|
|
1124
|
-
numbers: set.nr,
|
|
1125
|
-
plurals: _rulesPluralsTypes[set.fc]
|
|
1126
|
-
};
|
|
1127
|
-
});
|
|
1128
|
-
});
|
|
1129
|
-
return rules;
|
|
1130
|
-
}
|
|
1131
|
-
class PluralResolver {
|
|
1132
|
-
constructor(languageUtils) {
|
|
1133
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1134
|
-
this.languageUtils = languageUtils;
|
|
1135
|
-
this.options = options;
|
|
1136
|
-
this.logger = baseLogger.create('pluralResolver');
|
|
1137
|
-
if ((!this.options.compatibilityJSON || intlVersions.includes(this.options.compatibilityJSON)) && (typeof Intl === 'undefined' || !Intl.PluralRules)) {
|
|
1138
|
-
this.options.compatibilityJSON = 'v3';
|
|
1139
|
-
this.logger.error('Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.');
|
|
1140
|
-
}
|
|
1141
|
-
this.rules = createRules();
|
|
1142
|
-
}
|
|
1143
|
-
addRule(lng, obj) {
|
|
1144
|
-
this.rules[lng] = obj;
|
|
1145
|
-
}
|
|
1146
|
-
getRule(code) {
|
|
1147
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1148
|
-
if (this.shouldUseIntlApi()) {
|
|
1149
|
-
try {
|
|
1150
|
-
return new Intl.PluralRules(getCleanedCode(code), {
|
|
1151
|
-
type: options.ordinal ? 'ordinal' : 'cardinal'
|
|
1152
|
-
});
|
|
1153
|
-
} catch {
|
|
1154
|
-
return;
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
|
|
1158
|
-
}
|
|
1159
|
-
needsPlural(code) {
|
|
1160
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1161
|
-
const rule = this.getRule(code, options);
|
|
1162
|
-
if (this.shouldUseIntlApi()) {
|
|
1163
|
-
return rule && rule.resolvedOptions().pluralCategories.length > 1;
|
|
1164
|
-
}
|
|
1165
|
-
return rule && rule.numbers.length > 1;
|
|
1166
|
-
}
|
|
1167
|
-
getPluralFormsOfKey(code, key) {
|
|
1168
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1169
|
-
return this.getSuffixes(code, options).map(suffix => `${key}${suffix}`);
|
|
1170
|
-
}
|
|
1171
|
-
getSuffixes(code) {
|
|
1172
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1173
|
-
const rule = this.getRule(code, options);
|
|
1174
|
-
if (!rule) {
|
|
1175
|
-
return [];
|
|
1176
|
-
}
|
|
1177
|
-
if (this.shouldUseIntlApi()) {
|
|
1178
|
-
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map(pluralCategory => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${pluralCategory}`);
|
|
1179
|
-
}
|
|
1180
|
-
return rule.numbers.map(number => this.getSuffix(code, number, options));
|
|
1181
|
-
}
|
|
1182
|
-
getSuffix(code, count) {
|
|
1183
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1184
|
-
const rule = this.getRule(code, options);
|
|
1185
|
-
if (rule) {
|
|
1186
|
-
if (this.shouldUseIntlApi()) {
|
|
1187
|
-
return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${rule.select(count)}`;
|
|
1188
|
-
}
|
|
1189
|
-
return this.getSuffixRetroCompatible(rule, count);
|
|
1190
|
-
}
|
|
1191
|
-
this.logger.warn(`no plural rule found for: ${code}`);
|
|
1192
|
-
return '';
|
|
1193
|
-
}
|
|
1194
|
-
getSuffixRetroCompatible(rule, count) {
|
|
1195
|
-
const idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
|
|
1196
|
-
let suffix = rule.numbers[idx];
|
|
1197
|
-
if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1198
|
-
if (suffix === 2) {
|
|
1199
|
-
suffix = 'plural';
|
|
1200
|
-
} else if (suffix === 1) {
|
|
1201
|
-
suffix = '';
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
const returnSuffix = () => this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString();
|
|
1205
|
-
if (this.options.compatibilityJSON === 'v1') {
|
|
1206
|
-
if (suffix === 1) return '';
|
|
1207
|
-
if (typeof suffix === 'number') return `_plural_${suffix.toString()}`;
|
|
1208
|
-
return returnSuffix();
|
|
1209
|
-
} else if (this.options.compatibilityJSON === 'v2') {
|
|
1210
|
-
return returnSuffix();
|
|
1211
|
-
} else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1212
|
-
return returnSuffix();
|
|
1213
|
-
}
|
|
1214
|
-
return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
|
|
1215
|
-
}
|
|
1216
|
-
shouldUseIntlApi() {
|
|
1217
|
-
return !nonIntlVersions.includes(this.options.compatibilityJSON);
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
function deepFindWithDefaults(data, defaultData, key) {
|
|
1222
|
-
let keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
|
|
1223
|
-
let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
1224
|
-
let path = getPathWithDefaults(data, defaultData, key);
|
|
1225
|
-
if (!path && ignoreJSONStructure && typeof key === 'string') {
|
|
1226
|
-
path = deepFind(data, key, keySeparator);
|
|
1227
|
-
if (path === undefined) path = deepFind(defaultData, key, keySeparator);
|
|
1228
|
-
}
|
|
1229
|
-
return path;
|
|
1230
|
-
}
|
|
1231
|
-
class Interpolator {
|
|
1232
|
-
constructor() {
|
|
1233
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1234
|
-
this.logger = baseLogger.create('interpolator');
|
|
1235
|
-
this.options = options;
|
|
1236
|
-
this.format = options.interpolation && options.interpolation.format || (value => value);
|
|
1237
|
-
this.init(options);
|
|
1238
|
-
}
|
|
1239
|
-
init() {
|
|
1240
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1241
|
-
if (!options.interpolation) options.interpolation = {
|
|
1242
|
-
escapeValue: true
|
|
1243
|
-
};
|
|
1244
|
-
const iOpts = options.interpolation;
|
|
1245
|
-
this.escape = iOpts.escape !== undefined ? iOpts.escape : escape;
|
|
1246
|
-
this.escapeValue = iOpts.escapeValue !== undefined ? iOpts.escapeValue : true;
|
|
1247
|
-
this.useRawValueToEscape = iOpts.useRawValueToEscape !== undefined ? iOpts.useRawValueToEscape : false;
|
|
1248
|
-
this.prefix = iOpts.prefix ? regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{';
|
|
1249
|
-
this.suffix = iOpts.suffix ? regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}';
|
|
1250
|
-
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
|
|
1251
|
-
this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-';
|
|
1252
|
-
this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || '';
|
|
1253
|
-
this.nestingPrefix = iOpts.nestingPrefix ? regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || regexEscape('$t(');
|
|
1254
|
-
this.nestingSuffix = iOpts.nestingSuffix ? regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || regexEscape(')');
|
|
1255
|
-
this.nestingOptionsSeparator = iOpts.nestingOptionsSeparator ? iOpts.nestingOptionsSeparator : iOpts.nestingOptionsSeparator || ',';
|
|
1256
|
-
this.maxReplaces = iOpts.maxReplaces ? iOpts.maxReplaces : 1000;
|
|
1257
|
-
this.alwaysFormat = iOpts.alwaysFormat !== undefined ? iOpts.alwaysFormat : false;
|
|
1258
|
-
this.resetRegExp();
|
|
1259
|
-
}
|
|
1260
|
-
reset() {
|
|
1261
|
-
if (this.options) this.init(this.options);
|
|
1262
|
-
}
|
|
1263
|
-
resetRegExp() {
|
|
1264
|
-
const regexpStr = `${this.prefix}(.+?)${this.suffix}`;
|
|
1265
|
-
this.regexp = new RegExp(regexpStr, 'g');
|
|
1266
|
-
const regexpUnescapeStr = `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`;
|
|
1267
|
-
this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g');
|
|
1268
|
-
const nestingRegexpStr = `${this.nestingPrefix}(.+?)${this.nestingSuffix}`;
|
|
1269
|
-
this.nestingRegexp = new RegExp(nestingRegexpStr, 'g');
|
|
1270
|
-
}
|
|
1271
|
-
interpolate(str, data, lng, options) {
|
|
1272
|
-
let match;
|
|
1273
|
-
let value;
|
|
1274
|
-
let replaces;
|
|
1275
|
-
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
1276
|
-
function regexSafe(val) {
|
|
1277
|
-
return val.replace(/\$/g, '$$$$');
|
|
1278
|
-
}
|
|
1279
|
-
const handleFormat = key => {
|
|
1280
|
-
if (key.indexOf(this.formatSeparator) < 0) {
|
|
1281
|
-
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
1282
|
-
return this.alwaysFormat ? this.format(path, undefined, lng, {
|
|
1283
|
-
...options,
|
|
1284
|
-
...data,
|
|
1285
|
-
interpolationkey: key
|
|
1286
|
-
}) : path;
|
|
1287
|
-
}
|
|
1288
|
-
const p = key.split(this.formatSeparator);
|
|
1289
|
-
const k = p.shift().trim();
|
|
1290
|
-
const f = p.join(this.formatSeparator).trim();
|
|
1291
|
-
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
|
|
1292
|
-
...options,
|
|
1293
|
-
...data,
|
|
1294
|
-
interpolationkey: k
|
|
1295
|
-
});
|
|
1296
|
-
};
|
|
1297
|
-
this.resetRegExp();
|
|
1298
|
-
const missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
1299
|
-
const skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
1300
|
-
const todos = [{
|
|
1301
|
-
regex: this.regexpUnescape,
|
|
1302
|
-
safeValue: val => regexSafe(val)
|
|
1303
|
-
}, {
|
|
1304
|
-
regex: this.regexp,
|
|
1305
|
-
safeValue: val => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
|
|
1306
|
-
}];
|
|
1307
|
-
todos.forEach(todo => {
|
|
1308
|
-
replaces = 0;
|
|
1309
|
-
while (match = todo.regex.exec(str)) {
|
|
1310
|
-
const matchedVar = match[1].trim();
|
|
1311
|
-
value = handleFormat(matchedVar);
|
|
1312
|
-
if (value === undefined) {
|
|
1313
|
-
if (typeof missingInterpolationHandler === 'function') {
|
|
1314
|
-
const temp = missingInterpolationHandler(str, match, options);
|
|
1315
|
-
value = typeof temp === 'string' ? temp : '';
|
|
1316
|
-
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
|
|
1317
|
-
value = '';
|
|
1318
|
-
} else if (skipOnVariables) {
|
|
1319
|
-
value = match[0];
|
|
1320
|
-
continue;
|
|
1321
|
-
} else {
|
|
1322
|
-
this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
|
|
1323
|
-
value = '';
|
|
1324
|
-
}
|
|
1325
|
-
} else if (typeof value !== 'string' && !this.useRawValueToEscape) {
|
|
1326
|
-
value = makeString(value);
|
|
1327
|
-
}
|
|
1328
|
-
const safeValue = todo.safeValue(value);
|
|
1329
|
-
str = str.replace(match[0], safeValue);
|
|
1330
|
-
if (skipOnVariables) {
|
|
1331
|
-
todo.regex.lastIndex += value.length;
|
|
1332
|
-
todo.regex.lastIndex -= match[0].length;
|
|
1333
|
-
} else {
|
|
1334
|
-
todo.regex.lastIndex = 0;
|
|
1335
|
-
}
|
|
1336
|
-
replaces++;
|
|
1337
|
-
if (replaces >= this.maxReplaces) {
|
|
1338
|
-
break;
|
|
1339
|
-
}
|
|
1340
|
-
}
|
|
1341
|
-
});
|
|
1342
|
-
return str;
|
|
1343
|
-
}
|
|
1344
|
-
nest(str, fc) {
|
|
1345
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1346
|
-
let match;
|
|
1347
|
-
let value;
|
|
1348
|
-
let clonedOptions;
|
|
1349
|
-
function handleHasOptions(key, inheritedOptions) {
|
|
1350
|
-
const sep = this.nestingOptionsSeparator;
|
|
1351
|
-
if (key.indexOf(sep) < 0) return key;
|
|
1352
|
-
const c = key.split(new RegExp(`${sep}[ ]*{`));
|
|
1353
|
-
let optionsString = `{${c[1]}`;
|
|
1354
|
-
key = c[0];
|
|
1355
|
-
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
1356
|
-
const matchedSingleQuotes = optionsString.match(/'/g);
|
|
1357
|
-
const matchedDoubleQuotes = optionsString.match(/"/g);
|
|
1358
|
-
if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
|
|
1359
|
-
optionsString = optionsString.replace(/'/g, '"');
|
|
1360
|
-
}
|
|
1361
|
-
try {
|
|
1362
|
-
clonedOptions = JSON.parse(optionsString);
|
|
1363
|
-
if (inheritedOptions) clonedOptions = {
|
|
1364
|
-
...inheritedOptions,
|
|
1365
|
-
...clonedOptions
|
|
1366
|
-
};
|
|
1367
|
-
} catch (e) {
|
|
1368
|
-
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
1369
|
-
return `${key}${sep}${optionsString}`;
|
|
1370
|
-
}
|
|
1371
|
-
delete clonedOptions.defaultValue;
|
|
1372
|
-
return key;
|
|
1373
|
-
}
|
|
1374
|
-
while (match = this.nestingRegexp.exec(str)) {
|
|
1375
|
-
let formatters = [];
|
|
1376
|
-
clonedOptions = {
|
|
1377
|
-
...options
|
|
1378
|
-
};
|
|
1379
|
-
clonedOptions = clonedOptions.replace && typeof clonedOptions.replace !== 'string' ? clonedOptions.replace : clonedOptions;
|
|
1380
|
-
clonedOptions.applyPostProcessor = false;
|
|
1381
|
-
delete clonedOptions.defaultValue;
|
|
1382
|
-
let doReduce = false;
|
|
1383
|
-
if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
|
|
1384
|
-
const r = match[1].split(this.formatSeparator).map(elem => elem.trim());
|
|
1385
|
-
match[1] = r.shift();
|
|
1386
|
-
formatters = r;
|
|
1387
|
-
doReduce = true;
|
|
1388
|
-
}
|
|
1389
|
-
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
1390
|
-
if (value && match[0] === str && typeof value !== 'string') return value;
|
|
1391
|
-
if (typeof value !== 'string') value = makeString(value);
|
|
1392
|
-
if (!value) {
|
|
1393
|
-
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
1394
|
-
value = '';
|
|
1395
|
-
}
|
|
1396
|
-
if (doReduce) {
|
|
1397
|
-
value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
1398
|
-
...options,
|
|
1399
|
-
interpolationkey: match[1].trim()
|
|
1400
|
-
}), value.trim());
|
|
1401
|
-
}
|
|
1402
|
-
str = str.replace(match[0], value);
|
|
1403
|
-
this.regexp.lastIndex = 0;
|
|
1404
|
-
}
|
|
1405
|
-
return str;
|
|
1406
|
-
}
|
|
1407
|
-
}
|
|
1408
|
-
|
|
1409
|
-
function parseFormatStr(formatStr) {
|
|
1410
|
-
let formatName = formatStr.toLowerCase().trim();
|
|
1411
|
-
const formatOptions = {};
|
|
1412
|
-
if (formatStr.indexOf('(') > -1) {
|
|
1413
|
-
const p = formatStr.split('(');
|
|
1414
|
-
formatName = p[0].toLowerCase().trim();
|
|
1415
|
-
const optStr = p[1].substring(0, p[1].length - 1);
|
|
1416
|
-
if (formatName === 'currency' && optStr.indexOf(':') < 0) {
|
|
1417
|
-
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
1418
|
-
} else if (formatName === 'relativetime' && optStr.indexOf(':') < 0) {
|
|
1419
|
-
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
1420
|
-
} else {
|
|
1421
|
-
const opts = optStr.split(';');
|
|
1422
|
-
opts.forEach(opt => {
|
|
1423
|
-
if (!opt) return;
|
|
1424
|
-
const [key, ...rest] = opt.split(':');
|
|
1425
|
-
const val = rest.join(':').trim().replace(/^'+|'+$/g, '');
|
|
1426
|
-
if (!formatOptions[key.trim()]) formatOptions[key.trim()] = val;
|
|
1427
|
-
if (val === 'false') formatOptions[key.trim()] = false;
|
|
1428
|
-
if (val === 'true') formatOptions[key.trim()] = true;
|
|
1429
|
-
if (!isNaN(val)) formatOptions[key.trim()] = parseInt(val, 10);
|
|
1430
|
-
});
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
return {
|
|
1434
|
-
formatName,
|
|
1435
|
-
formatOptions
|
|
1436
|
-
};
|
|
1437
|
-
}
|
|
1438
|
-
function createCachedFormatter(fn) {
|
|
1439
|
-
const cache = {};
|
|
1440
|
-
return function invokeFormatter(val, lng, options) {
|
|
1441
|
-
const key = lng + JSON.stringify(options);
|
|
1442
|
-
let formatter = cache[key];
|
|
1443
|
-
if (!formatter) {
|
|
1444
|
-
formatter = fn(getCleanedCode(lng), options);
|
|
1445
|
-
cache[key] = formatter;
|
|
1446
|
-
}
|
|
1447
|
-
return formatter(val);
|
|
1448
|
-
};
|
|
1449
|
-
}
|
|
1450
|
-
class Formatter {
|
|
1451
|
-
constructor() {
|
|
1452
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1453
|
-
this.logger = baseLogger.create('formatter');
|
|
1454
|
-
this.options = options;
|
|
1455
|
-
this.formats = {
|
|
1456
|
-
number: createCachedFormatter((lng, opt) => {
|
|
1457
|
-
const formatter = new Intl.NumberFormat(lng, {
|
|
1458
|
-
...opt
|
|
1459
|
-
});
|
|
1460
|
-
return val => formatter.format(val);
|
|
1461
|
-
}),
|
|
1462
|
-
currency: createCachedFormatter((lng, opt) => {
|
|
1463
|
-
const formatter = new Intl.NumberFormat(lng, {
|
|
1464
|
-
...opt,
|
|
1465
|
-
style: 'currency'
|
|
1466
|
-
});
|
|
1467
|
-
return val => formatter.format(val);
|
|
1468
|
-
}),
|
|
1469
|
-
datetime: createCachedFormatter((lng, opt) => {
|
|
1470
|
-
const formatter = new Intl.DateTimeFormat(lng, {
|
|
1471
|
-
...opt
|
|
1472
|
-
});
|
|
1473
|
-
return val => formatter.format(val);
|
|
1474
|
-
}),
|
|
1475
|
-
relativetime: createCachedFormatter((lng, opt) => {
|
|
1476
|
-
const formatter = new Intl.RelativeTimeFormat(lng, {
|
|
1477
|
-
...opt
|
|
1478
|
-
});
|
|
1479
|
-
return val => formatter.format(val, opt.range || 'day');
|
|
1480
|
-
}),
|
|
1481
|
-
list: createCachedFormatter((lng, opt) => {
|
|
1482
|
-
const formatter = new Intl.ListFormat(lng, {
|
|
1483
|
-
...opt
|
|
1484
|
-
});
|
|
1485
|
-
return val => formatter.format(val);
|
|
1486
|
-
})
|
|
1487
|
-
};
|
|
1488
|
-
this.init(options);
|
|
1489
|
-
}
|
|
1490
|
-
init(services) {
|
|
1491
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
1492
|
-
interpolation: {}
|
|
1493
|
-
};
|
|
1494
|
-
const iOpts = options.interpolation;
|
|
1495
|
-
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
|
|
1496
|
-
}
|
|
1497
|
-
add(name, fc) {
|
|
1498
|
-
this.formats[name.toLowerCase().trim()] = fc;
|
|
1499
|
-
}
|
|
1500
|
-
addCached(name, fc) {
|
|
1501
|
-
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
1502
|
-
}
|
|
1503
|
-
format(value, format, lng) {
|
|
1504
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1505
|
-
const formats = format.split(this.formatSeparator);
|
|
1506
|
-
const result = formats.reduce((mem, f) => {
|
|
1507
|
-
const {
|
|
1508
|
-
formatName,
|
|
1509
|
-
formatOptions
|
|
1510
|
-
} = parseFormatStr(f);
|
|
1511
|
-
if (this.formats[formatName]) {
|
|
1512
|
-
let formatted = mem;
|
|
1513
|
-
try {
|
|
1514
|
-
const valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
|
|
1515
|
-
const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
1516
|
-
formatted = this.formats[formatName](mem, l, {
|
|
1517
|
-
...formatOptions,
|
|
1518
|
-
...options,
|
|
1519
|
-
...valOptions
|
|
1520
|
-
});
|
|
1521
|
-
} catch (error) {
|
|
1522
|
-
this.logger.warn(error);
|
|
1523
|
-
}
|
|
1524
|
-
return formatted;
|
|
1525
|
-
} else {
|
|
1526
|
-
this.logger.warn(`there was no format function for ${formatName}`);
|
|
1527
|
-
}
|
|
1528
|
-
return mem;
|
|
1529
|
-
}, value);
|
|
1530
|
-
return result;
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
|
|
1534
|
-
function removePending(q, name) {
|
|
1535
|
-
if (q.pending[name] !== undefined) {
|
|
1536
|
-
delete q.pending[name];
|
|
1537
|
-
q.pendingCount--;
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
class Connector extends EventEmitter {
|
|
1541
|
-
constructor(backend, store, services) {
|
|
1542
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1543
|
-
super();
|
|
1544
|
-
this.backend = backend;
|
|
1545
|
-
this.store = store;
|
|
1546
|
-
this.services = services;
|
|
1547
|
-
this.languageUtils = services.languageUtils;
|
|
1548
|
-
this.options = options;
|
|
1549
|
-
this.logger = baseLogger.create('backendConnector');
|
|
1550
|
-
this.waitingReads = [];
|
|
1551
|
-
this.maxParallelReads = options.maxParallelReads || 10;
|
|
1552
|
-
this.readingCalls = 0;
|
|
1553
|
-
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
1554
|
-
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
1555
|
-
this.state = {};
|
|
1556
|
-
this.queue = [];
|
|
1557
|
-
if (this.backend && this.backend.init) {
|
|
1558
|
-
this.backend.init(services, options.backend, options);
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
queueLoad(languages, namespaces, options, callback) {
|
|
1562
|
-
const toLoad = {};
|
|
1563
|
-
const pending = {};
|
|
1564
|
-
const toLoadLanguages = {};
|
|
1565
|
-
const toLoadNamespaces = {};
|
|
1566
|
-
languages.forEach(lng => {
|
|
1567
|
-
let hasAllNamespaces = true;
|
|
1568
|
-
namespaces.forEach(ns => {
|
|
1569
|
-
const name = `${lng}|${ns}`;
|
|
1570
|
-
if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
|
|
1571
|
-
this.state[name] = 2;
|
|
1572
|
-
} else if (this.state[name] < 0) ; else if (this.state[name] === 1) {
|
|
1573
|
-
if (pending[name] === undefined) pending[name] = true;
|
|
1574
|
-
} else {
|
|
1575
|
-
this.state[name] = 1;
|
|
1576
|
-
hasAllNamespaces = false;
|
|
1577
|
-
if (pending[name] === undefined) pending[name] = true;
|
|
1578
|
-
if (toLoad[name] === undefined) toLoad[name] = true;
|
|
1579
|
-
if (toLoadNamespaces[ns] === undefined) toLoadNamespaces[ns] = true;
|
|
1580
|
-
}
|
|
1581
|
-
});
|
|
1582
|
-
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
1583
|
-
});
|
|
1584
|
-
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
1585
|
-
this.queue.push({
|
|
1586
|
-
pending,
|
|
1587
|
-
pendingCount: Object.keys(pending).length,
|
|
1588
|
-
loaded: {},
|
|
1589
|
-
errors: [],
|
|
1590
|
-
callback
|
|
1591
|
-
});
|
|
1592
|
-
}
|
|
1593
|
-
return {
|
|
1594
|
-
toLoad: Object.keys(toLoad),
|
|
1595
|
-
pending: Object.keys(pending),
|
|
1596
|
-
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
1597
|
-
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
1598
|
-
};
|
|
1599
|
-
}
|
|
1600
|
-
loaded(name, err, data) {
|
|
1601
|
-
const s = name.split('|');
|
|
1602
|
-
const lng = s[0];
|
|
1603
|
-
const ns = s[1];
|
|
1604
|
-
if (err) this.emit('failedLoading', lng, ns, err);
|
|
1605
|
-
if (data) {
|
|
1606
|
-
this.store.addResourceBundle(lng, ns, data);
|
|
1607
|
-
}
|
|
1608
|
-
this.state[name] = err ? -1 : 2;
|
|
1609
|
-
const loaded = {};
|
|
1610
|
-
this.queue.forEach(q => {
|
|
1611
|
-
pushPath(q.loaded, [lng], ns);
|
|
1612
|
-
removePending(q, name);
|
|
1613
|
-
if (err) q.errors.push(err);
|
|
1614
|
-
if (q.pendingCount === 0 && !q.done) {
|
|
1615
|
-
Object.keys(q.loaded).forEach(l => {
|
|
1616
|
-
if (!loaded[l]) loaded[l] = {};
|
|
1617
|
-
const loadedKeys = q.loaded[l];
|
|
1618
|
-
if (loadedKeys.length) {
|
|
1619
|
-
loadedKeys.forEach(n => {
|
|
1620
|
-
if (loaded[l][n] === undefined) loaded[l][n] = true;
|
|
1621
|
-
});
|
|
1622
|
-
}
|
|
1623
|
-
});
|
|
1624
|
-
q.done = true;
|
|
1625
|
-
if (q.errors.length) {
|
|
1626
|
-
q.callback(q.errors);
|
|
1627
|
-
} else {
|
|
1628
|
-
q.callback();
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
});
|
|
1632
|
-
this.emit('loaded', loaded);
|
|
1633
|
-
this.queue = this.queue.filter(q => !q.done);
|
|
1634
|
-
}
|
|
1635
|
-
read(lng, ns, fcName) {
|
|
1636
|
-
let tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
1637
|
-
let wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
|
|
1638
|
-
let callback = arguments.length > 5 ? arguments[5] : undefined;
|
|
1639
|
-
if (!lng.length) return callback(null, {});
|
|
1640
|
-
if (this.readingCalls >= this.maxParallelReads) {
|
|
1641
|
-
this.waitingReads.push({
|
|
1642
|
-
lng,
|
|
1643
|
-
ns,
|
|
1644
|
-
fcName,
|
|
1645
|
-
tried,
|
|
1646
|
-
wait,
|
|
1647
|
-
callback
|
|
1648
|
-
});
|
|
1649
|
-
return;
|
|
1650
|
-
}
|
|
1651
|
-
this.readingCalls++;
|
|
1652
|
-
const resolver = (err, data) => {
|
|
1653
|
-
this.readingCalls--;
|
|
1654
|
-
if (this.waitingReads.length > 0) {
|
|
1655
|
-
const next = this.waitingReads.shift();
|
|
1656
|
-
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
1657
|
-
}
|
|
1658
|
-
if (err && data && tried < this.maxRetries) {
|
|
1659
|
-
setTimeout(() => {
|
|
1660
|
-
this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
1661
|
-
}, wait);
|
|
1662
|
-
return;
|
|
1663
|
-
}
|
|
1664
|
-
callback(err, data);
|
|
1665
|
-
};
|
|
1666
|
-
const fc = this.backend[fcName].bind(this.backend);
|
|
1667
|
-
if (fc.length === 2) {
|
|
1668
|
-
try {
|
|
1669
|
-
const r = fc(lng, ns);
|
|
1670
|
-
if (r && typeof r.then === 'function') {
|
|
1671
|
-
r.then(data => resolver(null, data)).catch(resolver);
|
|
1672
|
-
} else {
|
|
1673
|
-
resolver(null, r);
|
|
1674
|
-
}
|
|
1675
|
-
} catch (err) {
|
|
1676
|
-
resolver(err);
|
|
1677
|
-
}
|
|
1678
|
-
return;
|
|
1679
|
-
}
|
|
1680
|
-
return fc(lng, ns, resolver);
|
|
1681
|
-
}
|
|
1682
|
-
prepareLoading(languages, namespaces) {
|
|
1683
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1684
|
-
let callback = arguments.length > 3 ? arguments[3] : undefined;
|
|
1685
|
-
if (!this.backend) {
|
|
1686
|
-
this.logger.warn('No backend was added via i18next.use. Will not load resources.');
|
|
1687
|
-
return callback && callback();
|
|
1688
|
-
}
|
|
1689
|
-
if (typeof languages === 'string') languages = this.languageUtils.toResolveHierarchy(languages);
|
|
1690
|
-
if (typeof namespaces === 'string') namespaces = [namespaces];
|
|
1691
|
-
const toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
1692
|
-
if (!toLoad.toLoad.length) {
|
|
1693
|
-
if (!toLoad.pending.length) callback();
|
|
1694
|
-
return null;
|
|
1695
|
-
}
|
|
1696
|
-
toLoad.toLoad.forEach(name => {
|
|
1697
|
-
this.loadOne(name);
|
|
1698
|
-
});
|
|
1699
|
-
}
|
|
1700
|
-
load(languages, namespaces, callback) {
|
|
1701
|
-
this.prepareLoading(languages, namespaces, {}, callback);
|
|
1702
|
-
}
|
|
1703
|
-
reload(languages, namespaces, callback) {
|
|
1704
|
-
this.prepareLoading(languages, namespaces, {
|
|
1705
|
-
reload: true
|
|
1706
|
-
}, callback);
|
|
1707
|
-
}
|
|
1708
|
-
loadOne(name) {
|
|
1709
|
-
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
1710
|
-
const s = name.split('|');
|
|
1711
|
-
const lng = s[0];
|
|
1712
|
-
const ns = s[1];
|
|
1713
|
-
this.read(lng, ns, 'read', undefined, undefined, (err, data) => {
|
|
1714
|
-
if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
1715
|
-
if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
1716
|
-
this.loaded(name, err, data);
|
|
1717
|
-
});
|
|
1718
|
-
}
|
|
1719
|
-
saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
1720
|
-
let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
1721
|
-
let clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : () => {};
|
|
1722
|
-
if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
|
|
1723
|
-
this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, 'This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!');
|
|
1724
|
-
return;
|
|
1725
|
-
}
|
|
1726
|
-
if (key === undefined || key === null || key === '') return;
|
|
1727
|
-
if (this.backend && this.backend.create) {
|
|
1728
|
-
const opts = {
|
|
1729
|
-
...options,
|
|
1730
|
-
isUpdate
|
|
1731
|
-
};
|
|
1732
|
-
const fc = this.backend.create.bind(this.backend);
|
|
1733
|
-
if (fc.length < 6) {
|
|
1734
|
-
try {
|
|
1735
|
-
let r;
|
|
1736
|
-
if (fc.length === 5) {
|
|
1737
|
-
r = fc(languages, namespace, key, fallbackValue, opts);
|
|
1738
|
-
} else {
|
|
1739
|
-
r = fc(languages, namespace, key, fallbackValue);
|
|
1740
|
-
}
|
|
1741
|
-
if (r && typeof r.then === 'function') {
|
|
1742
|
-
r.then(data => clb(null, data)).catch(clb);
|
|
1743
|
-
} else {
|
|
1744
|
-
clb(null, r);
|
|
1745
|
-
}
|
|
1746
|
-
} catch (err) {
|
|
1747
|
-
clb(err);
|
|
1748
|
-
}
|
|
1749
|
-
} else {
|
|
1750
|
-
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
1751
|
-
}
|
|
1752
|
-
}
|
|
1753
|
-
if (!languages || !languages[0]) return;
|
|
1754
|
-
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
1755
|
-
}
|
|
1756
|
-
}
|
|
16
|
+
var devtools = require('react-query/devtools');
|
|
17
|
+
var axios = require('axios');
|
|
18
|
+
var DateFormat = require('@bigbinary/neeto-molecules/DateFormat');
|
|
19
|
+
var i18next = require('i18next');
|
|
20
|
+
var ramda = require('ramda');
|
|
21
|
+
var neetoIcons = require('@bigbinary/neeto-icons');
|
|
22
|
+
var formik = require('@bigbinary/neetoui/formik');
|
|
23
|
+
var utils = require('@bigbinary/neeto-commons-frontend/utils');
|
|
24
|
+
var yup = require('yup');
|
|
1757
25
|
|
|
1758
|
-
function
|
|
1759
|
-
return {
|
|
1760
|
-
debug: false,
|
|
1761
|
-
initImmediate: true,
|
|
1762
|
-
ns: ['translation'],
|
|
1763
|
-
defaultNS: ['translation'],
|
|
1764
|
-
fallbackLng: ['dev'],
|
|
1765
|
-
fallbackNS: false,
|
|
1766
|
-
supportedLngs: false,
|
|
1767
|
-
nonExplicitSupportedLngs: false,
|
|
1768
|
-
load: 'all',
|
|
1769
|
-
preload: false,
|
|
1770
|
-
simplifyPluralSuffix: true,
|
|
1771
|
-
keySeparator: '.',
|
|
1772
|
-
nsSeparator: ':',
|
|
1773
|
-
pluralSeparator: '_',
|
|
1774
|
-
contextSeparator: '_',
|
|
1775
|
-
partialBundledLanguages: false,
|
|
1776
|
-
saveMissing: false,
|
|
1777
|
-
updateMissing: false,
|
|
1778
|
-
saveMissingTo: 'fallback',
|
|
1779
|
-
saveMissingPlurals: true,
|
|
1780
|
-
missingKeyHandler: false,
|
|
1781
|
-
missingInterpolationHandler: false,
|
|
1782
|
-
postProcess: false,
|
|
1783
|
-
postProcessPassResolved: false,
|
|
1784
|
-
returnNull: false,
|
|
1785
|
-
returnEmptyString: true,
|
|
1786
|
-
returnObjects: false,
|
|
1787
|
-
joinArrays: false,
|
|
1788
|
-
returnedObjectHandler: false,
|
|
1789
|
-
parseMissingKeyHandler: false,
|
|
1790
|
-
appendNamespaceToMissingKey: false,
|
|
1791
|
-
appendNamespaceToCIMode: false,
|
|
1792
|
-
overloadTranslationOptionHandler: function handle(args) {
|
|
1793
|
-
let ret = {};
|
|
1794
|
-
if (typeof args[1] === 'object') ret = args[1];
|
|
1795
|
-
if (typeof args[1] === 'string') ret.defaultValue = args[1];
|
|
1796
|
-
if (typeof args[2] === 'string') ret.tDescription = args[2];
|
|
1797
|
-
if (typeof args[2] === 'object' || typeof args[3] === 'object') {
|
|
1798
|
-
const options = args[3] || args[2];
|
|
1799
|
-
Object.keys(options).forEach(key => {
|
|
1800
|
-
ret[key] = options[key];
|
|
1801
|
-
});
|
|
1802
|
-
}
|
|
1803
|
-
return ret;
|
|
1804
|
-
},
|
|
1805
|
-
interpolation: {
|
|
1806
|
-
escapeValue: true,
|
|
1807
|
-
format: (value, format, lng, options) => value,
|
|
1808
|
-
prefix: '{{',
|
|
1809
|
-
suffix: '}}',
|
|
1810
|
-
formatSeparator: ',',
|
|
1811
|
-
unescapePrefix: '-',
|
|
1812
|
-
nestingPrefix: '$t(',
|
|
1813
|
-
nestingSuffix: ')',
|
|
1814
|
-
nestingOptionsSeparator: ',',
|
|
1815
|
-
maxReplaces: 1000,
|
|
1816
|
-
skipOnVariables: true
|
|
1817
|
-
}
|
|
1818
|
-
};
|
|
1819
|
-
}
|
|
1820
|
-
function transformOptions(options) {
|
|
1821
|
-
if (typeof options.ns === 'string') options.ns = [options.ns];
|
|
1822
|
-
if (typeof options.fallbackLng === 'string') options.fallbackLng = [options.fallbackLng];
|
|
1823
|
-
if (typeof options.fallbackNS === 'string') options.fallbackNS = [options.fallbackNS];
|
|
1824
|
-
if (options.supportedLngs && options.supportedLngs.indexOf('cimode') < 0) {
|
|
1825
|
-
options.supportedLngs = options.supportedLngs.concat(['cimode']);
|
|
1826
|
-
}
|
|
1827
|
-
return options;
|
|
1828
|
-
}
|
|
26
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
1829
27
|
|
|
1830
|
-
function
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
constructor() {
|
|
1841
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1842
|
-
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
1843
|
-
super();
|
|
1844
|
-
this.options = transformOptions(options);
|
|
1845
|
-
this.services = {};
|
|
1846
|
-
this.logger = baseLogger;
|
|
1847
|
-
this.modules = {
|
|
1848
|
-
external: []
|
|
1849
|
-
};
|
|
1850
|
-
bindMemberFunctions(this);
|
|
1851
|
-
if (callback && !this.isInitialized && !options.isClone) {
|
|
1852
|
-
if (!this.options.initImmediate) {
|
|
1853
|
-
this.init(options, callback);
|
|
1854
|
-
return this;
|
|
1855
|
-
}
|
|
1856
|
-
setTimeout(() => {
|
|
1857
|
-
this.init(options, callback);
|
|
1858
|
-
}, 0);
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
|
-
init() {
|
|
1862
|
-
var _this = this;
|
|
1863
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1864
|
-
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
1865
|
-
if (typeof options === 'function') {
|
|
1866
|
-
callback = options;
|
|
1867
|
-
options = {};
|
|
1868
|
-
}
|
|
1869
|
-
if (!options.defaultNS && options.defaultNS !== false && options.ns) {
|
|
1870
|
-
if (typeof options.ns === 'string') {
|
|
1871
|
-
options.defaultNS = options.ns;
|
|
1872
|
-
} else if (options.ns.indexOf('translation') < 0) {
|
|
1873
|
-
options.defaultNS = options.ns[0];
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
const defOpts = get();
|
|
1877
|
-
this.options = {
|
|
1878
|
-
...defOpts,
|
|
1879
|
-
...this.options,
|
|
1880
|
-
...transformOptions(options)
|
|
1881
|
-
};
|
|
1882
|
-
if (this.options.compatibilityAPI !== 'v1') {
|
|
1883
|
-
this.options.interpolation = {
|
|
1884
|
-
...defOpts.interpolation,
|
|
1885
|
-
...this.options.interpolation
|
|
1886
|
-
};
|
|
1887
|
-
}
|
|
1888
|
-
if (options.keySeparator !== undefined) {
|
|
1889
|
-
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
1890
|
-
}
|
|
1891
|
-
if (options.nsSeparator !== undefined) {
|
|
1892
|
-
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
1893
|
-
}
|
|
1894
|
-
function createClassOnDemand(ClassOrObject) {
|
|
1895
|
-
if (!ClassOrObject) return null;
|
|
1896
|
-
if (typeof ClassOrObject === 'function') return new ClassOrObject();
|
|
1897
|
-
return ClassOrObject;
|
|
1898
|
-
}
|
|
1899
|
-
if (!this.options.isClone) {
|
|
1900
|
-
if (this.modules.logger) {
|
|
1901
|
-
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
1902
|
-
} else {
|
|
1903
|
-
baseLogger.init(null, this.options);
|
|
1904
|
-
}
|
|
1905
|
-
let formatter;
|
|
1906
|
-
if (this.modules.formatter) {
|
|
1907
|
-
formatter = this.modules.formatter;
|
|
1908
|
-
} else if (typeof Intl !== 'undefined') {
|
|
1909
|
-
formatter = Formatter;
|
|
1910
|
-
}
|
|
1911
|
-
const lu = new LanguageUtil(this.options);
|
|
1912
|
-
this.store = new ResourceStore(this.options.resources, this.options);
|
|
1913
|
-
const s = this.services;
|
|
1914
|
-
s.logger = baseLogger;
|
|
1915
|
-
s.resourceStore = this.store;
|
|
1916
|
-
s.languageUtils = lu;
|
|
1917
|
-
s.pluralResolver = new PluralResolver(lu, {
|
|
1918
|
-
prepend: this.options.pluralSeparator,
|
|
1919
|
-
compatibilityJSON: this.options.compatibilityJSON,
|
|
1920
|
-
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
1921
|
-
});
|
|
1922
|
-
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
1923
|
-
s.formatter = createClassOnDemand(formatter);
|
|
1924
|
-
s.formatter.init(s, this.options);
|
|
1925
|
-
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
1926
|
-
}
|
|
1927
|
-
s.interpolator = new Interpolator(this.options);
|
|
1928
|
-
s.utils = {
|
|
1929
|
-
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
1930
|
-
};
|
|
1931
|
-
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
1932
|
-
s.backendConnector.on('*', function (event) {
|
|
1933
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1934
|
-
args[_key - 1] = arguments[_key];
|
|
1935
|
-
}
|
|
1936
|
-
_this.emit(event, ...args);
|
|
1937
|
-
});
|
|
1938
|
-
if (this.modules.languageDetector) {
|
|
1939
|
-
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
1940
|
-
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
1941
|
-
}
|
|
1942
|
-
if (this.modules.i18nFormat) {
|
|
1943
|
-
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
1944
|
-
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
1945
|
-
}
|
|
1946
|
-
this.translator = new Translator(this.services, this.options);
|
|
1947
|
-
this.translator.on('*', function (event) {
|
|
1948
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
1949
|
-
args[_key2 - 1] = arguments[_key2];
|
|
1950
|
-
}
|
|
1951
|
-
_this.emit(event, ...args);
|
|
1952
|
-
});
|
|
1953
|
-
this.modules.external.forEach(m => {
|
|
1954
|
-
if (m.init) m.init(this);
|
|
1955
|
-
});
|
|
1956
|
-
}
|
|
1957
|
-
this.format = this.options.interpolation.format;
|
|
1958
|
-
if (!callback) callback = noop;
|
|
1959
|
-
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
1960
|
-
const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
1961
|
-
if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
|
|
1962
|
-
}
|
|
1963
|
-
if (!this.services.languageDetector && !this.options.lng) {
|
|
1964
|
-
this.logger.warn('init: no languageDetector is used and no lng is defined');
|
|
1965
|
-
}
|
|
1966
|
-
const storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
|
|
1967
|
-
storeApi.forEach(fcName => {
|
|
1968
|
-
this[fcName] = function () {
|
|
1969
|
-
return _this.store[fcName](...arguments);
|
|
1970
|
-
};
|
|
1971
|
-
});
|
|
1972
|
-
const storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
|
|
1973
|
-
storeApiChained.forEach(fcName => {
|
|
1974
|
-
this[fcName] = function () {
|
|
1975
|
-
_this.store[fcName](...arguments);
|
|
1976
|
-
return _this;
|
|
1977
|
-
};
|
|
1978
|
-
});
|
|
1979
|
-
const deferred = defer();
|
|
1980
|
-
const load = () => {
|
|
1981
|
-
const finish = (err, t) => {
|
|
1982
|
-
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn('init: i18next is already initialized. You should call init just once!');
|
|
1983
|
-
this.isInitialized = true;
|
|
1984
|
-
if (!this.options.isClone) this.logger.log('initialized', this.options);
|
|
1985
|
-
this.emit('initialized', this.options);
|
|
1986
|
-
deferred.resolve(t);
|
|
1987
|
-
callback(err, t);
|
|
1988
|
-
};
|
|
1989
|
-
if (this.languages && this.options.compatibilityAPI !== 'v1' && !this.isInitialized) return finish(null, this.t.bind(this));
|
|
1990
|
-
this.changeLanguage(this.options.lng, finish);
|
|
1991
|
-
};
|
|
1992
|
-
if (this.options.resources || !this.options.initImmediate) {
|
|
1993
|
-
load();
|
|
1994
|
-
} else {
|
|
1995
|
-
setTimeout(load, 0);
|
|
1996
|
-
}
|
|
1997
|
-
return deferred;
|
|
1998
|
-
}
|
|
1999
|
-
loadResources(language) {
|
|
2000
|
-
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
2001
|
-
let usedCallback = callback;
|
|
2002
|
-
const usedLng = typeof language === 'string' ? language : this.language;
|
|
2003
|
-
if (typeof language === 'function') usedCallback = language;
|
|
2004
|
-
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
2005
|
-
if (usedLng && usedLng.toLowerCase() === 'cimode') return usedCallback();
|
|
2006
|
-
const toLoad = [];
|
|
2007
|
-
const append = lng => {
|
|
2008
|
-
if (!lng) return;
|
|
2009
|
-
const lngs = this.services.languageUtils.toResolveHierarchy(lng);
|
|
2010
|
-
lngs.forEach(l => {
|
|
2011
|
-
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
|
28
|
+
function _interopNamespace(e) {
|
|
29
|
+
if (e && e.__esModule) return e;
|
|
30
|
+
var n = Object.create(null);
|
|
31
|
+
if (e) {
|
|
32
|
+
Object.keys(e).forEach(function (k) {
|
|
33
|
+
if (k !== 'default') {
|
|
34
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
35
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () { return e[k]; }
|
|
2012
38
|
});
|
|
2013
|
-
};
|
|
2014
|
-
if (!usedLng) {
|
|
2015
|
-
const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
2016
|
-
fallbacks.forEach(l => append(l));
|
|
2017
|
-
} else {
|
|
2018
|
-
append(usedLng);
|
|
2019
|
-
}
|
|
2020
|
-
if (this.options.preload) {
|
|
2021
|
-
this.options.preload.forEach(l => append(l));
|
|
2022
|
-
}
|
|
2023
|
-
this.services.backendConnector.load(toLoad, this.options.ns, e => {
|
|
2024
|
-
if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
2025
|
-
usedCallback(e);
|
|
2026
|
-
});
|
|
2027
|
-
} else {
|
|
2028
|
-
usedCallback(null);
|
|
2029
|
-
}
|
|
2030
|
-
}
|
|
2031
|
-
reloadResources(lngs, ns, callback) {
|
|
2032
|
-
const deferred = defer();
|
|
2033
|
-
if (!lngs) lngs = this.languages;
|
|
2034
|
-
if (!ns) ns = this.options.ns;
|
|
2035
|
-
if (!callback) callback = noop;
|
|
2036
|
-
this.services.backendConnector.reload(lngs, ns, err => {
|
|
2037
|
-
deferred.resolve();
|
|
2038
|
-
callback(err);
|
|
2039
|
-
});
|
|
2040
|
-
return deferred;
|
|
2041
|
-
}
|
|
2042
|
-
use(module) {
|
|
2043
|
-
if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
|
|
2044
|
-
if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
|
|
2045
|
-
if (module.type === 'backend') {
|
|
2046
|
-
this.modules.backend = module;
|
|
2047
|
-
}
|
|
2048
|
-
if (module.type === 'logger' || module.log && module.warn && module.error) {
|
|
2049
|
-
this.modules.logger = module;
|
|
2050
|
-
}
|
|
2051
|
-
if (module.type === 'languageDetector') {
|
|
2052
|
-
this.modules.languageDetector = module;
|
|
2053
|
-
}
|
|
2054
|
-
if (module.type === 'i18nFormat') {
|
|
2055
|
-
this.modules.i18nFormat = module;
|
|
2056
|
-
}
|
|
2057
|
-
if (module.type === 'postProcessor') {
|
|
2058
|
-
postProcessor.addPostProcessor(module);
|
|
2059
|
-
}
|
|
2060
|
-
if (module.type === 'formatter') {
|
|
2061
|
-
this.modules.formatter = module;
|
|
2062
|
-
}
|
|
2063
|
-
if (module.type === '3rdParty') {
|
|
2064
|
-
this.modules.external.push(module);
|
|
2065
|
-
}
|
|
2066
|
-
return this;
|
|
2067
|
-
}
|
|
2068
|
-
setResolvedLanguage(l) {
|
|
2069
|
-
if (!l || !this.languages) return;
|
|
2070
|
-
if (['cimode', 'dev'].indexOf(l) > -1) return;
|
|
2071
|
-
for (let li = 0; li < this.languages.length; li++) {
|
|
2072
|
-
const lngInLngs = this.languages[li];
|
|
2073
|
-
if (['cimode', 'dev'].indexOf(lngInLngs) > -1) continue;
|
|
2074
|
-
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
2075
|
-
this.resolvedLanguage = lngInLngs;
|
|
2076
|
-
break;
|
|
2077
|
-
}
|
|
2078
|
-
}
|
|
2079
|
-
}
|
|
2080
|
-
changeLanguage(lng, callback) {
|
|
2081
|
-
var _this2 = this;
|
|
2082
|
-
this.isLanguageChangingTo = lng;
|
|
2083
|
-
const deferred = defer();
|
|
2084
|
-
this.emit('languageChanging', lng);
|
|
2085
|
-
const setLngProps = l => {
|
|
2086
|
-
this.language = l;
|
|
2087
|
-
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
2088
|
-
this.resolvedLanguage = undefined;
|
|
2089
|
-
this.setResolvedLanguage(l);
|
|
2090
|
-
};
|
|
2091
|
-
const done = (err, l) => {
|
|
2092
|
-
if (l) {
|
|
2093
|
-
setLngProps(l);
|
|
2094
|
-
this.translator.changeLanguage(l);
|
|
2095
|
-
this.isLanguageChangingTo = undefined;
|
|
2096
|
-
this.emit('languageChanged', l);
|
|
2097
|
-
this.logger.log('languageChanged', l);
|
|
2098
|
-
} else {
|
|
2099
|
-
this.isLanguageChangingTo = undefined;
|
|
2100
|
-
}
|
|
2101
|
-
deferred.resolve(function () {
|
|
2102
|
-
return _this2.t(...arguments);
|
|
2103
|
-
});
|
|
2104
|
-
if (callback) callback(err, function () {
|
|
2105
|
-
return _this2.t(...arguments);
|
|
2106
|
-
});
|
|
2107
|
-
};
|
|
2108
|
-
const setLng = lngs => {
|
|
2109
|
-
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
2110
|
-
const l = typeof lngs === 'string' ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
|
|
2111
|
-
if (l) {
|
|
2112
|
-
if (!this.language) {
|
|
2113
|
-
setLngProps(l);
|
|
2114
|
-
}
|
|
2115
|
-
if (!this.translator.language) this.translator.changeLanguage(l);
|
|
2116
|
-
if (this.services.languageDetector && this.services.languageDetector.cacheUserLanguage) this.services.languageDetector.cacheUserLanguage(l);
|
|
2117
|
-
}
|
|
2118
|
-
this.loadResources(l, err => {
|
|
2119
|
-
done(err, l);
|
|
2120
|
-
});
|
|
2121
|
-
};
|
|
2122
|
-
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
2123
|
-
setLng(this.services.languageDetector.detect());
|
|
2124
|
-
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
2125
|
-
if (this.services.languageDetector.detect.length === 0) {
|
|
2126
|
-
this.services.languageDetector.detect().then(setLng);
|
|
2127
|
-
} else {
|
|
2128
|
-
this.services.languageDetector.detect(setLng);
|
|
2129
|
-
}
|
|
2130
|
-
} else {
|
|
2131
|
-
setLng(lng);
|
|
2132
|
-
}
|
|
2133
|
-
return deferred;
|
|
2134
|
-
}
|
|
2135
|
-
getFixedT(lng, ns, keyPrefix) {
|
|
2136
|
-
var _this3 = this;
|
|
2137
|
-
const fixedT = function (key, opts) {
|
|
2138
|
-
let options;
|
|
2139
|
-
if (typeof opts !== 'object') {
|
|
2140
|
-
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
2141
|
-
rest[_key3 - 2] = arguments[_key3];
|
|
2142
|
-
}
|
|
2143
|
-
options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
2144
|
-
} else {
|
|
2145
|
-
options = {
|
|
2146
|
-
...opts
|
|
2147
|
-
};
|
|
2148
|
-
}
|
|
2149
|
-
options.lng = options.lng || fixedT.lng;
|
|
2150
|
-
options.lngs = options.lngs || fixedT.lngs;
|
|
2151
|
-
options.ns = options.ns || fixedT.ns;
|
|
2152
|
-
options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
2153
|
-
const keySeparator = _this3.options.keySeparator || '.';
|
|
2154
|
-
let resultKey;
|
|
2155
|
-
if (options.keyPrefix && Array.isArray(key)) {
|
|
2156
|
-
resultKey = key.map(k => `${options.keyPrefix}${keySeparator}${k}`);
|
|
2157
|
-
} else {
|
|
2158
|
-
resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
|
|
2159
|
-
}
|
|
2160
|
-
return _this3.t(resultKey, options);
|
|
2161
|
-
};
|
|
2162
|
-
if (typeof lng === 'string') {
|
|
2163
|
-
fixedT.lng = lng;
|
|
2164
|
-
} else {
|
|
2165
|
-
fixedT.lngs = lng;
|
|
2166
|
-
}
|
|
2167
|
-
fixedT.ns = ns;
|
|
2168
|
-
fixedT.keyPrefix = keyPrefix;
|
|
2169
|
-
return fixedT;
|
|
2170
|
-
}
|
|
2171
|
-
t() {
|
|
2172
|
-
return this.translator && this.translator.translate(...arguments);
|
|
2173
|
-
}
|
|
2174
|
-
exists() {
|
|
2175
|
-
return this.translator && this.translator.exists(...arguments);
|
|
2176
|
-
}
|
|
2177
|
-
setDefaultNamespace(ns) {
|
|
2178
|
-
this.options.defaultNS = ns;
|
|
2179
|
-
}
|
|
2180
|
-
hasLoadedNamespace(ns) {
|
|
2181
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2182
|
-
if (!this.isInitialized) {
|
|
2183
|
-
this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
|
|
2184
|
-
return false;
|
|
2185
|
-
}
|
|
2186
|
-
if (!this.languages || !this.languages.length) {
|
|
2187
|
-
this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages);
|
|
2188
|
-
return false;
|
|
2189
|
-
}
|
|
2190
|
-
const lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
2191
|
-
const fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
2192
|
-
const lastLng = this.languages[this.languages.length - 1];
|
|
2193
|
-
if (lng.toLowerCase() === 'cimode') return true;
|
|
2194
|
-
const loadNotPending = (l, n) => {
|
|
2195
|
-
const loadState = this.services.backendConnector.state[`${l}|${n}`];
|
|
2196
|
-
return loadState === -1 || loadState === 2;
|
|
2197
|
-
};
|
|
2198
|
-
if (options.precheck) {
|
|
2199
|
-
const preResult = options.precheck(this, loadNotPending);
|
|
2200
|
-
if (preResult !== undefined) return preResult;
|
|
2201
|
-
}
|
|
2202
|
-
if (this.hasResourceBundle(lng, ns)) return true;
|
|
2203
|
-
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
2204
|
-
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
2205
|
-
return false;
|
|
2206
|
-
}
|
|
2207
|
-
loadNamespaces(ns, callback) {
|
|
2208
|
-
const deferred = defer();
|
|
2209
|
-
if (!this.options.ns) {
|
|
2210
|
-
if (callback) callback();
|
|
2211
|
-
return Promise.resolve();
|
|
2212
|
-
}
|
|
2213
|
-
if (typeof ns === 'string') ns = [ns];
|
|
2214
|
-
ns.forEach(n => {
|
|
2215
|
-
if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
|
|
2216
|
-
});
|
|
2217
|
-
this.loadResources(err => {
|
|
2218
|
-
deferred.resolve();
|
|
2219
|
-
if (callback) callback(err);
|
|
2220
|
-
});
|
|
2221
|
-
return deferred;
|
|
2222
|
-
}
|
|
2223
|
-
loadLanguages(lngs, callback) {
|
|
2224
|
-
const deferred = defer();
|
|
2225
|
-
if (typeof lngs === 'string') lngs = [lngs];
|
|
2226
|
-
const preloaded = this.options.preload || [];
|
|
2227
|
-
const newLngs = lngs.filter(lng => preloaded.indexOf(lng) < 0);
|
|
2228
|
-
if (!newLngs.length) {
|
|
2229
|
-
if (callback) callback();
|
|
2230
|
-
return Promise.resolve();
|
|
2231
|
-
}
|
|
2232
|
-
this.options.preload = preloaded.concat(newLngs);
|
|
2233
|
-
this.loadResources(err => {
|
|
2234
|
-
deferred.resolve();
|
|
2235
|
-
if (callback) callback(err);
|
|
2236
|
-
});
|
|
2237
|
-
return deferred;
|
|
2238
|
-
}
|
|
2239
|
-
dir(lng) {
|
|
2240
|
-
if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
|
|
2241
|
-
if (!lng) return 'rtl';
|
|
2242
|
-
const rtlLngs = ['ar', 'shu', 'sqr', 'ssh', 'xaa', 'yhd', 'yud', 'aao', 'abh', 'abv', 'acm', 'acq', 'acw', 'acx', 'acy', 'adf', 'ads', 'aeb', 'aec', 'afb', 'ajp', 'apc', 'apd', 'arb', 'arq', 'ars', 'ary', 'arz', 'auz', 'avl', 'ayh', 'ayl', 'ayn', 'ayp', 'bbz', 'pga', 'he', 'iw', 'ps', 'pbt', 'pbu', 'pst', 'prp', 'prd', 'ug', 'ur', 'ydd', 'yds', 'yih', 'ji', 'yi', 'hbo', 'men', 'xmn', 'fa', 'jpr', 'peo', 'pes', 'prs', 'dv', 'sam', 'ckb'];
|
|
2243
|
-
const languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
|
|
2244
|
-
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
|
|
2245
|
-
}
|
|
2246
|
-
static createInstance() {
|
|
2247
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2248
|
-
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
2249
|
-
return new I18n(options, callback);
|
|
2250
|
-
}
|
|
2251
|
-
cloneInstance() {
|
|
2252
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2253
|
-
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
2254
|
-
const forkResourceStore = options.forkResourceStore;
|
|
2255
|
-
if (forkResourceStore) delete options.forkResourceStore;
|
|
2256
|
-
const mergedOptions = {
|
|
2257
|
-
...this.options,
|
|
2258
|
-
...options,
|
|
2259
|
-
...{
|
|
2260
|
-
isClone: true
|
|
2261
|
-
}
|
|
2262
|
-
};
|
|
2263
|
-
const clone = new I18n(mergedOptions);
|
|
2264
|
-
if (options.debug !== undefined || options.prefix !== undefined) {
|
|
2265
|
-
clone.logger = clone.logger.clone(options);
|
|
2266
|
-
}
|
|
2267
|
-
const membersToCopy = ['store', 'services', 'language'];
|
|
2268
|
-
membersToCopy.forEach(m => {
|
|
2269
|
-
clone[m] = this[m];
|
|
2270
|
-
});
|
|
2271
|
-
clone.services = {
|
|
2272
|
-
...this.services
|
|
2273
|
-
};
|
|
2274
|
-
clone.services.utils = {
|
|
2275
|
-
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2276
|
-
};
|
|
2277
|
-
if (forkResourceStore) {
|
|
2278
|
-
clone.store = new ResourceStore(this.store.data, mergedOptions);
|
|
2279
|
-
clone.services.resourceStore = clone.store;
|
|
2280
|
-
}
|
|
2281
|
-
clone.translator = new Translator(clone.services, mergedOptions);
|
|
2282
|
-
clone.translator.on('*', function (event) {
|
|
2283
|
-
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
2284
|
-
args[_key4 - 1] = arguments[_key4];
|
|
2285
|
-
}
|
|
2286
|
-
clone.emit(event, ...args);
|
|
2287
|
-
});
|
|
2288
|
-
clone.init(mergedOptions, callback);
|
|
2289
|
-
clone.translator.options = mergedOptions;
|
|
2290
|
-
clone.translator.backendConnector.services.utils = {
|
|
2291
|
-
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2292
|
-
};
|
|
2293
|
-
return clone;
|
|
2294
|
-
}
|
|
2295
|
-
toJSON() {
|
|
2296
|
-
return {
|
|
2297
|
-
options: this.options,
|
|
2298
|
-
store: this.store,
|
|
2299
|
-
language: this.language,
|
|
2300
|
-
languages: this.languages,
|
|
2301
|
-
resolvedLanguage: this.resolvedLanguage
|
|
2302
|
-
};
|
|
2303
|
-
}
|
|
2304
|
-
}
|
|
2305
|
-
const instance = I18n.createInstance();
|
|
2306
|
-
instance.createInstance = I18n.createInstance;
|
|
2307
|
-
|
|
2308
|
-
instance.createInstance;
|
|
2309
|
-
instance.dir;
|
|
2310
|
-
instance.init;
|
|
2311
|
-
instance.loadResources;
|
|
2312
|
-
instance.reloadResources;
|
|
2313
|
-
instance.use;
|
|
2314
|
-
instance.changeLanguage;
|
|
2315
|
-
instance.getFixedT;
|
|
2316
|
-
const t$2 = instance.t;
|
|
2317
|
-
instance.exists;
|
|
2318
|
-
instance.setDefaultNamespace;
|
|
2319
|
-
instance.hasLoadedNamespace;
|
|
2320
|
-
instance.loadNamespaces;
|
|
2321
|
-
instance.loadLanguages;
|
|
2322
|
-
|
|
2323
|
-
function getDefaultExportFromCjs (x) {
|
|
2324
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
2325
|
-
}
|
|
2326
|
-
|
|
2327
|
-
/**
|
|
2328
|
-
* This file automatically generated from `pre-publish.js`.
|
|
2329
|
-
* Do not manually edit.
|
|
2330
|
-
*/
|
|
2331
|
-
|
|
2332
|
-
var voidElements = {
|
|
2333
|
-
"area": true,
|
|
2334
|
-
"base": true,
|
|
2335
|
-
"br": true,
|
|
2336
|
-
"col": true,
|
|
2337
|
-
"embed": true,
|
|
2338
|
-
"hr": true,
|
|
2339
|
-
"img": true,
|
|
2340
|
-
"input": true,
|
|
2341
|
-
"link": true,
|
|
2342
|
-
"meta": true,
|
|
2343
|
-
"param": true,
|
|
2344
|
-
"source": true,
|
|
2345
|
-
"track": true,
|
|
2346
|
-
"wbr": true
|
|
2347
|
-
};
|
|
2348
|
-
|
|
2349
|
-
var e$1 = /*@__PURE__*/getDefaultExportFromCjs(voidElements);
|
|
2350
|
-
|
|
2351
|
-
var t$1=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function n$1(n){var r={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},i=n.match(/<\/?([^\s]+?)[/\s>]/);if(i&&(r.name=i[1],(e$1[i[1]]||"/"===n.charAt(n.length-2))&&(r.voidElement=!0),r.name.startsWith("!--"))){var s=n.indexOf("--\x3e");return {type:"comment",comment:-1!==s?n.slice(4,s):""}}for(var a=new RegExp(t$1),c=null;null!==(c=a.exec(n));)if(c[0].trim())if(c[1]){var o=c[1].trim(),l=[o,""];o.indexOf("=")>-1&&(l=o.split("=")),r.attrs[l[0]]=l[1],a.lastIndex--;}else c[2]&&(r.attrs[c[2]]=c[3].trim().substring(1,c[3].length-1));return r}var r=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,i=/^\s*$/,s=Object.create(null);function a(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(a,"")+"</"+t.name+">";case"comment":return e+"\x3c!--"+t.comment+"--\x3e"}}var c={parse:function(e,t){t||(t={}),t.components||(t.components=s);var a,c=[],o=[],l=-1,m=!1;if(0!==e.indexOf("<")){var u=e.indexOf("<");c.push({type:"text",content:-1===u?e:e.substring(0,u)});}return e.replace(r,function(r,s){if(m){if(r!=="</"+a.name+">")return;m=!1;}var u,f="/"!==r.charAt(1),h=r.startsWith("\x3c!--"),p=s+r.length,d=e.charAt(p);if(h){var v=n$1(r);return l<0?(c.push(v),c):((u=o[l]).children.push(v),c)}if(f&&(l++,"tag"===(a=n$1(r)).type&&t.components[a.name]&&(a.type="component",m=!0),a.voidElement||m||!d||"<"===d||a.children.push({type:"text",content:e.slice(p,e.indexOf("<",p))}),0===l&&c.push(a),(u=o[l-1])&&u.children.push(a),o[l]=a),(!f||a.voidElement)&&(l>-1&&(a.voidElement||a.name===r.slice(2,-1))&&(l--,a=-1===l?c:o[l]),!m&&"<"!==d&&d)){u=-1===l?c:o[l].children;var x=e.indexOf("<",p),g=e.slice(p,-1===x?void 0:x);i.test(g)&&(g=" "),(x>-1&&l+u.length>=0||" "!==g)&&u.push({type:"text",content:g});}}),c},stringify:function(e){return e.reduce(function(e,t){return e+a("",t)},"")}};
|
|
2352
|
-
|
|
2353
|
-
function warn() {
|
|
2354
|
-
if (console && console.warn) {
|
|
2355
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2356
|
-
args[_key] = arguments[_key];
|
|
2357
|
-
}
|
|
2358
|
-
if (typeof args[0] === 'string') args[0] = `react-i18next:: ${args[0]}`;
|
|
2359
|
-
console.warn(...args);
|
|
2360
|
-
}
|
|
2361
|
-
}
|
|
2362
|
-
const alreadyWarned = {};
|
|
2363
|
-
function warnOnce() {
|
|
2364
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
2365
|
-
args[_key2] = arguments[_key2];
|
|
2366
|
-
}
|
|
2367
|
-
if (typeof args[0] === 'string' && alreadyWarned[args[0]]) return;
|
|
2368
|
-
if (typeof args[0] === 'string') alreadyWarned[args[0]] = new Date();
|
|
2369
|
-
warn(...args);
|
|
2370
|
-
}
|
|
2371
|
-
const loadedClb = (i18n, cb) => () => {
|
|
2372
|
-
if (i18n.isInitialized) {
|
|
2373
|
-
cb();
|
|
2374
|
-
} else {
|
|
2375
|
-
const initialized = () => {
|
|
2376
|
-
setTimeout(() => {
|
|
2377
|
-
i18n.off('initialized', initialized);
|
|
2378
|
-
}, 0);
|
|
2379
|
-
cb();
|
|
2380
|
-
};
|
|
2381
|
-
i18n.on('initialized', initialized);
|
|
2382
|
-
}
|
|
2383
|
-
};
|
|
2384
|
-
function loadNamespaces(i18n, ns, cb) {
|
|
2385
|
-
i18n.loadNamespaces(ns, loadedClb(i18n, cb));
|
|
2386
|
-
}
|
|
2387
|
-
function loadLanguages(i18n, lng, ns, cb) {
|
|
2388
|
-
if (typeof ns === 'string') ns = [ns];
|
|
2389
|
-
ns.forEach(n => {
|
|
2390
|
-
if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
|
|
2391
|
-
});
|
|
2392
|
-
i18n.loadLanguages(lng, loadedClb(i18n, cb));
|
|
2393
|
-
}
|
|
2394
|
-
function oldI18nextHasLoadedNamespace(ns, i18n) {
|
|
2395
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2396
|
-
const lng = i18n.languages[0];
|
|
2397
|
-
const fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
|
|
2398
|
-
const lastLng = i18n.languages[i18n.languages.length - 1];
|
|
2399
|
-
if (lng.toLowerCase() === 'cimode') return true;
|
|
2400
|
-
const loadNotPending = (l, n) => {
|
|
2401
|
-
const loadState = i18n.services.backendConnector.state[`${l}|${n}`];
|
|
2402
|
-
return loadState === -1 || loadState === 2;
|
|
2403
|
-
};
|
|
2404
|
-
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false;
|
|
2405
|
-
if (i18n.hasResourceBundle(lng, ns)) return true;
|
|
2406
|
-
if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true;
|
|
2407
|
-
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
2408
|
-
return false;
|
|
2409
|
-
}
|
|
2410
|
-
function hasLoadedNamespace(ns, i18n) {
|
|
2411
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2412
|
-
if (!i18n.languages || !i18n.languages.length) {
|
|
2413
|
-
warnOnce('i18n.languages were undefined or empty', i18n.languages);
|
|
2414
|
-
return true;
|
|
2415
|
-
}
|
|
2416
|
-
const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined;
|
|
2417
|
-
if (!isNewerI18next) {
|
|
2418
|
-
return oldI18nextHasLoadedNamespace(ns, i18n, options);
|
|
2419
|
-
}
|
|
2420
|
-
return i18n.hasLoadedNamespace(ns, {
|
|
2421
|
-
lng: options.lng,
|
|
2422
|
-
precheck: (i18nInstance, loadNotPending) => {
|
|
2423
|
-
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
|
|
2424
|
-
}
|
|
2425
|
-
});
|
|
2426
|
-
}
|
|
2427
|
-
|
|
2428
|
-
const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
|
|
2429
|
-
const htmlEntities = {
|
|
2430
|
-
'&': '&',
|
|
2431
|
-
'&': '&',
|
|
2432
|
-
'<': '<',
|
|
2433
|
-
'<': '<',
|
|
2434
|
-
'>': '>',
|
|
2435
|
-
'>': '>',
|
|
2436
|
-
''': "'",
|
|
2437
|
-
''': "'",
|
|
2438
|
-
'"': '"',
|
|
2439
|
-
'"': '"',
|
|
2440
|
-
' ': ' ',
|
|
2441
|
-
' ': ' ',
|
|
2442
|
-
'©': '©',
|
|
2443
|
-
'©': '©',
|
|
2444
|
-
'®': '®',
|
|
2445
|
-
'®': '®',
|
|
2446
|
-
'…': '…',
|
|
2447
|
-
'…': '…',
|
|
2448
|
-
'/': '/',
|
|
2449
|
-
'/': '/'
|
|
2450
|
-
};
|
|
2451
|
-
const unescapeHtmlEntity = m => htmlEntities[m];
|
|
2452
|
-
const unescape = text => text.replace(matchHtmlEntity, unescapeHtmlEntity);
|
|
2453
|
-
|
|
2454
|
-
let defaultOptions = {
|
|
2455
|
-
bindI18n: 'languageChanged',
|
|
2456
|
-
bindI18nStore: '',
|
|
2457
|
-
transEmptyNodeValue: '',
|
|
2458
|
-
transSupportBasicHtmlNodes: true,
|
|
2459
|
-
transWrapTextNodes: '',
|
|
2460
|
-
transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
|
|
2461
|
-
useSuspense: true,
|
|
2462
|
-
unescape
|
|
2463
|
-
};
|
|
2464
|
-
function setDefaults() {
|
|
2465
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2466
|
-
defaultOptions = {
|
|
2467
|
-
...defaultOptions,
|
|
2468
|
-
...options
|
|
2469
|
-
};
|
|
2470
|
-
}
|
|
2471
|
-
function getDefaults() {
|
|
2472
|
-
return defaultOptions;
|
|
2473
|
-
}
|
|
2474
|
-
|
|
2475
|
-
let i18nInstance;
|
|
2476
|
-
function setI18n(instance) {
|
|
2477
|
-
i18nInstance = instance;
|
|
2478
|
-
}
|
|
2479
|
-
function getI18n() {
|
|
2480
|
-
return i18nInstance;
|
|
2481
|
-
}
|
|
2482
|
-
|
|
2483
|
-
function hasChildren(node, checkLength) {
|
|
2484
|
-
if (!node) return false;
|
|
2485
|
-
const base = node.props ? node.props.children : node.children;
|
|
2486
|
-
if (checkLength) return base.length > 0;
|
|
2487
|
-
return !!base;
|
|
2488
|
-
}
|
|
2489
|
-
function getChildren(node) {
|
|
2490
|
-
if (!node) return [];
|
|
2491
|
-
return node.props ? node.props.children : node.children;
|
|
2492
|
-
}
|
|
2493
|
-
function hasValidReactChildren(children) {
|
|
2494
|
-
if (Object.prototype.toString.call(children) !== '[object Array]') return false;
|
|
2495
|
-
return children.every(child => React.isValidElement(child));
|
|
2496
|
-
}
|
|
2497
|
-
function getAsArray(data) {
|
|
2498
|
-
return Array.isArray(data) ? data : [data];
|
|
2499
|
-
}
|
|
2500
|
-
function mergeProps(source, target) {
|
|
2501
|
-
const newTarget = {
|
|
2502
|
-
...target
|
|
2503
|
-
};
|
|
2504
|
-
newTarget.props = Object.assign(source.props, target.props);
|
|
2505
|
-
return newTarget;
|
|
2506
|
-
}
|
|
2507
|
-
function nodesToString(children, i18nOptions) {
|
|
2508
|
-
if (!children) return '';
|
|
2509
|
-
let stringNode = '';
|
|
2510
|
-
const childrenArray = getAsArray(children);
|
|
2511
|
-
const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : [];
|
|
2512
|
-
childrenArray.forEach((child, childIndex) => {
|
|
2513
|
-
if (typeof child === 'string') {
|
|
2514
|
-
stringNode += `${child}`;
|
|
2515
|
-
} else if (React.isValidElement(child)) {
|
|
2516
|
-
const childPropsCount = Object.keys(child.props).length;
|
|
2517
|
-
const shouldKeepChild = keepArray.indexOf(child.type) > -1;
|
|
2518
|
-
const childChildren = child.props.children;
|
|
2519
|
-
if (!childChildren && shouldKeepChild && childPropsCount === 0) {
|
|
2520
|
-
stringNode += `<${child.type}/>`;
|
|
2521
|
-
} else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
|
|
2522
|
-
stringNode += `<${childIndex}></${childIndex}>`;
|
|
2523
|
-
} else if (child.props.i18nIsDynamicList) {
|
|
2524
|
-
stringNode += `<${childIndex}></${childIndex}>`;
|
|
2525
|
-
} else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
|
|
2526
|
-
stringNode += `<${child.type}>${childChildren}</${child.type}>`;
|
|
2527
|
-
} else {
|
|
2528
|
-
const content = nodesToString(childChildren, i18nOptions);
|
|
2529
|
-
stringNode += `<${childIndex}>${content}</${childIndex}>`;
|
|
2530
39
|
}
|
|
2531
|
-
} else if (child === null) {
|
|
2532
|
-
warn(`Trans: the passed in value is invalid - seems you passed in a null child.`);
|
|
2533
|
-
} else if (typeof child === 'object') {
|
|
2534
|
-
const {
|
|
2535
|
-
format,
|
|
2536
|
-
...clone
|
|
2537
|
-
} = child;
|
|
2538
|
-
const keys = Object.keys(clone);
|
|
2539
|
-
if (keys.length === 1) {
|
|
2540
|
-
const value = format ? `${keys[0]}, ${format}` : keys[0];
|
|
2541
|
-
stringNode += `{{${value}}}`;
|
|
2542
|
-
} else {
|
|
2543
|
-
warn(`react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child);
|
|
2544
|
-
}
|
|
2545
|
-
} else {
|
|
2546
|
-
warn(`Trans: the passed in value is invalid - seems you passed in a variable like {number} - please pass in variables for interpolation as full objects like {{number}}.`, child);
|
|
2547
|
-
}
|
|
2548
|
-
});
|
|
2549
|
-
return stringNode;
|
|
2550
|
-
}
|
|
2551
|
-
function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) {
|
|
2552
|
-
if (targetString === '') return [];
|
|
2553
|
-
const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
2554
|
-
const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString);
|
|
2555
|
-
if (!children && !emptyChildrenButNeedsHandling) return [targetString];
|
|
2556
|
-
const data = {};
|
|
2557
|
-
function getData(childs) {
|
|
2558
|
-
const childrenArray = getAsArray(childs);
|
|
2559
|
-
childrenArray.forEach(child => {
|
|
2560
|
-
if (typeof child === 'string') return;
|
|
2561
|
-
if (hasChildren(child)) getData(getChildren(child));else if (typeof child === 'object' && !React.isValidElement(child)) Object.assign(data, child);
|
|
2562
|
-
});
|
|
2563
|
-
}
|
|
2564
|
-
getData(children);
|
|
2565
|
-
const ast = c.parse(`<0>${targetString}</0>`);
|
|
2566
|
-
const opts = {
|
|
2567
|
-
...data,
|
|
2568
|
-
...combinedTOpts
|
|
2569
|
-
};
|
|
2570
|
-
function renderInner(child, node, rootReactNode) {
|
|
2571
|
-
const childs = getChildren(child);
|
|
2572
|
-
const mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
2573
|
-
return hasValidReactChildren(childs) && mappedChildren.length === 0 ? childs : mappedChildren;
|
|
2574
|
-
}
|
|
2575
|
-
function pushTranslatedJSX(child, inner, mem, i, isVoid) {
|
|
2576
|
-
if (child.dummy) child.children = inner;
|
|
2577
|
-
mem.push(React.cloneElement(child, {
|
|
2578
|
-
...child.props,
|
|
2579
|
-
key: i
|
|
2580
|
-
}, isVoid ? undefined : inner));
|
|
2581
|
-
}
|
|
2582
|
-
function mapAST(reactNode, astNode, rootReactNode) {
|
|
2583
|
-
const reactNodes = getAsArray(reactNode);
|
|
2584
|
-
const astNodes = getAsArray(astNode);
|
|
2585
|
-
return astNodes.reduce((mem, node, i) => {
|
|
2586
|
-
const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
2587
|
-
if (node.type === 'tag') {
|
|
2588
|
-
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
2589
|
-
if (!tmp && rootReactNode.length === 1 && rootReactNode[0][node.name]) tmp = rootReactNode[0][node.name];
|
|
2590
|
-
if (!tmp) tmp = {};
|
|
2591
|
-
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
2592
|
-
props: node.attrs
|
|
2593
|
-
}, tmp) : tmp;
|
|
2594
|
-
const isElement = React.isValidElement(child);
|
|
2595
|
-
const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
2596
|
-
const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && typeof child === 'object' && child.dummy && !isElement;
|
|
2597
|
-
const isKnownComponent = typeof children === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name);
|
|
2598
|
-
if (typeof child === 'string') {
|
|
2599
|
-
const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
2600
|
-
mem.push(value);
|
|
2601
|
-
} else if (hasChildren(child) || isValidTranslationWithChildren) {
|
|
2602
|
-
const inner = renderInner(child, node, rootReactNode);
|
|
2603
|
-
pushTranslatedJSX(child, inner, mem, i);
|
|
2604
|
-
} else if (isEmptyTransWithHTML) {
|
|
2605
|
-
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
2606
|
-
mem.push(React.cloneElement(child, {
|
|
2607
|
-
...child.props,
|
|
2608
|
-
key: i
|
|
2609
|
-
}, inner));
|
|
2610
|
-
} else if (Number.isNaN(parseFloat(node.name))) {
|
|
2611
|
-
if (isKnownComponent) {
|
|
2612
|
-
const inner = renderInner(child, node, rootReactNode);
|
|
2613
|
-
pushTranslatedJSX(child, inner, mem, i, node.voidElement);
|
|
2614
|
-
} else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
|
|
2615
|
-
if (node.voidElement) {
|
|
2616
|
-
mem.push(React.createElement(node.name, {
|
|
2617
|
-
key: `${node.name}-${i}`
|
|
2618
|
-
}));
|
|
2619
|
-
} else {
|
|
2620
|
-
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
2621
|
-
mem.push(React.createElement(node.name, {
|
|
2622
|
-
key: `${node.name}-${i}`
|
|
2623
|
-
}, inner));
|
|
2624
|
-
}
|
|
2625
|
-
} else if (node.voidElement) {
|
|
2626
|
-
mem.push(`<${node.name} />`);
|
|
2627
|
-
} else {
|
|
2628
|
-
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
2629
|
-
mem.push(`<${node.name}>${inner}</${node.name}>`);
|
|
2630
|
-
}
|
|
2631
|
-
} else if (typeof child === 'object' && !isElement) {
|
|
2632
|
-
const content = node.children[0] ? translationContent : null;
|
|
2633
|
-
if (content) mem.push(content);
|
|
2634
|
-
} else if (node.children.length === 1 && translationContent) {
|
|
2635
|
-
mem.push(React.cloneElement(child, {
|
|
2636
|
-
...child.props,
|
|
2637
|
-
key: i
|
|
2638
|
-
}, translationContent));
|
|
2639
|
-
} else {
|
|
2640
|
-
mem.push(React.cloneElement(child, {
|
|
2641
|
-
...child.props,
|
|
2642
|
-
key: i
|
|
2643
|
-
}));
|
|
2644
|
-
}
|
|
2645
|
-
} else if (node.type === 'text') {
|
|
2646
|
-
const wrapTextNodes = i18nOptions.transWrapTextNodes;
|
|
2647
|
-
const content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
|
|
2648
|
-
if (wrapTextNodes) {
|
|
2649
|
-
mem.push(React.createElement(wrapTextNodes, {
|
|
2650
|
-
key: `${node.name}-${i}`
|
|
2651
|
-
}, content));
|
|
2652
|
-
} else {
|
|
2653
|
-
mem.push(content);
|
|
2654
|
-
}
|
|
2655
|
-
}
|
|
2656
|
-
return mem;
|
|
2657
|
-
}, []);
|
|
2658
|
-
}
|
|
2659
|
-
const result = mapAST([{
|
|
2660
|
-
dummy: true,
|
|
2661
|
-
children: children || []
|
|
2662
|
-
}], ast, getAsArray(children || []));
|
|
2663
|
-
return getChildren(result[0]);
|
|
2664
|
-
}
|
|
2665
|
-
function Trans$1(_ref) {
|
|
2666
|
-
let {
|
|
2667
|
-
children,
|
|
2668
|
-
count,
|
|
2669
|
-
parent,
|
|
2670
|
-
i18nKey,
|
|
2671
|
-
context,
|
|
2672
|
-
tOptions = {},
|
|
2673
|
-
values,
|
|
2674
|
-
defaults,
|
|
2675
|
-
components,
|
|
2676
|
-
ns,
|
|
2677
|
-
i18n: i18nFromProps,
|
|
2678
|
-
t: tFromProps,
|
|
2679
|
-
shouldUnescape,
|
|
2680
|
-
...additionalProps
|
|
2681
|
-
} = _ref;
|
|
2682
|
-
const i18n = i18nFromProps || getI18n();
|
|
2683
|
-
if (!i18n) {
|
|
2684
|
-
warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
|
|
2685
|
-
return children;
|
|
2686
|
-
}
|
|
2687
|
-
const t = tFromProps || i18n.t.bind(i18n) || (k => k);
|
|
2688
|
-
if (context) tOptions.context = context;
|
|
2689
|
-
const reactI18nextOptions = {
|
|
2690
|
-
...getDefaults(),
|
|
2691
|
-
...(i18n.options && i18n.options.react)
|
|
2692
|
-
};
|
|
2693
|
-
let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS;
|
|
2694
|
-
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
2695
|
-
const defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
|
|
2696
|
-
const {
|
|
2697
|
-
hashTransKey
|
|
2698
|
-
} = reactI18nextOptions;
|
|
2699
|
-
const key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
|
|
2700
|
-
const interpolationOverride = values ? tOptions.interpolation : {
|
|
2701
|
-
interpolation: {
|
|
2702
|
-
...tOptions.interpolation,
|
|
2703
|
-
prefix: '#$?',
|
|
2704
|
-
suffix: '?$#'
|
|
2705
|
-
}
|
|
2706
|
-
};
|
|
2707
|
-
const combinedTOpts = {
|
|
2708
|
-
...tOptions,
|
|
2709
|
-
count,
|
|
2710
|
-
...values,
|
|
2711
|
-
...interpolationOverride,
|
|
2712
|
-
defaultValue,
|
|
2713
|
-
ns: namespaces
|
|
2714
|
-
};
|
|
2715
|
-
const translation = key ? t(key, combinedTOpts) : defaultValue;
|
|
2716
|
-
const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
|
|
2717
|
-
const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
|
|
2718
|
-
return useAsParent ? React.createElement(useAsParent, additionalProps, content) : content;
|
|
2719
|
-
}
|
|
2720
|
-
|
|
2721
|
-
const initReactI18next = {
|
|
2722
|
-
type: '3rdParty',
|
|
2723
|
-
init(instance) {
|
|
2724
|
-
setDefaults(instance.options.react);
|
|
2725
|
-
setI18n(instance);
|
|
2726
|
-
}
|
|
2727
|
-
};
|
|
2728
|
-
|
|
2729
|
-
const I18nContext = React.createContext();
|
|
2730
|
-
class ReportNamespaces {
|
|
2731
|
-
constructor() {
|
|
2732
|
-
this.usedNamespaces = {};
|
|
2733
|
-
}
|
|
2734
|
-
addUsedNamespaces(namespaces) {
|
|
2735
|
-
namespaces.forEach(ns => {
|
|
2736
|
-
if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
|
|
2737
40
|
});
|
|
2738
41
|
}
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
}
|
|
2742
|
-
}
|
|
2743
|
-
|
|
2744
|
-
function Trans(_ref) {
|
|
2745
|
-
let {
|
|
2746
|
-
children,
|
|
2747
|
-
count,
|
|
2748
|
-
parent,
|
|
2749
|
-
i18nKey,
|
|
2750
|
-
context,
|
|
2751
|
-
tOptions = {},
|
|
2752
|
-
values,
|
|
2753
|
-
defaults,
|
|
2754
|
-
components,
|
|
2755
|
-
ns,
|
|
2756
|
-
i18n: i18nFromProps,
|
|
2757
|
-
t: tFromProps,
|
|
2758
|
-
shouldUnescape,
|
|
2759
|
-
...additionalProps
|
|
2760
|
-
} = _ref;
|
|
2761
|
-
const {
|
|
2762
|
-
i18n: i18nFromContext,
|
|
2763
|
-
defaultNS: defaultNSFromContext
|
|
2764
|
-
} = React.useContext(I18nContext) || {};
|
|
2765
|
-
const i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
2766
|
-
const t = tFromProps || i18n && i18n.t.bind(i18n);
|
|
2767
|
-
return Trans$1({
|
|
2768
|
-
children,
|
|
2769
|
-
count,
|
|
2770
|
-
parent,
|
|
2771
|
-
i18nKey,
|
|
2772
|
-
context,
|
|
2773
|
-
tOptions,
|
|
2774
|
-
values,
|
|
2775
|
-
defaults,
|
|
2776
|
-
components,
|
|
2777
|
-
ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS,
|
|
2778
|
-
i18n,
|
|
2779
|
-
t: tFromProps,
|
|
2780
|
-
shouldUnescape,
|
|
2781
|
-
...additionalProps
|
|
2782
|
-
});
|
|
2783
|
-
}
|
|
2784
|
-
|
|
2785
|
-
const usePrevious = (value, ignore) => {
|
|
2786
|
-
const ref = React.useRef();
|
|
2787
|
-
React.useEffect(() => {
|
|
2788
|
-
ref.current = ignore ? ref.current : value;
|
|
2789
|
-
}, [value, ignore]);
|
|
2790
|
-
return ref.current;
|
|
2791
|
-
};
|
|
2792
|
-
function useTranslation(ns) {
|
|
2793
|
-
let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2794
|
-
const {
|
|
2795
|
-
i18n: i18nFromProps
|
|
2796
|
-
} = props;
|
|
2797
|
-
const {
|
|
2798
|
-
i18n: i18nFromContext,
|
|
2799
|
-
defaultNS: defaultNSFromContext
|
|
2800
|
-
} = React.useContext(I18nContext) || {};
|
|
2801
|
-
const i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
2802
|
-
if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
|
|
2803
|
-
if (!i18n) {
|
|
2804
|
-
warnOnce('You will need to pass in an i18next instance by using initReactI18next');
|
|
2805
|
-
const notReadyT = (k, optsOrDefaultValue) => {
|
|
2806
|
-
if (typeof optsOrDefaultValue === 'string') return optsOrDefaultValue;
|
|
2807
|
-
if (optsOrDefaultValue && typeof optsOrDefaultValue === 'object' && typeof optsOrDefaultValue.defaultValue === 'string') return optsOrDefaultValue.defaultValue;
|
|
2808
|
-
return Array.isArray(k) ? k[k.length - 1] : k;
|
|
2809
|
-
};
|
|
2810
|
-
const retNotReady = [notReadyT, {}, false];
|
|
2811
|
-
retNotReady.t = notReadyT;
|
|
2812
|
-
retNotReady.i18n = {};
|
|
2813
|
-
retNotReady.ready = false;
|
|
2814
|
-
return retNotReady;
|
|
2815
|
-
}
|
|
2816
|
-
if (i18n.options.react && i18n.options.react.wait !== undefined) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
|
|
2817
|
-
const i18nOptions = {
|
|
2818
|
-
...getDefaults(),
|
|
2819
|
-
...i18n.options.react,
|
|
2820
|
-
...props
|
|
2821
|
-
};
|
|
2822
|
-
const {
|
|
2823
|
-
useSuspense,
|
|
2824
|
-
keyPrefix
|
|
2825
|
-
} = i18nOptions;
|
|
2826
|
-
let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
|
|
2827
|
-
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
2828
|
-
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
|
|
2829
|
-
const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions));
|
|
2830
|
-
function getT() {
|
|
2831
|
-
return i18n.getFixedT(props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
|
|
2832
|
-
}
|
|
2833
|
-
const [t, setT] = React.useState(getT);
|
|
2834
|
-
let joinedNS = namespaces.join();
|
|
2835
|
-
if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
|
|
2836
|
-
const previousJoinedNS = usePrevious(joinedNS);
|
|
2837
|
-
const isMounted = React.useRef(true);
|
|
2838
|
-
React.useEffect(() => {
|
|
2839
|
-
const {
|
|
2840
|
-
bindI18n,
|
|
2841
|
-
bindI18nStore
|
|
2842
|
-
} = i18nOptions;
|
|
2843
|
-
isMounted.current = true;
|
|
2844
|
-
if (!ready && !useSuspense) {
|
|
2845
|
-
if (props.lng) {
|
|
2846
|
-
loadLanguages(i18n, props.lng, namespaces, () => {
|
|
2847
|
-
if (isMounted.current) setT(getT);
|
|
2848
|
-
});
|
|
2849
|
-
} else {
|
|
2850
|
-
loadNamespaces(i18n, namespaces, () => {
|
|
2851
|
-
if (isMounted.current) setT(getT);
|
|
2852
|
-
});
|
|
2853
|
-
}
|
|
2854
|
-
}
|
|
2855
|
-
if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
|
|
2856
|
-
setT(getT);
|
|
2857
|
-
}
|
|
2858
|
-
function boundReset() {
|
|
2859
|
-
if (isMounted.current) setT(getT);
|
|
2860
|
-
}
|
|
2861
|
-
if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
|
|
2862
|
-
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
|
|
2863
|
-
return () => {
|
|
2864
|
-
isMounted.current = false;
|
|
2865
|
-
if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset));
|
|
2866
|
-
if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
|
|
2867
|
-
};
|
|
2868
|
-
}, [i18n, joinedNS]);
|
|
2869
|
-
const isInitial = React.useRef(true);
|
|
2870
|
-
React.useEffect(() => {
|
|
2871
|
-
if (isMounted.current && !isInitial.current) {
|
|
2872
|
-
setT(getT);
|
|
2873
|
-
}
|
|
2874
|
-
isInitial.current = false;
|
|
2875
|
-
}, [i18n, keyPrefix]);
|
|
2876
|
-
const ret = [t, i18n, ready];
|
|
2877
|
-
ret.t = t;
|
|
2878
|
-
ret.i18n = i18n;
|
|
2879
|
-
ret.ready = ready;
|
|
2880
|
-
if (ready) return ret;
|
|
2881
|
-
if (!ready && !useSuspense) return ret;
|
|
2882
|
-
throw new Promise(resolve => {
|
|
2883
|
-
if (props.lng) {
|
|
2884
|
-
loadLanguages(i18n, props.lng, namespaces, () => resolve());
|
|
2885
|
-
} else {
|
|
2886
|
-
loadNamespaces(i18n, namespaces, () => resolve());
|
|
2887
|
-
}
|
|
2888
|
-
});
|
|
42
|
+
n["default"] = e;
|
|
43
|
+
return Object.freeze(n);
|
|
2889
44
|
}
|
|
2890
45
|
|
|
2891
|
-
var
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
var
|
|
2898
|
-
|
|
2899
|
-
configure: "Configure"
|
|
2900
|
-
};
|
|
2901
|
-
var buttons = {
|
|
2902
|
-
saveChanges: "Save changes",
|
|
2903
|
-
cancel: "Cancel",
|
|
2904
|
-
"delete": "Delete",
|
|
2905
|
-
edit: "Edit",
|
|
2906
|
-
viewDetails: "View details"
|
|
2907
|
-
};
|
|
2908
|
-
var errors = {
|
|
2909
|
-
webhook: {
|
|
2910
|
-
required: "Please enter your endpoint URL",
|
|
2911
|
-
invalidUrl: "Please enter a valid URL",
|
|
2912
|
-
invalidUrlProtocol: "Please enter a valid URL. URL must begin with http or https",
|
|
2913
|
-
urlNotUnique: "Endpoint URL must be unique",
|
|
2914
|
-
events: {
|
|
2915
|
-
required: "Please select atleast one webhook event"
|
|
2916
|
-
}
|
|
2917
|
-
}
|
|
2918
|
-
};
|
|
2919
|
-
var delivery = {
|
|
2920
|
-
title: "Deliveries",
|
|
2921
|
-
redeliver: "Redeliver",
|
|
2922
|
-
redelivery: "redelivery",
|
|
2923
|
-
request: "Request",
|
|
2924
|
-
response: "Response",
|
|
2925
|
-
header: "Header",
|
|
2926
|
-
body: "Body",
|
|
2927
|
-
payload: "Payload",
|
|
2928
|
-
identifier: "Identifier",
|
|
2929
|
-
empty: {
|
|
2930
|
-
title: "There are no deliveries to show.",
|
|
2931
|
-
description: "No events have been sent to this webhook"
|
|
2932
|
-
}
|
|
2933
|
-
};
|
|
2934
|
-
var webhook = {
|
|
2935
|
-
title: "Webhooks",
|
|
2936
|
-
description: "All new action event details will be posted to the configured webhook URLs",
|
|
2937
|
-
empty: "There are no webhooks defined currently",
|
|
2938
|
-
add: "Add new webhook",
|
|
2939
|
-
endpoint: "Endpoint",
|
|
2940
|
-
event_one: "Event",
|
|
2941
|
-
event_other: "Events",
|
|
2942
|
-
endpointPlaceholder: "Enter endpoint URL",
|
|
2943
|
-
eventPlaceholder: "Select webhook events",
|
|
2944
|
-
secret: "Secret key (optional) <helpLink><info></helpLink>",
|
|
2945
|
-
secretPlaceholder: "Enter secret key",
|
|
2946
|
-
edit: "Edit Webhook",
|
|
2947
|
-
active: "Active",
|
|
2948
|
-
activeStatuses: {
|
|
2949
|
-
yes: "Yes",
|
|
2950
|
-
no: "No"
|
|
2951
|
-
}
|
|
2952
|
-
};
|
|
2953
|
-
var operation = {
|
|
2954
|
-
edit: "Edit",
|
|
2955
|
-
"delete": "Delete"
|
|
2956
|
-
};
|
|
2957
|
-
var alert = {
|
|
2958
|
-
"delete": {
|
|
2959
|
-
title: "Delete {{entity}}?",
|
|
2960
|
-
message: "You are deleting the {{entity}}."
|
|
2961
|
-
}
|
|
2962
|
-
};
|
|
2963
|
-
var tableHeaders = {
|
|
2964
|
-
active: "Active",
|
|
2965
|
-
details: "Details",
|
|
2966
|
-
createdAt: "Created at"
|
|
2967
|
-
};
|
|
2968
|
-
var en = {
|
|
2969
|
-
common: common,
|
|
2970
|
-
entity: entity,
|
|
2971
|
-
buttons: buttons,
|
|
2972
|
-
errors: errors,
|
|
2973
|
-
delivery: delivery,
|
|
2974
|
-
webhook: webhook,
|
|
2975
|
-
operation: operation,
|
|
2976
|
-
alert: alert,
|
|
2977
|
-
tableHeaders: tableHeaders
|
|
2978
|
-
};
|
|
2979
|
-
|
|
2980
|
-
instance.use(initReactI18next).init({
|
|
2981
|
-
resources: {
|
|
2982
|
-
en: {
|
|
2983
|
-
translation: en
|
|
2984
|
-
}
|
|
2985
|
-
},
|
|
2986
|
-
fallbackLng: "en"
|
|
2987
|
-
});
|
|
46
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
47
|
+
var Container__default = /*#__PURE__*/_interopDefaultLegacy(Container);
|
|
48
|
+
var Header__default = /*#__PURE__*/_interopDefaultLegacy(Header$2);
|
|
49
|
+
var PageLoader__default = /*#__PURE__*/_interopDefaultLegacy(PageLoader);
|
|
50
|
+
var TableWrapper__default = /*#__PURE__*/_interopDefaultLegacy(TableWrapper);
|
|
51
|
+
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
52
|
+
var DateFormat__default = /*#__PURE__*/_interopDefaultLegacy(DateFormat);
|
|
53
|
+
var yup__namespace = /*#__PURE__*/_interopNamespace(yup);
|
|
2988
54
|
|
|
2989
55
|
var getDeliveriesPath = function getDeliveriesPath(webhooksPath) {
|
|
2990
56
|
return "".concat(webhooksPath, "/:webhookId/deliveries");
|
|
@@ -3137,8 +203,6 @@ var useRedeliverWebhook = function useRedeliverWebhook() {
|
|
|
3137
203
|
});
|
|
3138
204
|
};
|
|
3139
205
|
|
|
3140
|
-
var DEFAULT_PAGE_SIZE = 10;
|
|
3141
|
-
|
|
3142
206
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
3143
207
|
try {
|
|
3144
208
|
var info = gen[key](arg);
|
|
@@ -3170,6 +234,10 @@ function _asyncToGenerator(fn) {
|
|
|
3170
234
|
};
|
|
3171
235
|
}
|
|
3172
236
|
|
|
237
|
+
function getDefaultExportFromCjs (x) {
|
|
238
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
239
|
+
}
|
|
240
|
+
|
|
3173
241
|
var regeneratorRuntime$1 = {exports: {}};
|
|
3174
242
|
|
|
3175
243
|
var _typeof$1 = {exports: {}};
|
|
@@ -3541,7 +609,7 @@ var TransactionDetails = function TransactionDetails(_ref) {
|
|
|
3541
609
|
_useState2 = _slicedToArray(_useState, 2),
|
|
3542
610
|
activeHeader = _useState2[0],
|
|
3543
611
|
setActiveHeader = _useState2[1];
|
|
3544
|
-
var _useTranslation = useTranslation(),
|
|
612
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
3545
613
|
t = _useTranslation.t;
|
|
3546
614
|
var _useShowDelivery = useShowDelivery(deliveryId),
|
|
3547
615
|
isLoading = _useShowDelivery.isLoading,
|
|
@@ -3560,12 +628,12 @@ var TransactionDetails = function TransactionDetails(_ref) {
|
|
|
3560
628
|
className: "flex w-full flex-col space-y-2 pb-4"
|
|
3561
629
|
}, /*#__PURE__*/React__default["default"].createElement("span", {
|
|
3562
630
|
className: "flex items-center space-x-1"
|
|
3563
|
-
}, t("delivery.identifier"), ":", /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
631
|
+
}, t("neetoWebhooks.delivery.identifier"), ":", /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
3564
632
|
className: "px-2 font-bold",
|
|
3565
633
|
style: "body2"
|
|
3566
634
|
}, identifier)), /*#__PURE__*/React__default["default"].createElement("span", {
|
|
3567
635
|
className: "flex items-center"
|
|
3568
|
-
}, t("common.responseStatus"), ":", /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
636
|
+
}, t("neetoWebhooks.common.responseStatus"), ":", /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
3569
637
|
className: "px-2 font-bold",
|
|
3570
638
|
style: "body2"
|
|
3571
639
|
}, responseStatusCode), /*#__PURE__*/React__default["default"].createElement(neetoui.Tag, {
|
|
@@ -3575,34 +643,35 @@ var TransactionDetails = function TransactionDetails(_ref) {
|
|
|
3575
643
|
onClick: function onClick() {
|
|
3576
644
|
return setActiveHeader(DELIVERY_TAB.request);
|
|
3577
645
|
}
|
|
3578
|
-
}, t("delivery.request")), /*#__PURE__*/React__default["default"].createElement(neetoui.Tab.Item, {
|
|
646
|
+
}, t("neetoWebhooks.delivery.request")), /*#__PURE__*/React__default["default"].createElement(neetoui.Tab.Item, {
|
|
3579
647
|
active: activeHeader === DELIVERY_TAB.response,
|
|
3580
648
|
onClick: function onClick() {
|
|
3581
649
|
return setActiveHeader(DELIVERY_TAB.response);
|
|
3582
650
|
}
|
|
3583
|
-
}, t("delivery.response")))), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
651
|
+
}, t("neetoWebhooks.delivery.response")))), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3584
652
|
className: "mt-2"
|
|
3585
653
|
}, activeHeader === DELIVERY_TAB.request ? /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3586
654
|
className: "space-y-4"
|
|
3587
655
|
}, /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
3588
656
|
style: "h5"
|
|
3589
|
-
}, t("delivery.header")), /*#__PURE__*/React__default["default"].createElement(Snippet, null, deliveryDetails.requestHeader)), /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
657
|
+
}, t("neetoWebhooks.delivery.header")), /*#__PURE__*/React__default["default"].createElement(Snippet, null, deliveryDetails.requestHeader)), /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
3590
658
|
style: "h5"
|
|
3591
|
-
}, t("delivery.payload")), /*#__PURE__*/React__default["default"].createElement(Snippet, null, JSON.stringify(JSON.parse(deliveryDetails.requestBody), null, 2)))) : /*#__PURE__*/React__default["default"].createElement("div", {
|
|
659
|
+
}, t("neetoWebhooks.delivery.payload")), /*#__PURE__*/React__default["default"].createElement(Snippet, null, JSON.stringify(JSON.parse(deliveryDetails.requestBody), null, 2)))) : /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3592
660
|
className: "space-y-4"
|
|
3593
661
|
}, /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
3594
662
|
style: "h5"
|
|
3595
|
-
}, t("delivery.header")), /*#__PURE__*/React__default["default"].createElement(Snippet, null, deliveryDetails.responseHeader)), /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
663
|
+
}, t("neetoWebhooks.delivery.header")), /*#__PURE__*/React__default["default"].createElement(Snippet, null, deliveryDetails.responseHeader)), /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement(neetoui.Typography, {
|
|
3596
664
|
style: "h5"
|
|
3597
|
-
}, t("delivery.body")), /*#__PURE__*/React__default["default"].createElement(Snippet, null, deliveryDetails.responseBody)))));
|
|
665
|
+
}, t("neetoWebhooks.delivery.body")), /*#__PURE__*/React__default["default"].createElement(Snippet, null, deliveryDetails.responseBody)))));
|
|
3598
666
|
};
|
|
3599
667
|
|
|
3600
668
|
var Details = function Details(_ref) {
|
|
3601
669
|
var delivery = _ref.delivery,
|
|
3602
670
|
onClose = _ref.onClose;
|
|
3603
671
|
var createdAt = delivery.createdAt,
|
|
3604
|
-
id = delivery.id
|
|
3605
|
-
|
|
672
|
+
id = delivery.id,
|
|
673
|
+
event = delivery.event;
|
|
674
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
3606
675
|
t = _useTranslation.t;
|
|
3607
676
|
var _useRedeliverWebhook = useRedeliverWebhook(),
|
|
3608
677
|
isRedelivering = _useRedeliverWebhook.isLoading,
|
|
@@ -3625,7 +694,7 @@ var Details = function Details(_ref) {
|
|
|
3625
694
|
};
|
|
3626
695
|
}();
|
|
3627
696
|
return /*#__PURE__*/React__default["default"].createElement(neetoui.Pane, {
|
|
3628
|
-
isOpen:
|
|
697
|
+
isOpen: neetoCist.isPresent(delivery),
|
|
3629
698
|
size: "large",
|
|
3630
699
|
onClose: onClose
|
|
3631
700
|
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Pane.Header, null, /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(DateFormat__default["default"].Date, {
|
|
@@ -3640,18 +709,18 @@ var Details = function Details(_ref) {
|
|
|
3640
709
|
style: "h2",
|
|
3641
710
|
weight: "normal"
|
|
3642
711
|
}
|
|
3643
|
-
}))), /*#__PURE__*/React__default["default"].createElement(neetoui.Pane.Body, null,
|
|
712
|
+
}))), /*#__PURE__*/React__default["default"].createElement(neetoui.Pane.Body, null, neetoCist.isPresent(delivery) && /*#__PURE__*/React__default["default"].createElement(TransactionDetails, {
|
|
3644
713
|
delivery: delivery
|
|
3645
714
|
})), /*#__PURE__*/React__default["default"].createElement(neetoui.Pane.Footer, {
|
|
3646
715
|
className: "gap-x-2"
|
|
3647
|
-
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
|
|
716
|
+
}, event && /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
|
|
3648
717
|
disabled: isRedelivering,
|
|
3649
|
-
label: t("delivery.redeliver"),
|
|
718
|
+
label: t("neetoWebhooks.delivery.redeliver"),
|
|
3650
719
|
loading: isRedelivering,
|
|
3651
720
|
style: "primary",
|
|
3652
721
|
onClick: handleRedeliverClick
|
|
3653
722
|
}), /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
|
|
3654
|
-
label: t("buttons.cancel"),
|
|
723
|
+
label: t("neetoWebhooks.buttons.cancel"),
|
|
3655
724
|
style: "text",
|
|
3656
725
|
onClick: onClose
|
|
3657
726
|
})));
|
|
@@ -3660,7 +729,7 @@ var Details = function Details(_ref) {
|
|
|
3660
729
|
var buildColumns$1 = function buildColumns(_ref) {
|
|
3661
730
|
var handleDetailsClick = _ref.handleDetailsClick;
|
|
3662
731
|
return [{
|
|
3663
|
-
title: t
|
|
732
|
+
title: i18next.t("neetoWebhooks.delivery.identifier", constants.SINGULAR),
|
|
3664
733
|
key: "identifier",
|
|
3665
734
|
width: 300,
|
|
3666
735
|
render: function render(_ref2) {
|
|
@@ -3674,10 +743,10 @@ var buildColumns$1 = function buildColumns(_ref) {
|
|
|
3674
743
|
weight: "semibold"
|
|
3675
744
|
}, identifier), redelivery && /*#__PURE__*/React__default["default"].createElement(neetoui.Tag, {
|
|
3676
745
|
style: "info"
|
|
3677
|
-
}, t
|
|
746
|
+
}, i18next.t("neetoWebhooks.delivery.redelivery")));
|
|
3678
747
|
}
|
|
3679
748
|
}, {
|
|
3680
|
-
title: t
|
|
749
|
+
title: i18next.t("neetoWebhooks.tableHeaders.createdAt"),
|
|
3681
750
|
key: "createdAt",
|
|
3682
751
|
dataIndex: "createdAt",
|
|
3683
752
|
width: 300,
|
|
@@ -3698,7 +767,7 @@ var buildColumns$1 = function buildColumns(_ref) {
|
|
|
3698
767
|
})));
|
|
3699
768
|
}
|
|
3700
769
|
}, {
|
|
3701
|
-
title: t
|
|
770
|
+
title: i18next.t("neetoWebhooks.common.responseStatus"),
|
|
3702
771
|
key: "responseStatusCode",
|
|
3703
772
|
width: 150,
|
|
3704
773
|
render: function render(_ref3) {
|
|
@@ -3714,19 +783,19 @@ var buildColumns$1 = function buildColumns(_ref) {
|
|
|
3714
783
|
}, status));
|
|
3715
784
|
}
|
|
3716
785
|
}, {
|
|
3717
|
-
title: t
|
|
786
|
+
title: i18next.t("neetoWebhooks.common.event", constants.SINGULAR),
|
|
3718
787
|
key: "event",
|
|
3719
788
|
dataIndex: "event",
|
|
3720
789
|
width: 100,
|
|
3721
790
|
render: ramda.prop("label")
|
|
3722
791
|
}, {
|
|
3723
|
-
title: t
|
|
792
|
+
title: i18next.t("neetoWebhooks.tableHeaders.details"),
|
|
3724
793
|
key: "details",
|
|
3725
794
|
dataIndex: "details",
|
|
3726
795
|
width: 150,
|
|
3727
796
|
render: function render(_, delivery) {
|
|
3728
797
|
return /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
|
|
3729
|
-
label: t
|
|
798
|
+
label: i18next.t("neetoWebhooks.buttons.viewDetails"),
|
|
3730
799
|
size: "small",
|
|
3731
800
|
onClick: function onClick() {
|
|
3732
801
|
return handleDetailsClick(delivery);
|
|
@@ -3747,14 +816,14 @@ var Deliveries = function Deliveries(_ref) {
|
|
|
3747
816
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
3748
817
|
selectedDelivery = _useState4[0],
|
|
3749
818
|
setSelectedDelivery = _useState4[1];
|
|
3750
|
-
var _useTranslation = useTranslation(),
|
|
819
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
3751
820
|
t = _useTranslation.t;
|
|
3752
821
|
var _useParams = reactRouterDom.useParams(),
|
|
3753
822
|
webhookId = _useParams.webhookId;
|
|
3754
823
|
var _useFetchDeliveries = useFetchDeliveries({
|
|
3755
824
|
webhookId: webhookId,
|
|
3756
825
|
page: pageNumber,
|
|
3757
|
-
|
|
826
|
+
pageSize: constants.DEFAULT_PAGE_SIZE
|
|
3758
827
|
}),
|
|
3759
828
|
isLoading = _useFetchDeliveries.isLoading,
|
|
3760
829
|
isFetching = _useFetchDeliveries.isFetching,
|
|
@@ -3764,12 +833,12 @@ var Deliveries = function Deliveries(_ref) {
|
|
|
3764
833
|
totalCount = _useFetchDeliveries$d2.totalCount,
|
|
3765
834
|
_useFetchDeliveries$d3 = _useFetchDeliveries$d2.deliveries,
|
|
3766
835
|
deliveries = _useFetchDeliveries$d3 === void 0 ? [] : _useFetchDeliveries$d3;
|
|
3767
|
-
var breadcrumbsWithoutWebhooksTitle =
|
|
3768
|
-
text: t("webhook.title")
|
|
836
|
+
var breadcrumbsWithoutWebhooksTitle = neetoCist.removeBy({
|
|
837
|
+
text: t("neetoWebhooks.webhook.title")
|
|
3769
838
|
}, hostBreadcrumbs);
|
|
3770
839
|
var breadcrumbs = [].concat(_toConsumableArray(breadcrumbsWithoutWebhooksTitle), [{
|
|
3771
840
|
link: webhooksUrl,
|
|
3772
|
-
text: t("webhook.title")
|
|
841
|
+
text: t("neetoWebhooks.webhook.title")
|
|
3773
842
|
}, {
|
|
3774
843
|
link: window.location.pathname,
|
|
3775
844
|
text: endpoint
|
|
@@ -3779,14 +848,14 @@ var Deliveries = function Deliveries(_ref) {
|
|
|
3779
848
|
className: "w-full"
|
|
3780
849
|
}, /*#__PURE__*/React__default["default"].createElement(Header__default["default"], {
|
|
3781
850
|
breadcrumbs: breadcrumbs,
|
|
3782
|
-
title: t("delivery.title")
|
|
3783
|
-
}),
|
|
3784
|
-
hasPagination: totalCount > DEFAULT_PAGE_SIZE
|
|
851
|
+
title: t("neetoWebhooks.delivery.title")
|
|
852
|
+
}), neetoCist.isNotEmpty(deliveries) ? /*#__PURE__*/React__default["default"].createElement(TableWrapper__default["default"], {
|
|
853
|
+
hasPagination: totalCount > constants.DEFAULT_PAGE_SIZE
|
|
3785
854
|
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Table, {
|
|
3786
855
|
totalCount: totalCount,
|
|
3787
856
|
fixedHeight: true,
|
|
3788
857
|
currentPageNumber: pageNumber,
|
|
3789
|
-
defaultPageSize: DEFAULT_PAGE_SIZE,
|
|
858
|
+
defaultPageSize: constants.DEFAULT_PAGE_SIZE,
|
|
3790
859
|
handlePageChange: function handlePageChange(page) {
|
|
3791
860
|
return setPageNumber(page);
|
|
3792
861
|
},
|
|
@@ -3798,8 +867,8 @@ var Deliveries = function Deliveries(_ref) {
|
|
|
3798
867
|
})) : /*#__PURE__*/React__default["default"].createElement("div", {
|
|
3799
868
|
className: "flex h-full w-full items-center justify-center"
|
|
3800
869
|
}, /*#__PURE__*/React__default["default"].createElement(neetoui.NoData, {
|
|
3801
|
-
description: t("delivery.empty.description"),
|
|
3802
|
-
title: t("delivery.empty.title")
|
|
870
|
+
description: t("neetoWebhooks.delivery.empty.description"),
|
|
871
|
+
title: t("neetoWebhooks.delivery.empty.title")
|
|
3803
872
|
})), /*#__PURE__*/React__default["default"].createElement(Details, {
|
|
3804
873
|
delivery: selectedDelivery,
|
|
3805
874
|
onClose: function onClose() {
|
|
@@ -3953,7 +1022,7 @@ var Menu = neetoui.Dropdown.Menu,
|
|
|
3953
1022
|
var ActionDropdown = function ActionDropdown(_ref) {
|
|
3954
1023
|
var onEdit = _ref.onEdit,
|
|
3955
1024
|
onDelete = _ref.onDelete;
|
|
3956
|
-
var _useTranslation = useTranslation(),
|
|
1025
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
3957
1026
|
t = _useTranslation.t;
|
|
3958
1027
|
return /*#__PURE__*/React__default["default"].createElement(neetoui.Dropdown, {
|
|
3959
1028
|
buttonStyle: "text",
|
|
@@ -3961,20 +1030,20 @@ var ActionDropdown = function ActionDropdown(_ref) {
|
|
|
3961
1030
|
strategy: "fixed"
|
|
3962
1031
|
}, /*#__PURE__*/React__default["default"].createElement(Menu, null, /*#__PURE__*/React__default["default"].createElement(MenuItem.Button, {
|
|
3963
1032
|
onClick: onEdit
|
|
3964
|
-
}, t("buttons.edit")), /*#__PURE__*/React__default["default"].createElement(MenuItem.Button, {
|
|
1033
|
+
}, t("neetoWebhooks.buttons.edit")), /*#__PURE__*/React__default["default"].createElement(MenuItem.Button, {
|
|
3965
1034
|
style: "danger",
|
|
3966
1035
|
onClick: onDelete
|
|
3967
|
-
}, t("buttons.delete"))));
|
|
1036
|
+
}, t("neetoWebhooks.buttons.delete"))));
|
|
3968
1037
|
};
|
|
3969
1038
|
|
|
3970
1039
|
function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3971
1040
|
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3972
1041
|
var getValidationSchema = function getValidationSchema(webhooks) {
|
|
3973
1042
|
return yup__namespace.object().shape({
|
|
3974
|
-
endpoint: yup__namespace.string().trim().matches(/^(https?):\/\//i, t
|
|
3975
|
-
return !ramda.pluck("endpoint",
|
|
1043
|
+
endpoint: yup__namespace.string().trim().matches(/^(https?):\/\//i, i18next.t("neetoWebhooks.errors.webhook.invalidUrlProtocol")).url(i18next.t("neetoWebhooks.errors.webhook.invalidUrl")).required(i18next.t("neetoWebhooks.errors.webhook.required")).test("Is endpoint unique", i18next.t("neetoWebhooks.errors.webhook.urlNotUnique"), function (endpoint, ctx) {
|
|
1044
|
+
return !ramda.pluck("endpoint", neetoCist.removeById(ctx.parent.id, webhooks)).includes(endpoint === null || endpoint === void 0 ? void 0 : endpoint.trim());
|
|
3976
1045
|
}),
|
|
3977
|
-
events: yup__namespace.array().min(1, t
|
|
1046
|
+
events: yup__namespace.array().min(1, i18next.t("neetoWebhooks.errors.webhook.events.required")),
|
|
3978
1047
|
secret: yup__namespace.string().trim().nullable()
|
|
3979
1048
|
});
|
|
3980
1049
|
};
|
|
@@ -3994,13 +1063,13 @@ var buildPayload = function buildPayload(_ref) {
|
|
|
3994
1063
|
});
|
|
3995
1064
|
var deletable = ((_initialValues$events = initialValues.events) !== null && _initialValues$events !== void 0 ? _initialValues$events : []).filter(function (_ref3) {
|
|
3996
1065
|
var identifier = _ref3.identifier;
|
|
3997
|
-
return !
|
|
1066
|
+
return !neetoCist.findBy({
|
|
3998
1067
|
identifier: identifier
|
|
3999
1068
|
}, values.events);
|
|
4000
1069
|
}).map(ramda.assoc("_destroy", true));
|
|
4001
1070
|
var creatable = values.events.filter(function (_ref4) {
|
|
4002
1071
|
var identifier = _ref4.identifier;
|
|
4003
|
-
return !
|
|
1072
|
+
return !neetoCist.findBy({
|
|
4004
1073
|
identifier: identifier
|
|
4005
1074
|
}, initialValues.events);
|
|
4006
1075
|
});
|
|
@@ -4013,7 +1082,7 @@ var buildColumns = function buildColumns(_ref5) {
|
|
|
4013
1082
|
handleEdit = _ref5.handleEdit,
|
|
4014
1083
|
deliveriesPath = _ref5.deliveriesPath;
|
|
4015
1084
|
return [{
|
|
4016
|
-
title: t
|
|
1085
|
+
title: i18next.t("neetoWebhooks.common.endpoint"),
|
|
4017
1086
|
key: "endpoint",
|
|
4018
1087
|
dataIndex: "endpoint",
|
|
4019
1088
|
render: function render(endpoint, webhook) {
|
|
@@ -4034,15 +1103,15 @@ var buildColumns = function buildColumns(_ref5) {
|
|
|
4034
1103
|
}));
|
|
4035
1104
|
}
|
|
4036
1105
|
}, {
|
|
4037
|
-
title: t
|
|
1106
|
+
title: i18next.t("neetoWebhooks.webhook.active"),
|
|
4038
1107
|
key: "isActive",
|
|
4039
1108
|
dataIndex: "isActive",
|
|
4040
1109
|
render: function render(isActive) {
|
|
4041
|
-
return isActive ? t
|
|
1110
|
+
return isActive ? i18next.t("neetoWebhooks.webhook.activeStatuses.yes") : i18next.t("neetoWebhooks.webhook.activeStatuses.no");
|
|
4042
1111
|
},
|
|
4043
1112
|
width: 100
|
|
4044
1113
|
}, {
|
|
4045
|
-
title: t
|
|
1114
|
+
title: i18next.t("neetoWebhooks.common.event", constants.PLURAL),
|
|
4046
1115
|
dataIndex: "events",
|
|
4047
1116
|
key: "events",
|
|
4048
1117
|
render: function render(events) {
|
|
@@ -4061,7 +1130,7 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
|
|
|
4061
1130
|
isOpen = _ref.isOpen,
|
|
4062
1131
|
onClose = _ref.onClose,
|
|
4063
1132
|
webhooks = _ref.webhooks;
|
|
4064
|
-
var _useTranslation = useTranslation(),
|
|
1133
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
4065
1134
|
t = _useTranslation.t;
|
|
4066
1135
|
var _useCreateWebhook = useCreateWebhook({
|
|
4067
1136
|
onSuccess: function onSuccess() {
|
|
@@ -4114,7 +1183,7 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
|
|
|
4114
1183
|
"data-cy": "add-new-webhook-pane-header",
|
|
4115
1184
|
style: "h2",
|
|
4116
1185
|
weight: "semibold"
|
|
4117
|
-
}, editingWebhookId ? t("webhook.edit") : t("webhook.add")), /*#__PURE__*/React__default["default"].createElement("a", {
|
|
1186
|
+
}, editingWebhookId ? t("neetoWebhooks.webhook.edit") : t("neetoWebhooks.webhook.add")), /*#__PURE__*/React__default["default"].createElement("a", {
|
|
4118
1187
|
href: WEBHOOK_HELP_URL,
|
|
4119
1188
|
rel: "noreferrer",
|
|
4120
1189
|
target: "_blank"
|
|
@@ -4141,24 +1210,24 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
|
|
|
4141
1210
|
}, /*#__PURE__*/React__default["default"].createElement(formik.Input, {
|
|
4142
1211
|
required: true,
|
|
4143
1212
|
"data-cy": "endpoint-input-field",
|
|
4144
|
-
label: t("webhook.endpoint"),
|
|
1213
|
+
label: t("neetoWebhooks.webhook.endpoint"),
|
|
4145
1214
|
name: "endpoint",
|
|
4146
|
-
placeholder: t("webhook.endpointPlaceholder"),
|
|
1215
|
+
placeholder: t("neetoWebhooks.webhook.endpointPlaceholder"),
|
|
4147
1216
|
ref: endpointRef
|
|
4148
1217
|
}), !isLoading && /*#__PURE__*/React__default["default"].createElement(formik.Select, {
|
|
4149
1218
|
isMulti: true,
|
|
4150
1219
|
required: true,
|
|
4151
1220
|
getOptionLabel: ramda.prop("label"),
|
|
4152
1221
|
getOptionValue: ramda.prop("identifier"),
|
|
4153
|
-
label: t("common.event", constants.PLURAL),
|
|
1222
|
+
label: t("neetoWebhooks.common.event", constants.PLURAL),
|
|
4154
1223
|
name: "events",
|
|
4155
1224
|
options: events,
|
|
4156
|
-
placeholder: t("webhook.eventPlaceholder")
|
|
1225
|
+
placeholder: t("neetoWebhooks.webhook.eventPlaceholder")
|
|
4157
1226
|
}), /*#__PURE__*/React__default["default"].createElement(formik.Input, {
|
|
4158
1227
|
"data-cy": "secret-key-input-field",
|
|
4159
1228
|
name: "secret",
|
|
4160
|
-
placeholder: t("webhook.secretPlaceholder"),
|
|
4161
|
-
label: /*#__PURE__*/React__default["default"].createElement(Trans, {
|
|
1229
|
+
placeholder: t("neetoWebhooks.webhook.secretPlaceholder"),
|
|
1230
|
+
label: /*#__PURE__*/React__default["default"].createElement(reactI18next.Trans, {
|
|
4162
1231
|
i18nKey: "webhook.secret",
|
|
4163
1232
|
components: {
|
|
4164
1233
|
helpLink: /*#__PURE__*/React__default["default"].createElement("a", {
|
|
@@ -4173,7 +1242,7 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
|
|
|
4173
1242
|
}
|
|
4174
1243
|
})
|
|
4175
1244
|
}), /*#__PURE__*/React__default["default"].createElement(formik.Switch, {
|
|
4176
|
-
label: t("webhook.active"),
|
|
1245
|
+
label: t("neetoWebhooks.webhook.active"),
|
|
4177
1246
|
name: "isActive"
|
|
4178
1247
|
}))), /*#__PURE__*/React__default["default"].createElement(neetoui.Pane.Footer, {
|
|
4179
1248
|
className: "flex gap-2"
|
|
@@ -4182,10 +1251,10 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
|
|
|
4182
1251
|
cancelButtonProps: {
|
|
4183
1252
|
onClick: onClose,
|
|
4184
1253
|
disabled: false,
|
|
4185
|
-
label: t("buttons.cancel")
|
|
1254
|
+
label: t("neetoWebhooks.buttons.cancel")
|
|
4186
1255
|
},
|
|
4187
1256
|
submitButtonProps: {
|
|
4188
|
-
label: t("buttons.saveChanges"),
|
|
1257
|
+
label: t("neetoWebhooks.buttons.saveChanges"),
|
|
4189
1258
|
disabled: !dirty || !isValid,
|
|
4190
1259
|
loading: isSubmitting
|
|
4191
1260
|
}
|
|
@@ -4196,14 +1265,14 @@ var AddWebhookPane = function AddWebhookPane(_ref) {
|
|
|
4196
1265
|
var Header = function Header(_ref) {
|
|
4197
1266
|
var breadcrumbs = _ref.breadcrumbs,
|
|
4198
1267
|
setIsAddWebhookPaneOpen = _ref.setIsAddWebhookPaneOpen;
|
|
4199
|
-
var _useTranslation = useTranslation(),
|
|
1268
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
4200
1269
|
t = _useTranslation.t;
|
|
4201
1270
|
return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(Header__default["default"], {
|
|
4202
1271
|
breadcrumbs: breadcrumbs,
|
|
4203
|
-
title: t("webhook.title"),
|
|
1272
|
+
title: t("neetoWebhooks.webhook.title"),
|
|
4204
1273
|
actionBlock: /*#__PURE__*/React__default["default"].createElement(neetoui.Button, {
|
|
4205
1274
|
"data-cy": "add-new-webhook-button",
|
|
4206
|
-
label: t("webhook.add"),
|
|
1275
|
+
label: t("neetoWebhooks.webhook.add"),
|
|
4207
1276
|
onClick: function onClick() {
|
|
4208
1277
|
return setIsAddWebhookPaneOpen(true);
|
|
4209
1278
|
}
|
|
@@ -4213,7 +1282,7 @@ var Header = function Header(_ref) {
|
|
|
4213
1282
|
"data-cy": "webhook-description-header",
|
|
4214
1283
|
style: "h5",
|
|
4215
1284
|
weight: "normal"
|
|
4216
|
-
}, t("webhook.description")));
|
|
1285
|
+
}, t("neetoWebhooks.webhook.description")));
|
|
4217
1286
|
};
|
|
4218
1287
|
var Header$1 = /*#__PURE__*/React__default["default"].memo(Header);
|
|
4219
1288
|
|
|
@@ -4242,12 +1311,12 @@ var Webhooks = function Webhooks(_ref) {
|
|
|
4242
1311
|
_useState10 = _slicedToArray(_useState9, 2),
|
|
4243
1312
|
pageNumber = _useState10[0],
|
|
4244
1313
|
setPageNumber = _useState10[1];
|
|
4245
|
-
var _useTranslation = useTranslation(),
|
|
1314
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
4246
1315
|
t = _useTranslation.t;
|
|
4247
1316
|
var _useFetchWebhooks = useFetchWebhooks({
|
|
4248
1317
|
entityId: entityId,
|
|
4249
1318
|
page: pageNumber,
|
|
4250
|
-
|
|
1319
|
+
pageSize: constants.DEFAULT_PAGE_SIZE
|
|
4251
1320
|
}),
|
|
4252
1321
|
isLoading = _useFetchWebhooks.isLoading,
|
|
4253
1322
|
isFetching = _useFetchWebhooks.isFetching,
|
|
@@ -4284,13 +1353,13 @@ var Webhooks = function Webhooks(_ref) {
|
|
|
4284
1353
|
}, /*#__PURE__*/React__default["default"].createElement(Header$1, {
|
|
4285
1354
|
breadcrumbs: breadcrumbs,
|
|
4286
1355
|
setIsAddWebhookPaneOpen: setIsAddWebhookPaneOpen
|
|
4287
|
-
}),
|
|
4288
|
-
hasPagination: totalCount > DEFAULT_PAGE_SIZE
|
|
1356
|
+
}), neetoCist.isNotEmpty(webhooks) ? /*#__PURE__*/React__default["default"].createElement(TableWrapper__default["default"], {
|
|
1357
|
+
hasPagination: totalCount > constants.DEFAULT_PAGE_SIZE
|
|
4289
1358
|
}, /*#__PURE__*/React__default["default"].createElement(neetoui.Table, {
|
|
4290
1359
|
totalCount: totalCount,
|
|
4291
1360
|
fixedHeight: true,
|
|
4292
1361
|
currentPageNumber: pageNumber,
|
|
4293
|
-
defaultPageSize: DEFAULT_PAGE_SIZE,
|
|
1362
|
+
defaultPageSize: constants.DEFAULT_PAGE_SIZE,
|
|
4294
1363
|
handlePageChange: function handlePageChange(page) {
|
|
4295
1364
|
return setPageNumber(page);
|
|
4296
1365
|
},
|
|
@@ -4304,23 +1373,23 @@ var Webhooks = function Webhooks(_ref) {
|
|
|
4304
1373
|
})) : /*#__PURE__*/React__default["default"].createElement("div", {
|
|
4305
1374
|
className: "flex h-full w-full items-center justify-center"
|
|
4306
1375
|
}, /*#__PURE__*/React__default["default"].createElement(neetoui.NoData, {
|
|
4307
|
-
title: t("webhook.empty")
|
|
1376
|
+
title: t("neetoWebhooks.webhook.empty")
|
|
4308
1377
|
})), /*#__PURE__*/React__default["default"].createElement(AddWebhookPane, {
|
|
4309
1378
|
editingWebhookId: editingWebhookId,
|
|
4310
1379
|
entityId: entityId,
|
|
4311
1380
|
entityType: entityType,
|
|
4312
|
-
isOpen: isAddWebhookPaneOpen,
|
|
4313
1381
|
webhooks: webhooks,
|
|
1382
|
+
isOpen: isAddWebhookPaneOpen,
|
|
4314
1383
|
onClose: handlePaneClose
|
|
4315
1384
|
}), /*#__PURE__*/React__default["default"].createElement(neetoui.Alert, {
|
|
4316
1385
|
isOpen: isDeleteAlertOpen,
|
|
4317
1386
|
isSubmitting: isDeleting,
|
|
4318
|
-
submitButtonLabel: t("buttons.delete"),
|
|
4319
|
-
message: t("alert.delete.message", {
|
|
4320
|
-
entity: t("entity.webhook")
|
|
1387
|
+
submitButtonLabel: t("neetoWebhooks.buttons.delete"),
|
|
1388
|
+
message: t("neetoWebhooks.alert.delete.message", {
|
|
1389
|
+
entity: t("neetoWebhooks.entity.webhook")
|
|
4321
1390
|
}),
|
|
4322
|
-
title: t("alert.delete.title", {
|
|
4323
|
-
entity: t("entity.webhook")
|
|
1391
|
+
title: t("neetoWebhooks.alert.delete.title", {
|
|
1392
|
+
entity: t("neetoWebhooks.entity.webhook")
|
|
4324
1393
|
}),
|
|
4325
1394
|
onClose: function onClose() {
|
|
4326
1395
|
return setIsDeleteAlertOpen(false);
|