@bigbinary/neeto-approvals-frontend 0.2.6 → 0.2.7
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/dist/index.cjs.js +215 -4246
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +162 -4194
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
- package/src/translations/en.json +101 -0
- package/src/translations/fr.json +89 -0
- package/src/translations/index.js +4 -0
package/dist/index.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useMemo, useState, useCallback, useEffect, useRef } from 'react';
|
|
2
2
|
import Container from '@bigbinary/neeto-molecules/Container';
|
|
3
3
|
import { useLocation, useHistory, Link, Switch, Route, Redirect, useParams } from 'react-router-dom';
|
|
4
|
+
import i18next, { t as t$1 } from 'i18next';
|
|
4
5
|
import * as yup from 'yup';
|
|
5
6
|
import { DEFAULT_PAGE_INDEX, SINGULAR, PLURAL } from '@bigbinary/neeto-commons-frontend/constants';
|
|
6
7
|
import { Pane, Typography, Button, Dropdown, NoData, Table as Table$1, Alert, Tag, Label, Textarea, Tab as Tab$1, Select as Select$1, Callout } from '@bigbinary/neetoui';
|
|
7
|
-
import { useDebounce } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
8
|
+
import { useMutationWithInvalidation, useDebounce } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
8
9
|
import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
|
|
10
|
+
import { useTranslation, Trans } from 'react-i18next';
|
|
9
11
|
import { isEmpty, curryN, isNil, complement, either, curry, fromPairs, assoc, keys, modify } from 'ramda';
|
|
12
|
+
import { useQuery, useQueryClient } from 'react-query';
|
|
10
13
|
import axios from 'axios';
|
|
11
|
-
import { useQuery, useQueryClient, useMutation } from 'react-query';
|
|
12
14
|
import { Form as Form$3, Input, Textarea as Textarea$1, Select } from '@bigbinary/neetoui/formik';
|
|
13
15
|
import { MenuHorizontal, Delete } from '@bigbinary/neeto-icons';
|
|
14
16
|
import TableWrapper from '@bigbinary/neeto-molecules/TableWrapper';
|
|
@@ -22,3992 +24,6 @@ import { removeBy } from '@bigbinary/neeto-commons-frontend/pure';
|
|
|
22
24
|
import { useFormikContext, FieldArray } from 'formik';
|
|
23
25
|
import NeetoHeader from '@bigbinary/neeto-molecules/Header';
|
|
24
26
|
|
|
25
|
-
function _typeof$4(o) {
|
|
26
|
-
"@babel/helpers - typeof";
|
|
27
|
-
|
|
28
|
-
return _typeof$4 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
29
|
-
return typeof o;
|
|
30
|
-
} : function (o) {
|
|
31
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
32
|
-
}, _typeof$4(o);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function _classCallCheck$2(instance, Constructor) {
|
|
36
|
-
if (!(instance instanceof Constructor)) {
|
|
37
|
-
throw new TypeError("Cannot call a class as a function");
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function _toPrimitive$3(input, hint) {
|
|
42
|
-
if (_typeof$4(input) !== "object" || input === null) return input;
|
|
43
|
-
var prim = input[Symbol.toPrimitive];
|
|
44
|
-
if (prim !== undefined) {
|
|
45
|
-
var res = prim.call(input, hint || "default");
|
|
46
|
-
if (_typeof$4(res) !== "object") return res;
|
|
47
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
48
|
-
}
|
|
49
|
-
return (hint === "string" ? String : Number)(input);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function _toPropertyKey$3(arg) {
|
|
53
|
-
var key = _toPrimitive$3(arg, "string");
|
|
54
|
-
return _typeof$4(key) === "symbol" ? key : String(key);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function _defineProperties$2(target, props) {
|
|
58
|
-
for (var i = 0; i < props.length; i++) {
|
|
59
|
-
var descriptor = props[i];
|
|
60
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
61
|
-
descriptor.configurable = true;
|
|
62
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
63
|
-
Object.defineProperty(target, _toPropertyKey$3(descriptor.key), descriptor);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
function _createClass$2(Constructor, protoProps, staticProps) {
|
|
67
|
-
if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
|
|
68
|
-
if (staticProps) _defineProperties$2(Constructor, staticProps);
|
|
69
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
70
|
-
writable: false
|
|
71
|
-
});
|
|
72
|
-
return Constructor;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function _assertThisInitialized(self) {
|
|
76
|
-
if (self === void 0) {
|
|
77
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
78
|
-
}
|
|
79
|
-
return self;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function _setPrototypeOf(o, p) {
|
|
83
|
-
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
84
|
-
o.__proto__ = p;
|
|
85
|
-
return o;
|
|
86
|
-
};
|
|
87
|
-
return _setPrototypeOf(o, p);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function _inherits(subClass, superClass) {
|
|
91
|
-
if (typeof superClass !== "function" && superClass !== null) {
|
|
92
|
-
throw new TypeError("Super expression must either be null or a function");
|
|
93
|
-
}
|
|
94
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
95
|
-
constructor: {
|
|
96
|
-
value: subClass,
|
|
97
|
-
writable: true,
|
|
98
|
-
configurable: true
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
Object.defineProperty(subClass, "prototype", {
|
|
102
|
-
writable: false
|
|
103
|
-
});
|
|
104
|
-
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function _possibleConstructorReturn(self, call) {
|
|
108
|
-
if (call && (_typeof$4(call) === "object" || typeof call === "function")) {
|
|
109
|
-
return call;
|
|
110
|
-
} else if (call !== void 0) {
|
|
111
|
-
throw new TypeError("Derived constructors may only return object or undefined");
|
|
112
|
-
}
|
|
113
|
-
return _assertThisInitialized(self);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function _getPrototypeOf(o) {
|
|
117
|
-
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
|
|
118
|
-
return o.__proto__ || Object.getPrototypeOf(o);
|
|
119
|
-
};
|
|
120
|
-
return _getPrototypeOf(o);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function _defineProperty$2(obj, key, value) {
|
|
124
|
-
key = _toPropertyKey$3(key);
|
|
125
|
-
if (key in obj) {
|
|
126
|
-
Object.defineProperty(obj, key, {
|
|
127
|
-
value: value,
|
|
128
|
-
enumerable: true,
|
|
129
|
-
configurable: true,
|
|
130
|
-
writable: true
|
|
131
|
-
});
|
|
132
|
-
} else {
|
|
133
|
-
obj[key] = value;
|
|
134
|
-
}
|
|
135
|
-
return obj;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function _arrayWithHoles$3(arr) {
|
|
139
|
-
if (Array.isArray(arr)) return arr;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function _iterableToArray$1(iter) {
|
|
143
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function _arrayLikeToArray$3(arr, len) {
|
|
147
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
148
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
149
|
-
return arr2;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function _unsupportedIterableToArray$3(o, minLen) {
|
|
153
|
-
if (!o) return;
|
|
154
|
-
if (typeof o === "string") return _arrayLikeToArray$3(o, minLen);
|
|
155
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
156
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
157
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
158
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$3(o, minLen);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function _nonIterableRest$3() {
|
|
162
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function _toArray(arr) {
|
|
166
|
-
return _arrayWithHoles$3(arr) || _iterableToArray$1(arr) || _unsupportedIterableToArray$3(arr) || _nonIterableRest$3();
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function ownKeys$6$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; }
|
|
170
|
-
function _objectSpread$6$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$6$1(Object(source), !0).forEach(function (key) { _defineProperty$2(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$6$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
171
|
-
var consoleLogger = {
|
|
172
|
-
type: 'logger',
|
|
173
|
-
log: function log(args) {
|
|
174
|
-
this.output('log', args);
|
|
175
|
-
},
|
|
176
|
-
warn: function warn(args) {
|
|
177
|
-
this.output('warn', args);
|
|
178
|
-
},
|
|
179
|
-
error: function error(args) {
|
|
180
|
-
this.output('error', args);
|
|
181
|
-
},
|
|
182
|
-
output: function output(type, args) {
|
|
183
|
-
if (console && console[type]) console[type].apply(console, args);
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
var Logger = function () {
|
|
187
|
-
function Logger(concreteLogger) {
|
|
188
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
189
|
-
_classCallCheck$2(this, Logger);
|
|
190
|
-
this.init(concreteLogger, options);
|
|
191
|
-
}
|
|
192
|
-
_createClass$2(Logger, [{
|
|
193
|
-
key: "init",
|
|
194
|
-
value: function init(concreteLogger) {
|
|
195
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
196
|
-
this.prefix = options.prefix || 'i18next:';
|
|
197
|
-
this.logger = concreteLogger || consoleLogger;
|
|
198
|
-
this.options = options;
|
|
199
|
-
this.debug = options.debug;
|
|
200
|
-
}
|
|
201
|
-
}, {
|
|
202
|
-
key: "setDebug",
|
|
203
|
-
value: function setDebug(bool) {
|
|
204
|
-
this.debug = bool;
|
|
205
|
-
}
|
|
206
|
-
}, {
|
|
207
|
-
key: "log",
|
|
208
|
-
value: function log() {
|
|
209
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
210
|
-
args[_key] = arguments[_key];
|
|
211
|
-
}
|
|
212
|
-
return this.forward(args, 'log', '', true);
|
|
213
|
-
}
|
|
214
|
-
}, {
|
|
215
|
-
key: "warn",
|
|
216
|
-
value: function warn() {
|
|
217
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
218
|
-
args[_key2] = arguments[_key2];
|
|
219
|
-
}
|
|
220
|
-
return this.forward(args, 'warn', '', true);
|
|
221
|
-
}
|
|
222
|
-
}, {
|
|
223
|
-
key: "error",
|
|
224
|
-
value: function error() {
|
|
225
|
-
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
226
|
-
args[_key3] = arguments[_key3];
|
|
227
|
-
}
|
|
228
|
-
return this.forward(args, 'error', '');
|
|
229
|
-
}
|
|
230
|
-
}, {
|
|
231
|
-
key: "deprecate",
|
|
232
|
-
value: function deprecate() {
|
|
233
|
-
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
234
|
-
args[_key4] = arguments[_key4];
|
|
235
|
-
}
|
|
236
|
-
return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
|
|
237
|
-
}
|
|
238
|
-
}, {
|
|
239
|
-
key: "forward",
|
|
240
|
-
value: function forward(args, lvl, prefix, debugOnly) {
|
|
241
|
-
if (debugOnly && !this.debug) return null;
|
|
242
|
-
if (typeof args[0] === 'string') args[0] = "".concat(prefix).concat(this.prefix, " ").concat(args[0]);
|
|
243
|
-
return this.logger[lvl](args);
|
|
244
|
-
}
|
|
245
|
-
}, {
|
|
246
|
-
key: "create",
|
|
247
|
-
value: function create(moduleName) {
|
|
248
|
-
return new Logger(this.logger, _objectSpread$6$1(_objectSpread$6$1({}, {
|
|
249
|
-
prefix: "".concat(this.prefix, ":").concat(moduleName, ":")
|
|
250
|
-
}), this.options));
|
|
251
|
-
}
|
|
252
|
-
}, {
|
|
253
|
-
key: "clone",
|
|
254
|
-
value: function clone(options) {
|
|
255
|
-
options = options || this.options;
|
|
256
|
-
options.prefix = options.prefix || this.prefix;
|
|
257
|
-
return new Logger(this.logger, options);
|
|
258
|
-
}
|
|
259
|
-
}]);
|
|
260
|
-
return Logger;
|
|
261
|
-
}();
|
|
262
|
-
var baseLogger = new Logger();
|
|
263
|
-
|
|
264
|
-
var EventEmitter = function () {
|
|
265
|
-
function EventEmitter() {
|
|
266
|
-
_classCallCheck$2(this, EventEmitter);
|
|
267
|
-
this.observers = {};
|
|
268
|
-
}
|
|
269
|
-
_createClass$2(EventEmitter, [{
|
|
270
|
-
key: "on",
|
|
271
|
-
value: function on(events, listener) {
|
|
272
|
-
var _this = this;
|
|
273
|
-
events.split(' ').forEach(function (event) {
|
|
274
|
-
_this.observers[event] = _this.observers[event] || [];
|
|
275
|
-
_this.observers[event].push(listener);
|
|
276
|
-
});
|
|
277
|
-
return this;
|
|
278
|
-
}
|
|
279
|
-
}, {
|
|
280
|
-
key: "off",
|
|
281
|
-
value: function off(event, listener) {
|
|
282
|
-
if (!this.observers[event]) return;
|
|
283
|
-
if (!listener) {
|
|
284
|
-
delete this.observers[event];
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
this.observers[event] = this.observers[event].filter(function (l) {
|
|
288
|
-
return l !== listener;
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
}, {
|
|
292
|
-
key: "emit",
|
|
293
|
-
value: function emit(event) {
|
|
294
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
295
|
-
args[_key - 1] = arguments[_key];
|
|
296
|
-
}
|
|
297
|
-
if (this.observers[event]) {
|
|
298
|
-
var cloned = [].concat(this.observers[event]);
|
|
299
|
-
cloned.forEach(function (observer) {
|
|
300
|
-
observer.apply(void 0, args);
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
if (this.observers['*']) {
|
|
304
|
-
var _cloned = [].concat(this.observers['*']);
|
|
305
|
-
_cloned.forEach(function (observer) {
|
|
306
|
-
observer.apply(observer, [event].concat(args));
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}]);
|
|
311
|
-
return EventEmitter;
|
|
312
|
-
}();
|
|
313
|
-
|
|
314
|
-
function defer() {
|
|
315
|
-
var res;
|
|
316
|
-
var rej;
|
|
317
|
-
var promise = new Promise(function (resolve, reject) {
|
|
318
|
-
res = resolve;
|
|
319
|
-
rej = reject;
|
|
320
|
-
});
|
|
321
|
-
promise.resolve = res;
|
|
322
|
-
promise.reject = rej;
|
|
323
|
-
return promise;
|
|
324
|
-
}
|
|
325
|
-
function makeString(object) {
|
|
326
|
-
if (object == null) return '';
|
|
327
|
-
return '' + object;
|
|
328
|
-
}
|
|
329
|
-
function copy(a, s, t) {
|
|
330
|
-
a.forEach(function (m) {
|
|
331
|
-
if (s[m]) t[m] = s[m];
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
function getLastOfPath(object, path, Empty) {
|
|
335
|
-
function cleanKey(key) {
|
|
336
|
-
return key && key.indexOf('###') > -1 ? key.replace(/###/g, '.') : key;
|
|
337
|
-
}
|
|
338
|
-
function canNotTraverseDeeper() {
|
|
339
|
-
return !object || typeof object === 'string';
|
|
340
|
-
}
|
|
341
|
-
var stack = typeof path !== 'string' ? [].concat(path) : path.split('.');
|
|
342
|
-
while (stack.length > 1) {
|
|
343
|
-
if (canNotTraverseDeeper()) return {};
|
|
344
|
-
var key = cleanKey(stack.shift());
|
|
345
|
-
if (!object[key] && Empty) object[key] = new Empty();
|
|
346
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
347
|
-
object = object[key];
|
|
348
|
-
} else {
|
|
349
|
-
object = {};
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
if (canNotTraverseDeeper()) return {};
|
|
353
|
-
return {
|
|
354
|
-
obj: object,
|
|
355
|
-
k: cleanKey(stack.shift())
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
function setPath(object, path, newValue) {
|
|
359
|
-
var _getLastOfPath = getLastOfPath(object, path, Object),
|
|
360
|
-
obj = _getLastOfPath.obj,
|
|
361
|
-
k = _getLastOfPath.k;
|
|
362
|
-
obj[k] = newValue;
|
|
363
|
-
}
|
|
364
|
-
function pushPath(object, path, newValue, concat) {
|
|
365
|
-
var _getLastOfPath2 = getLastOfPath(object, path, Object),
|
|
366
|
-
obj = _getLastOfPath2.obj,
|
|
367
|
-
k = _getLastOfPath2.k;
|
|
368
|
-
obj[k] = obj[k] || [];
|
|
369
|
-
if (concat) obj[k] = obj[k].concat(newValue);
|
|
370
|
-
if (!concat) obj[k].push(newValue);
|
|
371
|
-
}
|
|
372
|
-
function getPath(object, path) {
|
|
373
|
-
var _getLastOfPath3 = getLastOfPath(object, path),
|
|
374
|
-
obj = _getLastOfPath3.obj,
|
|
375
|
-
k = _getLastOfPath3.k;
|
|
376
|
-
if (!obj) return undefined;
|
|
377
|
-
return obj[k];
|
|
378
|
-
}
|
|
379
|
-
function getPathWithDefaults(data, defaultData, key) {
|
|
380
|
-
var value = getPath(data, key);
|
|
381
|
-
if (value !== undefined) {
|
|
382
|
-
return value;
|
|
383
|
-
}
|
|
384
|
-
return getPath(defaultData, key);
|
|
385
|
-
}
|
|
386
|
-
function deepExtend(target, source, overwrite) {
|
|
387
|
-
for (var prop in source) {
|
|
388
|
-
if (prop !== '__proto__' && prop !== 'constructor') {
|
|
389
|
-
if (prop in target) {
|
|
390
|
-
if (typeof target[prop] === 'string' || target[prop] instanceof String || typeof source[prop] === 'string' || source[prop] instanceof String) {
|
|
391
|
-
if (overwrite) target[prop] = source[prop];
|
|
392
|
-
} else {
|
|
393
|
-
deepExtend(target[prop], source[prop], overwrite);
|
|
394
|
-
}
|
|
395
|
-
} else {
|
|
396
|
-
target[prop] = source[prop];
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
return target;
|
|
401
|
-
}
|
|
402
|
-
function regexEscape(str) {
|
|
403
|
-
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
|
|
404
|
-
}
|
|
405
|
-
var _entityMap = {
|
|
406
|
-
'&': '&',
|
|
407
|
-
'<': '<',
|
|
408
|
-
'>': '>',
|
|
409
|
-
'"': '"',
|
|
410
|
-
"'": ''',
|
|
411
|
-
'/': '/'
|
|
412
|
-
};
|
|
413
|
-
function escape(data) {
|
|
414
|
-
if (typeof data === 'string') {
|
|
415
|
-
return data.replace(/[&<>"'\/]/g, function (s) {
|
|
416
|
-
return _entityMap[s];
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
return data;
|
|
420
|
-
}
|
|
421
|
-
var isIE10 = typeof window !== 'undefined' && window.navigator && typeof window.navigator.userAgentData === 'undefined' && window.navigator.userAgent && window.navigator.userAgent.indexOf('MSIE') > -1;
|
|
422
|
-
var chars = [' ', ',', '?', '!', ';'];
|
|
423
|
-
function looksLikeObjectPath(key, nsSeparator, keySeparator) {
|
|
424
|
-
nsSeparator = nsSeparator || '';
|
|
425
|
-
keySeparator = keySeparator || '';
|
|
426
|
-
var possibleChars = chars.filter(function (c) {
|
|
427
|
-
return nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0;
|
|
428
|
-
});
|
|
429
|
-
if (possibleChars.length === 0) return true;
|
|
430
|
-
var r = new RegExp("(".concat(possibleChars.map(function (c) {
|
|
431
|
-
return c === '?' ? '\\?' : c;
|
|
432
|
-
}).join('|'), ")"));
|
|
433
|
-
var matched = !r.test(key);
|
|
434
|
-
if (!matched) {
|
|
435
|
-
var ki = key.indexOf(keySeparator);
|
|
436
|
-
if (ki > 0 && !r.test(key.substring(0, ki))) {
|
|
437
|
-
matched = true;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
return matched;
|
|
441
|
-
}
|
|
442
|
-
function deepFind(obj, path) {
|
|
443
|
-
var keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
|
|
444
|
-
if (!obj) return undefined;
|
|
445
|
-
if (obj[path]) return obj[path];
|
|
446
|
-
var paths = path.split(keySeparator);
|
|
447
|
-
var current = obj;
|
|
448
|
-
for (var i = 0; i < paths.length; ++i) {
|
|
449
|
-
if (!current) return undefined;
|
|
450
|
-
if (typeof current[paths[i]] === 'string' && i + 1 < paths.length) {
|
|
451
|
-
return undefined;
|
|
452
|
-
}
|
|
453
|
-
if (current[paths[i]] === undefined) {
|
|
454
|
-
var j = 2;
|
|
455
|
-
var p = paths.slice(i, i + j).join(keySeparator);
|
|
456
|
-
var mix = current[p];
|
|
457
|
-
while (mix === undefined && paths.length > i + j) {
|
|
458
|
-
j++;
|
|
459
|
-
p = paths.slice(i, i + j).join(keySeparator);
|
|
460
|
-
mix = current[p];
|
|
461
|
-
}
|
|
462
|
-
if (mix === undefined) return undefined;
|
|
463
|
-
if (mix === null) return null;
|
|
464
|
-
if (path.endsWith(p)) {
|
|
465
|
-
if (typeof mix === 'string') return mix;
|
|
466
|
-
if (p && typeof mix[p] === 'string') return mix[p];
|
|
467
|
-
}
|
|
468
|
-
var joinedPath = paths.slice(i + j).join(keySeparator);
|
|
469
|
-
if (joinedPath) return deepFind(mix, joinedPath, keySeparator);
|
|
470
|
-
return undefined;
|
|
471
|
-
}
|
|
472
|
-
current = current[paths[i]];
|
|
473
|
-
}
|
|
474
|
-
return current;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
function ownKeys$5$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; }
|
|
478
|
-
function _objectSpread$5$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$5$1(Object(source), !0).forEach(function (key) { _defineProperty$2(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$5$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
479
|
-
function _createSuper$3(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$3(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
480
|
-
function _isNativeReflectConstruct$3() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
481
|
-
var ResourceStore = function (_EventEmitter) {
|
|
482
|
-
_inherits(ResourceStore, _EventEmitter);
|
|
483
|
-
var _super = _createSuper$3(ResourceStore);
|
|
484
|
-
function ResourceStore(data) {
|
|
485
|
-
var _this;
|
|
486
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
487
|
-
ns: ['translation'],
|
|
488
|
-
defaultNS: 'translation'
|
|
489
|
-
};
|
|
490
|
-
_classCallCheck$2(this, ResourceStore);
|
|
491
|
-
_this = _super.call(this);
|
|
492
|
-
if (isIE10) {
|
|
493
|
-
EventEmitter.call(_assertThisInitialized(_this));
|
|
494
|
-
}
|
|
495
|
-
_this.data = data || {};
|
|
496
|
-
_this.options = options;
|
|
497
|
-
if (_this.options.keySeparator === undefined) {
|
|
498
|
-
_this.options.keySeparator = '.';
|
|
499
|
-
}
|
|
500
|
-
if (_this.options.ignoreJSONStructure === undefined) {
|
|
501
|
-
_this.options.ignoreJSONStructure = true;
|
|
502
|
-
}
|
|
503
|
-
return _this;
|
|
504
|
-
}
|
|
505
|
-
_createClass$2(ResourceStore, [{
|
|
506
|
-
key: "addNamespaces",
|
|
507
|
-
value: function addNamespaces(ns) {
|
|
508
|
-
if (this.options.ns.indexOf(ns) < 0) {
|
|
509
|
-
this.options.ns.push(ns);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
}, {
|
|
513
|
-
key: "removeNamespaces",
|
|
514
|
-
value: function removeNamespaces(ns) {
|
|
515
|
-
var index = this.options.ns.indexOf(ns);
|
|
516
|
-
if (index > -1) {
|
|
517
|
-
this.options.ns.splice(index, 1);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
}, {
|
|
521
|
-
key: "getResource",
|
|
522
|
-
value: function getResource(lng, ns, key) {
|
|
523
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
524
|
-
var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
525
|
-
var ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
526
|
-
var path = [lng, ns];
|
|
527
|
-
if (key && typeof key !== 'string') path = path.concat(key);
|
|
528
|
-
if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
529
|
-
if (lng.indexOf('.') > -1) {
|
|
530
|
-
path = lng.split('.');
|
|
531
|
-
}
|
|
532
|
-
var result = getPath(this.data, path);
|
|
533
|
-
if (result || !ignoreJSONStructure || typeof key !== 'string') return result;
|
|
534
|
-
return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
|
|
535
|
-
}
|
|
536
|
-
}, {
|
|
537
|
-
key: "addResource",
|
|
538
|
-
value: function addResource(lng, ns, key, value) {
|
|
539
|
-
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
540
|
-
silent: false
|
|
541
|
-
};
|
|
542
|
-
var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
543
|
-
var path = [lng, ns];
|
|
544
|
-
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
545
|
-
if (lng.indexOf('.') > -1) {
|
|
546
|
-
path = lng.split('.');
|
|
547
|
-
value = ns;
|
|
548
|
-
ns = path[1];
|
|
549
|
-
}
|
|
550
|
-
this.addNamespaces(ns);
|
|
551
|
-
setPath(this.data, path, value);
|
|
552
|
-
if (!options.silent) this.emit('added', lng, ns, key, value);
|
|
553
|
-
}
|
|
554
|
-
}, {
|
|
555
|
-
key: "addResources",
|
|
556
|
-
value: function addResources(lng, ns, resources) {
|
|
557
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
558
|
-
silent: false
|
|
559
|
-
};
|
|
560
|
-
for (var m in resources) {
|
|
561
|
-
if (typeof resources[m] === 'string' || Object.prototype.toString.apply(resources[m]) === '[object Array]') this.addResource(lng, ns, m, resources[m], {
|
|
562
|
-
silent: true
|
|
563
|
-
});
|
|
564
|
-
}
|
|
565
|
-
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
566
|
-
}
|
|
567
|
-
}, {
|
|
568
|
-
key: "addResourceBundle",
|
|
569
|
-
value: function addResourceBundle(lng, ns, resources, deep, overwrite) {
|
|
570
|
-
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
|
|
571
|
-
silent: false
|
|
572
|
-
};
|
|
573
|
-
var path = [lng, ns];
|
|
574
|
-
if (lng.indexOf('.') > -1) {
|
|
575
|
-
path = lng.split('.');
|
|
576
|
-
deep = resources;
|
|
577
|
-
resources = ns;
|
|
578
|
-
ns = path[1];
|
|
579
|
-
}
|
|
580
|
-
this.addNamespaces(ns);
|
|
581
|
-
var pack = getPath(this.data, path) || {};
|
|
582
|
-
if (deep) {
|
|
583
|
-
deepExtend(pack, resources, overwrite);
|
|
584
|
-
} else {
|
|
585
|
-
pack = _objectSpread$5$1(_objectSpread$5$1({}, pack), resources);
|
|
586
|
-
}
|
|
587
|
-
setPath(this.data, path, pack);
|
|
588
|
-
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
589
|
-
}
|
|
590
|
-
}, {
|
|
591
|
-
key: "removeResourceBundle",
|
|
592
|
-
value: function removeResourceBundle(lng, ns) {
|
|
593
|
-
if (this.hasResourceBundle(lng, ns)) {
|
|
594
|
-
delete this.data[lng][ns];
|
|
595
|
-
}
|
|
596
|
-
this.removeNamespaces(ns);
|
|
597
|
-
this.emit('removed', lng, ns);
|
|
598
|
-
}
|
|
599
|
-
}, {
|
|
600
|
-
key: "hasResourceBundle",
|
|
601
|
-
value: function hasResourceBundle(lng, ns) {
|
|
602
|
-
return this.getResource(lng, ns) !== undefined;
|
|
603
|
-
}
|
|
604
|
-
}, {
|
|
605
|
-
key: "getResourceBundle",
|
|
606
|
-
value: function getResourceBundle(lng, ns) {
|
|
607
|
-
if (!ns) ns = this.options.defaultNS;
|
|
608
|
-
if (this.options.compatibilityAPI === 'v1') return _objectSpread$5$1(_objectSpread$5$1({}, {}), this.getResource(lng, ns));
|
|
609
|
-
return this.getResource(lng, ns);
|
|
610
|
-
}
|
|
611
|
-
}, {
|
|
612
|
-
key: "getDataByLanguage",
|
|
613
|
-
value: function getDataByLanguage(lng) {
|
|
614
|
-
return this.data[lng];
|
|
615
|
-
}
|
|
616
|
-
}, {
|
|
617
|
-
key: "hasLanguageSomeTranslations",
|
|
618
|
-
value: function hasLanguageSomeTranslations(lng) {
|
|
619
|
-
var data = this.getDataByLanguage(lng);
|
|
620
|
-
var n = data && Object.keys(data) || [];
|
|
621
|
-
return !!n.find(function (v) {
|
|
622
|
-
return data[v] && Object.keys(data[v]).length > 0;
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
}, {
|
|
626
|
-
key: "toJSON",
|
|
627
|
-
value: function toJSON() {
|
|
628
|
-
return this.data;
|
|
629
|
-
}
|
|
630
|
-
}]);
|
|
631
|
-
return ResourceStore;
|
|
632
|
-
}(EventEmitter);
|
|
633
|
-
|
|
634
|
-
var postProcessor = {
|
|
635
|
-
processors: {},
|
|
636
|
-
addPostProcessor: function addPostProcessor(module) {
|
|
637
|
-
this.processors[module.name] = module;
|
|
638
|
-
},
|
|
639
|
-
handle: function handle(processors, value, key, options, translator) {
|
|
640
|
-
var _this = this;
|
|
641
|
-
processors.forEach(function (processor) {
|
|
642
|
-
if (_this.processors[processor]) value = _this.processors[processor].process(value, key, options, translator);
|
|
643
|
-
});
|
|
644
|
-
return value;
|
|
645
|
-
}
|
|
646
|
-
};
|
|
647
|
-
|
|
648
|
-
function ownKeys$4$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; }
|
|
649
|
-
function _objectSpread$4$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$4$1(Object(source), !0).forEach(function (key) { _defineProperty$2(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$4$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
650
|
-
function _createSuper$2(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$2(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
651
|
-
function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
652
|
-
var checkedLoadedFor = {};
|
|
653
|
-
var Translator = function (_EventEmitter) {
|
|
654
|
-
_inherits(Translator, _EventEmitter);
|
|
655
|
-
var _super = _createSuper$2(Translator);
|
|
656
|
-
function Translator(services) {
|
|
657
|
-
var _this;
|
|
658
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
659
|
-
_classCallCheck$2(this, Translator);
|
|
660
|
-
_this = _super.call(this);
|
|
661
|
-
if (isIE10) {
|
|
662
|
-
EventEmitter.call(_assertThisInitialized(_this));
|
|
663
|
-
}
|
|
664
|
-
copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, _assertThisInitialized(_this));
|
|
665
|
-
_this.options = options;
|
|
666
|
-
if (_this.options.keySeparator === undefined) {
|
|
667
|
-
_this.options.keySeparator = '.';
|
|
668
|
-
}
|
|
669
|
-
_this.logger = baseLogger.create('translator');
|
|
670
|
-
return _this;
|
|
671
|
-
}
|
|
672
|
-
_createClass$2(Translator, [{
|
|
673
|
-
key: "changeLanguage",
|
|
674
|
-
value: function changeLanguage(lng) {
|
|
675
|
-
if (lng) this.language = lng;
|
|
676
|
-
}
|
|
677
|
-
}, {
|
|
678
|
-
key: "exists",
|
|
679
|
-
value: function exists(key) {
|
|
680
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
681
|
-
interpolation: {}
|
|
682
|
-
};
|
|
683
|
-
if (key === undefined || key === null) {
|
|
684
|
-
return false;
|
|
685
|
-
}
|
|
686
|
-
var resolved = this.resolve(key, options);
|
|
687
|
-
return resolved && resolved.res !== undefined;
|
|
688
|
-
}
|
|
689
|
-
}, {
|
|
690
|
-
key: "extractFromKey",
|
|
691
|
-
value: function extractFromKey(key, options) {
|
|
692
|
-
var nsSeparator = options.nsSeparator !== undefined ? options.nsSeparator : this.options.nsSeparator;
|
|
693
|
-
if (nsSeparator === undefined) nsSeparator = ':';
|
|
694
|
-
var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
695
|
-
var namespaces = options.ns || this.options.defaultNS || [];
|
|
696
|
-
var wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
697
|
-
var seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
698
|
-
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
699
|
-
var m = key.match(this.interpolator.nestingRegexp);
|
|
700
|
-
if (m && m.length > 0) {
|
|
701
|
-
return {
|
|
702
|
-
key: key,
|
|
703
|
-
namespaces: namespaces
|
|
704
|
-
};
|
|
705
|
-
}
|
|
706
|
-
var parts = key.split(nsSeparator);
|
|
707
|
-
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
|
|
708
|
-
key = parts.join(keySeparator);
|
|
709
|
-
}
|
|
710
|
-
if (typeof namespaces === 'string') namespaces = [namespaces];
|
|
711
|
-
return {
|
|
712
|
-
key: key,
|
|
713
|
-
namespaces: namespaces
|
|
714
|
-
};
|
|
715
|
-
}
|
|
716
|
-
}, {
|
|
717
|
-
key: "translate",
|
|
718
|
-
value: function translate(keys, options, lastKey) {
|
|
719
|
-
var _this2 = this;
|
|
720
|
-
if (_typeof$4(options) !== 'object' && this.options.overloadTranslationOptionHandler) {
|
|
721
|
-
options = this.options.overloadTranslationOptionHandler(arguments);
|
|
722
|
-
}
|
|
723
|
-
if (_typeof$4(options) === 'object') options = _objectSpread$4$1({}, options);
|
|
724
|
-
if (!options) options = {};
|
|
725
|
-
if (keys === undefined || keys === null) return '';
|
|
726
|
-
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
727
|
-
var returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
|
|
728
|
-
var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
729
|
-
var _this$extractFromKey = this.extractFromKey(keys[keys.length - 1], options),
|
|
730
|
-
key = _this$extractFromKey.key,
|
|
731
|
-
namespaces = _this$extractFromKey.namespaces;
|
|
732
|
-
var namespace = namespaces[namespaces.length - 1];
|
|
733
|
-
var lng = options.lng || this.language;
|
|
734
|
-
var appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
735
|
-
if (lng && lng.toLowerCase() === 'cimode') {
|
|
736
|
-
if (appendNamespaceToCIMode) {
|
|
737
|
-
var nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
738
|
-
if (returnDetails) {
|
|
739
|
-
return {
|
|
740
|
-
res: "".concat(namespace).concat(nsSeparator).concat(key),
|
|
741
|
-
usedKey: key,
|
|
742
|
-
exactUsedKey: key,
|
|
743
|
-
usedLng: lng,
|
|
744
|
-
usedNS: namespace
|
|
745
|
-
};
|
|
746
|
-
}
|
|
747
|
-
return "".concat(namespace).concat(nsSeparator).concat(key);
|
|
748
|
-
}
|
|
749
|
-
if (returnDetails) {
|
|
750
|
-
return {
|
|
751
|
-
res: key,
|
|
752
|
-
usedKey: key,
|
|
753
|
-
exactUsedKey: key,
|
|
754
|
-
usedLng: lng,
|
|
755
|
-
usedNS: namespace
|
|
756
|
-
};
|
|
757
|
-
}
|
|
758
|
-
return key;
|
|
759
|
-
}
|
|
760
|
-
var resolved = this.resolve(keys, options);
|
|
761
|
-
var res = resolved && resolved.res;
|
|
762
|
-
var resUsedKey = resolved && resolved.usedKey || key;
|
|
763
|
-
var resExactUsedKey = resolved && resolved.exactUsedKey || key;
|
|
764
|
-
var resType = Object.prototype.toString.apply(res);
|
|
765
|
-
var noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
|
|
766
|
-
var joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
|
|
767
|
-
var handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
768
|
-
var handleAsObject = typeof res !== 'string' && typeof res !== 'boolean' && typeof res !== 'number';
|
|
769
|
-
if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === 'string' && resType === '[object Array]')) {
|
|
770
|
-
if (!options.returnObjects && !this.options.returnObjects) {
|
|
771
|
-
if (!this.options.returnedObjectHandler) {
|
|
772
|
-
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
773
|
-
}
|
|
774
|
-
var r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, _objectSpread$4$1(_objectSpread$4$1({}, options), {}, {
|
|
775
|
-
ns: namespaces
|
|
776
|
-
})) : "key '".concat(key, " (").concat(this.language, ")' returned an object instead of string.");
|
|
777
|
-
if (returnDetails) {
|
|
778
|
-
resolved.res = r;
|
|
779
|
-
return resolved;
|
|
780
|
-
}
|
|
781
|
-
return r;
|
|
782
|
-
}
|
|
783
|
-
if (keySeparator) {
|
|
784
|
-
var resTypeIsArray = resType === '[object Array]';
|
|
785
|
-
var copy = resTypeIsArray ? [] : {};
|
|
786
|
-
var newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
787
|
-
for (var m in res) {
|
|
788
|
-
if (Object.prototype.hasOwnProperty.call(res, m)) {
|
|
789
|
-
var deepKey = "".concat(newKeyToUse).concat(keySeparator).concat(m);
|
|
790
|
-
copy[m] = this.translate(deepKey, _objectSpread$4$1(_objectSpread$4$1({}, options), {
|
|
791
|
-
joinArrays: false,
|
|
792
|
-
ns: namespaces
|
|
793
|
-
}));
|
|
794
|
-
if (copy[m] === deepKey) copy[m] = res[m];
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
res = copy;
|
|
798
|
-
}
|
|
799
|
-
} else if (handleAsObjectInI18nFormat && typeof joinArrays === 'string' && resType === '[object Array]') {
|
|
800
|
-
res = res.join(joinArrays);
|
|
801
|
-
if (res) res = this.extendTranslation(res, keys, options, lastKey);
|
|
802
|
-
} else {
|
|
803
|
-
var usedDefault = false;
|
|
804
|
-
var usedKey = false;
|
|
805
|
-
var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
|
|
806
|
-
var hasDefaultValue = Translator.hasDefaultValue(options);
|
|
807
|
-
var defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : '';
|
|
808
|
-
var defaultValue = options["defaultValue".concat(defaultValueSuffix)] || options.defaultValue;
|
|
809
|
-
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
810
|
-
usedDefault = true;
|
|
811
|
-
res = defaultValue;
|
|
812
|
-
}
|
|
813
|
-
if (!this.isValidLookup(res)) {
|
|
814
|
-
usedKey = true;
|
|
815
|
-
res = key;
|
|
816
|
-
}
|
|
817
|
-
var missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
818
|
-
var resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
|
|
819
|
-
var updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
820
|
-
if (usedKey || usedDefault || updateMissing) {
|
|
821
|
-
this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
|
|
822
|
-
if (keySeparator) {
|
|
823
|
-
var fk = this.resolve(key, _objectSpread$4$1(_objectSpread$4$1({}, options), {}, {
|
|
824
|
-
keySeparator: false
|
|
825
|
-
}));
|
|
826
|
-
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.');
|
|
827
|
-
}
|
|
828
|
-
var lngs = [];
|
|
829
|
-
var fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
|
|
830
|
-
if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
|
|
831
|
-
for (var i = 0; i < fallbackLngs.length; i++) {
|
|
832
|
-
lngs.push(fallbackLngs[i]);
|
|
833
|
-
}
|
|
834
|
-
} else if (this.options.saveMissingTo === 'all') {
|
|
835
|
-
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
|
|
836
|
-
} else {
|
|
837
|
-
lngs.push(options.lng || this.language);
|
|
838
|
-
}
|
|
839
|
-
var send = function send(l, k, specificDefaultValue) {
|
|
840
|
-
var defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
841
|
-
if (_this2.options.missingKeyHandler) {
|
|
842
|
-
_this2.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
843
|
-
} else if (_this2.backendConnector && _this2.backendConnector.saveMissing) {
|
|
844
|
-
_this2.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
845
|
-
}
|
|
846
|
-
_this2.emit('missingKey', l, namespace, k, res);
|
|
847
|
-
};
|
|
848
|
-
if (this.options.saveMissing) {
|
|
849
|
-
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
850
|
-
lngs.forEach(function (language) {
|
|
851
|
-
_this2.pluralResolver.getSuffixes(language, options).forEach(function (suffix) {
|
|
852
|
-
send([language], key + suffix, options["defaultValue".concat(suffix)] || defaultValue);
|
|
853
|
-
});
|
|
854
|
-
});
|
|
855
|
-
} else {
|
|
856
|
-
send(lngs, key, defaultValue);
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
res = this.extendTranslation(res, keys, options, resolved, lastKey);
|
|
861
|
-
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = "".concat(namespace, ":").concat(key);
|
|
862
|
-
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
863
|
-
if (this.options.compatibilityAPI !== 'v1') {
|
|
864
|
-
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? "".concat(namespace, ":").concat(key) : key, usedDefault ? res : undefined);
|
|
865
|
-
} else {
|
|
866
|
-
res = this.options.parseMissingKeyHandler(res);
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
if (returnDetails) {
|
|
871
|
-
resolved.res = res;
|
|
872
|
-
return resolved;
|
|
873
|
-
}
|
|
874
|
-
return res;
|
|
875
|
-
}
|
|
876
|
-
}, {
|
|
877
|
-
key: "extendTranslation",
|
|
878
|
-
value: function extendTranslation(res, key, options, resolved, lastKey) {
|
|
879
|
-
var _this3 = this;
|
|
880
|
-
if (this.i18nFormat && this.i18nFormat.parse) {
|
|
881
|
-
res = this.i18nFormat.parse(res, _objectSpread$4$1(_objectSpread$4$1({}, this.options.interpolation.defaultVariables), options), resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
882
|
-
resolved: resolved
|
|
883
|
-
});
|
|
884
|
-
} else if (!options.skipInterpolation) {
|
|
885
|
-
if (options.interpolation) this.interpolator.init(_objectSpread$4$1(_objectSpread$4$1({}, options), {
|
|
886
|
-
interpolation: _objectSpread$4$1(_objectSpread$4$1({}, this.options.interpolation), options.interpolation)
|
|
887
|
-
}));
|
|
888
|
-
var skipOnVariables = typeof res === 'string' && (options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
889
|
-
var nestBef;
|
|
890
|
-
if (skipOnVariables) {
|
|
891
|
-
var nb = res.match(this.interpolator.nestingRegexp);
|
|
892
|
-
nestBef = nb && nb.length;
|
|
893
|
-
}
|
|
894
|
-
var data = options.replace && typeof options.replace !== 'string' ? options.replace : options;
|
|
895
|
-
if (this.options.interpolation.defaultVariables) data = _objectSpread$4$1(_objectSpread$4$1({}, this.options.interpolation.defaultVariables), data);
|
|
896
|
-
res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
|
|
897
|
-
if (skipOnVariables) {
|
|
898
|
-
var na = res.match(this.interpolator.nestingRegexp);
|
|
899
|
-
var nestAft = na && na.length;
|
|
900
|
-
if (nestBef < nestAft) options.nest = false;
|
|
901
|
-
}
|
|
902
|
-
if (!options.lng && this.options.compatibilityAPI !== 'v1' && resolved && resolved.res) options.lng = resolved.usedLng;
|
|
903
|
-
if (options.nest !== false) res = this.interpolator.nest(res, function () {
|
|
904
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
905
|
-
args[_key] = arguments[_key];
|
|
906
|
-
}
|
|
907
|
-
if (lastKey && lastKey[0] === args[0] && !options.context) {
|
|
908
|
-
_this3.logger.warn("It seems you are nesting recursively key: ".concat(args[0], " in key: ").concat(key[0]));
|
|
909
|
-
return null;
|
|
910
|
-
}
|
|
911
|
-
return _this3.translate.apply(_this3, args.concat([key]));
|
|
912
|
-
}, options);
|
|
913
|
-
if (options.interpolation) this.interpolator.reset();
|
|
914
|
-
}
|
|
915
|
-
var postProcess = options.postProcess || this.options.postProcess;
|
|
916
|
-
var postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess;
|
|
917
|
-
if (res !== undefined && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
|
|
918
|
-
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? _objectSpread$4$1({
|
|
919
|
-
i18nResolved: resolved
|
|
920
|
-
}, options) : options, this);
|
|
921
|
-
}
|
|
922
|
-
return res;
|
|
923
|
-
}
|
|
924
|
-
}, {
|
|
925
|
-
key: "resolve",
|
|
926
|
-
value: function resolve(keys) {
|
|
927
|
-
var _this4 = this;
|
|
928
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
929
|
-
var found;
|
|
930
|
-
var usedKey;
|
|
931
|
-
var exactUsedKey;
|
|
932
|
-
var usedLng;
|
|
933
|
-
var usedNS;
|
|
934
|
-
if (typeof keys === 'string') keys = [keys];
|
|
935
|
-
keys.forEach(function (k) {
|
|
936
|
-
if (_this4.isValidLookup(found)) return;
|
|
937
|
-
var extracted = _this4.extractFromKey(k, options);
|
|
938
|
-
var key = extracted.key;
|
|
939
|
-
usedKey = key;
|
|
940
|
-
var namespaces = extracted.namespaces;
|
|
941
|
-
if (_this4.options.fallbackNS) namespaces = namespaces.concat(_this4.options.fallbackNS);
|
|
942
|
-
var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
|
|
943
|
-
var needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && _this4.pluralResolver.shouldUseIntlApi();
|
|
944
|
-
var needsContextHandling = options.context !== undefined && (typeof options.context === 'string' || typeof options.context === 'number') && options.context !== '';
|
|
945
|
-
var codes = options.lngs ? options.lngs : _this4.languageUtils.toResolveHierarchy(options.lng || _this4.language, options.fallbackLng);
|
|
946
|
-
namespaces.forEach(function (ns) {
|
|
947
|
-
if (_this4.isValidLookup(found)) return;
|
|
948
|
-
usedNS = ns;
|
|
949
|
-
if (!checkedLoadedFor["".concat(codes[0], "-").concat(ns)] && _this4.utils && _this4.utils.hasLoadedNamespace && !_this4.utils.hasLoadedNamespace(usedNS)) {
|
|
950
|
-
checkedLoadedFor["".concat(codes[0], "-").concat(ns)] = true;
|
|
951
|
-
_this4.logger.warn("key \"".concat(usedKey, "\" for languages \"").concat(codes.join(', '), "\" won't get resolved as namespace \"").concat(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!!!');
|
|
952
|
-
}
|
|
953
|
-
codes.forEach(function (code) {
|
|
954
|
-
if (_this4.isValidLookup(found)) return;
|
|
955
|
-
usedLng = code;
|
|
956
|
-
var finalKeys = [key];
|
|
957
|
-
if (_this4.i18nFormat && _this4.i18nFormat.addLookupKeys) {
|
|
958
|
-
_this4.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
|
|
959
|
-
} else {
|
|
960
|
-
var pluralSuffix;
|
|
961
|
-
if (needsPluralHandling) pluralSuffix = _this4.pluralResolver.getSuffix(code, options.count, options);
|
|
962
|
-
var zeroSuffix = "".concat(_this4.options.pluralSeparator, "zero");
|
|
963
|
-
if (needsPluralHandling) {
|
|
964
|
-
finalKeys.push(key + pluralSuffix);
|
|
965
|
-
if (needsZeroSuffixLookup) {
|
|
966
|
-
finalKeys.push(key + zeroSuffix);
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
if (needsContextHandling) {
|
|
970
|
-
var contextKey = "".concat(key).concat(_this4.options.contextSeparator).concat(options.context);
|
|
971
|
-
finalKeys.push(contextKey);
|
|
972
|
-
if (needsPluralHandling) {
|
|
973
|
-
finalKeys.push(contextKey + pluralSuffix);
|
|
974
|
-
if (needsZeroSuffixLookup) {
|
|
975
|
-
finalKeys.push(contextKey + zeroSuffix);
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
var possibleKey;
|
|
981
|
-
while (possibleKey = finalKeys.pop()) {
|
|
982
|
-
if (!_this4.isValidLookup(found)) {
|
|
983
|
-
exactUsedKey = possibleKey;
|
|
984
|
-
found = _this4.getResource(code, ns, possibleKey, options);
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
});
|
|
988
|
-
});
|
|
989
|
-
});
|
|
990
|
-
return {
|
|
991
|
-
res: found,
|
|
992
|
-
usedKey: usedKey,
|
|
993
|
-
exactUsedKey: exactUsedKey,
|
|
994
|
-
usedLng: usedLng,
|
|
995
|
-
usedNS: usedNS
|
|
996
|
-
};
|
|
997
|
-
}
|
|
998
|
-
}, {
|
|
999
|
-
key: "isValidLookup",
|
|
1000
|
-
value: function isValidLookup(res) {
|
|
1001
|
-
return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
|
|
1002
|
-
}
|
|
1003
|
-
}, {
|
|
1004
|
-
key: "getResource",
|
|
1005
|
-
value: function getResource(code, ns, key) {
|
|
1006
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1007
|
-
if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
1008
|
-
return this.resourceStore.getResource(code, ns, key, options);
|
|
1009
|
-
}
|
|
1010
|
-
}], [{
|
|
1011
|
-
key: "hasDefaultValue",
|
|
1012
|
-
value: function hasDefaultValue(options) {
|
|
1013
|
-
var prefix = 'defaultValue';
|
|
1014
|
-
for (var option in options) {
|
|
1015
|
-
if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
|
|
1016
|
-
return true;
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
return false;
|
|
1020
|
-
}
|
|
1021
|
-
}]);
|
|
1022
|
-
return Translator;
|
|
1023
|
-
}(EventEmitter);
|
|
1024
|
-
|
|
1025
|
-
function capitalize$1(string) {
|
|
1026
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
1027
|
-
}
|
|
1028
|
-
var LanguageUtil = function () {
|
|
1029
|
-
function LanguageUtil(options) {
|
|
1030
|
-
_classCallCheck$2(this, LanguageUtil);
|
|
1031
|
-
this.options = options;
|
|
1032
|
-
this.supportedLngs = this.options.supportedLngs || false;
|
|
1033
|
-
this.logger = baseLogger.create('languageUtils');
|
|
1034
|
-
}
|
|
1035
|
-
_createClass$2(LanguageUtil, [{
|
|
1036
|
-
key: "getScriptPartFromCode",
|
|
1037
|
-
value: function getScriptPartFromCode(code) {
|
|
1038
|
-
if (!code || code.indexOf('-') < 0) return null;
|
|
1039
|
-
var p = code.split('-');
|
|
1040
|
-
if (p.length === 2) return null;
|
|
1041
|
-
p.pop();
|
|
1042
|
-
if (p[p.length - 1].toLowerCase() === 'x') return null;
|
|
1043
|
-
return this.formatLanguageCode(p.join('-'));
|
|
1044
|
-
}
|
|
1045
|
-
}, {
|
|
1046
|
-
key: "getLanguagePartFromCode",
|
|
1047
|
-
value: function getLanguagePartFromCode(code) {
|
|
1048
|
-
if (!code || code.indexOf('-') < 0) return code;
|
|
1049
|
-
var p = code.split('-');
|
|
1050
|
-
return this.formatLanguageCode(p[0]);
|
|
1051
|
-
}
|
|
1052
|
-
}, {
|
|
1053
|
-
key: "formatLanguageCode",
|
|
1054
|
-
value: function formatLanguageCode(code) {
|
|
1055
|
-
if (typeof code === 'string' && code.indexOf('-') > -1) {
|
|
1056
|
-
var specialCases = ['hans', 'hant', 'latn', 'cyrl', 'cans', 'mong', 'arab'];
|
|
1057
|
-
var p = code.split('-');
|
|
1058
|
-
if (this.options.lowerCaseLng) {
|
|
1059
|
-
p = p.map(function (part) {
|
|
1060
|
-
return part.toLowerCase();
|
|
1061
|
-
});
|
|
1062
|
-
} else if (p.length === 2) {
|
|
1063
|
-
p[0] = p[0].toLowerCase();
|
|
1064
|
-
p[1] = p[1].toUpperCase();
|
|
1065
|
-
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize$1(p[1].toLowerCase());
|
|
1066
|
-
} else if (p.length === 3) {
|
|
1067
|
-
p[0] = p[0].toLowerCase();
|
|
1068
|
-
if (p[1].length === 2) p[1] = p[1].toUpperCase();
|
|
1069
|
-
if (p[0] !== 'sgn' && p[2].length === 2) p[2] = p[2].toUpperCase();
|
|
1070
|
-
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize$1(p[1].toLowerCase());
|
|
1071
|
-
if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize$1(p[2].toLowerCase());
|
|
1072
|
-
}
|
|
1073
|
-
return p.join('-');
|
|
1074
|
-
}
|
|
1075
|
-
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
1076
|
-
}
|
|
1077
|
-
}, {
|
|
1078
|
-
key: "isSupportedCode",
|
|
1079
|
-
value: function isSupportedCode(code) {
|
|
1080
|
-
if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
|
|
1081
|
-
code = this.getLanguagePartFromCode(code);
|
|
1082
|
-
}
|
|
1083
|
-
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
1084
|
-
}
|
|
1085
|
-
}, {
|
|
1086
|
-
key: "getBestMatchFromCodes",
|
|
1087
|
-
value: function getBestMatchFromCodes(codes) {
|
|
1088
|
-
var _this = this;
|
|
1089
|
-
if (!codes) return null;
|
|
1090
|
-
var found;
|
|
1091
|
-
codes.forEach(function (code) {
|
|
1092
|
-
if (found) return;
|
|
1093
|
-
var cleanedLng = _this.formatLanguageCode(code);
|
|
1094
|
-
if (!_this.options.supportedLngs || _this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
1095
|
-
});
|
|
1096
|
-
if (!found && this.options.supportedLngs) {
|
|
1097
|
-
codes.forEach(function (code) {
|
|
1098
|
-
if (found) return;
|
|
1099
|
-
var lngOnly = _this.getLanguagePartFromCode(code);
|
|
1100
|
-
if (_this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
1101
|
-
found = _this.options.supportedLngs.find(function (supportedLng) {
|
|
1102
|
-
if (supportedLng === lngOnly) return supportedLng;
|
|
1103
|
-
if (supportedLng.indexOf('-') < 0 && lngOnly.indexOf('-') < 0) return;
|
|
1104
|
-
if (supportedLng.indexOf(lngOnly) === 0) return supportedLng;
|
|
1105
|
-
});
|
|
1106
|
-
});
|
|
1107
|
-
}
|
|
1108
|
-
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
1109
|
-
return found;
|
|
1110
|
-
}
|
|
1111
|
-
}, {
|
|
1112
|
-
key: "getFallbackCodes",
|
|
1113
|
-
value: function getFallbackCodes(fallbacks, code) {
|
|
1114
|
-
if (!fallbacks) return [];
|
|
1115
|
-
if (typeof fallbacks === 'function') fallbacks = fallbacks(code);
|
|
1116
|
-
if (typeof fallbacks === 'string') fallbacks = [fallbacks];
|
|
1117
|
-
if (Object.prototype.toString.apply(fallbacks) === '[object Array]') return fallbacks;
|
|
1118
|
-
if (!code) return fallbacks["default"] || [];
|
|
1119
|
-
var found = fallbacks[code];
|
|
1120
|
-
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
1121
|
-
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
1122
|
-
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
1123
|
-
if (!found) found = fallbacks["default"];
|
|
1124
|
-
return found || [];
|
|
1125
|
-
}
|
|
1126
|
-
}, {
|
|
1127
|
-
key: "toResolveHierarchy",
|
|
1128
|
-
value: function toResolveHierarchy(code, fallbackCode) {
|
|
1129
|
-
var _this2 = this;
|
|
1130
|
-
var fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
1131
|
-
var codes = [];
|
|
1132
|
-
var addCode = function addCode(c) {
|
|
1133
|
-
if (!c) return;
|
|
1134
|
-
if (_this2.isSupportedCode(c)) {
|
|
1135
|
-
codes.push(c);
|
|
1136
|
-
} else {
|
|
1137
|
-
_this2.logger.warn("rejecting language code not found in supportedLngs: ".concat(c));
|
|
1138
|
-
}
|
|
1139
|
-
};
|
|
1140
|
-
if (typeof code === 'string' && code.indexOf('-') > -1) {
|
|
1141
|
-
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
|
|
1142
|
-
if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
|
|
1143
|
-
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
|
|
1144
|
-
} else if (typeof code === 'string') {
|
|
1145
|
-
addCode(this.formatLanguageCode(code));
|
|
1146
|
-
}
|
|
1147
|
-
fallbackCodes.forEach(function (fc) {
|
|
1148
|
-
if (codes.indexOf(fc) < 0) addCode(_this2.formatLanguageCode(fc));
|
|
1149
|
-
});
|
|
1150
|
-
return codes;
|
|
1151
|
-
}
|
|
1152
|
-
}]);
|
|
1153
|
-
return LanguageUtil;
|
|
1154
|
-
}();
|
|
1155
|
-
|
|
1156
|
-
var sets = [{
|
|
1157
|
-
lngs: ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'gun', 'ln', 'mfe', 'mg', 'mi', 'oc', 'pt', 'pt-BR', 'tg', 'tl', 'ti', 'tr', 'uz', 'wa'],
|
|
1158
|
-
nr: [1, 2],
|
|
1159
|
-
fc: 1
|
|
1160
|
-
}, {
|
|
1161
|
-
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'],
|
|
1162
|
-
nr: [1, 2],
|
|
1163
|
-
fc: 2
|
|
1164
|
-
}, {
|
|
1165
|
-
lngs: ['ay', 'bo', 'cgg', 'fa', 'ht', 'id', 'ja', 'jbo', 'ka', 'km', 'ko', 'ky', 'lo', 'ms', 'sah', 'su', 'th', 'tt', 'ug', 'vi', 'wo', 'zh'],
|
|
1166
|
-
nr: [1],
|
|
1167
|
-
fc: 3
|
|
1168
|
-
}, {
|
|
1169
|
-
lngs: ['be', 'bs', 'cnr', 'dz', 'hr', 'ru', 'sr', 'uk'],
|
|
1170
|
-
nr: [1, 2, 5],
|
|
1171
|
-
fc: 4
|
|
1172
|
-
}, {
|
|
1173
|
-
lngs: ['ar'],
|
|
1174
|
-
nr: [0, 1, 2, 3, 11, 100],
|
|
1175
|
-
fc: 5
|
|
1176
|
-
}, {
|
|
1177
|
-
lngs: ['cs', 'sk'],
|
|
1178
|
-
nr: [1, 2, 5],
|
|
1179
|
-
fc: 6
|
|
1180
|
-
}, {
|
|
1181
|
-
lngs: ['csb', 'pl'],
|
|
1182
|
-
nr: [1, 2, 5],
|
|
1183
|
-
fc: 7
|
|
1184
|
-
}, {
|
|
1185
|
-
lngs: ['cy'],
|
|
1186
|
-
nr: [1, 2, 3, 8],
|
|
1187
|
-
fc: 8
|
|
1188
|
-
}, {
|
|
1189
|
-
lngs: ['fr'],
|
|
1190
|
-
nr: [1, 2],
|
|
1191
|
-
fc: 9
|
|
1192
|
-
}, {
|
|
1193
|
-
lngs: ['ga'],
|
|
1194
|
-
nr: [1, 2, 3, 7, 11],
|
|
1195
|
-
fc: 10
|
|
1196
|
-
}, {
|
|
1197
|
-
lngs: ['gd'],
|
|
1198
|
-
nr: [1, 2, 3, 20],
|
|
1199
|
-
fc: 11
|
|
1200
|
-
}, {
|
|
1201
|
-
lngs: ['is'],
|
|
1202
|
-
nr: [1, 2],
|
|
1203
|
-
fc: 12
|
|
1204
|
-
}, {
|
|
1205
|
-
lngs: ['jv'],
|
|
1206
|
-
nr: [0, 1],
|
|
1207
|
-
fc: 13
|
|
1208
|
-
}, {
|
|
1209
|
-
lngs: ['kw'],
|
|
1210
|
-
nr: [1, 2, 3, 4],
|
|
1211
|
-
fc: 14
|
|
1212
|
-
}, {
|
|
1213
|
-
lngs: ['lt'],
|
|
1214
|
-
nr: [1, 2, 10],
|
|
1215
|
-
fc: 15
|
|
1216
|
-
}, {
|
|
1217
|
-
lngs: ['lv'],
|
|
1218
|
-
nr: [1, 2, 0],
|
|
1219
|
-
fc: 16
|
|
1220
|
-
}, {
|
|
1221
|
-
lngs: ['mk'],
|
|
1222
|
-
nr: [1, 2],
|
|
1223
|
-
fc: 17
|
|
1224
|
-
}, {
|
|
1225
|
-
lngs: ['mnk'],
|
|
1226
|
-
nr: [0, 1, 2],
|
|
1227
|
-
fc: 18
|
|
1228
|
-
}, {
|
|
1229
|
-
lngs: ['mt'],
|
|
1230
|
-
nr: [1, 2, 11, 20],
|
|
1231
|
-
fc: 19
|
|
1232
|
-
}, {
|
|
1233
|
-
lngs: ['or'],
|
|
1234
|
-
nr: [2, 1],
|
|
1235
|
-
fc: 2
|
|
1236
|
-
}, {
|
|
1237
|
-
lngs: ['ro'],
|
|
1238
|
-
nr: [1, 2, 20],
|
|
1239
|
-
fc: 20
|
|
1240
|
-
}, {
|
|
1241
|
-
lngs: ['sl'],
|
|
1242
|
-
nr: [5, 1, 2, 3],
|
|
1243
|
-
fc: 21
|
|
1244
|
-
}, {
|
|
1245
|
-
lngs: ['he', 'iw'],
|
|
1246
|
-
nr: [1, 2, 20, 21],
|
|
1247
|
-
fc: 22
|
|
1248
|
-
}];
|
|
1249
|
-
var _rulesPluralsTypes = {
|
|
1250
|
-
1: function _(n) {
|
|
1251
|
-
return Number(n > 1);
|
|
1252
|
-
},
|
|
1253
|
-
2: function _(n) {
|
|
1254
|
-
return Number(n != 1);
|
|
1255
|
-
},
|
|
1256
|
-
3: function _(n) {
|
|
1257
|
-
return 0;
|
|
1258
|
-
},
|
|
1259
|
-
4: function _(n) {
|
|
1260
|
-
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1261
|
-
},
|
|
1262
|
-
5: function _(n) {
|
|
1263
|
-
return Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5);
|
|
1264
|
-
},
|
|
1265
|
-
6: function _(n) {
|
|
1266
|
-
return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2);
|
|
1267
|
-
},
|
|
1268
|
-
7: function _(n) {
|
|
1269
|
-
return Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1270
|
-
},
|
|
1271
|
-
8: function _(n) {
|
|
1272
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3);
|
|
1273
|
-
},
|
|
1274
|
-
9: function _(n) {
|
|
1275
|
-
return Number(n >= 2);
|
|
1276
|
-
},
|
|
1277
|
-
10: function _(n) {
|
|
1278
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4);
|
|
1279
|
-
},
|
|
1280
|
-
11: function _(n) {
|
|
1281
|
-
return Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3);
|
|
1282
|
-
},
|
|
1283
|
-
12: function _(n) {
|
|
1284
|
-
return Number(n % 10 != 1 || n % 100 == 11);
|
|
1285
|
-
},
|
|
1286
|
-
13: function _(n) {
|
|
1287
|
-
return Number(n !== 0);
|
|
1288
|
-
},
|
|
1289
|
-
14: function _(n) {
|
|
1290
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3);
|
|
1291
|
-
},
|
|
1292
|
-
15: function _(n) {
|
|
1293
|
-
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1294
|
-
},
|
|
1295
|
-
16: function _(n) {
|
|
1296
|
-
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2);
|
|
1297
|
-
},
|
|
1298
|
-
17: function _(n) {
|
|
1299
|
-
return Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1);
|
|
1300
|
-
},
|
|
1301
|
-
18: function _(n) {
|
|
1302
|
-
return Number(n == 0 ? 0 : n == 1 ? 1 : 2);
|
|
1303
|
-
},
|
|
1304
|
-
19: function _(n) {
|
|
1305
|
-
return Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3);
|
|
1306
|
-
},
|
|
1307
|
-
20: function _(n) {
|
|
1308
|
-
return Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2);
|
|
1309
|
-
},
|
|
1310
|
-
21: function _(n) {
|
|
1311
|
-
return Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0);
|
|
1312
|
-
},
|
|
1313
|
-
22: function _(n) {
|
|
1314
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3);
|
|
1315
|
-
}
|
|
1316
|
-
};
|
|
1317
|
-
var deprecatedJsonVersions = ['v1', 'v2', 'v3'];
|
|
1318
|
-
var suffixesOrder = {
|
|
1319
|
-
zero: 0,
|
|
1320
|
-
one: 1,
|
|
1321
|
-
two: 2,
|
|
1322
|
-
few: 3,
|
|
1323
|
-
many: 4,
|
|
1324
|
-
other: 5
|
|
1325
|
-
};
|
|
1326
|
-
function createRules() {
|
|
1327
|
-
var rules = {};
|
|
1328
|
-
sets.forEach(function (set) {
|
|
1329
|
-
set.lngs.forEach(function (l) {
|
|
1330
|
-
rules[l] = {
|
|
1331
|
-
numbers: set.nr,
|
|
1332
|
-
plurals: _rulesPluralsTypes[set.fc]
|
|
1333
|
-
};
|
|
1334
|
-
});
|
|
1335
|
-
});
|
|
1336
|
-
return rules;
|
|
1337
|
-
}
|
|
1338
|
-
var PluralResolver = function () {
|
|
1339
|
-
function PluralResolver(languageUtils) {
|
|
1340
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1341
|
-
_classCallCheck$2(this, PluralResolver);
|
|
1342
|
-
this.languageUtils = languageUtils;
|
|
1343
|
-
this.options = options;
|
|
1344
|
-
this.logger = baseLogger.create('pluralResolver');
|
|
1345
|
-
if ((!this.options.compatibilityJSON || this.options.compatibilityJSON === 'v4') && (typeof Intl === 'undefined' || !Intl.PluralRules)) {
|
|
1346
|
-
this.options.compatibilityJSON = 'v3';
|
|
1347
|
-
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.');
|
|
1348
|
-
}
|
|
1349
|
-
this.rules = createRules();
|
|
1350
|
-
}
|
|
1351
|
-
_createClass$2(PluralResolver, [{
|
|
1352
|
-
key: "addRule",
|
|
1353
|
-
value: function addRule(lng, obj) {
|
|
1354
|
-
this.rules[lng] = obj;
|
|
1355
|
-
}
|
|
1356
|
-
}, {
|
|
1357
|
-
key: "getRule",
|
|
1358
|
-
value: function getRule(code) {
|
|
1359
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1360
|
-
if (this.shouldUseIntlApi()) {
|
|
1361
|
-
try {
|
|
1362
|
-
return new Intl.PluralRules(code, {
|
|
1363
|
-
type: options.ordinal ? 'ordinal' : 'cardinal'
|
|
1364
|
-
});
|
|
1365
|
-
} catch (_unused) {
|
|
1366
|
-
return;
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
|
|
1370
|
-
}
|
|
1371
|
-
}, {
|
|
1372
|
-
key: "needsPlural",
|
|
1373
|
-
value: function needsPlural(code) {
|
|
1374
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1375
|
-
var rule = this.getRule(code, options);
|
|
1376
|
-
if (this.shouldUseIntlApi()) {
|
|
1377
|
-
return rule && rule.resolvedOptions().pluralCategories.length > 1;
|
|
1378
|
-
}
|
|
1379
|
-
return rule && rule.numbers.length > 1;
|
|
1380
|
-
}
|
|
1381
|
-
}, {
|
|
1382
|
-
key: "getPluralFormsOfKey",
|
|
1383
|
-
value: function getPluralFormsOfKey(code, key) {
|
|
1384
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1385
|
-
return this.getSuffixes(code, options).map(function (suffix) {
|
|
1386
|
-
return "".concat(key).concat(suffix);
|
|
1387
|
-
});
|
|
1388
|
-
}
|
|
1389
|
-
}, {
|
|
1390
|
-
key: "getSuffixes",
|
|
1391
|
-
value: function getSuffixes(code) {
|
|
1392
|
-
var _this = this;
|
|
1393
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1394
|
-
var rule = this.getRule(code, options);
|
|
1395
|
-
if (!rule) {
|
|
1396
|
-
return [];
|
|
1397
|
-
}
|
|
1398
|
-
if (this.shouldUseIntlApi()) {
|
|
1399
|
-
return rule.resolvedOptions().pluralCategories.sort(function (pluralCategory1, pluralCategory2) {
|
|
1400
|
-
return suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2];
|
|
1401
|
-
}).map(function (pluralCategory) {
|
|
1402
|
-
return "".concat(_this.options.prepend).concat(pluralCategory);
|
|
1403
|
-
});
|
|
1404
|
-
}
|
|
1405
|
-
return rule.numbers.map(function (number) {
|
|
1406
|
-
return _this.getSuffix(code, number, options);
|
|
1407
|
-
});
|
|
1408
|
-
}
|
|
1409
|
-
}, {
|
|
1410
|
-
key: "getSuffix",
|
|
1411
|
-
value: function getSuffix(code, count) {
|
|
1412
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1413
|
-
var rule = this.getRule(code, options);
|
|
1414
|
-
if (rule) {
|
|
1415
|
-
if (this.shouldUseIntlApi()) {
|
|
1416
|
-
return "".concat(this.options.prepend).concat(rule.select(count));
|
|
1417
|
-
}
|
|
1418
|
-
return this.getSuffixRetroCompatible(rule, count);
|
|
1419
|
-
}
|
|
1420
|
-
this.logger.warn("no plural rule found for: ".concat(code));
|
|
1421
|
-
return '';
|
|
1422
|
-
}
|
|
1423
|
-
}, {
|
|
1424
|
-
key: "getSuffixRetroCompatible",
|
|
1425
|
-
value: function getSuffixRetroCompatible(rule, count) {
|
|
1426
|
-
var _this2 = this;
|
|
1427
|
-
var idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
|
|
1428
|
-
var suffix = rule.numbers[idx];
|
|
1429
|
-
if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1430
|
-
if (suffix === 2) {
|
|
1431
|
-
suffix = 'plural';
|
|
1432
|
-
} else if (suffix === 1) {
|
|
1433
|
-
suffix = '';
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
var returnSuffix = function returnSuffix() {
|
|
1437
|
-
return _this2.options.prepend && suffix.toString() ? _this2.options.prepend + suffix.toString() : suffix.toString();
|
|
1438
|
-
};
|
|
1439
|
-
if (this.options.compatibilityJSON === 'v1') {
|
|
1440
|
-
if (suffix === 1) return '';
|
|
1441
|
-
if (typeof suffix === 'number') return "_plural_".concat(suffix.toString());
|
|
1442
|
-
return returnSuffix();
|
|
1443
|
-
} else if (this.options.compatibilityJSON === 'v2') {
|
|
1444
|
-
return returnSuffix();
|
|
1445
|
-
} else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1446
|
-
return returnSuffix();
|
|
1447
|
-
}
|
|
1448
|
-
return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
|
|
1449
|
-
}
|
|
1450
|
-
}, {
|
|
1451
|
-
key: "shouldUseIntlApi",
|
|
1452
|
-
value: function shouldUseIntlApi() {
|
|
1453
|
-
return !deprecatedJsonVersions.includes(this.options.compatibilityJSON);
|
|
1454
|
-
}
|
|
1455
|
-
}]);
|
|
1456
|
-
return PluralResolver;
|
|
1457
|
-
}();
|
|
1458
|
-
|
|
1459
|
-
function ownKeys$3$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; }
|
|
1460
|
-
function _objectSpread$3$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$3$1(Object(source), !0).forEach(function (key) { _defineProperty$2(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$3$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
1461
|
-
function deepFindWithDefaults(data, defaultData, key) {
|
|
1462
|
-
var keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
|
|
1463
|
-
var ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
1464
|
-
var path = getPathWithDefaults(data, defaultData, key);
|
|
1465
|
-
if (!path && ignoreJSONStructure && typeof key === 'string') {
|
|
1466
|
-
path = deepFind(data, key, keySeparator);
|
|
1467
|
-
if (path === undefined) path = deepFind(defaultData, key, keySeparator);
|
|
1468
|
-
}
|
|
1469
|
-
return path;
|
|
1470
|
-
}
|
|
1471
|
-
var Interpolator = function () {
|
|
1472
|
-
function Interpolator() {
|
|
1473
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1474
|
-
_classCallCheck$2(this, Interpolator);
|
|
1475
|
-
this.logger = baseLogger.create('interpolator');
|
|
1476
|
-
this.options = options;
|
|
1477
|
-
this.format = options.interpolation && options.interpolation.format || function (value) {
|
|
1478
|
-
return value;
|
|
1479
|
-
};
|
|
1480
|
-
this.init(options);
|
|
1481
|
-
}
|
|
1482
|
-
_createClass$2(Interpolator, [{
|
|
1483
|
-
key: "init",
|
|
1484
|
-
value: function init() {
|
|
1485
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1486
|
-
if (!options.interpolation) options.interpolation = {
|
|
1487
|
-
escapeValue: true
|
|
1488
|
-
};
|
|
1489
|
-
var iOpts = options.interpolation;
|
|
1490
|
-
this.escape = iOpts.escape !== undefined ? iOpts.escape : escape;
|
|
1491
|
-
this.escapeValue = iOpts.escapeValue !== undefined ? iOpts.escapeValue : true;
|
|
1492
|
-
this.useRawValueToEscape = iOpts.useRawValueToEscape !== undefined ? iOpts.useRawValueToEscape : false;
|
|
1493
|
-
this.prefix = iOpts.prefix ? regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{';
|
|
1494
|
-
this.suffix = iOpts.suffix ? regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}';
|
|
1495
|
-
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
|
|
1496
|
-
this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-';
|
|
1497
|
-
this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || '';
|
|
1498
|
-
this.nestingPrefix = iOpts.nestingPrefix ? regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || regexEscape('$t(');
|
|
1499
|
-
this.nestingSuffix = iOpts.nestingSuffix ? regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || regexEscape(')');
|
|
1500
|
-
this.nestingOptionsSeparator = iOpts.nestingOptionsSeparator ? iOpts.nestingOptionsSeparator : iOpts.nestingOptionsSeparator || ',';
|
|
1501
|
-
this.maxReplaces = iOpts.maxReplaces ? iOpts.maxReplaces : 1000;
|
|
1502
|
-
this.alwaysFormat = iOpts.alwaysFormat !== undefined ? iOpts.alwaysFormat : false;
|
|
1503
|
-
this.resetRegExp();
|
|
1504
|
-
}
|
|
1505
|
-
}, {
|
|
1506
|
-
key: "reset",
|
|
1507
|
-
value: function reset() {
|
|
1508
|
-
if (this.options) this.init(this.options);
|
|
1509
|
-
}
|
|
1510
|
-
}, {
|
|
1511
|
-
key: "resetRegExp",
|
|
1512
|
-
value: function resetRegExp() {
|
|
1513
|
-
var regexpStr = "".concat(this.prefix, "(.+?)").concat(this.suffix);
|
|
1514
|
-
this.regexp = new RegExp(regexpStr, 'g');
|
|
1515
|
-
var regexpUnescapeStr = "".concat(this.prefix).concat(this.unescapePrefix, "(.+?)").concat(this.unescapeSuffix).concat(this.suffix);
|
|
1516
|
-
this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g');
|
|
1517
|
-
var nestingRegexpStr = "".concat(this.nestingPrefix, "(.+?)").concat(this.nestingSuffix);
|
|
1518
|
-
this.nestingRegexp = new RegExp(nestingRegexpStr, 'g');
|
|
1519
|
-
}
|
|
1520
|
-
}, {
|
|
1521
|
-
key: "interpolate",
|
|
1522
|
-
value: function interpolate(str, data, lng, options) {
|
|
1523
|
-
var _this = this;
|
|
1524
|
-
var match;
|
|
1525
|
-
var value;
|
|
1526
|
-
var replaces;
|
|
1527
|
-
var defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
1528
|
-
function regexSafe(val) {
|
|
1529
|
-
return val.replace(/\$/g, '$$$$');
|
|
1530
|
-
}
|
|
1531
|
-
var handleFormat = function handleFormat(key) {
|
|
1532
|
-
if (key.indexOf(_this.formatSeparator) < 0) {
|
|
1533
|
-
var path = deepFindWithDefaults(data, defaultData, key, _this.options.keySeparator, _this.options.ignoreJSONStructure);
|
|
1534
|
-
return _this.alwaysFormat ? _this.format(path, undefined, lng, _objectSpread$3$1(_objectSpread$3$1(_objectSpread$3$1({}, options), data), {}, {
|
|
1535
|
-
interpolationkey: key
|
|
1536
|
-
})) : path;
|
|
1537
|
-
}
|
|
1538
|
-
var p = key.split(_this.formatSeparator);
|
|
1539
|
-
var k = p.shift().trim();
|
|
1540
|
-
var f = p.join(_this.formatSeparator).trim();
|
|
1541
|
-
return _this.format(deepFindWithDefaults(data, defaultData, k, _this.options.keySeparator, _this.options.ignoreJSONStructure), f, lng, _objectSpread$3$1(_objectSpread$3$1(_objectSpread$3$1({}, options), data), {}, {
|
|
1542
|
-
interpolationkey: k
|
|
1543
|
-
}));
|
|
1544
|
-
};
|
|
1545
|
-
this.resetRegExp();
|
|
1546
|
-
var missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
1547
|
-
var skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
1548
|
-
var todos = [{
|
|
1549
|
-
regex: this.regexpUnescape,
|
|
1550
|
-
safeValue: function safeValue(val) {
|
|
1551
|
-
return regexSafe(val);
|
|
1552
|
-
}
|
|
1553
|
-
}, {
|
|
1554
|
-
regex: this.regexp,
|
|
1555
|
-
safeValue: function safeValue(val) {
|
|
1556
|
-
return _this.escapeValue ? regexSafe(_this.escape(val)) : regexSafe(val);
|
|
1557
|
-
}
|
|
1558
|
-
}];
|
|
1559
|
-
todos.forEach(function (todo) {
|
|
1560
|
-
replaces = 0;
|
|
1561
|
-
while (match = todo.regex.exec(str)) {
|
|
1562
|
-
var matchedVar = match[1].trim();
|
|
1563
|
-
value = handleFormat(matchedVar);
|
|
1564
|
-
if (value === undefined) {
|
|
1565
|
-
if (typeof missingInterpolationHandler === 'function') {
|
|
1566
|
-
var temp = missingInterpolationHandler(str, match, options);
|
|
1567
|
-
value = typeof temp === 'string' ? temp : '';
|
|
1568
|
-
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
|
|
1569
|
-
value = '';
|
|
1570
|
-
} else if (skipOnVariables) {
|
|
1571
|
-
value = match[0];
|
|
1572
|
-
continue;
|
|
1573
|
-
} else {
|
|
1574
|
-
_this.logger.warn("missed to pass in variable ".concat(matchedVar, " for interpolating ").concat(str));
|
|
1575
|
-
value = '';
|
|
1576
|
-
}
|
|
1577
|
-
} else if (typeof value !== 'string' && !_this.useRawValueToEscape) {
|
|
1578
|
-
value = makeString(value);
|
|
1579
|
-
}
|
|
1580
|
-
var safeValue = todo.safeValue(value);
|
|
1581
|
-
str = str.replace(match[0], safeValue);
|
|
1582
|
-
if (skipOnVariables) {
|
|
1583
|
-
todo.regex.lastIndex += value.length;
|
|
1584
|
-
todo.regex.lastIndex -= match[0].length;
|
|
1585
|
-
} else {
|
|
1586
|
-
todo.regex.lastIndex = 0;
|
|
1587
|
-
}
|
|
1588
|
-
replaces++;
|
|
1589
|
-
if (replaces >= _this.maxReplaces) {
|
|
1590
|
-
break;
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1593
|
-
});
|
|
1594
|
-
return str;
|
|
1595
|
-
}
|
|
1596
|
-
}, {
|
|
1597
|
-
key: "nest",
|
|
1598
|
-
value: function nest(str, fc) {
|
|
1599
|
-
var _this2 = this;
|
|
1600
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1601
|
-
var match;
|
|
1602
|
-
var value;
|
|
1603
|
-
var clonedOptions;
|
|
1604
|
-
function handleHasOptions(key, inheritedOptions) {
|
|
1605
|
-
var sep = this.nestingOptionsSeparator;
|
|
1606
|
-
if (key.indexOf(sep) < 0) return key;
|
|
1607
|
-
var c = key.split(new RegExp("".concat(sep, "[ ]*{")));
|
|
1608
|
-
var optionsString = "{".concat(c[1]);
|
|
1609
|
-
key = c[0];
|
|
1610
|
-
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
1611
|
-
var matchedSingleQuotes = optionsString.match(/'/g);
|
|
1612
|
-
var matchedDoubleQuotes = optionsString.match(/"/g);
|
|
1613
|
-
if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
|
|
1614
|
-
optionsString = optionsString.replace(/'/g, '"');
|
|
1615
|
-
}
|
|
1616
|
-
try {
|
|
1617
|
-
clonedOptions = JSON.parse(optionsString);
|
|
1618
|
-
if (inheritedOptions) clonedOptions = _objectSpread$3$1(_objectSpread$3$1({}, inheritedOptions), clonedOptions);
|
|
1619
|
-
} catch (e) {
|
|
1620
|
-
this.logger.warn("failed parsing options string in nesting for key ".concat(key), e);
|
|
1621
|
-
return "".concat(key).concat(sep).concat(optionsString);
|
|
1622
|
-
}
|
|
1623
|
-
delete clonedOptions.defaultValue;
|
|
1624
|
-
return key;
|
|
1625
|
-
}
|
|
1626
|
-
while (match = this.nestingRegexp.exec(str)) {
|
|
1627
|
-
var formatters = [];
|
|
1628
|
-
clonedOptions = _objectSpread$3$1({}, options);
|
|
1629
|
-
clonedOptions = clonedOptions.replace && typeof clonedOptions.replace !== 'string' ? clonedOptions.replace : clonedOptions;
|
|
1630
|
-
clonedOptions.applyPostProcessor = false;
|
|
1631
|
-
delete clonedOptions.defaultValue;
|
|
1632
|
-
var doReduce = false;
|
|
1633
|
-
if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
|
|
1634
|
-
var r = match[1].split(this.formatSeparator).map(function (elem) {
|
|
1635
|
-
return elem.trim();
|
|
1636
|
-
});
|
|
1637
|
-
match[1] = r.shift();
|
|
1638
|
-
formatters = r;
|
|
1639
|
-
doReduce = true;
|
|
1640
|
-
}
|
|
1641
|
-
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
1642
|
-
if (value && match[0] === str && typeof value !== 'string') return value;
|
|
1643
|
-
if (typeof value !== 'string') value = makeString(value);
|
|
1644
|
-
if (!value) {
|
|
1645
|
-
this.logger.warn("missed to resolve ".concat(match[1], " for nesting ").concat(str));
|
|
1646
|
-
value = '';
|
|
1647
|
-
}
|
|
1648
|
-
if (doReduce) {
|
|
1649
|
-
value = formatters.reduce(function (v, f) {
|
|
1650
|
-
return _this2.format(v, f, options.lng, _objectSpread$3$1(_objectSpread$3$1({}, options), {}, {
|
|
1651
|
-
interpolationkey: match[1].trim()
|
|
1652
|
-
}));
|
|
1653
|
-
}, value.trim());
|
|
1654
|
-
}
|
|
1655
|
-
str = str.replace(match[0], value);
|
|
1656
|
-
this.regexp.lastIndex = 0;
|
|
1657
|
-
}
|
|
1658
|
-
return str;
|
|
1659
|
-
}
|
|
1660
|
-
}]);
|
|
1661
|
-
return Interpolator;
|
|
1662
|
-
}();
|
|
1663
|
-
|
|
1664
|
-
function ownKeys$2$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; }
|
|
1665
|
-
function _objectSpread$2$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$2$1(Object(source), !0).forEach(function (key) { _defineProperty$2(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
1666
|
-
function parseFormatStr(formatStr) {
|
|
1667
|
-
var formatName = formatStr.toLowerCase().trim();
|
|
1668
|
-
var formatOptions = {};
|
|
1669
|
-
if (formatStr.indexOf('(') > -1) {
|
|
1670
|
-
var p = formatStr.split('(');
|
|
1671
|
-
formatName = p[0].toLowerCase().trim();
|
|
1672
|
-
var optStr = p[1].substring(0, p[1].length - 1);
|
|
1673
|
-
if (formatName === 'currency' && optStr.indexOf(':') < 0) {
|
|
1674
|
-
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
1675
|
-
} else if (formatName === 'relativetime' && optStr.indexOf(':') < 0) {
|
|
1676
|
-
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
1677
|
-
} else {
|
|
1678
|
-
var opts = optStr.split(';');
|
|
1679
|
-
opts.forEach(function (opt) {
|
|
1680
|
-
if (!opt) return;
|
|
1681
|
-
var _opt$split = opt.split(':'),
|
|
1682
|
-
_opt$split2 = _toArray(_opt$split),
|
|
1683
|
-
key = _opt$split2[0],
|
|
1684
|
-
rest = _opt$split2.slice(1);
|
|
1685
|
-
var val = rest.join(':').trim().replace(/^'+|'+$/g, '');
|
|
1686
|
-
if (!formatOptions[key.trim()]) formatOptions[key.trim()] = val;
|
|
1687
|
-
if (val === 'false') formatOptions[key.trim()] = false;
|
|
1688
|
-
if (val === 'true') formatOptions[key.trim()] = true;
|
|
1689
|
-
if (!isNaN(val)) formatOptions[key.trim()] = parseInt(val, 10);
|
|
1690
|
-
});
|
|
1691
|
-
}
|
|
1692
|
-
}
|
|
1693
|
-
return {
|
|
1694
|
-
formatName: formatName,
|
|
1695
|
-
formatOptions: formatOptions
|
|
1696
|
-
};
|
|
1697
|
-
}
|
|
1698
|
-
function createCachedFormatter(fn) {
|
|
1699
|
-
var cache = {};
|
|
1700
|
-
return function invokeFormatter(val, lng, options) {
|
|
1701
|
-
var key = lng + JSON.stringify(options);
|
|
1702
|
-
var formatter = cache[key];
|
|
1703
|
-
if (!formatter) {
|
|
1704
|
-
formatter = fn(lng, options);
|
|
1705
|
-
cache[key] = formatter;
|
|
1706
|
-
}
|
|
1707
|
-
return formatter(val);
|
|
1708
|
-
};
|
|
1709
|
-
}
|
|
1710
|
-
var Formatter = function () {
|
|
1711
|
-
function Formatter() {
|
|
1712
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1713
|
-
_classCallCheck$2(this, Formatter);
|
|
1714
|
-
this.logger = baseLogger.create('formatter');
|
|
1715
|
-
this.options = options;
|
|
1716
|
-
this.formats = {
|
|
1717
|
-
number: createCachedFormatter(function (lng, opt) {
|
|
1718
|
-
var formatter = new Intl.NumberFormat(lng, _objectSpread$2$1({}, opt));
|
|
1719
|
-
return function (val) {
|
|
1720
|
-
return formatter.format(val);
|
|
1721
|
-
};
|
|
1722
|
-
}),
|
|
1723
|
-
currency: createCachedFormatter(function (lng, opt) {
|
|
1724
|
-
var formatter = new Intl.NumberFormat(lng, _objectSpread$2$1(_objectSpread$2$1({}, opt), {}, {
|
|
1725
|
-
style: 'currency'
|
|
1726
|
-
}));
|
|
1727
|
-
return function (val) {
|
|
1728
|
-
return formatter.format(val);
|
|
1729
|
-
};
|
|
1730
|
-
}),
|
|
1731
|
-
datetime: createCachedFormatter(function (lng, opt) {
|
|
1732
|
-
var formatter = new Intl.DateTimeFormat(lng, _objectSpread$2$1({}, opt));
|
|
1733
|
-
return function (val) {
|
|
1734
|
-
return formatter.format(val);
|
|
1735
|
-
};
|
|
1736
|
-
}),
|
|
1737
|
-
relativetime: createCachedFormatter(function (lng, opt) {
|
|
1738
|
-
var formatter = new Intl.RelativeTimeFormat(lng, _objectSpread$2$1({}, opt));
|
|
1739
|
-
return function (val) {
|
|
1740
|
-
return formatter.format(val, opt.range || 'day');
|
|
1741
|
-
};
|
|
1742
|
-
}),
|
|
1743
|
-
list: createCachedFormatter(function (lng, opt) {
|
|
1744
|
-
var formatter = new Intl.ListFormat(lng, _objectSpread$2$1({}, opt));
|
|
1745
|
-
return function (val) {
|
|
1746
|
-
return formatter.format(val);
|
|
1747
|
-
};
|
|
1748
|
-
})
|
|
1749
|
-
};
|
|
1750
|
-
this.init(options);
|
|
1751
|
-
}
|
|
1752
|
-
_createClass$2(Formatter, [{
|
|
1753
|
-
key: "init",
|
|
1754
|
-
value: function init(services) {
|
|
1755
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
1756
|
-
interpolation: {}
|
|
1757
|
-
};
|
|
1758
|
-
var iOpts = options.interpolation;
|
|
1759
|
-
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
|
|
1760
|
-
}
|
|
1761
|
-
}, {
|
|
1762
|
-
key: "add",
|
|
1763
|
-
value: function add(name, fc) {
|
|
1764
|
-
this.formats[name.toLowerCase().trim()] = fc;
|
|
1765
|
-
}
|
|
1766
|
-
}, {
|
|
1767
|
-
key: "addCached",
|
|
1768
|
-
value: function addCached(name, fc) {
|
|
1769
|
-
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
1770
|
-
}
|
|
1771
|
-
}, {
|
|
1772
|
-
key: "format",
|
|
1773
|
-
value: function format(value, _format, lng) {
|
|
1774
|
-
var _this = this;
|
|
1775
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1776
|
-
var formats = _format.split(this.formatSeparator);
|
|
1777
|
-
var result = formats.reduce(function (mem, f) {
|
|
1778
|
-
var _parseFormatStr = parseFormatStr(f),
|
|
1779
|
-
formatName = _parseFormatStr.formatName,
|
|
1780
|
-
formatOptions = _parseFormatStr.formatOptions;
|
|
1781
|
-
if (_this.formats[formatName]) {
|
|
1782
|
-
var formatted = mem;
|
|
1783
|
-
try {
|
|
1784
|
-
var valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
|
|
1785
|
-
var l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
1786
|
-
formatted = _this.formats[formatName](mem, l, _objectSpread$2$1(_objectSpread$2$1(_objectSpread$2$1({}, formatOptions), options), valOptions));
|
|
1787
|
-
} catch (error) {
|
|
1788
|
-
_this.logger.warn(error);
|
|
1789
|
-
}
|
|
1790
|
-
return formatted;
|
|
1791
|
-
} else {
|
|
1792
|
-
_this.logger.warn("there was no format function for ".concat(formatName));
|
|
1793
|
-
}
|
|
1794
|
-
return mem;
|
|
1795
|
-
}, value);
|
|
1796
|
-
return result;
|
|
1797
|
-
}
|
|
1798
|
-
}]);
|
|
1799
|
-
return Formatter;
|
|
1800
|
-
}();
|
|
1801
|
-
|
|
1802
|
-
function ownKeys$1$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; }
|
|
1803
|
-
function _objectSpread$1$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1$1(Object(source), !0).forEach(function (key) { _defineProperty$2(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
1804
|
-
function _createSuper$1(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$1(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
1805
|
-
function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
1806
|
-
function removePending(q, name) {
|
|
1807
|
-
if (q.pending[name] !== undefined) {
|
|
1808
|
-
delete q.pending[name];
|
|
1809
|
-
q.pendingCount--;
|
|
1810
|
-
}
|
|
1811
|
-
}
|
|
1812
|
-
var Connector = function (_EventEmitter) {
|
|
1813
|
-
_inherits(Connector, _EventEmitter);
|
|
1814
|
-
var _super = _createSuper$1(Connector);
|
|
1815
|
-
function Connector(backend, store, services) {
|
|
1816
|
-
var _this;
|
|
1817
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1818
|
-
_classCallCheck$2(this, Connector);
|
|
1819
|
-
_this = _super.call(this);
|
|
1820
|
-
if (isIE10) {
|
|
1821
|
-
EventEmitter.call(_assertThisInitialized(_this));
|
|
1822
|
-
}
|
|
1823
|
-
_this.backend = backend;
|
|
1824
|
-
_this.store = store;
|
|
1825
|
-
_this.services = services;
|
|
1826
|
-
_this.languageUtils = services.languageUtils;
|
|
1827
|
-
_this.options = options;
|
|
1828
|
-
_this.logger = baseLogger.create('backendConnector');
|
|
1829
|
-
_this.waitingReads = [];
|
|
1830
|
-
_this.maxParallelReads = options.maxParallelReads || 10;
|
|
1831
|
-
_this.readingCalls = 0;
|
|
1832
|
-
_this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
1833
|
-
_this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
1834
|
-
_this.state = {};
|
|
1835
|
-
_this.queue = [];
|
|
1836
|
-
if (_this.backend && _this.backend.init) {
|
|
1837
|
-
_this.backend.init(services, options.backend, options);
|
|
1838
|
-
}
|
|
1839
|
-
return _this;
|
|
1840
|
-
}
|
|
1841
|
-
_createClass$2(Connector, [{
|
|
1842
|
-
key: "queueLoad",
|
|
1843
|
-
value: function queueLoad(languages, namespaces, options, callback) {
|
|
1844
|
-
var _this2 = this;
|
|
1845
|
-
var toLoad = {};
|
|
1846
|
-
var pending = {};
|
|
1847
|
-
var toLoadLanguages = {};
|
|
1848
|
-
var toLoadNamespaces = {};
|
|
1849
|
-
languages.forEach(function (lng) {
|
|
1850
|
-
var hasAllNamespaces = true;
|
|
1851
|
-
namespaces.forEach(function (ns) {
|
|
1852
|
-
var name = "".concat(lng, "|").concat(ns);
|
|
1853
|
-
if (!options.reload && _this2.store.hasResourceBundle(lng, ns)) {
|
|
1854
|
-
_this2.state[name] = 2;
|
|
1855
|
-
} else if (_this2.state[name] < 0) ; else if (_this2.state[name] === 1) {
|
|
1856
|
-
if (pending[name] === undefined) pending[name] = true;
|
|
1857
|
-
} else {
|
|
1858
|
-
_this2.state[name] = 1;
|
|
1859
|
-
hasAllNamespaces = false;
|
|
1860
|
-
if (pending[name] === undefined) pending[name] = true;
|
|
1861
|
-
if (toLoad[name] === undefined) toLoad[name] = true;
|
|
1862
|
-
if (toLoadNamespaces[ns] === undefined) toLoadNamespaces[ns] = true;
|
|
1863
|
-
}
|
|
1864
|
-
});
|
|
1865
|
-
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
1866
|
-
});
|
|
1867
|
-
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
1868
|
-
this.queue.push({
|
|
1869
|
-
pending: pending,
|
|
1870
|
-
pendingCount: Object.keys(pending).length,
|
|
1871
|
-
loaded: {},
|
|
1872
|
-
errors: [],
|
|
1873
|
-
callback: callback
|
|
1874
|
-
});
|
|
1875
|
-
}
|
|
1876
|
-
return {
|
|
1877
|
-
toLoad: Object.keys(toLoad),
|
|
1878
|
-
pending: Object.keys(pending),
|
|
1879
|
-
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
1880
|
-
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
1881
|
-
};
|
|
1882
|
-
}
|
|
1883
|
-
}, {
|
|
1884
|
-
key: "loaded",
|
|
1885
|
-
value: function loaded(name, err, data) {
|
|
1886
|
-
var s = name.split('|');
|
|
1887
|
-
var lng = s[0];
|
|
1888
|
-
var ns = s[1];
|
|
1889
|
-
if (err) this.emit('failedLoading', lng, ns, err);
|
|
1890
|
-
if (data) {
|
|
1891
|
-
this.store.addResourceBundle(lng, ns, data);
|
|
1892
|
-
}
|
|
1893
|
-
this.state[name] = err ? -1 : 2;
|
|
1894
|
-
var loaded = {};
|
|
1895
|
-
this.queue.forEach(function (q) {
|
|
1896
|
-
pushPath(q.loaded, [lng], ns);
|
|
1897
|
-
removePending(q, name);
|
|
1898
|
-
if (err) q.errors.push(err);
|
|
1899
|
-
if (q.pendingCount === 0 && !q.done) {
|
|
1900
|
-
Object.keys(q.loaded).forEach(function (l) {
|
|
1901
|
-
if (!loaded[l]) loaded[l] = {};
|
|
1902
|
-
var loadedKeys = q.loaded[l];
|
|
1903
|
-
if (loadedKeys.length) {
|
|
1904
|
-
loadedKeys.forEach(function (n) {
|
|
1905
|
-
if (loaded[l][n] === undefined) loaded[l][n] = true;
|
|
1906
|
-
});
|
|
1907
|
-
}
|
|
1908
|
-
});
|
|
1909
|
-
q.done = true;
|
|
1910
|
-
if (q.errors.length) {
|
|
1911
|
-
q.callback(q.errors);
|
|
1912
|
-
} else {
|
|
1913
|
-
q.callback();
|
|
1914
|
-
}
|
|
1915
|
-
}
|
|
1916
|
-
});
|
|
1917
|
-
this.emit('loaded', loaded);
|
|
1918
|
-
this.queue = this.queue.filter(function (q) {
|
|
1919
|
-
return !q.done;
|
|
1920
|
-
});
|
|
1921
|
-
}
|
|
1922
|
-
}, {
|
|
1923
|
-
key: "read",
|
|
1924
|
-
value: function read(lng, ns, fcName) {
|
|
1925
|
-
var _this3 = this;
|
|
1926
|
-
var tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
1927
|
-
var wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
|
|
1928
|
-
var callback = arguments.length > 5 ? arguments[5] : undefined;
|
|
1929
|
-
if (!lng.length) return callback(null, {});
|
|
1930
|
-
if (this.readingCalls >= this.maxParallelReads) {
|
|
1931
|
-
this.waitingReads.push({
|
|
1932
|
-
lng: lng,
|
|
1933
|
-
ns: ns,
|
|
1934
|
-
fcName: fcName,
|
|
1935
|
-
tried: tried,
|
|
1936
|
-
wait: wait,
|
|
1937
|
-
callback: callback
|
|
1938
|
-
});
|
|
1939
|
-
return;
|
|
1940
|
-
}
|
|
1941
|
-
this.readingCalls++;
|
|
1942
|
-
var resolver = function resolver(err, data) {
|
|
1943
|
-
_this3.readingCalls--;
|
|
1944
|
-
if (_this3.waitingReads.length > 0) {
|
|
1945
|
-
var next = _this3.waitingReads.shift();
|
|
1946
|
-
_this3.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
1947
|
-
}
|
|
1948
|
-
if (err && data && tried < _this3.maxRetries) {
|
|
1949
|
-
setTimeout(function () {
|
|
1950
|
-
_this3.read.call(_this3, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
1951
|
-
}, wait);
|
|
1952
|
-
return;
|
|
1953
|
-
}
|
|
1954
|
-
callback(err, data);
|
|
1955
|
-
};
|
|
1956
|
-
var fc = this.backend[fcName].bind(this.backend);
|
|
1957
|
-
if (fc.length === 2) {
|
|
1958
|
-
try {
|
|
1959
|
-
var r = fc(lng, ns);
|
|
1960
|
-
if (r && typeof r.then === 'function') {
|
|
1961
|
-
r.then(function (data) {
|
|
1962
|
-
return resolver(null, data);
|
|
1963
|
-
})["catch"](resolver);
|
|
1964
|
-
} else {
|
|
1965
|
-
resolver(null, r);
|
|
1966
|
-
}
|
|
1967
|
-
} catch (err) {
|
|
1968
|
-
resolver(err);
|
|
1969
|
-
}
|
|
1970
|
-
return;
|
|
1971
|
-
}
|
|
1972
|
-
return fc(lng, ns, resolver);
|
|
1973
|
-
}
|
|
1974
|
-
}, {
|
|
1975
|
-
key: "prepareLoading",
|
|
1976
|
-
value: function prepareLoading(languages, namespaces) {
|
|
1977
|
-
var _this4 = this;
|
|
1978
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1979
|
-
var callback = arguments.length > 3 ? arguments[3] : undefined;
|
|
1980
|
-
if (!this.backend) {
|
|
1981
|
-
this.logger.warn('No backend was added via i18next.use. Will not load resources.');
|
|
1982
|
-
return callback && callback();
|
|
1983
|
-
}
|
|
1984
|
-
if (typeof languages === 'string') languages = this.languageUtils.toResolveHierarchy(languages);
|
|
1985
|
-
if (typeof namespaces === 'string') namespaces = [namespaces];
|
|
1986
|
-
var toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
1987
|
-
if (!toLoad.toLoad.length) {
|
|
1988
|
-
if (!toLoad.pending.length) callback();
|
|
1989
|
-
return null;
|
|
1990
|
-
}
|
|
1991
|
-
toLoad.toLoad.forEach(function (name) {
|
|
1992
|
-
_this4.loadOne(name);
|
|
1993
|
-
});
|
|
1994
|
-
}
|
|
1995
|
-
}, {
|
|
1996
|
-
key: "load",
|
|
1997
|
-
value: function load(languages, namespaces, callback) {
|
|
1998
|
-
this.prepareLoading(languages, namespaces, {}, callback);
|
|
1999
|
-
}
|
|
2000
|
-
}, {
|
|
2001
|
-
key: "reload",
|
|
2002
|
-
value: function reload(languages, namespaces, callback) {
|
|
2003
|
-
this.prepareLoading(languages, namespaces, {
|
|
2004
|
-
reload: true
|
|
2005
|
-
}, callback);
|
|
2006
|
-
}
|
|
2007
|
-
}, {
|
|
2008
|
-
key: "loadOne",
|
|
2009
|
-
value: function loadOne(name) {
|
|
2010
|
-
var _this5 = this;
|
|
2011
|
-
var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
2012
|
-
var s = name.split('|');
|
|
2013
|
-
var lng = s[0];
|
|
2014
|
-
var ns = s[1];
|
|
2015
|
-
this.read(lng, ns, 'read', undefined, undefined, function (err, data) {
|
|
2016
|
-
if (err) _this5.logger.warn("".concat(prefix, "loading namespace ").concat(ns, " for language ").concat(lng, " failed"), err);
|
|
2017
|
-
if (!err && data) _this5.logger.log("".concat(prefix, "loaded namespace ").concat(ns, " for language ").concat(lng), data);
|
|
2018
|
-
_this5.loaded(name, err, data);
|
|
2019
|
-
});
|
|
2020
|
-
}
|
|
2021
|
-
}, {
|
|
2022
|
-
key: "saveMissing",
|
|
2023
|
-
value: function saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
2024
|
-
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
2025
|
-
var clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : function () {};
|
|
2026
|
-
if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
|
|
2027
|
-
this.logger.warn("did not save key \"".concat(key, "\" as the namespace \"").concat(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!!!');
|
|
2028
|
-
return;
|
|
2029
|
-
}
|
|
2030
|
-
if (key === undefined || key === null || key === '') return;
|
|
2031
|
-
if (this.backend && this.backend.create) {
|
|
2032
|
-
var opts = _objectSpread$1$1(_objectSpread$1$1({}, options), {}, {
|
|
2033
|
-
isUpdate: isUpdate
|
|
2034
|
-
});
|
|
2035
|
-
var fc = this.backend.create.bind(this.backend);
|
|
2036
|
-
if (fc.length < 6) {
|
|
2037
|
-
try {
|
|
2038
|
-
var r;
|
|
2039
|
-
if (fc.length === 5) {
|
|
2040
|
-
r = fc(languages, namespace, key, fallbackValue, opts);
|
|
2041
|
-
} else {
|
|
2042
|
-
r = fc(languages, namespace, key, fallbackValue);
|
|
2043
|
-
}
|
|
2044
|
-
if (r && typeof r.then === 'function') {
|
|
2045
|
-
r.then(function (data) {
|
|
2046
|
-
return clb(null, data);
|
|
2047
|
-
})["catch"](clb);
|
|
2048
|
-
} else {
|
|
2049
|
-
clb(null, r);
|
|
2050
|
-
}
|
|
2051
|
-
} catch (err) {
|
|
2052
|
-
clb(err);
|
|
2053
|
-
}
|
|
2054
|
-
} else {
|
|
2055
|
-
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
if (!languages || !languages[0]) return;
|
|
2059
|
-
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
2060
|
-
}
|
|
2061
|
-
}]);
|
|
2062
|
-
return Connector;
|
|
2063
|
-
}(EventEmitter);
|
|
2064
|
-
|
|
2065
|
-
function get() {
|
|
2066
|
-
return {
|
|
2067
|
-
debug: false,
|
|
2068
|
-
initImmediate: true,
|
|
2069
|
-
ns: ['translation'],
|
|
2070
|
-
defaultNS: ['translation'],
|
|
2071
|
-
fallbackLng: ['dev'],
|
|
2072
|
-
fallbackNS: false,
|
|
2073
|
-
supportedLngs: false,
|
|
2074
|
-
nonExplicitSupportedLngs: false,
|
|
2075
|
-
load: 'all',
|
|
2076
|
-
preload: false,
|
|
2077
|
-
simplifyPluralSuffix: true,
|
|
2078
|
-
keySeparator: '.',
|
|
2079
|
-
nsSeparator: ':',
|
|
2080
|
-
pluralSeparator: '_',
|
|
2081
|
-
contextSeparator: '_',
|
|
2082
|
-
partialBundledLanguages: false,
|
|
2083
|
-
saveMissing: false,
|
|
2084
|
-
updateMissing: false,
|
|
2085
|
-
saveMissingTo: 'fallback',
|
|
2086
|
-
saveMissingPlurals: true,
|
|
2087
|
-
missingKeyHandler: false,
|
|
2088
|
-
missingInterpolationHandler: false,
|
|
2089
|
-
postProcess: false,
|
|
2090
|
-
postProcessPassResolved: false,
|
|
2091
|
-
returnNull: true,
|
|
2092
|
-
returnEmptyString: true,
|
|
2093
|
-
returnObjects: false,
|
|
2094
|
-
joinArrays: false,
|
|
2095
|
-
returnedObjectHandler: false,
|
|
2096
|
-
parseMissingKeyHandler: false,
|
|
2097
|
-
appendNamespaceToMissingKey: false,
|
|
2098
|
-
appendNamespaceToCIMode: false,
|
|
2099
|
-
overloadTranslationOptionHandler: function handle(args) {
|
|
2100
|
-
var ret = {};
|
|
2101
|
-
if (_typeof$4(args[1]) === 'object') ret = args[1];
|
|
2102
|
-
if (typeof args[1] === 'string') ret.defaultValue = args[1];
|
|
2103
|
-
if (typeof args[2] === 'string') ret.tDescription = args[2];
|
|
2104
|
-
if (_typeof$4(args[2]) === 'object' || _typeof$4(args[3]) === 'object') {
|
|
2105
|
-
var options = args[3] || args[2];
|
|
2106
|
-
Object.keys(options).forEach(function (key) {
|
|
2107
|
-
ret[key] = options[key];
|
|
2108
|
-
});
|
|
2109
|
-
}
|
|
2110
|
-
return ret;
|
|
2111
|
-
},
|
|
2112
|
-
interpolation: {
|
|
2113
|
-
escapeValue: true,
|
|
2114
|
-
format: function format(value, _format, lng, options) {
|
|
2115
|
-
return value;
|
|
2116
|
-
},
|
|
2117
|
-
prefix: '{{',
|
|
2118
|
-
suffix: '}}',
|
|
2119
|
-
formatSeparator: ',',
|
|
2120
|
-
unescapePrefix: '-',
|
|
2121
|
-
nestingPrefix: '$t(',
|
|
2122
|
-
nestingSuffix: ')',
|
|
2123
|
-
nestingOptionsSeparator: ',',
|
|
2124
|
-
maxReplaces: 1000,
|
|
2125
|
-
skipOnVariables: true
|
|
2126
|
-
}
|
|
2127
|
-
};
|
|
2128
|
-
}
|
|
2129
|
-
function transformOptions(options) {
|
|
2130
|
-
if (typeof options.ns === 'string') options.ns = [options.ns];
|
|
2131
|
-
if (typeof options.fallbackLng === 'string') options.fallbackLng = [options.fallbackLng];
|
|
2132
|
-
if (typeof options.fallbackNS === 'string') options.fallbackNS = [options.fallbackNS];
|
|
2133
|
-
if (options.supportedLngs && options.supportedLngs.indexOf('cimode') < 0) {
|
|
2134
|
-
options.supportedLngs = options.supportedLngs.concat(['cimode']);
|
|
2135
|
-
}
|
|
2136
|
-
return options;
|
|
2137
|
-
}
|
|
2138
|
-
|
|
2139
|
-
function ownKeys$g(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; }
|
|
2140
|
-
function _objectSpread$g(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$g(Object(source), !0).forEach(function (key) { _defineProperty$2(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$g(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
2141
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
2142
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
2143
|
-
function noop$1() {}
|
|
2144
|
-
function bindMemberFunctions(inst) {
|
|
2145
|
-
var mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
2146
|
-
mems.forEach(function (mem) {
|
|
2147
|
-
if (typeof inst[mem] === 'function') {
|
|
2148
|
-
inst[mem] = inst[mem].bind(inst);
|
|
2149
|
-
}
|
|
2150
|
-
});
|
|
2151
|
-
}
|
|
2152
|
-
var I18n = function (_EventEmitter) {
|
|
2153
|
-
_inherits(I18n, _EventEmitter);
|
|
2154
|
-
var _super = _createSuper(I18n);
|
|
2155
|
-
function I18n() {
|
|
2156
|
-
var _this;
|
|
2157
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2158
|
-
var callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
2159
|
-
_classCallCheck$2(this, I18n);
|
|
2160
|
-
_this = _super.call(this);
|
|
2161
|
-
if (isIE10) {
|
|
2162
|
-
EventEmitter.call(_assertThisInitialized(_this));
|
|
2163
|
-
}
|
|
2164
|
-
_this.options = transformOptions(options);
|
|
2165
|
-
_this.services = {};
|
|
2166
|
-
_this.logger = baseLogger;
|
|
2167
|
-
_this.modules = {
|
|
2168
|
-
external: []
|
|
2169
|
-
};
|
|
2170
|
-
bindMemberFunctions(_assertThisInitialized(_this));
|
|
2171
|
-
if (callback && !_this.isInitialized && !options.isClone) {
|
|
2172
|
-
if (!_this.options.initImmediate) {
|
|
2173
|
-
_this.init(options, callback);
|
|
2174
|
-
return _possibleConstructorReturn(_this, _assertThisInitialized(_this));
|
|
2175
|
-
}
|
|
2176
|
-
setTimeout(function () {
|
|
2177
|
-
_this.init(options, callback);
|
|
2178
|
-
}, 0);
|
|
2179
|
-
}
|
|
2180
|
-
return _this;
|
|
2181
|
-
}
|
|
2182
|
-
_createClass$2(I18n, [{
|
|
2183
|
-
key: "init",
|
|
2184
|
-
value: function init() {
|
|
2185
|
-
var _this2 = this;
|
|
2186
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2187
|
-
var callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
2188
|
-
if (typeof options === 'function') {
|
|
2189
|
-
callback = options;
|
|
2190
|
-
options = {};
|
|
2191
|
-
}
|
|
2192
|
-
if (!options.defaultNS && options.defaultNS !== false && options.ns) {
|
|
2193
|
-
if (typeof options.ns === 'string') {
|
|
2194
|
-
options.defaultNS = options.ns;
|
|
2195
|
-
} else if (options.ns.indexOf('translation') < 0) {
|
|
2196
|
-
options.defaultNS = options.ns[0];
|
|
2197
|
-
}
|
|
2198
|
-
}
|
|
2199
|
-
var defOpts = get();
|
|
2200
|
-
this.options = _objectSpread$g(_objectSpread$g(_objectSpread$g({}, defOpts), this.options), transformOptions(options));
|
|
2201
|
-
if (this.options.compatibilityAPI !== 'v1') {
|
|
2202
|
-
this.options.interpolation = _objectSpread$g(_objectSpread$g({}, defOpts.interpolation), this.options.interpolation);
|
|
2203
|
-
}
|
|
2204
|
-
if (options.keySeparator !== undefined) {
|
|
2205
|
-
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
2206
|
-
}
|
|
2207
|
-
if (options.nsSeparator !== undefined) {
|
|
2208
|
-
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
2209
|
-
}
|
|
2210
|
-
function createClassOnDemand(ClassOrObject) {
|
|
2211
|
-
if (!ClassOrObject) return null;
|
|
2212
|
-
if (typeof ClassOrObject === 'function') return new ClassOrObject();
|
|
2213
|
-
return ClassOrObject;
|
|
2214
|
-
}
|
|
2215
|
-
if (!this.options.isClone) {
|
|
2216
|
-
if (this.modules.logger) {
|
|
2217
|
-
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
2218
|
-
} else {
|
|
2219
|
-
baseLogger.init(null, this.options);
|
|
2220
|
-
}
|
|
2221
|
-
var formatter;
|
|
2222
|
-
if (this.modules.formatter) {
|
|
2223
|
-
formatter = this.modules.formatter;
|
|
2224
|
-
} else if (typeof Intl !== 'undefined') {
|
|
2225
|
-
formatter = Formatter;
|
|
2226
|
-
}
|
|
2227
|
-
var lu = new LanguageUtil(this.options);
|
|
2228
|
-
this.store = new ResourceStore(this.options.resources, this.options);
|
|
2229
|
-
var s = this.services;
|
|
2230
|
-
s.logger = baseLogger;
|
|
2231
|
-
s.resourceStore = this.store;
|
|
2232
|
-
s.languageUtils = lu;
|
|
2233
|
-
s.pluralResolver = new PluralResolver(lu, {
|
|
2234
|
-
prepend: this.options.pluralSeparator,
|
|
2235
|
-
compatibilityJSON: this.options.compatibilityJSON,
|
|
2236
|
-
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
2237
|
-
});
|
|
2238
|
-
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
2239
|
-
s.formatter = createClassOnDemand(formatter);
|
|
2240
|
-
s.formatter.init(s, this.options);
|
|
2241
|
-
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
2242
|
-
}
|
|
2243
|
-
s.interpolator = new Interpolator(this.options);
|
|
2244
|
-
s.utils = {
|
|
2245
|
-
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
2246
|
-
};
|
|
2247
|
-
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
2248
|
-
s.backendConnector.on('*', function (event) {
|
|
2249
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
2250
|
-
args[_key - 1] = arguments[_key];
|
|
2251
|
-
}
|
|
2252
|
-
_this2.emit.apply(_this2, [event].concat(args));
|
|
2253
|
-
});
|
|
2254
|
-
if (this.modules.languageDetector) {
|
|
2255
|
-
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
2256
|
-
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
2257
|
-
}
|
|
2258
|
-
if (this.modules.i18nFormat) {
|
|
2259
|
-
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
2260
|
-
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
2261
|
-
}
|
|
2262
|
-
this.translator = new Translator(this.services, this.options);
|
|
2263
|
-
this.translator.on('*', function (event) {
|
|
2264
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
2265
|
-
args[_key2 - 1] = arguments[_key2];
|
|
2266
|
-
}
|
|
2267
|
-
_this2.emit.apply(_this2, [event].concat(args));
|
|
2268
|
-
});
|
|
2269
|
-
this.modules.external.forEach(function (m) {
|
|
2270
|
-
if (m.init) m.init(_this2);
|
|
2271
|
-
});
|
|
2272
|
-
}
|
|
2273
|
-
this.format = this.options.interpolation.format;
|
|
2274
|
-
if (!callback) callback = noop$1;
|
|
2275
|
-
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
2276
|
-
var codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
2277
|
-
if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
|
|
2278
|
-
}
|
|
2279
|
-
if (!this.services.languageDetector && !this.options.lng) {
|
|
2280
|
-
this.logger.warn('init: no languageDetector is used and no lng is defined');
|
|
2281
|
-
}
|
|
2282
|
-
var storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
|
|
2283
|
-
storeApi.forEach(function (fcName) {
|
|
2284
|
-
_this2[fcName] = function () {
|
|
2285
|
-
var _this2$store;
|
|
2286
|
-
return (_this2$store = _this2.store)[fcName].apply(_this2$store, arguments);
|
|
2287
|
-
};
|
|
2288
|
-
});
|
|
2289
|
-
var storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
|
|
2290
|
-
storeApiChained.forEach(function (fcName) {
|
|
2291
|
-
_this2[fcName] = function () {
|
|
2292
|
-
var _this2$store2;
|
|
2293
|
-
(_this2$store2 = _this2.store)[fcName].apply(_this2$store2, arguments);
|
|
2294
|
-
return _this2;
|
|
2295
|
-
};
|
|
2296
|
-
});
|
|
2297
|
-
var deferred = defer();
|
|
2298
|
-
var load = function load() {
|
|
2299
|
-
var finish = function finish(err, t) {
|
|
2300
|
-
if (_this2.isInitialized && !_this2.initializedStoreOnce) _this2.logger.warn('init: i18next is already initialized. You should call init just once!');
|
|
2301
|
-
_this2.isInitialized = true;
|
|
2302
|
-
if (!_this2.options.isClone) _this2.logger.log('initialized', _this2.options);
|
|
2303
|
-
_this2.emit('initialized', _this2.options);
|
|
2304
|
-
deferred.resolve(t);
|
|
2305
|
-
callback(err, t);
|
|
2306
|
-
};
|
|
2307
|
-
if (_this2.languages && _this2.options.compatibilityAPI !== 'v1' && !_this2.isInitialized) return finish(null, _this2.t.bind(_this2));
|
|
2308
|
-
_this2.changeLanguage(_this2.options.lng, finish);
|
|
2309
|
-
};
|
|
2310
|
-
if (this.options.resources || !this.options.initImmediate) {
|
|
2311
|
-
load();
|
|
2312
|
-
} else {
|
|
2313
|
-
setTimeout(load, 0);
|
|
2314
|
-
}
|
|
2315
|
-
return deferred;
|
|
2316
|
-
}
|
|
2317
|
-
}, {
|
|
2318
|
-
key: "loadResources",
|
|
2319
|
-
value: function loadResources(language) {
|
|
2320
|
-
var _this3 = this;
|
|
2321
|
-
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$1;
|
|
2322
|
-
var usedCallback = callback;
|
|
2323
|
-
var usedLng = typeof language === 'string' ? language : this.language;
|
|
2324
|
-
if (typeof language === 'function') usedCallback = language;
|
|
2325
|
-
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
2326
|
-
if (usedLng && usedLng.toLowerCase() === 'cimode') return usedCallback();
|
|
2327
|
-
var toLoad = [];
|
|
2328
|
-
var append = function append(lng) {
|
|
2329
|
-
if (!lng) return;
|
|
2330
|
-
var lngs = _this3.services.languageUtils.toResolveHierarchy(lng);
|
|
2331
|
-
lngs.forEach(function (l) {
|
|
2332
|
-
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
|
2333
|
-
});
|
|
2334
|
-
};
|
|
2335
|
-
if (!usedLng) {
|
|
2336
|
-
var fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
2337
|
-
fallbacks.forEach(function (l) {
|
|
2338
|
-
return append(l);
|
|
2339
|
-
});
|
|
2340
|
-
} else {
|
|
2341
|
-
append(usedLng);
|
|
2342
|
-
}
|
|
2343
|
-
if (this.options.preload) {
|
|
2344
|
-
this.options.preload.forEach(function (l) {
|
|
2345
|
-
return append(l);
|
|
2346
|
-
});
|
|
2347
|
-
}
|
|
2348
|
-
this.services.backendConnector.load(toLoad, this.options.ns, function (e) {
|
|
2349
|
-
if (!e && !_this3.resolvedLanguage && _this3.language) _this3.setResolvedLanguage(_this3.language);
|
|
2350
|
-
usedCallback(e);
|
|
2351
|
-
});
|
|
2352
|
-
} else {
|
|
2353
|
-
usedCallback(null);
|
|
2354
|
-
}
|
|
2355
|
-
}
|
|
2356
|
-
}, {
|
|
2357
|
-
key: "reloadResources",
|
|
2358
|
-
value: function reloadResources(lngs, ns, callback) {
|
|
2359
|
-
var deferred = defer();
|
|
2360
|
-
if (!lngs) lngs = this.languages;
|
|
2361
|
-
if (!ns) ns = this.options.ns;
|
|
2362
|
-
if (!callback) callback = noop$1;
|
|
2363
|
-
this.services.backendConnector.reload(lngs, ns, function (err) {
|
|
2364
|
-
deferred.resolve();
|
|
2365
|
-
callback(err);
|
|
2366
|
-
});
|
|
2367
|
-
return deferred;
|
|
2368
|
-
}
|
|
2369
|
-
}, {
|
|
2370
|
-
key: "use",
|
|
2371
|
-
value: function use(module) {
|
|
2372
|
-
if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
|
|
2373
|
-
if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
|
|
2374
|
-
if (module.type === 'backend') {
|
|
2375
|
-
this.modules.backend = module;
|
|
2376
|
-
}
|
|
2377
|
-
if (module.type === 'logger' || module.log && module.warn && module.error) {
|
|
2378
|
-
this.modules.logger = module;
|
|
2379
|
-
}
|
|
2380
|
-
if (module.type === 'languageDetector') {
|
|
2381
|
-
this.modules.languageDetector = module;
|
|
2382
|
-
}
|
|
2383
|
-
if (module.type === 'i18nFormat') {
|
|
2384
|
-
this.modules.i18nFormat = module;
|
|
2385
|
-
}
|
|
2386
|
-
if (module.type === 'postProcessor') {
|
|
2387
|
-
postProcessor.addPostProcessor(module);
|
|
2388
|
-
}
|
|
2389
|
-
if (module.type === 'formatter') {
|
|
2390
|
-
this.modules.formatter = module;
|
|
2391
|
-
}
|
|
2392
|
-
if (module.type === '3rdParty') {
|
|
2393
|
-
this.modules.external.push(module);
|
|
2394
|
-
}
|
|
2395
|
-
return this;
|
|
2396
|
-
}
|
|
2397
|
-
}, {
|
|
2398
|
-
key: "setResolvedLanguage",
|
|
2399
|
-
value: function setResolvedLanguage(l) {
|
|
2400
|
-
if (!l || !this.languages) return;
|
|
2401
|
-
if (['cimode', 'dev'].indexOf(l) > -1) return;
|
|
2402
|
-
for (var li = 0; li < this.languages.length; li++) {
|
|
2403
|
-
var lngInLngs = this.languages[li];
|
|
2404
|
-
if (['cimode', 'dev'].indexOf(lngInLngs) > -1) continue;
|
|
2405
|
-
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
2406
|
-
this.resolvedLanguage = lngInLngs;
|
|
2407
|
-
break;
|
|
2408
|
-
}
|
|
2409
|
-
}
|
|
2410
|
-
}
|
|
2411
|
-
}, {
|
|
2412
|
-
key: "changeLanguage",
|
|
2413
|
-
value: function changeLanguage(lng, callback) {
|
|
2414
|
-
var _this4 = this;
|
|
2415
|
-
this.isLanguageChangingTo = lng;
|
|
2416
|
-
var deferred = defer();
|
|
2417
|
-
this.emit('languageChanging', lng);
|
|
2418
|
-
var setLngProps = function setLngProps(l) {
|
|
2419
|
-
_this4.language = l;
|
|
2420
|
-
_this4.languages = _this4.services.languageUtils.toResolveHierarchy(l);
|
|
2421
|
-
_this4.resolvedLanguage = undefined;
|
|
2422
|
-
_this4.setResolvedLanguage(l);
|
|
2423
|
-
};
|
|
2424
|
-
var done = function done(err, l) {
|
|
2425
|
-
if (l) {
|
|
2426
|
-
setLngProps(l);
|
|
2427
|
-
_this4.translator.changeLanguage(l);
|
|
2428
|
-
_this4.isLanguageChangingTo = undefined;
|
|
2429
|
-
_this4.emit('languageChanged', l);
|
|
2430
|
-
_this4.logger.log('languageChanged', l);
|
|
2431
|
-
} else {
|
|
2432
|
-
_this4.isLanguageChangingTo = undefined;
|
|
2433
|
-
}
|
|
2434
|
-
deferred.resolve(function () {
|
|
2435
|
-
return _this4.t.apply(_this4, arguments);
|
|
2436
|
-
});
|
|
2437
|
-
if (callback) callback(err, function () {
|
|
2438
|
-
return _this4.t.apply(_this4, arguments);
|
|
2439
|
-
});
|
|
2440
|
-
};
|
|
2441
|
-
var setLng = function setLng(lngs) {
|
|
2442
|
-
if (!lng && !lngs && _this4.services.languageDetector) lngs = [];
|
|
2443
|
-
var l = typeof lngs === 'string' ? lngs : _this4.services.languageUtils.getBestMatchFromCodes(lngs);
|
|
2444
|
-
if (l) {
|
|
2445
|
-
if (!_this4.language) {
|
|
2446
|
-
setLngProps(l);
|
|
2447
|
-
}
|
|
2448
|
-
if (!_this4.translator.language) _this4.translator.changeLanguage(l);
|
|
2449
|
-
if (_this4.services.languageDetector && _this4.services.languageDetector.cacheUserLanguage) _this4.services.languageDetector.cacheUserLanguage(l);
|
|
2450
|
-
}
|
|
2451
|
-
_this4.loadResources(l, function (err) {
|
|
2452
|
-
done(err, l);
|
|
2453
|
-
});
|
|
2454
|
-
};
|
|
2455
|
-
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
2456
|
-
setLng(this.services.languageDetector.detect());
|
|
2457
|
-
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
2458
|
-
if (this.services.languageDetector.detect.length === 0) {
|
|
2459
|
-
this.services.languageDetector.detect().then(setLng);
|
|
2460
|
-
} else {
|
|
2461
|
-
this.services.languageDetector.detect(setLng);
|
|
2462
|
-
}
|
|
2463
|
-
} else {
|
|
2464
|
-
setLng(lng);
|
|
2465
|
-
}
|
|
2466
|
-
return deferred;
|
|
2467
|
-
}
|
|
2468
|
-
}, {
|
|
2469
|
-
key: "getFixedT",
|
|
2470
|
-
value: function getFixedT(lng, ns, keyPrefix) {
|
|
2471
|
-
var _this5 = this;
|
|
2472
|
-
var fixedT = function fixedT(key, opts) {
|
|
2473
|
-
var options;
|
|
2474
|
-
if (_typeof$4(opts) !== 'object') {
|
|
2475
|
-
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
2476
|
-
rest[_key3 - 2] = arguments[_key3];
|
|
2477
|
-
}
|
|
2478
|
-
options = _this5.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
2479
|
-
} else {
|
|
2480
|
-
options = _objectSpread$g({}, opts);
|
|
2481
|
-
}
|
|
2482
|
-
options.lng = options.lng || fixedT.lng;
|
|
2483
|
-
options.lngs = options.lngs || fixedT.lngs;
|
|
2484
|
-
options.ns = options.ns || fixedT.ns;
|
|
2485
|
-
options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
2486
|
-
var keySeparator = _this5.options.keySeparator || '.';
|
|
2487
|
-
var resultKey;
|
|
2488
|
-
if (options.keyPrefix && Array.isArray(key)) {
|
|
2489
|
-
resultKey = key.map(function (k) {
|
|
2490
|
-
return "".concat(options.keyPrefix).concat(keySeparator).concat(k);
|
|
2491
|
-
});
|
|
2492
|
-
} else {
|
|
2493
|
-
resultKey = options.keyPrefix ? "".concat(options.keyPrefix).concat(keySeparator).concat(key) : key;
|
|
2494
|
-
}
|
|
2495
|
-
return _this5.t(resultKey, options);
|
|
2496
|
-
};
|
|
2497
|
-
if (typeof lng === 'string') {
|
|
2498
|
-
fixedT.lng = lng;
|
|
2499
|
-
} else {
|
|
2500
|
-
fixedT.lngs = lng;
|
|
2501
|
-
}
|
|
2502
|
-
fixedT.ns = ns;
|
|
2503
|
-
fixedT.keyPrefix = keyPrefix;
|
|
2504
|
-
return fixedT;
|
|
2505
|
-
}
|
|
2506
|
-
}, {
|
|
2507
|
-
key: "t",
|
|
2508
|
-
value: function t() {
|
|
2509
|
-
var _this$translator;
|
|
2510
|
-
return this.translator && (_this$translator = this.translator).translate.apply(_this$translator, arguments);
|
|
2511
|
-
}
|
|
2512
|
-
}, {
|
|
2513
|
-
key: "exists",
|
|
2514
|
-
value: function exists() {
|
|
2515
|
-
var _this$translator2;
|
|
2516
|
-
return this.translator && (_this$translator2 = this.translator).exists.apply(_this$translator2, arguments);
|
|
2517
|
-
}
|
|
2518
|
-
}, {
|
|
2519
|
-
key: "setDefaultNamespace",
|
|
2520
|
-
value: function setDefaultNamespace(ns) {
|
|
2521
|
-
this.options.defaultNS = ns;
|
|
2522
|
-
}
|
|
2523
|
-
}, {
|
|
2524
|
-
key: "hasLoadedNamespace",
|
|
2525
|
-
value: function hasLoadedNamespace(ns) {
|
|
2526
|
-
var _this6 = this;
|
|
2527
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2528
|
-
if (!this.isInitialized) {
|
|
2529
|
-
this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
|
|
2530
|
-
return false;
|
|
2531
|
-
}
|
|
2532
|
-
if (!this.languages || !this.languages.length) {
|
|
2533
|
-
this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages);
|
|
2534
|
-
return false;
|
|
2535
|
-
}
|
|
2536
|
-
var lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
2537
|
-
var fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
2538
|
-
var lastLng = this.languages[this.languages.length - 1];
|
|
2539
|
-
if (lng.toLowerCase() === 'cimode') return true;
|
|
2540
|
-
var loadNotPending = function loadNotPending(l, n) {
|
|
2541
|
-
var loadState = _this6.services.backendConnector.state["".concat(l, "|").concat(n)];
|
|
2542
|
-
return loadState === -1 || loadState === 2;
|
|
2543
|
-
};
|
|
2544
|
-
if (options.precheck) {
|
|
2545
|
-
var preResult = options.precheck(this, loadNotPending);
|
|
2546
|
-
if (preResult !== undefined) return preResult;
|
|
2547
|
-
}
|
|
2548
|
-
if (this.hasResourceBundle(lng, ns)) return true;
|
|
2549
|
-
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
2550
|
-
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
2551
|
-
return false;
|
|
2552
|
-
}
|
|
2553
|
-
}, {
|
|
2554
|
-
key: "loadNamespaces",
|
|
2555
|
-
value: function loadNamespaces(ns, callback) {
|
|
2556
|
-
var _this7 = this;
|
|
2557
|
-
var deferred = defer();
|
|
2558
|
-
if (!this.options.ns) {
|
|
2559
|
-
if (callback) callback();
|
|
2560
|
-
return Promise.resolve();
|
|
2561
|
-
}
|
|
2562
|
-
if (typeof ns === 'string') ns = [ns];
|
|
2563
|
-
ns.forEach(function (n) {
|
|
2564
|
-
if (_this7.options.ns.indexOf(n) < 0) _this7.options.ns.push(n);
|
|
2565
|
-
});
|
|
2566
|
-
this.loadResources(function (err) {
|
|
2567
|
-
deferred.resolve();
|
|
2568
|
-
if (callback) callback(err);
|
|
2569
|
-
});
|
|
2570
|
-
return deferred;
|
|
2571
|
-
}
|
|
2572
|
-
}, {
|
|
2573
|
-
key: "loadLanguages",
|
|
2574
|
-
value: function loadLanguages(lngs, callback) {
|
|
2575
|
-
var deferred = defer();
|
|
2576
|
-
if (typeof lngs === 'string') lngs = [lngs];
|
|
2577
|
-
var preloaded = this.options.preload || [];
|
|
2578
|
-
var newLngs = lngs.filter(function (lng) {
|
|
2579
|
-
return preloaded.indexOf(lng) < 0;
|
|
2580
|
-
});
|
|
2581
|
-
if (!newLngs.length) {
|
|
2582
|
-
if (callback) callback();
|
|
2583
|
-
return Promise.resolve();
|
|
2584
|
-
}
|
|
2585
|
-
this.options.preload = preloaded.concat(newLngs);
|
|
2586
|
-
this.loadResources(function (err) {
|
|
2587
|
-
deferred.resolve();
|
|
2588
|
-
if (callback) callback(err);
|
|
2589
|
-
});
|
|
2590
|
-
return deferred;
|
|
2591
|
-
}
|
|
2592
|
-
}, {
|
|
2593
|
-
key: "dir",
|
|
2594
|
-
value: function dir(lng) {
|
|
2595
|
-
if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
|
|
2596
|
-
if (!lng) return 'rtl';
|
|
2597
|
-
var 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'];
|
|
2598
|
-
var languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
|
|
2599
|
-
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
|
|
2600
|
-
}
|
|
2601
|
-
}, {
|
|
2602
|
-
key: "cloneInstance",
|
|
2603
|
-
value: function cloneInstance() {
|
|
2604
|
-
var _this8 = this;
|
|
2605
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2606
|
-
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$1;
|
|
2607
|
-
var mergedOptions = _objectSpread$g(_objectSpread$g(_objectSpread$g({}, this.options), options), {
|
|
2608
|
-
isClone: true
|
|
2609
|
-
});
|
|
2610
|
-
var clone = new I18n(mergedOptions);
|
|
2611
|
-
if (options.debug !== undefined || options.prefix !== undefined) {
|
|
2612
|
-
clone.logger = clone.logger.clone(options);
|
|
2613
|
-
}
|
|
2614
|
-
var membersToCopy = ['store', 'services', 'language'];
|
|
2615
|
-
membersToCopy.forEach(function (m) {
|
|
2616
|
-
clone[m] = _this8[m];
|
|
2617
|
-
});
|
|
2618
|
-
clone.services = _objectSpread$g({}, this.services);
|
|
2619
|
-
clone.services.utils = {
|
|
2620
|
-
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2621
|
-
};
|
|
2622
|
-
clone.translator = new Translator(clone.services, clone.options);
|
|
2623
|
-
clone.translator.on('*', function (event) {
|
|
2624
|
-
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
2625
|
-
args[_key4 - 1] = arguments[_key4];
|
|
2626
|
-
}
|
|
2627
|
-
clone.emit.apply(clone, [event].concat(args));
|
|
2628
|
-
});
|
|
2629
|
-
clone.init(mergedOptions, callback);
|
|
2630
|
-
clone.translator.options = clone.options;
|
|
2631
|
-
clone.translator.backendConnector.services.utils = {
|
|
2632
|
-
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2633
|
-
};
|
|
2634
|
-
return clone;
|
|
2635
|
-
}
|
|
2636
|
-
}, {
|
|
2637
|
-
key: "toJSON",
|
|
2638
|
-
value: function toJSON() {
|
|
2639
|
-
return {
|
|
2640
|
-
options: this.options,
|
|
2641
|
-
store: this.store,
|
|
2642
|
-
language: this.language,
|
|
2643
|
-
languages: this.languages,
|
|
2644
|
-
resolvedLanguage: this.resolvedLanguage
|
|
2645
|
-
};
|
|
2646
|
-
}
|
|
2647
|
-
}]);
|
|
2648
|
-
return I18n;
|
|
2649
|
-
}(EventEmitter);
|
|
2650
|
-
_defineProperty$2(I18n, "createInstance", function () {
|
|
2651
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2652
|
-
var callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
2653
|
-
return new I18n(options, callback);
|
|
2654
|
-
});
|
|
2655
|
-
var instance = I18n.createInstance();
|
|
2656
|
-
instance.createInstance = I18n.createInstance;
|
|
2657
|
-
|
|
2658
|
-
instance.createInstance;
|
|
2659
|
-
instance.dir;
|
|
2660
|
-
instance.init;
|
|
2661
|
-
instance.loadResources;
|
|
2662
|
-
instance.reloadResources;
|
|
2663
|
-
instance.use;
|
|
2664
|
-
instance.changeLanguage;
|
|
2665
|
-
instance.getFixedT;
|
|
2666
|
-
var t$2 = instance.t;
|
|
2667
|
-
instance.exists;
|
|
2668
|
-
instance.setDefaultNamespace;
|
|
2669
|
-
instance.hasLoadedNamespace;
|
|
2670
|
-
instance.loadNamespaces;
|
|
2671
|
-
instance.loadLanguages;
|
|
2672
|
-
|
|
2673
|
-
function _classCallCheck$1(instance, Constructor) {
|
|
2674
|
-
if (!(instance instanceof Constructor)) {
|
|
2675
|
-
throw new TypeError("Cannot call a class as a function");
|
|
2676
|
-
}
|
|
2677
|
-
}
|
|
2678
|
-
|
|
2679
|
-
function _typeof$3(obj) {
|
|
2680
|
-
"@babel/helpers - typeof";
|
|
2681
|
-
|
|
2682
|
-
return _typeof$3 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
2683
|
-
return typeof obj;
|
|
2684
|
-
} : function (obj) {
|
|
2685
|
-
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
2686
|
-
}, _typeof$3(obj);
|
|
2687
|
-
}
|
|
2688
|
-
|
|
2689
|
-
function _toPrimitive$2(input, hint) {
|
|
2690
|
-
if (_typeof$3(input) !== "object" || input === null) return input;
|
|
2691
|
-
var prim = input[Symbol.toPrimitive];
|
|
2692
|
-
if (prim !== undefined) {
|
|
2693
|
-
var res = prim.call(input, hint || "default");
|
|
2694
|
-
if (_typeof$3(res) !== "object") return res;
|
|
2695
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
2696
|
-
}
|
|
2697
|
-
return (hint === "string" ? String : Number)(input);
|
|
2698
|
-
}
|
|
2699
|
-
|
|
2700
|
-
function _toPropertyKey$2(arg) {
|
|
2701
|
-
var key = _toPrimitive$2(arg, "string");
|
|
2702
|
-
return _typeof$3(key) === "symbol" ? key : String(key);
|
|
2703
|
-
}
|
|
2704
|
-
|
|
2705
|
-
function _defineProperties$1(target, props) {
|
|
2706
|
-
for (var i = 0; i < props.length; i++) {
|
|
2707
|
-
var descriptor = props[i];
|
|
2708
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
2709
|
-
descriptor.configurable = true;
|
|
2710
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
2711
|
-
Object.defineProperty(target, _toPropertyKey$2(descriptor.key), descriptor);
|
|
2712
|
-
}
|
|
2713
|
-
}
|
|
2714
|
-
function _createClass$1(Constructor, protoProps, staticProps) {
|
|
2715
|
-
if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
|
|
2716
|
-
if (staticProps) _defineProperties$1(Constructor, staticProps);
|
|
2717
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
2718
|
-
writable: false
|
|
2719
|
-
});
|
|
2720
|
-
return Constructor;
|
|
2721
|
-
}
|
|
2722
|
-
|
|
2723
|
-
var arr = [];
|
|
2724
|
-
var each = arr.forEach;
|
|
2725
|
-
var slice = arr.slice;
|
|
2726
|
-
function defaults(obj) {
|
|
2727
|
-
each.call(slice.call(arguments, 1), function (source) {
|
|
2728
|
-
if (source) {
|
|
2729
|
-
for (var prop in source) {
|
|
2730
|
-
if (obj[prop] === undefined) obj[prop] = source[prop];
|
|
2731
|
-
}
|
|
2732
|
-
}
|
|
2733
|
-
});
|
|
2734
|
-
return obj;
|
|
2735
|
-
}
|
|
2736
|
-
|
|
2737
|
-
// eslint-disable-next-line no-control-regex
|
|
2738
|
-
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
2739
|
-
var serializeCookie = function serializeCookie(name, val, options) {
|
|
2740
|
-
var opt = options || {};
|
|
2741
|
-
opt.path = opt.path || '/';
|
|
2742
|
-
var value = encodeURIComponent(val);
|
|
2743
|
-
var str = "".concat(name, "=").concat(value);
|
|
2744
|
-
if (opt.maxAge > 0) {
|
|
2745
|
-
var maxAge = opt.maxAge - 0;
|
|
2746
|
-
if (Number.isNaN(maxAge)) throw new Error('maxAge should be a Number');
|
|
2747
|
-
str += "; Max-Age=".concat(Math.floor(maxAge));
|
|
2748
|
-
}
|
|
2749
|
-
if (opt.domain) {
|
|
2750
|
-
if (!fieldContentRegExp.test(opt.domain)) {
|
|
2751
|
-
throw new TypeError('option domain is invalid');
|
|
2752
|
-
}
|
|
2753
|
-
str += "; Domain=".concat(opt.domain);
|
|
2754
|
-
}
|
|
2755
|
-
if (opt.path) {
|
|
2756
|
-
if (!fieldContentRegExp.test(opt.path)) {
|
|
2757
|
-
throw new TypeError('option path is invalid');
|
|
2758
|
-
}
|
|
2759
|
-
str += "; Path=".concat(opt.path);
|
|
2760
|
-
}
|
|
2761
|
-
if (opt.expires) {
|
|
2762
|
-
if (typeof opt.expires.toUTCString !== 'function') {
|
|
2763
|
-
throw new TypeError('option expires is invalid');
|
|
2764
|
-
}
|
|
2765
|
-
str += "; Expires=".concat(opt.expires.toUTCString());
|
|
2766
|
-
}
|
|
2767
|
-
if (opt.httpOnly) str += '; HttpOnly';
|
|
2768
|
-
if (opt.secure) str += '; Secure';
|
|
2769
|
-
if (opt.sameSite) {
|
|
2770
|
-
var sameSite = typeof opt.sameSite === 'string' ? opt.sameSite.toLowerCase() : opt.sameSite;
|
|
2771
|
-
switch (sameSite) {
|
|
2772
|
-
case true:
|
|
2773
|
-
str += '; SameSite=Strict';
|
|
2774
|
-
break;
|
|
2775
|
-
case 'lax':
|
|
2776
|
-
str += '; SameSite=Lax';
|
|
2777
|
-
break;
|
|
2778
|
-
case 'strict':
|
|
2779
|
-
str += '; SameSite=Strict';
|
|
2780
|
-
break;
|
|
2781
|
-
case 'none':
|
|
2782
|
-
str += '; SameSite=None';
|
|
2783
|
-
break;
|
|
2784
|
-
default:
|
|
2785
|
-
throw new TypeError('option sameSite is invalid');
|
|
2786
|
-
}
|
|
2787
|
-
}
|
|
2788
|
-
return str;
|
|
2789
|
-
};
|
|
2790
|
-
var cookie = {
|
|
2791
|
-
create: function create(name, value, minutes, domain) {
|
|
2792
|
-
var cookieOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
2793
|
-
path: '/',
|
|
2794
|
-
sameSite: 'strict'
|
|
2795
|
-
};
|
|
2796
|
-
if (minutes) {
|
|
2797
|
-
cookieOptions.expires = new Date();
|
|
2798
|
-
cookieOptions.expires.setTime(cookieOptions.expires.getTime() + minutes * 60 * 1000);
|
|
2799
|
-
}
|
|
2800
|
-
if (domain) cookieOptions.domain = domain;
|
|
2801
|
-
document.cookie = serializeCookie(name, encodeURIComponent(value), cookieOptions);
|
|
2802
|
-
},
|
|
2803
|
-
read: function read(name) {
|
|
2804
|
-
var nameEQ = "".concat(name, "=");
|
|
2805
|
-
var ca = document.cookie.split(';');
|
|
2806
|
-
for (var i = 0; i < ca.length; i++) {
|
|
2807
|
-
var c = ca[i];
|
|
2808
|
-
while (c.charAt(0) === ' ') {
|
|
2809
|
-
c = c.substring(1, c.length);
|
|
2810
|
-
}
|
|
2811
|
-
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
|
2812
|
-
}
|
|
2813
|
-
return null;
|
|
2814
|
-
},
|
|
2815
|
-
remove: function remove(name) {
|
|
2816
|
-
this.create(name, '', -1);
|
|
2817
|
-
}
|
|
2818
|
-
};
|
|
2819
|
-
var cookie$1 = {
|
|
2820
|
-
name: 'cookie',
|
|
2821
|
-
lookup: function lookup(options) {
|
|
2822
|
-
var found;
|
|
2823
|
-
if (options.lookupCookie && typeof document !== 'undefined') {
|
|
2824
|
-
var c = cookie.read(options.lookupCookie);
|
|
2825
|
-
if (c) found = c;
|
|
2826
|
-
}
|
|
2827
|
-
return found;
|
|
2828
|
-
},
|
|
2829
|
-
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
|
2830
|
-
if (options.lookupCookie && typeof document !== 'undefined') {
|
|
2831
|
-
cookie.create(options.lookupCookie, lng, options.cookieMinutes, options.cookieDomain, options.cookieOptions);
|
|
2832
|
-
}
|
|
2833
|
-
}
|
|
2834
|
-
};
|
|
2835
|
-
|
|
2836
|
-
var querystring = {
|
|
2837
|
-
name: 'querystring',
|
|
2838
|
-
lookup: function lookup(options) {
|
|
2839
|
-
var found;
|
|
2840
|
-
if (typeof window !== 'undefined') {
|
|
2841
|
-
var search = window.location.search;
|
|
2842
|
-
if (!window.location.search && window.location.hash && window.location.hash.indexOf('?') > -1) {
|
|
2843
|
-
search = window.location.hash.substring(window.location.hash.indexOf('?'));
|
|
2844
|
-
}
|
|
2845
|
-
var query = search.substring(1);
|
|
2846
|
-
var params = query.split('&');
|
|
2847
|
-
for (var i = 0; i < params.length; i++) {
|
|
2848
|
-
var pos = params[i].indexOf('=');
|
|
2849
|
-
if (pos > 0) {
|
|
2850
|
-
var key = params[i].substring(0, pos);
|
|
2851
|
-
if (key === options.lookupQuerystring) {
|
|
2852
|
-
found = params[i].substring(pos + 1);
|
|
2853
|
-
}
|
|
2854
|
-
}
|
|
2855
|
-
}
|
|
2856
|
-
}
|
|
2857
|
-
return found;
|
|
2858
|
-
}
|
|
2859
|
-
};
|
|
2860
|
-
|
|
2861
|
-
var hasLocalStorageSupport = null;
|
|
2862
|
-
var localStorageAvailable = function localStorageAvailable() {
|
|
2863
|
-
if (hasLocalStorageSupport !== null) return hasLocalStorageSupport;
|
|
2864
|
-
try {
|
|
2865
|
-
hasLocalStorageSupport = window !== 'undefined' && window.localStorage !== null;
|
|
2866
|
-
var testKey = 'i18next.translate.boo';
|
|
2867
|
-
window.localStorage.setItem(testKey, 'foo');
|
|
2868
|
-
window.localStorage.removeItem(testKey);
|
|
2869
|
-
} catch (e) {
|
|
2870
|
-
hasLocalStorageSupport = false;
|
|
2871
|
-
}
|
|
2872
|
-
return hasLocalStorageSupport;
|
|
2873
|
-
};
|
|
2874
|
-
var localStorage = {
|
|
2875
|
-
name: 'localStorage',
|
|
2876
|
-
lookup: function lookup(options) {
|
|
2877
|
-
var found;
|
|
2878
|
-
if (options.lookupLocalStorage && localStorageAvailable()) {
|
|
2879
|
-
var lng = window.localStorage.getItem(options.lookupLocalStorage);
|
|
2880
|
-
if (lng) found = lng;
|
|
2881
|
-
}
|
|
2882
|
-
return found;
|
|
2883
|
-
},
|
|
2884
|
-
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
|
2885
|
-
if (options.lookupLocalStorage && localStorageAvailable()) {
|
|
2886
|
-
window.localStorage.setItem(options.lookupLocalStorage, lng);
|
|
2887
|
-
}
|
|
2888
|
-
}
|
|
2889
|
-
};
|
|
2890
|
-
|
|
2891
|
-
var hasSessionStorageSupport = null;
|
|
2892
|
-
var sessionStorageAvailable = function sessionStorageAvailable() {
|
|
2893
|
-
if (hasSessionStorageSupport !== null) return hasSessionStorageSupport;
|
|
2894
|
-
try {
|
|
2895
|
-
hasSessionStorageSupport = window !== 'undefined' && window.sessionStorage !== null;
|
|
2896
|
-
var testKey = 'i18next.translate.boo';
|
|
2897
|
-
window.sessionStorage.setItem(testKey, 'foo');
|
|
2898
|
-
window.sessionStorage.removeItem(testKey);
|
|
2899
|
-
} catch (e) {
|
|
2900
|
-
hasSessionStorageSupport = false;
|
|
2901
|
-
}
|
|
2902
|
-
return hasSessionStorageSupport;
|
|
2903
|
-
};
|
|
2904
|
-
var sessionStorage = {
|
|
2905
|
-
name: 'sessionStorage',
|
|
2906
|
-
lookup: function lookup(options) {
|
|
2907
|
-
var found;
|
|
2908
|
-
if (options.lookupSessionStorage && sessionStorageAvailable()) {
|
|
2909
|
-
var lng = window.sessionStorage.getItem(options.lookupSessionStorage);
|
|
2910
|
-
if (lng) found = lng;
|
|
2911
|
-
}
|
|
2912
|
-
return found;
|
|
2913
|
-
},
|
|
2914
|
-
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
|
2915
|
-
if (options.lookupSessionStorage && sessionStorageAvailable()) {
|
|
2916
|
-
window.sessionStorage.setItem(options.lookupSessionStorage, lng);
|
|
2917
|
-
}
|
|
2918
|
-
}
|
|
2919
|
-
};
|
|
2920
|
-
|
|
2921
|
-
var navigator$1 = {
|
|
2922
|
-
name: 'navigator',
|
|
2923
|
-
lookup: function lookup(options) {
|
|
2924
|
-
var found = [];
|
|
2925
|
-
if (typeof navigator !== 'undefined') {
|
|
2926
|
-
if (navigator.languages) {
|
|
2927
|
-
// chrome only; not an array, so can't use .push.apply instead of iterating
|
|
2928
|
-
for (var i = 0; i < navigator.languages.length; i++) {
|
|
2929
|
-
found.push(navigator.languages[i]);
|
|
2930
|
-
}
|
|
2931
|
-
}
|
|
2932
|
-
if (navigator.userLanguage) {
|
|
2933
|
-
found.push(navigator.userLanguage);
|
|
2934
|
-
}
|
|
2935
|
-
if (navigator.language) {
|
|
2936
|
-
found.push(navigator.language);
|
|
2937
|
-
}
|
|
2938
|
-
}
|
|
2939
|
-
return found.length > 0 ? found : undefined;
|
|
2940
|
-
}
|
|
2941
|
-
};
|
|
2942
|
-
|
|
2943
|
-
var htmlTag = {
|
|
2944
|
-
name: 'htmlTag',
|
|
2945
|
-
lookup: function lookup(options) {
|
|
2946
|
-
var found;
|
|
2947
|
-
var htmlTag = options.htmlTag || (typeof document !== 'undefined' ? document.documentElement : null);
|
|
2948
|
-
if (htmlTag && typeof htmlTag.getAttribute === 'function') {
|
|
2949
|
-
found = htmlTag.getAttribute('lang');
|
|
2950
|
-
}
|
|
2951
|
-
return found;
|
|
2952
|
-
}
|
|
2953
|
-
};
|
|
2954
|
-
|
|
2955
|
-
var path = {
|
|
2956
|
-
name: 'path',
|
|
2957
|
-
lookup: function lookup(options) {
|
|
2958
|
-
var found;
|
|
2959
|
-
if (typeof window !== 'undefined') {
|
|
2960
|
-
var language = window.location.pathname.match(/\/([a-zA-Z-]*)/g);
|
|
2961
|
-
if (language instanceof Array) {
|
|
2962
|
-
if (typeof options.lookupFromPathIndex === 'number') {
|
|
2963
|
-
if (typeof language[options.lookupFromPathIndex] !== 'string') {
|
|
2964
|
-
return undefined;
|
|
2965
|
-
}
|
|
2966
|
-
found = language[options.lookupFromPathIndex].replace('/', '');
|
|
2967
|
-
} else {
|
|
2968
|
-
found = language[0].replace('/', '');
|
|
2969
|
-
}
|
|
2970
|
-
}
|
|
2971
|
-
}
|
|
2972
|
-
return found;
|
|
2973
|
-
}
|
|
2974
|
-
};
|
|
2975
|
-
|
|
2976
|
-
var subdomain = {
|
|
2977
|
-
name: 'subdomain',
|
|
2978
|
-
lookup: function lookup(options) {
|
|
2979
|
-
// If given get the subdomain index else 1
|
|
2980
|
-
var lookupFromSubdomainIndex = typeof options.lookupFromSubdomainIndex === 'number' ? options.lookupFromSubdomainIndex + 1 : 1;
|
|
2981
|
-
// get all matches if window.location. is existing
|
|
2982
|
-
// first item of match is the match itself and the second is the first group macht which sould be the first subdomain match
|
|
2983
|
-
// is the hostname no public domain get the or option of localhost
|
|
2984
|
-
var language = typeof window !== 'undefined' && window.location && window.location.hostname && window.location.hostname.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i);
|
|
2985
|
-
|
|
2986
|
-
// if there is no match (null) return undefined
|
|
2987
|
-
if (!language) return undefined;
|
|
2988
|
-
// return the given group match
|
|
2989
|
-
return language[lookupFromSubdomainIndex];
|
|
2990
|
-
}
|
|
2991
|
-
};
|
|
2992
|
-
|
|
2993
|
-
function getDefaults$1() {
|
|
2994
|
-
return {
|
|
2995
|
-
order: ['querystring', 'cookie', 'localStorage', 'sessionStorage', 'navigator', 'htmlTag'],
|
|
2996
|
-
lookupQuerystring: 'lng',
|
|
2997
|
-
lookupCookie: 'i18next',
|
|
2998
|
-
lookupLocalStorage: 'i18nextLng',
|
|
2999
|
-
lookupSessionStorage: 'i18nextLng',
|
|
3000
|
-
// cache user language
|
|
3001
|
-
caches: ['localStorage'],
|
|
3002
|
-
excludeCacheFor: ['cimode']
|
|
3003
|
-
// cookieMinutes: 10,
|
|
3004
|
-
// cookieDomain: 'myDomain'
|
|
3005
|
-
};
|
|
3006
|
-
}
|
|
3007
|
-
var Browser = /*#__PURE__*/function () {
|
|
3008
|
-
function Browser(services) {
|
|
3009
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3010
|
-
_classCallCheck$1(this, Browser);
|
|
3011
|
-
this.type = 'languageDetector';
|
|
3012
|
-
this.detectors = {};
|
|
3013
|
-
this.init(services, options);
|
|
3014
|
-
}
|
|
3015
|
-
_createClass$1(Browser, [{
|
|
3016
|
-
key: "init",
|
|
3017
|
-
value: function init(services) {
|
|
3018
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3019
|
-
var i18nOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
3020
|
-
this.services = services;
|
|
3021
|
-
this.options = defaults(options, this.options || {}, getDefaults$1());
|
|
3022
|
-
|
|
3023
|
-
// backwards compatibility
|
|
3024
|
-
if (this.options.lookupFromUrlIndex) this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex;
|
|
3025
|
-
this.i18nOptions = i18nOptions;
|
|
3026
|
-
this.addDetector(cookie$1);
|
|
3027
|
-
this.addDetector(querystring);
|
|
3028
|
-
this.addDetector(localStorage);
|
|
3029
|
-
this.addDetector(sessionStorage);
|
|
3030
|
-
this.addDetector(navigator$1);
|
|
3031
|
-
this.addDetector(htmlTag);
|
|
3032
|
-
this.addDetector(path);
|
|
3033
|
-
this.addDetector(subdomain);
|
|
3034
|
-
}
|
|
3035
|
-
}, {
|
|
3036
|
-
key: "addDetector",
|
|
3037
|
-
value: function addDetector(detector) {
|
|
3038
|
-
this.detectors[detector.name] = detector;
|
|
3039
|
-
}
|
|
3040
|
-
}, {
|
|
3041
|
-
key: "detect",
|
|
3042
|
-
value: function detect(detectionOrder) {
|
|
3043
|
-
var _this = this;
|
|
3044
|
-
if (!detectionOrder) detectionOrder = this.options.order;
|
|
3045
|
-
var detected = [];
|
|
3046
|
-
detectionOrder.forEach(function (detectorName) {
|
|
3047
|
-
if (_this.detectors[detectorName]) {
|
|
3048
|
-
var lookup = _this.detectors[detectorName].lookup(_this.options);
|
|
3049
|
-
if (lookup && typeof lookup === 'string') lookup = [lookup];
|
|
3050
|
-
if (lookup) detected = detected.concat(lookup);
|
|
3051
|
-
}
|
|
3052
|
-
});
|
|
3053
|
-
if (this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0
|
|
3054
|
-
return detected.length > 0 ? detected[0] : null; // a little backward compatibility
|
|
3055
|
-
}
|
|
3056
|
-
}, {
|
|
3057
|
-
key: "cacheUserLanguage",
|
|
3058
|
-
value: function cacheUserLanguage(lng, caches) {
|
|
3059
|
-
var _this2 = this;
|
|
3060
|
-
if (!caches) caches = this.options.caches;
|
|
3061
|
-
if (!caches) return;
|
|
3062
|
-
if (this.options.excludeCacheFor && this.options.excludeCacheFor.indexOf(lng) > -1) return;
|
|
3063
|
-
caches.forEach(function (cacheName) {
|
|
3064
|
-
if (_this2.detectors[cacheName]) _this2.detectors[cacheName].cacheUserLanguage(lng, _this2.options);
|
|
3065
|
-
});
|
|
3066
|
-
}
|
|
3067
|
-
}]);
|
|
3068
|
-
return Browser;
|
|
3069
|
-
}();
|
|
3070
|
-
Browser.type = 'languageDetector';
|
|
3071
|
-
|
|
3072
|
-
function _objectWithoutPropertiesLoose$1(source, excluded) {
|
|
3073
|
-
if (source == null) return {};
|
|
3074
|
-
var target = {};
|
|
3075
|
-
var sourceKeys = Object.keys(source);
|
|
3076
|
-
var key, i;
|
|
3077
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
3078
|
-
key = sourceKeys[i];
|
|
3079
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
3080
|
-
target[key] = source[key];
|
|
3081
|
-
}
|
|
3082
|
-
return target;
|
|
3083
|
-
}
|
|
3084
|
-
|
|
3085
|
-
function _objectWithoutProperties$1(source, excluded) {
|
|
3086
|
-
if (source == null) return {};
|
|
3087
|
-
var target = _objectWithoutPropertiesLoose$1(source, excluded);
|
|
3088
|
-
var key, i;
|
|
3089
|
-
if (Object.getOwnPropertySymbols) {
|
|
3090
|
-
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
3091
|
-
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
|
3092
|
-
key = sourceSymbolKeys[i];
|
|
3093
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
3094
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
3095
|
-
target[key] = source[key];
|
|
3096
|
-
}
|
|
3097
|
-
}
|
|
3098
|
-
return target;
|
|
3099
|
-
}
|
|
3100
|
-
|
|
3101
|
-
function _typeof$2(obj) {
|
|
3102
|
-
"@babel/helpers - typeof";
|
|
3103
|
-
|
|
3104
|
-
return _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
3105
|
-
return typeof obj;
|
|
3106
|
-
} : function (obj) {
|
|
3107
|
-
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
3108
|
-
}, _typeof$2(obj);
|
|
3109
|
-
}
|
|
3110
|
-
|
|
3111
|
-
function _toPrimitive$1(input, hint) {
|
|
3112
|
-
if (_typeof$2(input) !== "object" || input === null) return input;
|
|
3113
|
-
var prim = input[Symbol.toPrimitive];
|
|
3114
|
-
if (prim !== undefined) {
|
|
3115
|
-
var res = prim.call(input, hint || "default");
|
|
3116
|
-
if (_typeof$2(res) !== "object") return res;
|
|
3117
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
3118
|
-
}
|
|
3119
|
-
return (hint === "string" ? String : Number)(input);
|
|
3120
|
-
}
|
|
3121
|
-
|
|
3122
|
-
function _toPropertyKey$1(arg) {
|
|
3123
|
-
var key = _toPrimitive$1(arg, "string");
|
|
3124
|
-
return _typeof$2(key) === "symbol" ? key : String(key);
|
|
3125
|
-
}
|
|
3126
|
-
|
|
3127
|
-
function _defineProperty$1(obj, key, value) {
|
|
3128
|
-
key = _toPropertyKey$1(key);
|
|
3129
|
-
if (key in obj) {
|
|
3130
|
-
Object.defineProperty(obj, key, {
|
|
3131
|
-
value: value,
|
|
3132
|
-
enumerable: true,
|
|
3133
|
-
configurable: true,
|
|
3134
|
-
writable: true
|
|
3135
|
-
});
|
|
3136
|
-
} else {
|
|
3137
|
-
obj[key] = value;
|
|
3138
|
-
}
|
|
3139
|
-
return obj;
|
|
3140
|
-
}
|
|
3141
|
-
|
|
3142
|
-
/**
|
|
3143
|
-
* This file automatically generated from `pre-publish.js`.
|
|
3144
|
-
* Do not manually edit.
|
|
3145
|
-
*/
|
|
3146
|
-
|
|
3147
|
-
var voidElements = {
|
|
3148
|
-
"area": true,
|
|
3149
|
-
"base": true,
|
|
3150
|
-
"br": true,
|
|
3151
|
-
"col": true,
|
|
3152
|
-
"embed": true,
|
|
3153
|
-
"hr": true,
|
|
3154
|
-
"img": true,
|
|
3155
|
-
"input": true,
|
|
3156
|
-
"link": true,
|
|
3157
|
-
"meta": true,
|
|
3158
|
-
"param": true,
|
|
3159
|
-
"source": true,
|
|
3160
|
-
"track": true,
|
|
3161
|
-
"wbr": true
|
|
3162
|
-
};
|
|
3163
|
-
|
|
3164
|
-
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],(voidElements[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)},"")}};
|
|
3165
|
-
|
|
3166
|
-
/**
|
|
3167
|
-
* Copyright (C) 2017-present by Andrea Giammarchi - @WebReflection
|
|
3168
|
-
*
|
|
3169
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
3170
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
3171
|
-
* in the Software without restriction, including without limitation the rights
|
|
3172
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
3173
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
3174
|
-
* furnished to do so, subject to the following conditions:
|
|
3175
|
-
*
|
|
3176
|
-
* The above copyright notice and this permission notice shall be included in
|
|
3177
|
-
* all copies or substantial portions of the Software.
|
|
3178
|
-
*
|
|
3179
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
3180
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
3181
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
3182
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
3183
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
3184
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
3185
|
-
* THE SOFTWARE.
|
|
3186
|
-
*/
|
|
3187
|
-
|
|
3188
|
-
var replace = ''.replace;
|
|
3189
|
-
var es = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
|
|
3190
|
-
var unes = {
|
|
3191
|
-
'&': '&',
|
|
3192
|
-
'&': '&',
|
|
3193
|
-
'<': '<',
|
|
3194
|
-
'<': '<',
|
|
3195
|
-
'>': '>',
|
|
3196
|
-
'>': '>',
|
|
3197
|
-
''': "'",
|
|
3198
|
-
''': "'",
|
|
3199
|
-
'"': '"',
|
|
3200
|
-
'"': '"'
|
|
3201
|
-
};
|
|
3202
|
-
|
|
3203
|
-
function unescape(un) {
|
|
3204
|
-
return replace.call(un, es, cape);
|
|
3205
|
-
}
|
|
3206
|
-
function cape(m) {
|
|
3207
|
-
return unes[m];
|
|
3208
|
-
}
|
|
3209
|
-
|
|
3210
|
-
function _classCallCheck(instance, Constructor) {
|
|
3211
|
-
if (!(instance instanceof Constructor)) {
|
|
3212
|
-
throw new TypeError("Cannot call a class as a function");
|
|
3213
|
-
}
|
|
3214
|
-
}
|
|
3215
|
-
|
|
3216
|
-
function _defineProperties(target, props) {
|
|
3217
|
-
for (var i = 0; i < props.length; i++) {
|
|
3218
|
-
var descriptor = props[i];
|
|
3219
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
3220
|
-
descriptor.configurable = true;
|
|
3221
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
3222
|
-
Object.defineProperty(target, _toPropertyKey$1(descriptor.key), descriptor);
|
|
3223
|
-
}
|
|
3224
|
-
}
|
|
3225
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
3226
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
3227
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
3228
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
3229
|
-
writable: false
|
|
3230
|
-
});
|
|
3231
|
-
return Constructor;
|
|
3232
|
-
}
|
|
3233
|
-
|
|
3234
|
-
function ownKeys$f(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
3235
|
-
|
|
3236
|
-
function _objectSpread$f(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$f(Object(source), true).forEach(function (key) { _defineProperty$1(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$f(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
3237
|
-
var defaultOptions = {
|
|
3238
|
-
bindI18n: 'languageChanged',
|
|
3239
|
-
bindI18nStore: '',
|
|
3240
|
-
transEmptyNodeValue: '',
|
|
3241
|
-
transSupportBasicHtmlNodes: true,
|
|
3242
|
-
transWrapTextNodes: '',
|
|
3243
|
-
transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
|
|
3244
|
-
useSuspense: true
|
|
3245
|
-
};
|
|
3246
|
-
var i18nInstance;
|
|
3247
|
-
var I18nContext = React.createContext();
|
|
3248
|
-
function setDefaults() {
|
|
3249
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3250
|
-
defaultOptions = _objectSpread$f(_objectSpread$f({}, defaultOptions), options);
|
|
3251
|
-
}
|
|
3252
|
-
function getDefaults() {
|
|
3253
|
-
return defaultOptions;
|
|
3254
|
-
}
|
|
3255
|
-
var ReportNamespaces = function () {
|
|
3256
|
-
function ReportNamespaces() {
|
|
3257
|
-
_classCallCheck(this, ReportNamespaces);
|
|
3258
|
-
|
|
3259
|
-
this.usedNamespaces = {};
|
|
3260
|
-
}
|
|
3261
|
-
|
|
3262
|
-
_createClass(ReportNamespaces, [{
|
|
3263
|
-
key: "addUsedNamespaces",
|
|
3264
|
-
value: function addUsedNamespaces(namespaces) {
|
|
3265
|
-
var _this = this;
|
|
3266
|
-
|
|
3267
|
-
namespaces.forEach(function (ns) {
|
|
3268
|
-
if (!_this.usedNamespaces[ns]) _this.usedNamespaces[ns] = true;
|
|
3269
|
-
});
|
|
3270
|
-
}
|
|
3271
|
-
}, {
|
|
3272
|
-
key: "getUsedNamespaces",
|
|
3273
|
-
value: function getUsedNamespaces() {
|
|
3274
|
-
return Object.keys(this.usedNamespaces);
|
|
3275
|
-
}
|
|
3276
|
-
}]);
|
|
3277
|
-
|
|
3278
|
-
return ReportNamespaces;
|
|
3279
|
-
}();
|
|
3280
|
-
function setI18n(instance) {
|
|
3281
|
-
i18nInstance = instance;
|
|
3282
|
-
}
|
|
3283
|
-
function getI18n() {
|
|
3284
|
-
return i18nInstance;
|
|
3285
|
-
}
|
|
3286
|
-
var initReactI18next = {
|
|
3287
|
-
type: '3rdParty',
|
|
3288
|
-
init: function init(instance) {
|
|
3289
|
-
setDefaults(instance.options.react);
|
|
3290
|
-
setI18n(instance);
|
|
3291
|
-
}
|
|
3292
|
-
};
|
|
3293
|
-
|
|
3294
|
-
function warn() {
|
|
3295
|
-
if (console && console.warn) {
|
|
3296
|
-
var _console;
|
|
3297
|
-
|
|
3298
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3299
|
-
args[_key] = arguments[_key];
|
|
3300
|
-
}
|
|
3301
|
-
|
|
3302
|
-
if (typeof args[0] === 'string') args[0] = "react-i18next:: ".concat(args[0]);
|
|
3303
|
-
|
|
3304
|
-
(_console = console).warn.apply(_console, args);
|
|
3305
|
-
}
|
|
3306
|
-
}
|
|
3307
|
-
var alreadyWarned = {};
|
|
3308
|
-
function warnOnce() {
|
|
3309
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
3310
|
-
args[_key2] = arguments[_key2];
|
|
3311
|
-
}
|
|
3312
|
-
|
|
3313
|
-
if (typeof args[0] === 'string' && alreadyWarned[args[0]]) return;
|
|
3314
|
-
if (typeof args[0] === 'string') alreadyWarned[args[0]] = new Date();
|
|
3315
|
-
warn.apply(void 0, args);
|
|
3316
|
-
}
|
|
3317
|
-
function loadNamespaces(i18n, ns, cb) {
|
|
3318
|
-
i18n.loadNamespaces(ns, function () {
|
|
3319
|
-
if (i18n.isInitialized) {
|
|
3320
|
-
cb();
|
|
3321
|
-
} else {
|
|
3322
|
-
var initialized = function initialized() {
|
|
3323
|
-
setTimeout(function () {
|
|
3324
|
-
i18n.off('initialized', initialized);
|
|
3325
|
-
}, 0);
|
|
3326
|
-
cb();
|
|
3327
|
-
};
|
|
3328
|
-
|
|
3329
|
-
i18n.on('initialized', initialized);
|
|
3330
|
-
}
|
|
3331
|
-
});
|
|
3332
|
-
}
|
|
3333
|
-
|
|
3334
|
-
function oldI18nextHasLoadedNamespace(ns, i18n) {
|
|
3335
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
3336
|
-
var lng = i18n.languages[0];
|
|
3337
|
-
var fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
|
|
3338
|
-
var lastLng = i18n.languages[i18n.languages.length - 1];
|
|
3339
|
-
if (lng.toLowerCase() === 'cimode') return true;
|
|
3340
|
-
|
|
3341
|
-
var loadNotPending = function loadNotPending(l, n) {
|
|
3342
|
-
var loadState = i18n.services.backendConnector.state["".concat(l, "|").concat(n)];
|
|
3343
|
-
return loadState === -1 || loadState === 2;
|
|
3344
|
-
};
|
|
3345
|
-
|
|
3346
|
-
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false;
|
|
3347
|
-
if (i18n.hasResourceBundle(lng, ns)) return true;
|
|
3348
|
-
if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true;
|
|
3349
|
-
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
3350
|
-
return false;
|
|
3351
|
-
}
|
|
3352
|
-
|
|
3353
|
-
function hasLoadedNamespace(ns, i18n) {
|
|
3354
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
3355
|
-
|
|
3356
|
-
if (!i18n.languages || !i18n.languages.length) {
|
|
3357
|
-
warnOnce('i18n.languages were undefined or empty', i18n.languages);
|
|
3358
|
-
return true;
|
|
3359
|
-
}
|
|
3360
|
-
|
|
3361
|
-
var isNewerI18next = i18n.options.ignoreJSONStructure !== undefined;
|
|
3362
|
-
|
|
3363
|
-
if (!isNewerI18next) {
|
|
3364
|
-
return oldI18nextHasLoadedNamespace(ns, i18n, options);
|
|
3365
|
-
}
|
|
3366
|
-
|
|
3367
|
-
return i18n.hasLoadedNamespace(ns, {
|
|
3368
|
-
precheck: function precheck(i18nInstance, loadNotPending) {
|
|
3369
|
-
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
|
|
3370
|
-
}
|
|
3371
|
-
});
|
|
3372
|
-
}
|
|
3373
|
-
|
|
3374
|
-
var _excluded$2 = ["format"],
|
|
3375
|
-
_excluded2 = ["children", "count", "parent", "i18nKey", "context", "tOptions", "values", "defaults", "components", "ns", "i18n", "t", "shouldUnescape"];
|
|
3376
|
-
|
|
3377
|
-
function ownKeys$e(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
3378
|
-
|
|
3379
|
-
function _objectSpread$e(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$e(Object(source), true).forEach(function (key) { _defineProperty$1(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$e(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
3380
|
-
|
|
3381
|
-
function hasChildren(node, checkLength) {
|
|
3382
|
-
if (!node) return false;
|
|
3383
|
-
var base = node.props ? node.props.children : node.children;
|
|
3384
|
-
if (checkLength) return base.length > 0;
|
|
3385
|
-
return !!base;
|
|
3386
|
-
}
|
|
3387
|
-
|
|
3388
|
-
function getChildren(node) {
|
|
3389
|
-
if (!node) return [];
|
|
3390
|
-
return node && node.children ? node.children : node.props && node.props.children;
|
|
3391
|
-
}
|
|
3392
|
-
|
|
3393
|
-
function hasValidReactChildren(children) {
|
|
3394
|
-
if (Object.prototype.toString.call(children) !== '[object Array]') return false;
|
|
3395
|
-
return children.every(function (child) {
|
|
3396
|
-
return React.isValidElement(child);
|
|
3397
|
-
});
|
|
3398
|
-
}
|
|
3399
|
-
|
|
3400
|
-
function getAsArray(data) {
|
|
3401
|
-
return Array.isArray(data) ? data : [data];
|
|
3402
|
-
}
|
|
3403
|
-
|
|
3404
|
-
function mergeProps(source, target) {
|
|
3405
|
-
var newTarget = _objectSpread$e({}, target);
|
|
3406
|
-
|
|
3407
|
-
newTarget.props = Object.assign(source.props, target.props);
|
|
3408
|
-
return newTarget;
|
|
3409
|
-
}
|
|
3410
|
-
|
|
3411
|
-
function nodesToString(children, i18nOptions) {
|
|
3412
|
-
if (!children) return '';
|
|
3413
|
-
var stringNode = '';
|
|
3414
|
-
var childrenArray = getAsArray(children);
|
|
3415
|
-
var keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : [];
|
|
3416
|
-
childrenArray.forEach(function (child, childIndex) {
|
|
3417
|
-
if (typeof child === 'string') {
|
|
3418
|
-
stringNode += "".concat(child);
|
|
3419
|
-
} else if (React.isValidElement(child)) {
|
|
3420
|
-
var childPropsCount = Object.keys(child.props).length;
|
|
3421
|
-
var shouldKeepChild = keepArray.indexOf(child.type) > -1;
|
|
3422
|
-
var childChildren = child.props.children;
|
|
3423
|
-
|
|
3424
|
-
if (!childChildren && shouldKeepChild && childPropsCount === 0) {
|
|
3425
|
-
stringNode += "<".concat(child.type, "/>");
|
|
3426
|
-
} else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
|
|
3427
|
-
stringNode += "<".concat(childIndex, "></").concat(childIndex, ">");
|
|
3428
|
-
} else if (child.props.i18nIsDynamicList) {
|
|
3429
|
-
stringNode += "<".concat(childIndex, "></").concat(childIndex, ">");
|
|
3430
|
-
} else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
|
|
3431
|
-
stringNode += "<".concat(child.type, ">").concat(childChildren, "</").concat(child.type, ">");
|
|
3432
|
-
} else {
|
|
3433
|
-
var content = nodesToString(childChildren, i18nOptions);
|
|
3434
|
-
stringNode += "<".concat(childIndex, ">").concat(content, "</").concat(childIndex, ">");
|
|
3435
|
-
}
|
|
3436
|
-
} else if (child === null) {
|
|
3437
|
-
warn("Trans: the passed in value is invalid - seems you passed in a null child.");
|
|
3438
|
-
} else if (_typeof$2(child) === 'object') {
|
|
3439
|
-
var format = child.format,
|
|
3440
|
-
clone = _objectWithoutProperties$1(child, _excluded$2);
|
|
3441
|
-
|
|
3442
|
-
var keys = Object.keys(clone);
|
|
3443
|
-
|
|
3444
|
-
if (keys.length === 1) {
|
|
3445
|
-
var value = format ? "".concat(keys[0], ", ").concat(format) : keys[0];
|
|
3446
|
-
stringNode += "{{".concat(value, "}}");
|
|
3447
|
-
} else {
|
|
3448
|
-
warn("react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.", child);
|
|
3449
|
-
}
|
|
3450
|
-
} else {
|
|
3451
|
-
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);
|
|
3452
|
-
}
|
|
3453
|
-
});
|
|
3454
|
-
return stringNode;
|
|
3455
|
-
}
|
|
3456
|
-
|
|
3457
|
-
function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) {
|
|
3458
|
-
if (targetString === '') return [];
|
|
3459
|
-
var keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
3460
|
-
var emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString);
|
|
3461
|
-
if (!children && !emptyChildrenButNeedsHandling) return [targetString];
|
|
3462
|
-
var data = {};
|
|
3463
|
-
|
|
3464
|
-
function getData(childs) {
|
|
3465
|
-
var childrenArray = getAsArray(childs);
|
|
3466
|
-
childrenArray.forEach(function (child) {
|
|
3467
|
-
if (typeof child === 'string') return;
|
|
3468
|
-
if (hasChildren(child)) getData(getChildren(child));else if (_typeof$2(child) === 'object' && !React.isValidElement(child)) Object.assign(data, child);
|
|
3469
|
-
});
|
|
3470
|
-
}
|
|
3471
|
-
|
|
3472
|
-
getData(children);
|
|
3473
|
-
var ast = c.parse("<0>".concat(targetString, "</0>"));
|
|
3474
|
-
|
|
3475
|
-
var opts = _objectSpread$e(_objectSpread$e({}, data), combinedTOpts);
|
|
3476
|
-
|
|
3477
|
-
function renderInner(child, node, rootReactNode) {
|
|
3478
|
-
var childs = getChildren(child);
|
|
3479
|
-
var mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
3480
|
-
return hasValidReactChildren(childs) && mappedChildren.length === 0 ? childs : mappedChildren;
|
|
3481
|
-
}
|
|
3482
|
-
|
|
3483
|
-
function pushTranslatedJSX(child, inner, mem, i, isVoid) {
|
|
3484
|
-
if (child.dummy) child.children = inner;
|
|
3485
|
-
mem.push(React.cloneElement(child, _objectSpread$e(_objectSpread$e({}, child.props), {}, {
|
|
3486
|
-
key: i
|
|
3487
|
-
}), isVoid ? undefined : inner));
|
|
3488
|
-
}
|
|
3489
|
-
|
|
3490
|
-
function mapAST(reactNode, astNode, rootReactNode) {
|
|
3491
|
-
var reactNodes = getAsArray(reactNode);
|
|
3492
|
-
var astNodes = getAsArray(astNode);
|
|
3493
|
-
return astNodes.reduce(function (mem, node, i) {
|
|
3494
|
-
var translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
3495
|
-
|
|
3496
|
-
if (node.type === 'tag') {
|
|
3497
|
-
var tmp = reactNodes[parseInt(node.name, 10)];
|
|
3498
|
-
if (!tmp && rootReactNode.length === 1 && rootReactNode[0][node.name]) tmp = rootReactNode[0][node.name];
|
|
3499
|
-
if (!tmp) tmp = {};
|
|
3500
|
-
var child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
3501
|
-
props: node.attrs
|
|
3502
|
-
}, tmp) : tmp;
|
|
3503
|
-
var isElement = React.isValidElement(child);
|
|
3504
|
-
var isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
3505
|
-
var isEmptyTransWithHTML = emptyChildrenButNeedsHandling && _typeof$2(child) === 'object' && child.dummy && !isElement;
|
|
3506
|
-
var isKnownComponent = _typeof$2(children) === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name);
|
|
3507
|
-
|
|
3508
|
-
if (typeof child === 'string') {
|
|
3509
|
-
var value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
3510
|
-
mem.push(value);
|
|
3511
|
-
} else if (hasChildren(child) || isValidTranslationWithChildren) {
|
|
3512
|
-
var inner = renderInner(child, node, rootReactNode);
|
|
3513
|
-
pushTranslatedJSX(child, inner, mem, i);
|
|
3514
|
-
} else if (isEmptyTransWithHTML) {
|
|
3515
|
-
var _inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
3516
|
-
|
|
3517
|
-
mem.push(React.cloneElement(child, _objectSpread$e(_objectSpread$e({}, child.props), {}, {
|
|
3518
|
-
key: i
|
|
3519
|
-
}), _inner));
|
|
3520
|
-
} else if (Number.isNaN(parseFloat(node.name))) {
|
|
3521
|
-
if (isKnownComponent) {
|
|
3522
|
-
var _inner2 = renderInner(child, node, rootReactNode);
|
|
3523
|
-
|
|
3524
|
-
pushTranslatedJSX(child, _inner2, mem, i, node.voidElement);
|
|
3525
|
-
} else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
|
|
3526
|
-
if (node.voidElement) {
|
|
3527
|
-
mem.push(React.createElement(node.name, {
|
|
3528
|
-
key: "".concat(node.name, "-").concat(i)
|
|
3529
|
-
}));
|
|
3530
|
-
} else {
|
|
3531
|
-
var _inner3 = mapAST(reactNodes, node.children, rootReactNode);
|
|
3532
|
-
|
|
3533
|
-
mem.push(React.createElement(node.name, {
|
|
3534
|
-
key: "".concat(node.name, "-").concat(i)
|
|
3535
|
-
}, _inner3));
|
|
3536
|
-
}
|
|
3537
|
-
} else if (node.voidElement) {
|
|
3538
|
-
mem.push("<".concat(node.name, " />"));
|
|
3539
|
-
} else {
|
|
3540
|
-
var _inner4 = mapAST(reactNodes, node.children, rootReactNode);
|
|
3541
|
-
|
|
3542
|
-
mem.push("<".concat(node.name, ">").concat(_inner4, "</").concat(node.name, ">"));
|
|
3543
|
-
}
|
|
3544
|
-
} else if (_typeof$2(child) === 'object' && !isElement) {
|
|
3545
|
-
var content = node.children[0] ? translationContent : null;
|
|
3546
|
-
if (content) mem.push(content);
|
|
3547
|
-
} else if (node.children.length === 1 && translationContent) {
|
|
3548
|
-
mem.push(React.cloneElement(child, _objectSpread$e(_objectSpread$e({}, child.props), {}, {
|
|
3549
|
-
key: i
|
|
3550
|
-
}), translationContent));
|
|
3551
|
-
} else {
|
|
3552
|
-
mem.push(React.cloneElement(child, _objectSpread$e(_objectSpread$e({}, child.props), {}, {
|
|
3553
|
-
key: i
|
|
3554
|
-
})));
|
|
3555
|
-
}
|
|
3556
|
-
} else if (node.type === 'text') {
|
|
3557
|
-
var wrapTextNodes = i18nOptions.transWrapTextNodes;
|
|
3558
|
-
|
|
3559
|
-
var _content = shouldUnescape ? unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
|
|
3560
|
-
|
|
3561
|
-
if (wrapTextNodes) {
|
|
3562
|
-
mem.push(React.createElement(wrapTextNodes, {
|
|
3563
|
-
key: "".concat(node.name, "-").concat(i)
|
|
3564
|
-
}, _content));
|
|
3565
|
-
} else {
|
|
3566
|
-
mem.push(_content);
|
|
3567
|
-
}
|
|
3568
|
-
}
|
|
3569
|
-
|
|
3570
|
-
return mem;
|
|
3571
|
-
}, []);
|
|
3572
|
-
}
|
|
3573
|
-
|
|
3574
|
-
var result = mapAST([{
|
|
3575
|
-
dummy: true,
|
|
3576
|
-
children: children || []
|
|
3577
|
-
}], ast, getAsArray(children || []));
|
|
3578
|
-
return getChildren(result[0]);
|
|
3579
|
-
}
|
|
3580
|
-
|
|
3581
|
-
function Trans(_ref) {
|
|
3582
|
-
var children = _ref.children,
|
|
3583
|
-
count = _ref.count,
|
|
3584
|
-
parent = _ref.parent,
|
|
3585
|
-
i18nKey = _ref.i18nKey,
|
|
3586
|
-
context = _ref.context,
|
|
3587
|
-
_ref$tOptions = _ref.tOptions,
|
|
3588
|
-
tOptions = _ref$tOptions === void 0 ? {} : _ref$tOptions,
|
|
3589
|
-
values = _ref.values,
|
|
3590
|
-
defaults = _ref.defaults,
|
|
3591
|
-
components = _ref.components,
|
|
3592
|
-
ns = _ref.ns,
|
|
3593
|
-
i18nFromProps = _ref.i18n,
|
|
3594
|
-
tFromProps = _ref.t,
|
|
3595
|
-
shouldUnescape = _ref.shouldUnescape,
|
|
3596
|
-
additionalProps = _objectWithoutProperties$1(_ref, _excluded2);
|
|
3597
|
-
|
|
3598
|
-
var _ref2 = useContext(I18nContext) || {},
|
|
3599
|
-
i18nFromContext = _ref2.i18n,
|
|
3600
|
-
defaultNSFromContext = _ref2.defaultNS;
|
|
3601
|
-
|
|
3602
|
-
var i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
3603
|
-
|
|
3604
|
-
if (!i18n) {
|
|
3605
|
-
warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
|
|
3606
|
-
return children;
|
|
3607
|
-
}
|
|
3608
|
-
|
|
3609
|
-
var t = tFromProps || i18n.t.bind(i18n) || function (k) {
|
|
3610
|
-
return k;
|
|
3611
|
-
};
|
|
3612
|
-
|
|
3613
|
-
if (context) tOptions.context = context;
|
|
3614
|
-
|
|
3615
|
-
var reactI18nextOptions = _objectSpread$e(_objectSpread$e({}, getDefaults()), i18n.options && i18n.options.react);
|
|
3616
|
-
|
|
3617
|
-
var namespaces = ns || t.ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
|
|
3618
|
-
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
3619
|
-
var defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
|
|
3620
|
-
var hashTransKey = reactI18nextOptions.hashTransKey;
|
|
3621
|
-
var key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
|
|
3622
|
-
var interpolationOverride = values ? tOptions.interpolation : {
|
|
3623
|
-
interpolation: _objectSpread$e(_objectSpread$e({}, tOptions.interpolation), {}, {
|
|
3624
|
-
prefix: '#$?',
|
|
3625
|
-
suffix: '?$#'
|
|
3626
|
-
})
|
|
3627
|
-
};
|
|
3628
|
-
|
|
3629
|
-
var combinedTOpts = _objectSpread$e(_objectSpread$e(_objectSpread$e(_objectSpread$e({}, tOptions), {}, {
|
|
3630
|
-
count: count
|
|
3631
|
-
}, values), interpolationOverride), {}, {
|
|
3632
|
-
defaultValue: defaultValue,
|
|
3633
|
-
ns: namespaces
|
|
3634
|
-
});
|
|
3635
|
-
|
|
3636
|
-
var translation = key ? t(key, combinedTOpts) : defaultValue;
|
|
3637
|
-
var content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
|
|
3638
|
-
var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
|
|
3639
|
-
return useAsParent ? React.createElement(useAsParent, additionalProps, content) : content;
|
|
3640
|
-
}
|
|
3641
|
-
|
|
3642
|
-
function _arrayWithHoles$2(arr) {
|
|
3643
|
-
if (Array.isArray(arr)) return arr;
|
|
3644
|
-
}
|
|
3645
|
-
|
|
3646
|
-
function _iterableToArrayLimit$2(arr, i) {
|
|
3647
|
-
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
|
|
3648
|
-
if (null != _i) {
|
|
3649
|
-
var _s,
|
|
3650
|
-
_e,
|
|
3651
|
-
_x,
|
|
3652
|
-
_r,
|
|
3653
|
-
_arr = [],
|
|
3654
|
-
_n = !0,
|
|
3655
|
-
_d = !1;
|
|
3656
|
-
try {
|
|
3657
|
-
if (_x = (_i = _i.call(arr)).next, 0 === i) {
|
|
3658
|
-
if (Object(_i) !== _i) return;
|
|
3659
|
-
_n = !1;
|
|
3660
|
-
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
|
|
3661
|
-
} catch (err) {
|
|
3662
|
-
_d = !0, _e = err;
|
|
3663
|
-
} finally {
|
|
3664
|
-
try {
|
|
3665
|
-
if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return;
|
|
3666
|
-
} finally {
|
|
3667
|
-
if (_d) throw _e;
|
|
3668
|
-
}
|
|
3669
|
-
}
|
|
3670
|
-
return _arr;
|
|
3671
|
-
}
|
|
3672
|
-
}
|
|
3673
|
-
|
|
3674
|
-
function _arrayLikeToArray$2(arr, len) {
|
|
3675
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
3676
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
3677
|
-
return arr2;
|
|
3678
|
-
}
|
|
3679
|
-
|
|
3680
|
-
function _unsupportedIterableToArray$2(o, minLen) {
|
|
3681
|
-
if (!o) return;
|
|
3682
|
-
if (typeof o === "string") return _arrayLikeToArray$2(o, minLen);
|
|
3683
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
3684
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
3685
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
3686
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$2(o, minLen);
|
|
3687
|
-
}
|
|
3688
|
-
|
|
3689
|
-
function _nonIterableRest$2() {
|
|
3690
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
3691
|
-
}
|
|
3692
|
-
|
|
3693
|
-
function _slicedToArray$2(arr, i) {
|
|
3694
|
-
return _arrayWithHoles$2(arr) || _iterableToArrayLimit$2(arr, i) || _unsupportedIterableToArray$2(arr, i) || _nonIterableRest$2();
|
|
3695
|
-
}
|
|
3696
|
-
|
|
3697
|
-
function ownKeys$d(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
3698
|
-
|
|
3699
|
-
function _objectSpread$d(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$d(Object(source), true).forEach(function (key) { _defineProperty$1(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$d(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
3700
|
-
function useTranslation(ns) {
|
|
3701
|
-
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3702
|
-
var i18nFromProps = props.i18n;
|
|
3703
|
-
|
|
3704
|
-
var _ref = useContext(I18nContext) || {},
|
|
3705
|
-
i18nFromContext = _ref.i18n,
|
|
3706
|
-
defaultNSFromContext = _ref.defaultNS;
|
|
3707
|
-
|
|
3708
|
-
var i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
3709
|
-
if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
|
|
3710
|
-
|
|
3711
|
-
if (!i18n) {
|
|
3712
|
-
warnOnce('You will need to pass in an i18next instance by using initReactI18next');
|
|
3713
|
-
|
|
3714
|
-
var notReadyT = function notReadyT(k) {
|
|
3715
|
-
return Array.isArray(k) ? k[k.length - 1] : k;
|
|
3716
|
-
};
|
|
3717
|
-
|
|
3718
|
-
var retNotReady = [notReadyT, {}, false];
|
|
3719
|
-
retNotReady.t = notReadyT;
|
|
3720
|
-
retNotReady.i18n = {};
|
|
3721
|
-
retNotReady.ready = false;
|
|
3722
|
-
return retNotReady;
|
|
3723
|
-
}
|
|
3724
|
-
|
|
3725
|
-
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.');
|
|
3726
|
-
|
|
3727
|
-
var i18nOptions = _objectSpread$d(_objectSpread$d(_objectSpread$d({}, getDefaults()), i18n.options.react), props);
|
|
3728
|
-
|
|
3729
|
-
var useSuspense = i18nOptions.useSuspense,
|
|
3730
|
-
keyPrefix = i18nOptions.keyPrefix;
|
|
3731
|
-
var namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
|
|
3732
|
-
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
3733
|
-
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
|
|
3734
|
-
var ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(function (n) {
|
|
3735
|
-
return hasLoadedNamespace(n, i18n, i18nOptions);
|
|
3736
|
-
});
|
|
3737
|
-
|
|
3738
|
-
function getT() {
|
|
3739
|
-
return i18n.getFixedT(null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
|
|
3740
|
-
}
|
|
3741
|
-
|
|
3742
|
-
var _useState = useState(getT),
|
|
3743
|
-
_useState2 = _slicedToArray$2(_useState, 2),
|
|
3744
|
-
t = _useState2[0],
|
|
3745
|
-
setT = _useState2[1];
|
|
3746
|
-
|
|
3747
|
-
var isMounted = useRef(true);
|
|
3748
|
-
useEffect(function () {
|
|
3749
|
-
var bindI18n = i18nOptions.bindI18n,
|
|
3750
|
-
bindI18nStore = i18nOptions.bindI18nStore;
|
|
3751
|
-
isMounted.current = true;
|
|
3752
|
-
|
|
3753
|
-
if (!ready && !useSuspense) {
|
|
3754
|
-
loadNamespaces(i18n, namespaces, function () {
|
|
3755
|
-
if (isMounted.current) setT(getT);
|
|
3756
|
-
});
|
|
3757
|
-
}
|
|
3758
|
-
|
|
3759
|
-
function boundReset() {
|
|
3760
|
-
if (isMounted.current) setT(getT);
|
|
3761
|
-
}
|
|
3762
|
-
|
|
3763
|
-
if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
|
|
3764
|
-
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
|
|
3765
|
-
return function () {
|
|
3766
|
-
isMounted.current = false;
|
|
3767
|
-
if (bindI18n && i18n) bindI18n.split(' ').forEach(function (e) {
|
|
3768
|
-
return i18n.off(e, boundReset);
|
|
3769
|
-
});
|
|
3770
|
-
if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(function (e) {
|
|
3771
|
-
return i18n.store.off(e, boundReset);
|
|
3772
|
-
});
|
|
3773
|
-
};
|
|
3774
|
-
}, [i18n, namespaces.join()]);
|
|
3775
|
-
var isInitial = useRef(true);
|
|
3776
|
-
useEffect(function () {
|
|
3777
|
-
if (isMounted.current && !isInitial.current) {
|
|
3778
|
-
setT(getT);
|
|
3779
|
-
}
|
|
3780
|
-
|
|
3781
|
-
isInitial.current = false;
|
|
3782
|
-
}, [i18n]);
|
|
3783
|
-
var ret = [t, i18n, ready];
|
|
3784
|
-
ret.t = t;
|
|
3785
|
-
ret.i18n = i18n;
|
|
3786
|
-
ret.ready = ready;
|
|
3787
|
-
if (ready) return ret;
|
|
3788
|
-
if (!ready && !useSuspense) return ret;
|
|
3789
|
-
throw new Promise(function (resolve) {
|
|
3790
|
-
loadNamespaces(i18n, namespaces, function () {
|
|
3791
|
-
resolve();
|
|
3792
|
-
});
|
|
3793
|
-
});
|
|
3794
|
-
}
|
|
3795
|
-
|
|
3796
|
-
var neetoApprovals = {
|
|
3797
|
-
alerts: {
|
|
3798
|
-
deleting_: "You are permanently deleting the {{what}} <strong>{{- name}}</strong>. This can't be undone."
|
|
3799
|
-
},
|
|
3800
|
-
buttons: {
|
|
3801
|
-
cancel: "Cancel",
|
|
3802
|
-
saveChanges: "Save changes",
|
|
3803
|
-
approve: "Approve",
|
|
3804
|
-
decline: "Decline",
|
|
3805
|
-
"delete": "Delete"
|
|
3806
|
-
},
|
|
3807
|
-
common: {
|
|
3808
|
-
approval_one: "Approval",
|
|
3809
|
-
approval_other: "Approvals",
|
|
3810
|
-
pending: "Pending",
|
|
3811
|
-
template_one: "Template",
|
|
3812
|
-
template_other: "Templates",
|
|
3813
|
-
approvalTemplate_one: "Approval template",
|
|
3814
|
-
approvalTemplate_other: "Approval templates",
|
|
3815
|
-
history: "History",
|
|
3816
|
-
approvalHistory: "Approval history",
|
|
3817
|
-
approver_one: "Approver",
|
|
3818
|
-
approver_other: "Approvers",
|
|
3819
|
-
email: "Email",
|
|
3820
|
-
edit: "Edit",
|
|
3821
|
-
"delete": "Delete",
|
|
3822
|
-
delete_: "Delete {{what}}?",
|
|
3823
|
-
add_: "Add {{what}}",
|
|
3824
|
-
edit_: "Edit {{what}}",
|
|
3825
|
-
name: "Name",
|
|
3826
|
-
notFound_: "There are no {{what}} to show",
|
|
3827
|
-
notFound: "Could not find the approval request.",
|
|
3828
|
-
visibility: "Visibility",
|
|
3829
|
-
variable: "Variable",
|
|
3830
|
-
variable_: "Variable {{number}}",
|
|
3831
|
-
pendingApproval_one: "Pending approval",
|
|
3832
|
-
pendingApproval_other: "Pending approvals",
|
|
3833
|
-
title: "Title",
|
|
3834
|
-
id: "Id",
|
|
3835
|
-
created: "Created",
|
|
3836
|
-
status: "Status",
|
|
3837
|
-
record_one: "Record",
|
|
3838
|
-
record_other: "Records",
|
|
3839
|
-
note: "Note",
|
|
3840
|
-
approvedBy: "Approved by",
|
|
3841
|
-
rejectedBy: "Rejected by",
|
|
3842
|
-
cancelledBy: "Cancelled by",
|
|
3843
|
-
waitingFor: "Waiting for",
|
|
3844
|
-
templateDetails: "Template details",
|
|
3845
|
-
field: "Field",
|
|
3846
|
-
noDataHelpText: "Here is how you can use <a>{{entity}}.</a>"
|
|
3847
|
-
},
|
|
3848
|
-
validations: {
|
|
3849
|
-
limitExceeded: "You have exceeded the limit of {{limit}} characters for the {{what}}.",
|
|
3850
|
-
approver: "Please select a approver",
|
|
3851
|
-
required: "{{what}} is required",
|
|
3852
|
-
variableName: "Name must be alphanumeric, may include underscore, must start with a letter and must not end with an underscore.",
|
|
3853
|
-
pleaseEnter_: "Please enter {{what}}"
|
|
3854
|
-
},
|
|
3855
|
-
sidebar: {
|
|
3856
|
-
description: "View and manage approvals."
|
|
3857
|
-
},
|
|
3858
|
-
inputs: {
|
|
3859
|
-
labels: {
|
|
3860
|
-
firstName: "First name",
|
|
3861
|
-
lastName: "Last name",
|
|
3862
|
-
description: "Description",
|
|
3863
|
-
approver: "Approver",
|
|
3864
|
-
variableMapping: "Variable mapping",
|
|
3865
|
-
message: "Message"
|
|
3866
|
-
},
|
|
3867
|
-
placeholders: {
|
|
3868
|
-
firstName: "Enter first name",
|
|
3869
|
-
lastName: "Enter last name",
|
|
3870
|
-
email: "Enter email",
|
|
3871
|
-
name: "Enter name",
|
|
3872
|
-
description: "Enter description",
|
|
3873
|
-
enter_: "Enter {{what}}",
|
|
3874
|
-
search_: "Search {{what}}",
|
|
3875
|
-
select_: "Select {{what}}",
|
|
3876
|
-
add_: "Add {{what}}"
|
|
3877
|
-
}
|
|
3878
|
-
},
|
|
3879
|
-
typography: {
|
|
3880
|
-
newApprover: "Add new approver",
|
|
3881
|
-
editApprover: "Edit approver",
|
|
3882
|
-
approvalRequest: "Approval request has been <strong>{{status}}</strong>."
|
|
3883
|
-
},
|
|
3884
|
-
select: {
|
|
3885
|
-
visibility: {
|
|
3886
|
-
everyone: "Everyone"
|
|
3887
|
-
},
|
|
3888
|
-
approval: "Select approval"
|
|
3889
|
-
},
|
|
3890
|
-
example: {
|
|
3891
|
-
settings: "Settings",
|
|
3892
|
-
general: "General"
|
|
3893
|
-
}
|
|
3894
|
-
};
|
|
3895
|
-
var en = {
|
|
3896
|
-
neetoApprovals: neetoApprovals
|
|
3897
|
-
};
|
|
3898
|
-
|
|
3899
|
-
var alerts = {
|
|
3900
|
-
activating_: "Vous activez <strong>{{- person}}</strong>. Es-tu sur de vouloir continuer?",
|
|
3901
|
-
deactivating_: "Vous désactivez <strong>{{- person}}</strong>. Es-tu sur de vouloir continuer?",
|
|
3902
|
-
deleting_: "Vous supprimez définitivement le {{what}} <strong>{{- name}}</strong>. Cette action ne peut pas être annulée. Êtes-vous sur de vouloir continuer?"
|
|
3903
|
-
};
|
|
3904
|
-
var buttons = {
|
|
3905
|
-
cancel: "Annuler",
|
|
3906
|
-
changeRole: "Changer de rôle",
|
|
3907
|
-
proceed: "Procéder",
|
|
3908
|
-
saveChanges: "Sauvegarder les modifications"
|
|
3909
|
-
};
|
|
3910
|
-
var columns = {
|
|
3911
|
-
search: "Colonnes de recherche",
|
|
3912
|
-
noColumnsFound: "Aucune colonne trouvée."
|
|
3913
|
-
};
|
|
3914
|
-
var common = {
|
|
3915
|
-
activate: "Activer",
|
|
3916
|
-
activate_: "Activer le {{what}}",
|
|
3917
|
-
active: "Actif",
|
|
3918
|
-
active_: "{{what}} actifs",
|
|
3919
|
-
add_: "Ajouter {{what}}",
|
|
3920
|
-
all: "Tous",
|
|
3921
|
-
all_: "tous les {{what}}",
|
|
3922
|
-
column_one: "Colonne",
|
|
3923
|
-
column_other: "Colonnes",
|
|
3924
|
-
deactivate: "Désactiver",
|
|
3925
|
-
deactivate_: "Désactiver le {{what}}",
|
|
3926
|
-
deactivated: "Désactivé",
|
|
3927
|
-
deactivated_: "{{what}} désactivés",
|
|
3928
|
-
"delete": "Effacer",
|
|
3929
|
-
delete_: "Supprimer le {{what}}",
|
|
3930
|
-
description: "La description",
|
|
3931
|
-
edit: "Éditer",
|
|
3932
|
-
edit_: "Modifier le {{what}}",
|
|
3933
|
-
email_one: "E-mail",
|
|
3934
|
-
email_other: "E-mails",
|
|
3935
|
-
manage_: "Gérer {{what}}",
|
|
3936
|
-
name: "Nom",
|
|
3937
|
-
notFound_: "Désolé, aucun {{what}} n'a été trouvé.",
|
|
3938
|
-
permission_one: "Autorisation",
|
|
3939
|
-
permission_other: "Autorisations",
|
|
3940
|
-
role_one: "Rôle",
|
|
3941
|
-
role_other: "Rôles",
|
|
3942
|
-
search_: "Rechercher des {{what}}",
|
|
3943
|
-
update_: "Mettre à jour le {{what}}",
|
|
3944
|
-
takeAction: "Passer à l'action"
|
|
3945
|
-
};
|
|
3946
|
-
var helpers = {
|
|
3947
|
-
configPermissions: "Configurez les autorisations pour les modules.",
|
|
3948
|
-
enterMultipleEmails: "Veuillez appuyer sur espace, tabulation ou entrée après avoir saisi une adresse e-mail.",
|
|
3949
|
-
moreInfoAboutPermissions: "Plus d'informations sur les autorisations",
|
|
3950
|
-
noRolesFound: "Aucun rôle trouvé.",
|
|
3951
|
-
searchRoles: "Rechercher des rôles",
|
|
3952
|
-
selectedMembersCount_one: "{{count}} {{metaName}} sélectionné sur",
|
|
3953
|
-
selectedMembersCount_other: "{{count}} {{metaName}} sélectionnés sur",
|
|
3954
|
-
visitToKnowMoreAboutPermissions: "Visitez pour en savoir plus sur les autorisations"
|
|
3955
|
-
};
|
|
3956
|
-
var metaNames = {
|
|
3957
|
-
member_one: "Membre",
|
|
3958
|
-
member_other: "Membres"
|
|
3959
|
-
};
|
|
3960
|
-
var placeholders = {
|
|
3961
|
-
email: "Veuillez saisir les adresses e-mail",
|
|
3962
|
-
enter_: "Veuillez entrer le {{what}}",
|
|
3963
|
-
enterDescription: "Veuillez entrer une description",
|
|
3964
|
-
enterRoleName: "Veuillez entrer le nom du rôle",
|
|
3965
|
-
role: "Veuillez sélectionner un rôle"
|
|
3966
|
-
};
|
|
3967
|
-
var tooltips = {
|
|
3968
|
-
activateUserToEdit: "Veuillez activer l'utilisateur pour modifier son rôle.",
|
|
3969
|
-
adminMustHaveAccess: "Les administrateurs doivent avoir accès à cette fonctionnalité.",
|
|
3970
|
-
noPermissionToAddMember: "Veuillez demander à l'administrateur de vous autoriser à ajouter des membres.",
|
|
3971
|
-
noPermissionToAddRole: "Veuillez demander à l'administrateur de vous autoriser à ajouter des rôles.",
|
|
3972
|
-
noPermissionToEditMembers: "Veuillez demander à l'administrateur de vous autoriser à modifier les membres.",
|
|
3973
|
-
noPermissionToEditRoles: "Veuillez demander à l'administrateur de vous autoriser à modifier les rôles.",
|
|
3974
|
-
noPermissionToRemoveRoles: "Veuillez demander à l'administrateur de vous autoriser à supprimer des rôles."
|
|
3975
|
-
};
|
|
3976
|
-
var validations = {
|
|
3977
|
-
enterRoleName: "Veuillez entrer le nom du rôle",
|
|
3978
|
-
filterInvalidEmails: "Cliquez ici pour supprimer les e-mails invalides.",
|
|
3979
|
-
limitExceeded: "Vous avez dépassé la limite de {{limit}} caractères pour le {{what}}.",
|
|
3980
|
-
minOneEmail: "Veuillez saisir au moins une adresse e-mail.",
|
|
3981
|
-
roleRequired: "Veuillez sélectionner un rôle.",
|
|
3982
|
-
validEmail: "Veuillez vous assurer que toutes les adresses e-mail sont valides."
|
|
3983
|
-
};
|
|
3984
|
-
var fr = {
|
|
3985
|
-
alerts: alerts,
|
|
3986
|
-
buttons: buttons,
|
|
3987
|
-
columns: columns,
|
|
3988
|
-
common: common,
|
|
3989
|
-
helpers: helpers,
|
|
3990
|
-
metaNames: metaNames,
|
|
3991
|
-
placeholders: placeholders,
|
|
3992
|
-
tooltips: tooltips,
|
|
3993
|
-
validations: validations
|
|
3994
|
-
};
|
|
3995
|
-
|
|
3996
|
-
instance.use(Browser).use(initReactI18next).init({
|
|
3997
|
-
resources: {
|
|
3998
|
-
en: {
|
|
3999
|
-
translation: en
|
|
4000
|
-
},
|
|
4001
|
-
fr: {
|
|
4002
|
-
translation: fr
|
|
4003
|
-
}
|
|
4004
|
-
},
|
|
4005
|
-
fallbackLng: "en",
|
|
4006
|
-
detection: {
|
|
4007
|
-
order: ["navigator"]
|
|
4008
|
-
}
|
|
4009
|
-
});
|
|
4010
|
-
|
|
4011
27
|
function _typeof$1(obj) {
|
|
4012
28
|
"@babel/helpers - typeof";
|
|
4013
29
|
|
|
@@ -4123,9 +139,9 @@ var routes = {
|
|
|
4123
139
|
new URLSearchParams(window.location.search);
|
|
4124
140
|
var DEFAULT_PAGE_SIZE = 8;
|
|
4125
141
|
var DEFAULT_FILTER_VALUES = {
|
|
4126
|
-
|
|
142
|
+
searchTerm: "",
|
|
4127
143
|
sortBy: "",
|
|
4128
|
-
|
|
144
|
+
orderBy: ""
|
|
4129
145
|
};
|
|
4130
146
|
var SEARCH_DELAY = 750;
|
|
4131
147
|
var STATUSES = {
|
|
@@ -4146,20 +162,20 @@ var APPROVAL_REQUEST_FORM_INITIAL_VALUES = {
|
|
|
4146
162
|
};
|
|
4147
163
|
var APPROVAL_REQUEST_FORM_VALIDATION_SCHEMA = yup.object().shape({
|
|
4148
164
|
variables: yup.array().of(yup.object().shape({
|
|
4149
|
-
variable: yup.string().trim().required(t$
|
|
4150
|
-
what: t$
|
|
165
|
+
variable: yup.string().trim().required(t$1("neetoApprovals.validations.required", {
|
|
166
|
+
what: t$1("neetoApprovals.common.field")
|
|
4151
167
|
}))
|
|
4152
168
|
}))
|
|
4153
169
|
});
|
|
4154
170
|
var STATUS_UPDATED_BY = {
|
|
4155
|
-
rejected: t$
|
|
4156
|
-
approved: t$
|
|
4157
|
-
cancelled: t$
|
|
171
|
+
rejected: t$1("neetoApprovals.common.rejectedBy"),
|
|
172
|
+
approved: t$1("neetoApprovals.common.approvedBy"),
|
|
173
|
+
cancelled: t$1("neetoApprovals.common.cancelledBy")
|
|
4158
174
|
};
|
|
4159
175
|
|
|
4160
176
|
var handleEmptyPage = function handleEmptyPage(data, pageProperties, handleTablePagination) {
|
|
4161
|
-
if (isEmpty(data) && pageProperties.
|
|
4162
|
-
handleTablePagination(pageProperties.
|
|
177
|
+
if (isEmpty(data) && pageProperties.page !== 1) {
|
|
178
|
+
handleTablePagination(pageProperties.page - 1, pageProperties.pageSize);
|
|
4163
179
|
}
|
|
4164
180
|
};
|
|
4165
181
|
|
|
@@ -4189,8 +205,6 @@ var approversApi = {
|
|
|
4189
205
|
destroy: destroy$1
|
|
4190
206
|
};
|
|
4191
207
|
|
|
4192
|
-
var DEFAULT_STALE_TIME = 300000; // 5 minutes
|
|
4193
|
-
|
|
4194
208
|
var QUERY_KEYS = {
|
|
4195
209
|
APPROVERS: "neeto-approvals-approvers",
|
|
4196
210
|
TEMPLATES: "neeto-approvals-templates",
|
|
@@ -4220,33 +234,19 @@ var useFetchApprovers = function useFetchApprovers() {
|
|
|
4220
234
|
}, options));
|
|
4221
235
|
};
|
|
4222
236
|
var useCreateApprover = function useCreateApprover(options) {
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
queryClient.invalidateQueries(QUERY_KEYS.APPROVERS);
|
|
4227
|
-
queryClient.invalidateQueries(QUERY_KEYS.VIEWS);
|
|
4228
|
-
options === null || options === void 0 ? void 0 : options.onSuccess();
|
|
4229
|
-
}
|
|
4230
|
-
}));
|
|
237
|
+
return useMutationWithInvalidation(approversApi.create, _objectSpread$c({
|
|
238
|
+
keysToInvalidate: [QUERY_KEYS.APPROVERS, QUERY_KEYS.VIEWS]
|
|
239
|
+
}, options));
|
|
4231
240
|
};
|
|
4232
241
|
var useUpdateApprover = function useUpdateApprover(options) {
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
queryClient.invalidateQueries(QUERY_KEYS.APPROVERS);
|
|
4237
|
-
options === null || options === void 0 ? void 0 : options.onSuccess();
|
|
4238
|
-
}
|
|
4239
|
-
}));
|
|
242
|
+
return useMutationWithInvalidation(approversApi.update, _objectSpread$c({
|
|
243
|
+
keysToInvalidate: [QUERY_KEYS.APPROVERS]
|
|
244
|
+
}, options));
|
|
4240
245
|
};
|
|
4241
246
|
var useDeleteApprover = function useDeleteApprover(options) {
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
queryClient.invalidateQueries(QUERY_KEYS.APPROVERS);
|
|
4246
|
-
queryClient.invalidateQueries(QUERY_KEYS.VIEWS);
|
|
4247
|
-
options === null || options === void 0 ? void 0 : options.onSuccess();
|
|
4248
|
-
}
|
|
4249
|
-
});
|
|
247
|
+
return useMutationWithInvalidation(approversApi.destroy, _objectSpread$c({
|
|
248
|
+
keysToInvalidate: [QUERY_KEYS.APPROVERS, QUERY_KEYS.VIEWS]
|
|
249
|
+
}, options));
|
|
4250
250
|
};
|
|
4251
251
|
|
|
4252
252
|
var useUrlSearchParams = function useUrlSearchParams() {
|
|
@@ -4260,30 +260,30 @@ var useUrlSearchParams = function useUrlSearchParams() {
|
|
|
4260
260
|
var usePaginate = function usePaginate() {
|
|
4261
261
|
var urlParams = useUrlSearchParams();
|
|
4262
262
|
var _useState = useState({
|
|
4263
|
-
|
|
4264
|
-
|
|
263
|
+
page: Number(urlParams.get("page")) || DEFAULT_PAGE_INDEX,
|
|
264
|
+
pageSize: Number(urlParams.get("size")) || DEFAULT_PAGE_SIZE
|
|
4265
265
|
}),
|
|
4266
266
|
_useState2 = _slicedToArray$1(_useState, 2),
|
|
4267
267
|
pageProperties = _useState2[0],
|
|
4268
268
|
setPageProperties = _useState2[1];
|
|
4269
269
|
var history = useHistory();
|
|
4270
|
-
var handleTablePagination = useCallback(function (
|
|
4271
|
-
urlParams.set("page",
|
|
4272
|
-
urlParams.set("size",
|
|
270
|
+
var handleTablePagination = useCallback(function (page, pageSize) {
|
|
271
|
+
urlParams.set("page", page);
|
|
272
|
+
urlParams.set("size", pageSize);
|
|
4273
273
|
history.push({
|
|
4274
274
|
search: urlParams.toString()
|
|
4275
275
|
});
|
|
4276
276
|
setPageProperties({
|
|
4277
|
-
|
|
4278
|
-
|
|
277
|
+
page: page,
|
|
278
|
+
pageSize: pageSize
|
|
4279
279
|
});
|
|
4280
280
|
}, [urlParams, history]);
|
|
4281
281
|
useEffect(function () {
|
|
4282
|
-
var
|
|
282
|
+
var page = urlParams.get("page") || DEFAULT_PAGE_INDEX;
|
|
4283
283
|
var pageSize = urlParams.get("size") || DEFAULT_PAGE_SIZE;
|
|
4284
284
|
setPageProperties({
|
|
4285
|
-
|
|
4286
|
-
|
|
285
|
+
page: Number(page),
|
|
286
|
+
pageSize: Number(pageSize)
|
|
4287
287
|
});
|
|
4288
288
|
}, [urlParams]);
|
|
4289
289
|
return {
|
|
@@ -4300,20 +300,20 @@ var APPROVER_FORM_INITIAL_VALUES = {
|
|
|
4300
300
|
email: ""
|
|
4301
301
|
};
|
|
4302
302
|
var APPROVER_FORM_VALIDATION_SCHEMA = yup.object().shape({
|
|
4303
|
-
firstName: yup.string().trim().max(MAX_NAME_LENGTH, t$
|
|
4304
|
-
what: (_t$1 = t$
|
|
303
|
+
firstName: yup.string().trim().max(MAX_NAME_LENGTH, t$1("neetoApprovals.validations.limitExceeded", {
|
|
304
|
+
what: (_t$1 = t$1("neetoApprovals.inputs.labels.firstName")) === null || _t$1 === void 0 ? void 0 : _t$1.toLocaleLowerCase(),
|
|
4305
305
|
limit: MAX_NAME_LENGTH
|
|
4306
|
-
})).required(t$
|
|
4307
|
-
what: t$
|
|
306
|
+
})).required(t$1("neetoApprovals.validations.required", {
|
|
307
|
+
what: t$1("neetoApprovals.inputs.labels.firstName")
|
|
4308
308
|
})),
|
|
4309
|
-
lastName: yup.string().trim().max(MAX_NAME_LENGTH, t$
|
|
4310
|
-
what: (_t2 = t$
|
|
309
|
+
lastName: yup.string().trim().max(MAX_NAME_LENGTH, t$1("neetoApprovals.validations.limitExceeded", {
|
|
310
|
+
what: (_t2 = t$1("neetoApprovals.inputs.labels.lastName")) === null || _t2 === void 0 ? void 0 : _t2.toLocaleLowerCase(),
|
|
4311
311
|
limit: MAX_NAME_LENGTH
|
|
4312
|
-
})).required(t$
|
|
4313
|
-
what: t$
|
|
312
|
+
})).required(t$1("neetoApprovals.validations.required", {
|
|
313
|
+
what: t$1("neetoApprovals.inputs.labels.lastName")
|
|
4314
314
|
})),
|
|
4315
|
-
email: yup.string().email().required(t$
|
|
4316
|
-
what: t$
|
|
315
|
+
email: yup.string().email().required(t$1("neetoApprovals.validations.required", {
|
|
316
|
+
what: t$1("neetoApprovals.common.email")
|
|
4317
317
|
}))
|
|
4318
318
|
});
|
|
4319
319
|
|
|
@@ -4383,7 +383,7 @@ var Create$1 = function Create(_ref) {
|
|
|
4383
383
|
createApprover = _useCreateApprover.mutate,
|
|
4384
384
|
isLoading = _useCreateApprover.isLoading;
|
|
4385
385
|
var getLastPageNumber = function getLastPageNumber() {
|
|
4386
|
-
return Math.ceil((totalCount + 1) / pageProperties.
|
|
386
|
+
return Math.ceil((totalCount + 1) / pageProperties.pageSize);
|
|
4387
387
|
};
|
|
4388
388
|
var onSubmit = function onSubmit(approver) {
|
|
4389
389
|
return createApprover({
|
|
@@ -4391,18 +391,18 @@ var Create$1 = function Create(_ref) {
|
|
|
4391
391
|
}, {
|
|
4392
392
|
onSuccess: function onSuccess() {
|
|
4393
393
|
var lastPageNumber = getLastPageNumber();
|
|
4394
|
-
lastPageNumber !== pageProperties.
|
|
394
|
+
lastPageNumber !== pageProperties.page && handleTablePagination(lastPageNumber, pageProperties.pageSize);
|
|
4395
395
|
setIsNewApproverPaneOpen(false);
|
|
4396
396
|
}
|
|
4397
397
|
});
|
|
4398
398
|
};
|
|
4399
399
|
return /*#__PURE__*/React.createElement(Form$2, {
|
|
4400
400
|
isLoading: isLoading,
|
|
401
|
+
onSubmit: onSubmit,
|
|
4401
402
|
isOpen: isNewApproverPaneOpen,
|
|
4402
403
|
onClose: function onClose() {
|
|
4403
404
|
return setIsNewApproverPaneOpen(false);
|
|
4404
|
-
}
|
|
4405
|
-
onSubmit: onSubmit
|
|
405
|
+
}
|
|
4406
406
|
});
|
|
4407
407
|
};
|
|
4408
408
|
var Create$2 = /*#__PURE__*/React.memo(Create$1);
|
|
@@ -4451,12 +451,12 @@ var columnData$1 = function columnData(_ref) {
|
|
|
4451
451
|
dataIndex: "name",
|
|
4452
452
|
key: "name",
|
|
4453
453
|
sorter: true,
|
|
4454
|
-
title:
|
|
454
|
+
title: i18next.t("neetoApprovals.common.name")
|
|
4455
455
|
}, {
|
|
4456
456
|
dataIndex: "email",
|
|
4457
457
|
key: "email",
|
|
4458
458
|
sorter: true,
|
|
4459
|
-
title:
|
|
459
|
+
title: i18next.t("neetoApprovals.common.email")
|
|
4460
460
|
}, {
|
|
4461
461
|
key: "actions",
|
|
4462
462
|
ellipsis: true,
|
|
@@ -4480,12 +480,12 @@ var columnData$1 = function columnData(_ref) {
|
|
|
4480
480
|
onClick: function onClick() {
|
|
4481
481
|
return onEditClick(approver);
|
|
4482
482
|
}
|
|
4483
|
-
},
|
|
483
|
+
}, i18next.t("neetoApprovals.common.edit")), /*#__PURE__*/React.createElement(MenuItem$1.Button, {
|
|
4484
484
|
"data-cy": "approvers-delete-button",
|
|
4485
485
|
onClick: function onClick() {
|
|
4486
486
|
return onDeleteClick(approver);
|
|
4487
487
|
}
|
|
4488
|
-
},
|
|
488
|
+
}, i18next.t("neetoApprovals.common.delete")))));
|
|
4489
489
|
}
|
|
4490
490
|
}];
|
|
4491
491
|
};
|
|
@@ -4582,7 +582,7 @@ var Table = function Table(_ref) {
|
|
|
4582
582
|
var handleTableChange = function handleTableChange(_, __, sorter) {
|
|
4583
583
|
setFilters(_objectSpread$b(_objectSpread$b({}, filters), {}, {
|
|
4584
584
|
sortBy: sorter.field,
|
|
4585
|
-
|
|
585
|
+
orderBy: sorter.order
|
|
4586
586
|
}));
|
|
4587
587
|
};
|
|
4588
588
|
var noDataProps = {
|
|
@@ -4606,19 +606,17 @@ var Table = function Table(_ref) {
|
|
|
4606
606
|
title: t("neetoApprovals.common.notFound_", {
|
|
4607
607
|
what: entity
|
|
4608
608
|
})
|
|
4609
|
-
}, !filters.
|
|
609
|
+
}, !filters.searchTerm && noDataProps)));
|
|
4610
610
|
}
|
|
4611
611
|
return /*#__PURE__*/React.createElement(TableWrapper, {
|
|
4612
612
|
className: "mt-12",
|
|
4613
|
-
hasPagination: totalCount > pageProperties.
|
|
613
|
+
hasPagination: totalCount > pageProperties.pageSize
|
|
4614
614
|
}, /*#__PURE__*/React.createElement(Table$1, _extends({
|
|
4615
615
|
fixedHeight: true,
|
|
4616
616
|
columnData: columns,
|
|
4617
|
-
currentPageNumber: pageProperties.
|
|
4618
|
-
defaultPageSize: pageProperties.
|
|
4619
|
-
handlePageChange:
|
|
4620
|
-
return handleTablePagination(index, size);
|
|
4621
|
-
},
|
|
617
|
+
currentPageNumber: pageProperties.page,
|
|
618
|
+
defaultPageSize: pageProperties.pageSize,
|
|
619
|
+
handlePageChange: handleTablePagination,
|
|
4622
620
|
rowData: items,
|
|
4623
621
|
paginationProps: {
|
|
4624
622
|
hideOnSinglePage: (items === null || items === void 0 ? void 0 : items.length) < DEFAULT_PAGE_SIZE + 1
|
|
@@ -4646,14 +644,14 @@ var Approvers = function Approvers(_ref) {
|
|
|
4646
644
|
_useState4 = _slicedToArray$1(_useState3, 2),
|
|
4647
645
|
approverToDelete = _useState4[0],
|
|
4648
646
|
setApproverToDelete = _useState4[1];
|
|
4649
|
-
var
|
|
647
|
+
var debouncedSearchTerm = useDebounce(filters.searchTerm, SEARCH_DELAY);
|
|
4650
648
|
var _usePaginate = usePaginate(),
|
|
4651
649
|
pageProperties = _usePaginate.pageProperties,
|
|
4652
650
|
handleTablePagination = _usePaginate.handleTablePagination;
|
|
4653
651
|
var _useTranslation = useTranslation(),
|
|
4654
652
|
t = _useTranslation.t;
|
|
4655
653
|
var _useFetchApprovers = useFetchApprovers(_objectSpread$a(_objectSpread$a(_objectSpread$a({}, pageProperties), filters), {}, {
|
|
4656
|
-
|
|
654
|
+
searchTerm: debouncedSearchTerm.trim()
|
|
4657
655
|
}), {
|
|
4658
656
|
onSuccess: function onSuccess(approvers) {
|
|
4659
657
|
handleEmptyPage(approvers, pageProperties, handleTablePagination);
|
|
@@ -4878,10 +876,12 @@ var requestsApi = {
|
|
|
4878
876
|
|
|
4879
877
|
function ownKeys$9(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; }
|
|
4880
878
|
function _objectSpread$9(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$9(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$9(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4881
|
-
var useFetchRequests = function useFetchRequests() {
|
|
4882
|
-
var
|
|
4883
|
-
|
|
4884
|
-
|
|
879
|
+
var useFetchRequests = function useFetchRequests(_ref) {
|
|
880
|
+
var requestUrl = _ref.requestUrl,
|
|
881
|
+
_ref$params = _ref.params,
|
|
882
|
+
params = _ref$params === void 0 ? {} : _ref$params,
|
|
883
|
+
_ref$options = _ref.options,
|
|
884
|
+
options = _ref$options === void 0 ? {} : _ref$options;
|
|
4885
885
|
return useQuery([QUERY_KEYS.REQUESTS, params], function () {
|
|
4886
886
|
return requestsApi.fetch(params, requestUrl);
|
|
4887
887
|
}, _objectSpread$9({
|
|
@@ -4889,23 +889,17 @@ var useFetchRequests = function useFetchRequests() {
|
|
|
4889
889
|
return response.data || response;
|
|
4890
890
|
},
|
|
4891
891
|
keepPreviousData: true,
|
|
4892
|
-
onSuccess: function onSuccess(
|
|
892
|
+
onSuccess: function onSuccess(_ref2) {
|
|
4893
893
|
var _options$onSuccess;
|
|
4894
|
-
var requests =
|
|
894
|
+
var requests = _ref2.requests;
|
|
4895
895
|
return (_options$onSuccess = options.onSuccess) === null || _options$onSuccess === void 0 ? void 0 : _options$onSuccess.call(options, requests);
|
|
4896
896
|
}
|
|
4897
897
|
}, options));
|
|
4898
898
|
};
|
|
4899
899
|
var useUpdateRequest = function useUpdateRequest(options) {
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
var _options$onSuccess2;
|
|
4904
|
-
queryClient.invalidateQueries(QUERY_KEYS.REQUESTS);
|
|
4905
|
-
queryClient.invalidateQueries(QUERY_KEYS.VIEWS);
|
|
4906
|
-
options === null || options === void 0 ? void 0 : (_options$onSuccess2 = options.onSuccess) === null || _options$onSuccess2 === void 0 ? void 0 : _options$onSuccess2.call(options);
|
|
4907
|
-
}
|
|
4908
|
-
}));
|
|
900
|
+
return useMutationWithInvalidation(requestsApi.update, _objectSpread$9({
|
|
901
|
+
keysToInvalidate: [QUERY_KEYS.REQUESTS, QUERY_KEYS.VIEWS]
|
|
902
|
+
}, options));
|
|
4909
903
|
};
|
|
4910
904
|
|
|
4911
905
|
dayjs.extend(utc);
|
|
@@ -4929,19 +923,19 @@ var timeInZone = function timeInZone(time) {
|
|
|
4929
923
|
var getApprovalFilter = function getApprovalFilter() {
|
|
4930
924
|
return {
|
|
4931
925
|
PENDING: {
|
|
4932
|
-
label: t$
|
|
926
|
+
label: t$1("neetoApprovals.common.pending"),
|
|
4933
927
|
value: "PENDING"
|
|
4934
928
|
},
|
|
4935
929
|
TEMPLATES: {
|
|
4936
|
-
label: t$
|
|
930
|
+
label: t$1("neetoApprovals.common.template", PLURAL),
|
|
4937
931
|
value: "TEMPLATES"
|
|
4938
932
|
},
|
|
4939
933
|
HISTORY: {
|
|
4940
|
-
label: t$
|
|
934
|
+
label: t$1("neetoApprovals.common.history"),
|
|
4941
935
|
value: "HISTORY"
|
|
4942
936
|
},
|
|
4943
937
|
APPROVERS: {
|
|
4944
|
-
label: t$
|
|
938
|
+
label: t$1("neetoApprovals.common.approver", PLURAL),
|
|
4945
939
|
value: "APPROVERS"
|
|
4946
940
|
}
|
|
4947
941
|
};
|
|
@@ -4952,7 +946,7 @@ var HISTORY_TABLE_COLUMNS = [{
|
|
|
4952
946
|
key: "approvalLabel",
|
|
4953
947
|
sorter: true,
|
|
4954
948
|
width: "25%",
|
|
4955
|
-
title: t$
|
|
949
|
+
title: t$1("neetoApprovals.common.id"),
|
|
4956
950
|
render: function render(approvalLabel, _ref) {
|
|
4957
951
|
var requestableUrl = _ref.requestableUrl;
|
|
4958
952
|
var url = new URL(requestableUrl || window.location.origin);
|
|
@@ -4967,13 +961,13 @@ var HISTORY_TABLE_COLUMNS = [{
|
|
|
4967
961
|
key: "title",
|
|
4968
962
|
sorter: true,
|
|
4969
963
|
width: "25%",
|
|
4970
|
-
title: t$
|
|
964
|
+
title: t$1("neetoApprovals.common.title")
|
|
4971
965
|
}, {
|
|
4972
966
|
dataIndex: "status",
|
|
4973
967
|
key: "status",
|
|
4974
968
|
sorter: true,
|
|
4975
969
|
width: "25%",
|
|
4976
|
-
title: t$
|
|
970
|
+
title: t$1("neetoApprovals.common.status"),
|
|
4977
971
|
render: function render(status) {
|
|
4978
972
|
return /*#__PURE__*/React.createElement(Tag, {
|
|
4979
973
|
label: capitalize(status),
|
|
@@ -4985,7 +979,7 @@ var HISTORY_TABLE_COLUMNS = [{
|
|
|
4985
979
|
key: "createdAt",
|
|
4986
980
|
sorter: true,
|
|
4987
981
|
width: "25%",
|
|
4988
|
-
title: t$
|
|
982
|
+
title: t$1("neetoApprovals.common.created"),
|
|
4989
983
|
render: function render(createdAt) {
|
|
4990
984
|
return dateFormat.fromNow(timeInZone(createdAt));
|
|
4991
985
|
}
|
|
@@ -5109,7 +1103,7 @@ var History = function History(_ref) {
|
|
|
5109
1103
|
_useState2 = _slicedToArray$1(_useState, 2),
|
|
5110
1104
|
filters = _useState2[0],
|
|
5111
1105
|
setFilters = _useState2[1];
|
|
5112
|
-
var
|
|
1106
|
+
var debouncedSearchTerm = useDebounce(filters.searchTerm, SEARCH_DELAY);
|
|
5113
1107
|
var _usePaginate = usePaginate(),
|
|
5114
1108
|
pageProperties = _usePaginate.pageProperties,
|
|
5115
1109
|
handleTablePagination = _usePaginate.handleTablePagination;
|
|
@@ -5119,20 +1113,24 @@ var History = function History(_ref) {
|
|
|
5119
1113
|
setApprovalDetails = _useState4[1];
|
|
5120
1114
|
var _useTranslation = useTranslation(),
|
|
5121
1115
|
t = _useTranslation.t;
|
|
5122
|
-
var _useFetchRequests = useFetchRequests(
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
1116
|
+
var _useFetchRequests = useFetchRequests({
|
|
1117
|
+
params: _objectSpread$8(_objectSpread$8(_objectSpread$8({}, pageProperties), filters), {}, {
|
|
1118
|
+
searchTerm: debouncedSearchTerm.trim(),
|
|
1119
|
+
status: [STATUSES.approved, STATUSES.rejected, STATUSES.cancelled]
|
|
1120
|
+
}),
|
|
1121
|
+
options: {
|
|
1122
|
+
onSuccess: function onSuccess(requests) {
|
|
1123
|
+
handleEmptyPage(requests, pageProperties, handleTablePagination);
|
|
1124
|
+
setApprovalDetails(function (approvalDetails) {
|
|
1125
|
+
return updateApprovalDetails({
|
|
1126
|
+
requestsData: requests,
|
|
1127
|
+
approvalDetails: approvalDetails
|
|
1128
|
+
});
|
|
5132
1129
|
});
|
|
5133
|
-
}
|
|
5134
|
-
}
|
|
5135
|
-
|
|
1130
|
+
}
|
|
1131
|
+
},
|
|
1132
|
+
requestUrl: requestUrl
|
|
1133
|
+
}),
|
|
5136
1134
|
_useFetchRequests$dat = _useFetchRequests.data,
|
|
5137
1135
|
_useFetchRequests$dat2 = _useFetchRequests$dat === void 0 ? {} : _useFetchRequests$dat,
|
|
5138
1136
|
_useFetchRequests$dat3 = _useFetchRequests$dat2.requests,
|
|
@@ -5142,7 +1140,7 @@ var History = function History(_ref) {
|
|
|
5142
1140
|
var handleTableChange = function handleTableChange(_, __, sorter) {
|
|
5143
1141
|
setFilters(_objectSpread$8(_objectSpread$8({}, filters), {}, {
|
|
5144
1142
|
sortBy: camelToSnakeCase(sorter.field),
|
|
5145
|
-
|
|
1143
|
+
orderBy: sorter.order
|
|
5146
1144
|
}));
|
|
5147
1145
|
};
|
|
5148
1146
|
return /*#__PURE__*/React.createElement(React.Fragment, null, !isEmpty(approvalHistories) ? /*#__PURE__*/React.createElement("div", {
|
|
@@ -5151,13 +1149,11 @@ var History = function History(_ref) {
|
|
|
5151
1149
|
allowRowClick: true,
|
|
5152
1150
|
fixedHeight: true,
|
|
5153
1151
|
columnData: HISTORY_TABLE_COLUMNS,
|
|
5154
|
-
currentPageNumber: pageProperties.
|
|
5155
|
-
defaultPageSize: pageProperties.
|
|
1152
|
+
currentPageNumber: pageProperties.page,
|
|
1153
|
+
defaultPageSize: pageProperties.pageSize,
|
|
5156
1154
|
rowData: approvalHistories,
|
|
5157
1155
|
totalCount: totalCount,
|
|
5158
|
-
handlePageChange:
|
|
5159
|
-
return handleTablePagination(index, size);
|
|
5160
|
-
},
|
|
1156
|
+
handlePageChange: handleTablePagination,
|
|
5161
1157
|
paginationProps: {
|
|
5162
1158
|
hideOnSinglePage: (approvalHistories === null || approvalHistories === void 0 ? void 0 : approvalHistories.length) < DEFAULT_PAGE_SIZE + 1
|
|
5163
1159
|
},
|
|
@@ -5197,20 +1193,24 @@ var PendingRequests = function PendingRequests(_ref) {
|
|
|
5197
1193
|
_useState4 = _slicedToArray$1(_useState3, 2),
|
|
5198
1194
|
approvalDetails = _useState4[0],
|
|
5199
1195
|
setApprovalDetails = _useState4[1];
|
|
5200
|
-
var
|
|
1196
|
+
var debouncedSearchTerm = useDebounce(filters.searchTerm, SEARCH_DELAY);
|
|
5201
1197
|
var _usePaginate = usePaginate(),
|
|
5202
1198
|
pageProperties = _usePaginate.pageProperties,
|
|
5203
1199
|
handleTablePagination = _usePaginate.handleTablePagination;
|
|
5204
1200
|
var _useTranslation = useTranslation(),
|
|
5205
1201
|
t = _useTranslation.t;
|
|
5206
|
-
var _useFetchRequests = useFetchRequests(
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
|
|
5213
|
-
|
|
1202
|
+
var _useFetchRequests = useFetchRequests({
|
|
1203
|
+
params: _objectSpread$7(_objectSpread$7(_objectSpread$7({}, pageProperties), filters), {}, {
|
|
1204
|
+
searchTerm: debouncedSearchTerm.trim(),
|
|
1205
|
+
status: [STATUSES.pending]
|
|
1206
|
+
}),
|
|
1207
|
+
options: {
|
|
1208
|
+
onSuccess: function onSuccess(requests) {
|
|
1209
|
+
handleEmptyPage(requests, pageProperties, handleTablePagination);
|
|
1210
|
+
}
|
|
1211
|
+
},
|
|
1212
|
+
requestUrl: requestUrl
|
|
1213
|
+
}),
|
|
5214
1214
|
_useFetchRequests$dat = _useFetchRequests.data,
|
|
5215
1215
|
_useFetchRequests$dat2 = _useFetchRequests$dat === void 0 ? {} : _useFetchRequests$dat,
|
|
5216
1216
|
_useFetchRequests$dat3 = _useFetchRequests$dat2.requests,
|
|
@@ -5223,7 +1223,7 @@ var PendingRequests = function PendingRequests(_ref) {
|
|
|
5223
1223
|
var handleTableChange = function handleTableChange(_, __, sorter) {
|
|
5224
1224
|
setFilters(_objectSpread$7(_objectSpread$7({}, filters), {}, {
|
|
5225
1225
|
sortBy: camelToSnakeCase(sorter.field),
|
|
5226
|
-
|
|
1226
|
+
orderBy: sorter.order
|
|
5227
1227
|
}));
|
|
5228
1228
|
};
|
|
5229
1229
|
var onSubmit = function onSubmit(payload) {
|
|
@@ -5242,13 +1242,11 @@ var PendingRequests = function PendingRequests(_ref) {
|
|
|
5242
1242
|
allowRowClick: true,
|
|
5243
1243
|
fixedHeight: true,
|
|
5244
1244
|
columnData: PENDING_TABLE_COLUMNS,
|
|
5245
|
-
currentPageNumber: pageProperties.
|
|
5246
|
-
defaultPageSize: pageProperties.
|
|
1245
|
+
currentPageNumber: pageProperties.page,
|
|
1246
|
+
defaultPageSize: pageProperties.pageSize,
|
|
5247
1247
|
rowData: pendingRequests,
|
|
5248
1248
|
totalCount: totalCount,
|
|
5249
|
-
handlePageChange:
|
|
5250
|
-
return handleTablePagination(index, size);
|
|
5251
|
-
},
|
|
1249
|
+
handlePageChange: handleTablePagination,
|
|
5252
1250
|
paginationProps: {
|
|
5253
1251
|
hideOnSinglePage: (pendingRequests === null || pendingRequests === void 0 ? void 0 : pendingRequests.length) < DEFAULT_PAGE_SIZE + 1
|
|
5254
1252
|
},
|
|
@@ -5327,38 +1325,22 @@ var useFetchTemplates = function useFetchTemplates() {
|
|
|
5327
1325
|
}, options));
|
|
5328
1326
|
};
|
|
5329
1327
|
var useCreateTemplate = function useCreateTemplate(options) {
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
var _options$onSuccess;
|
|
5334
|
-
queryClient.invalidateQueries(QUERY_KEYS.TEMPLATES);
|
|
5335
|
-
queryClient.invalidateQueries(QUERY_KEYS.VIEWS);
|
|
5336
|
-
options === null || options === void 0 ? void 0 : (_options$onSuccess = options.onSuccess) === null || _options$onSuccess === void 0 ? void 0 : _options$onSuccess.call(options);
|
|
5337
|
-
}
|
|
5338
|
-
}));
|
|
1328
|
+
return useMutationWithInvalidation(templatesApi.create, _objectSpread$6({
|
|
1329
|
+
keysToInvalidate: [QUERY_KEYS.TEMPLATES, QUERY_KEYS.VIEWS]
|
|
1330
|
+
}, options));
|
|
5339
1331
|
};
|
|
5340
1332
|
var useUpdateTemplate = function useUpdateTemplate(options) {
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
onSuccess: function onSuccess(_, _ref3) {
|
|
5344
|
-
var _options$onSuccess2;
|
|
1333
|
+
return useMutationWithInvalidation(templatesApi.update, _objectSpread$6({
|
|
1334
|
+
keysToInvalidate: [QUERY_KEYS.TEMPLATES, function (_, _ref3) {
|
|
5345
1335
|
var id = _ref3.id;
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
}
|
|
5350
|
-
}));
|
|
1336
|
+
return [QUERY_KEYS.SHOW_TEMPLATE, id];
|
|
1337
|
+
}]
|
|
1338
|
+
}, options));
|
|
5351
1339
|
};
|
|
5352
1340
|
var useDeleteTemplate = function useDeleteTemplate(options) {
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
var _options$onSuccess3;
|
|
5357
|
-
queryClient.invalidateQueries(QUERY_KEYS.TEMPLATES);
|
|
5358
|
-
queryClient.invalidateQueries(QUERY_KEYS.VIEWS);
|
|
5359
|
-
options === null || options === void 0 ? void 0 : (_options$onSuccess3 = options.onSuccess) === null || _options$onSuccess3 === void 0 ? void 0 : _options$onSuccess3.call(options);
|
|
5360
|
-
}
|
|
5361
|
-
});
|
|
1341
|
+
return useMutationWithInvalidation(templatesApi.destroy, _objectSpread$6({
|
|
1342
|
+
keysToInvalidate: [QUERY_KEYS.TEMPLATES, QUERY_KEYS.VIEWS]
|
|
1343
|
+
}, options));
|
|
5362
1344
|
};
|
|
5363
1345
|
|
|
5364
1346
|
function _arrayWithoutHoles(arr) {
|
|
@@ -5380,7 +1362,7 @@ function _toConsumableArray(arr) {
|
|
|
5380
1362
|
var _t;
|
|
5381
1363
|
var VALID_VARIABLE_NAME_REGEX = /^[a-z](?:\w*[a-z0-9])*$/i;
|
|
5382
1364
|
var EVERYONE_VISIBILITY = {
|
|
5383
|
-
label: t$
|
|
1365
|
+
label: t$1("neetoApprovals.select.visibility.everyone"),
|
|
5384
1366
|
value: "everyone"
|
|
5385
1367
|
};
|
|
5386
1368
|
var TEMPLATE_FORM_INITIAL_VALUES = {
|
|
@@ -5392,19 +1374,19 @@ var TEMPLATE_FORM_INITIAL_VALUES = {
|
|
|
5392
1374
|
message: ""
|
|
5393
1375
|
};
|
|
5394
1376
|
var TEMPLATE_FORM_VALIDATION_SCHEMA = yup.object().shape({
|
|
5395
|
-
name: yup.string().trim().required(t$
|
|
5396
|
-
what: t$
|
|
1377
|
+
name: yup.string().trim().required(t$1("neetoApprovals.validations.required", {
|
|
1378
|
+
what: t$1("neetoApprovals.common.name")
|
|
5397
1379
|
})),
|
|
5398
|
-
approver: yup.object().required(t$
|
|
5399
|
-
message: yup.string().test("message", t$
|
|
5400
|
-
what: t$
|
|
1380
|
+
approver: yup.object().required(t$1("neetoApprovals.validations.approver")),
|
|
1381
|
+
message: yup.string().test("message", t$1("neetoApprovals.validations.required", {
|
|
1382
|
+
what: t$1("neetoApprovals.inputs.labels.message")
|
|
5401
1383
|
}), function (content) {
|
|
5402
1384
|
return !isEditorEmpty(content);
|
|
5403
1385
|
}),
|
|
5404
1386
|
variables: yup.array().of(yup.object().shape({
|
|
5405
|
-
variable: yup.string().trim().required(t$
|
|
5406
|
-
what: (_t = t$
|
|
5407
|
-
})).matches(VALID_VARIABLE_NAME_REGEX, t$
|
|
1387
|
+
variable: yup.string().trim().required(t$1("neetoApprovals.validations.pleaseEnter_", {
|
|
1388
|
+
what: (_t = t$1("neetoApprovals.common.variable")) === null || _t === void 0 ? void 0 : _t.toLocaleLowerCase()
|
|
1389
|
+
})).matches(VALID_VARIABLE_NAME_REGEX, t$1("neetoApprovals.validations.variableName"))
|
|
5408
1390
|
}))
|
|
5409
1391
|
});
|
|
5410
1392
|
|
|
@@ -5734,11 +1716,11 @@ var columnData = function columnData(_ref) {
|
|
|
5734
1716
|
dataIndex: "name",
|
|
5735
1717
|
key: "name",
|
|
5736
1718
|
sorter: true,
|
|
5737
|
-
title:
|
|
1719
|
+
title: i18next.t("neetoApprovals.common.name")
|
|
5738
1720
|
}, {
|
|
5739
1721
|
dataIndex: "visibility",
|
|
5740
1722
|
key: "visibility",
|
|
5741
|
-
title:
|
|
1723
|
+
title: i18next.t("neetoApprovals.common.visibility"),
|
|
5742
1724
|
render: function render(_, _ref2) {
|
|
5743
1725
|
var accessible = _ref2.accessible;
|
|
5744
1726
|
return (accessible === null || accessible === void 0 ? void 0 : accessible.label) || EVERYONE_VISIBILITY.label;
|
|
@@ -5766,12 +1748,12 @@ var columnData = function columnData(_ref) {
|
|
|
5766
1748
|
onClick: function onClick() {
|
|
5767
1749
|
return onEditClick(template);
|
|
5768
1750
|
}
|
|
5769
|
-
},
|
|
1751
|
+
}, i18next.t("neetoApprovals.common.edit")), /*#__PURE__*/React.createElement(MenuItem.Button, {
|
|
5770
1752
|
"data-cy": "approvers-delete-button",
|
|
5771
1753
|
onClick: function onClick() {
|
|
5772
1754
|
return onDeleteClick(template);
|
|
5773
1755
|
}
|
|
5774
|
-
},
|
|
1756
|
+
}, i18next.t("neetoApprovals.common.delete")))));
|
|
5775
1757
|
}
|
|
5776
1758
|
}];
|
|
5777
1759
|
};
|
|
@@ -5803,14 +1785,14 @@ var Templates = function Templates(_ref) {
|
|
|
5803
1785
|
_useState8 = _slicedToArray$1(_useState7, 2),
|
|
5804
1786
|
isShowPaneOpen = _useState8[0],
|
|
5805
1787
|
setIsShowPaneOpen = _useState8[1];
|
|
5806
|
-
var
|
|
1788
|
+
var debouncedSearchTerm = useDebounce(filters.searchTerm, SEARCH_DELAY);
|
|
5807
1789
|
var _usePaginate = usePaginate(),
|
|
5808
1790
|
pageProperties = _usePaginate.pageProperties,
|
|
5809
1791
|
handleTablePagination = _usePaginate.handleTablePagination;
|
|
5810
1792
|
var _useTranslation = useTranslation(),
|
|
5811
1793
|
t = _useTranslation.t;
|
|
5812
1794
|
var _useFetchTemplates = useFetchTemplates(_objectSpread$4(_objectSpread$4(_objectSpread$4({}, pageProperties), filters), {}, {
|
|
5813
|
-
|
|
1795
|
+
searchTerm: debouncedSearchTerm.trim()
|
|
5814
1796
|
}), {
|
|
5815
1797
|
onSuccess: function onSuccess(templates) {
|
|
5816
1798
|
handleEmptyPage(templates, pageProperties, handleTablePagination);
|
|
@@ -5928,16 +1910,16 @@ var createRoutes = function createRoutes(_ref) {
|
|
|
5928
1910
|
path: "".concat(config.approvalsPath).concat(routes.approvers),
|
|
5929
1911
|
actionBlock: function actionBlock() {
|
|
5930
1912
|
return /*#__PURE__*/React.createElement(Button, {
|
|
5931
|
-
label: t$
|
|
5932
|
-
what: t$
|
|
1913
|
+
label: t$1("neetoApprovals.common.add_", {
|
|
1914
|
+
what: t$1("neetoApprovals.common.approver", SINGULAR).toLocaleLowerCase()
|
|
5933
1915
|
}),
|
|
5934
1916
|
onClick: function onClick() {
|
|
5935
1917
|
return setIsNewApproverPaneOpen(true);
|
|
5936
1918
|
}
|
|
5937
1919
|
});
|
|
5938
1920
|
},
|
|
5939
|
-
searchPlaceholder: t$
|
|
5940
|
-
what: t$
|
|
1921
|
+
searchPlaceholder: t$1("neetoApprovals.inputs.placeholders.search_", {
|
|
1922
|
+
what: t$1("neetoApprovals.common.approver", PLURAL).toLocaleLowerCase()
|
|
5941
1923
|
})
|
|
5942
1924
|
}, {
|
|
5943
1925
|
component: function component() {
|
|
@@ -5951,16 +1933,16 @@ var createRoutes = function createRoutes(_ref) {
|
|
|
5951
1933
|
path: "".concat(config.approvalsPath).concat(routes.templates.index),
|
|
5952
1934
|
actionBlock: function actionBlock() {
|
|
5953
1935
|
return /*#__PURE__*/React.createElement(Button, {
|
|
5954
|
-
label: t$
|
|
5955
|
-
what: t$
|
|
1936
|
+
label: t$1("neetoApprovals.common.add_", {
|
|
1937
|
+
what: t$1("neetoApprovals.common.approvalTemplate", SINGULAR).toLocaleLowerCase()
|
|
5956
1938
|
}),
|
|
5957
1939
|
onClick: function onClick() {
|
|
5958
1940
|
return setIsNewTemplatePaneOpen(true);
|
|
5959
1941
|
}
|
|
5960
1942
|
});
|
|
5961
1943
|
},
|
|
5962
|
-
searchPlaceholder: t$
|
|
5963
|
-
what: t$
|
|
1944
|
+
searchPlaceholder: t$1("neetoApprovals.inputs.placeholders.search_", {
|
|
1945
|
+
what: t$1("neetoApprovals.common.template", PLURAL).toLocaleLowerCase()
|
|
5964
1946
|
})
|
|
5965
1947
|
}, {
|
|
5966
1948
|
component: function component() {
|
|
@@ -5993,9 +1975,9 @@ var Header = function Header(_ref) {
|
|
|
5993
1975
|
title: t("neetoApprovals.common.approval", PLURAL),
|
|
5994
1976
|
searchProps: (currentTab === null || currentTab === void 0 ? void 0 : currentTab.searchPlaceholder) && {
|
|
5995
1977
|
onChange: function onChange(event) {
|
|
5996
|
-
return setFilters(assoc("
|
|
1978
|
+
return setFilters(assoc("searchTerm", event.target.value));
|
|
5997
1979
|
},
|
|
5998
|
-
value: filters.
|
|
1980
|
+
value: filters.searchTerm,
|
|
5999
1981
|
placeholder: currentTab === null || currentTab === void 0 ? void 0 : currentTab.searchPlaceholder
|
|
6000
1982
|
},
|
|
6001
1983
|
breadcrumbs: breadcrumbs
|
|
@@ -6259,33 +2241,19 @@ var useFetchPublicRequest = function useFetchPublicRequest(_ref, options) {
|
|
|
6259
2241
|
var requestId = _ref.requestId;
|
|
6260
2242
|
return useQuery([QUERY_KEYS.SHOW_PUBLIC_REQUEST, requestId], function () {
|
|
6261
2243
|
return publicRequestsApi.show(requestId);
|
|
6262
|
-
}, _objectSpread({
|
|
6263
|
-
staleTime: DEFAULT_STALE_TIME
|
|
6264
|
-
}, options));
|
|
2244
|
+
}, _objectSpread({}, options));
|
|
6265
2245
|
};
|
|
6266
2246
|
var useAcceptPendingRequest = function useAcceptPendingRequest(options) {
|
|
6267
|
-
|
|
6268
|
-
return
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
queryClient.invalidateQueries(QUERY_KEYS.SHOW_PUBLIC_REQUEST);
|
|
6272
|
-
queryClient.invalidateQueries(QUERY_KEYS.REQUESTS);
|
|
6273
|
-
queryClient.invalidateQueries(QUERY_KEYS.VIEWS);
|
|
6274
|
-
options === null || options === void 0 ? void 0 : (_options$onSuccess = options.onSuccess) === null || _options$onSuccess === void 0 ? void 0 : _options$onSuccess.call(options);
|
|
6275
|
-
}
|
|
6276
|
-
}));
|
|
2247
|
+
useQueryClient();
|
|
2248
|
+
return useMutationWithInvalidation(publicRequestsApi.accept, _objectSpread({
|
|
2249
|
+
keysToInvalidate: [QUERY_KEYS.SHOW_PUBLIC_REQUEST, QUERY_KEYS.REQUESTS, QUERY_KEYS.VIEWS]
|
|
2250
|
+
}, options));
|
|
6277
2251
|
};
|
|
6278
2252
|
var useDeclinePendingRequest = function useDeclinePendingRequest(options) {
|
|
6279
|
-
|
|
6280
|
-
return
|
|
6281
|
-
|
|
6282
|
-
|
|
6283
|
-
queryClient.invalidateQueries(QUERY_KEYS.SHOW_PUBLIC_REQUEST);
|
|
6284
|
-
queryClient.invalidateQueries(QUERY_KEYS.REQUESTS);
|
|
6285
|
-
queryClient.invalidateQueries(QUERY_KEYS.VIEWS);
|
|
6286
|
-
options === null || options === void 0 ? void 0 : (_options$onSuccess2 = options.onSuccess) === null || _options$onSuccess2 === void 0 ? void 0 : _options$onSuccess2.call(options);
|
|
6287
|
-
}
|
|
6288
|
-
}));
|
|
2253
|
+
useQueryClient();
|
|
2254
|
+
return useMutationWithInvalidation(publicRequestsApi.decline, _objectSpread({
|
|
2255
|
+
keysToInvalidate: [QUERY_KEYS.SHOW_PUBLIC_REQUEST, QUERY_KEYS.REQUESTS, QUERY_KEYS.VIEWS]
|
|
2256
|
+
}, options));
|
|
6289
2257
|
};
|
|
6290
2258
|
|
|
6291
2259
|
var Public = function Public() {
|