@bigbinary/neeto-filters-frontend 2.14.2 → 2.14.3
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 +116 -2945
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +102 -2932
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
- package/src/translations/en.json +66 -0
- package/src/translations/index.js +3 -0
package/dist/index.cjs.js
CHANGED
|
@@ -6,9 +6,11 @@ var React = require('react');
|
|
|
6
6
|
var classnames = require('classnames');
|
|
7
7
|
var ramda = require('ramda');
|
|
8
8
|
var neetoui = require('@bigbinary/neetoui');
|
|
9
|
+
var reactI18next = require('react-i18next');
|
|
9
10
|
var reactRouterDom = require('react-router-dom');
|
|
10
11
|
var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
|
|
11
12
|
var neetoIcons = require('@bigbinary/neeto-icons');
|
|
13
|
+
var i18next = require('i18next');
|
|
12
14
|
var dayjs = require('dayjs');
|
|
13
15
|
var utils = require('@bigbinary/neeto-commons-frontend/utils');
|
|
14
16
|
var yup = require('yup');
|
|
@@ -43,6 +45,7 @@ function _interopNamespace(e) {
|
|
|
43
45
|
|
|
44
46
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
45
47
|
var classnames__default = /*#__PURE__*/_interopDefaultLegacy(classnames);
|
|
48
|
+
var i18next__default = /*#__PURE__*/_interopDefaultLegacy(i18next);
|
|
46
49
|
var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
|
|
47
50
|
var yup__namespace = /*#__PURE__*/_interopNamespace(yup);
|
|
48
51
|
var timezone__default = /*#__PURE__*/_interopDefaultLegacy(timezone);
|
|
@@ -52,2915 +55,6 @@ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
|
52
55
|
var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
|
|
53
56
|
var MenuBar__default = /*#__PURE__*/_interopDefaultLegacy(MenuBar);
|
|
54
57
|
|
|
55
|
-
const consoleLogger = {
|
|
56
|
-
type: 'logger',
|
|
57
|
-
log(args) {
|
|
58
|
-
this.output('log', args);
|
|
59
|
-
},
|
|
60
|
-
warn(args) {
|
|
61
|
-
this.output('warn', args);
|
|
62
|
-
},
|
|
63
|
-
error(args) {
|
|
64
|
-
this.output('error', args);
|
|
65
|
-
},
|
|
66
|
-
output(type, args) {
|
|
67
|
-
if (console && console[type]) console[type].apply(console, args);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
class Logger {
|
|
71
|
-
constructor(concreteLogger) {
|
|
72
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
73
|
-
this.init(concreteLogger, options);
|
|
74
|
-
}
|
|
75
|
-
init(concreteLogger) {
|
|
76
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
77
|
-
this.prefix = options.prefix || 'i18next:';
|
|
78
|
-
this.logger = concreteLogger || consoleLogger;
|
|
79
|
-
this.options = options;
|
|
80
|
-
this.debug = options.debug;
|
|
81
|
-
}
|
|
82
|
-
log() {
|
|
83
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
84
|
-
args[_key] = arguments[_key];
|
|
85
|
-
}
|
|
86
|
-
return this.forward(args, 'log', '', true);
|
|
87
|
-
}
|
|
88
|
-
warn() {
|
|
89
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
90
|
-
args[_key2] = arguments[_key2];
|
|
91
|
-
}
|
|
92
|
-
return this.forward(args, 'warn', '', true);
|
|
93
|
-
}
|
|
94
|
-
error() {
|
|
95
|
-
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
96
|
-
args[_key3] = arguments[_key3];
|
|
97
|
-
}
|
|
98
|
-
return this.forward(args, 'error', '');
|
|
99
|
-
}
|
|
100
|
-
deprecate() {
|
|
101
|
-
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
102
|
-
args[_key4] = arguments[_key4];
|
|
103
|
-
}
|
|
104
|
-
return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
|
|
105
|
-
}
|
|
106
|
-
forward(args, lvl, prefix, debugOnly) {
|
|
107
|
-
if (debugOnly && !this.debug) return null;
|
|
108
|
-
if (typeof args[0] === 'string') args[0] = `${prefix}${this.prefix} ${args[0]}`;
|
|
109
|
-
return this.logger[lvl](args);
|
|
110
|
-
}
|
|
111
|
-
create(moduleName) {
|
|
112
|
-
return new Logger(this.logger, {
|
|
113
|
-
...{
|
|
114
|
-
prefix: `${this.prefix}:${moduleName}:`
|
|
115
|
-
},
|
|
116
|
-
...this.options
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
clone(options) {
|
|
120
|
-
options = options || this.options;
|
|
121
|
-
options.prefix = options.prefix || this.prefix;
|
|
122
|
-
return new Logger(this.logger, options);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
var baseLogger = new Logger();
|
|
126
|
-
|
|
127
|
-
class EventEmitter {
|
|
128
|
-
constructor() {
|
|
129
|
-
this.observers = {};
|
|
130
|
-
}
|
|
131
|
-
on(events, listener) {
|
|
132
|
-
events.split(' ').forEach(event => {
|
|
133
|
-
this.observers[event] = this.observers[event] || [];
|
|
134
|
-
this.observers[event].push(listener);
|
|
135
|
-
});
|
|
136
|
-
return this;
|
|
137
|
-
}
|
|
138
|
-
off(event, listener) {
|
|
139
|
-
if (!this.observers[event]) return;
|
|
140
|
-
if (!listener) {
|
|
141
|
-
delete this.observers[event];
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
this.observers[event] = this.observers[event].filter(l => l !== listener);
|
|
145
|
-
}
|
|
146
|
-
emit(event) {
|
|
147
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
148
|
-
args[_key - 1] = arguments[_key];
|
|
149
|
-
}
|
|
150
|
-
if (this.observers[event]) {
|
|
151
|
-
const cloned = [].concat(this.observers[event]);
|
|
152
|
-
cloned.forEach(observer => {
|
|
153
|
-
observer(...args);
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
if (this.observers['*']) {
|
|
157
|
-
const cloned = [].concat(this.observers['*']);
|
|
158
|
-
cloned.forEach(observer => {
|
|
159
|
-
observer.apply(observer, [event, ...args]);
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function defer() {
|
|
166
|
-
let res;
|
|
167
|
-
let rej;
|
|
168
|
-
const promise = new Promise((resolve, reject) => {
|
|
169
|
-
res = resolve;
|
|
170
|
-
rej = reject;
|
|
171
|
-
});
|
|
172
|
-
promise.resolve = res;
|
|
173
|
-
promise.reject = rej;
|
|
174
|
-
return promise;
|
|
175
|
-
}
|
|
176
|
-
function makeString(object) {
|
|
177
|
-
if (object == null) return '';
|
|
178
|
-
return '' + object;
|
|
179
|
-
}
|
|
180
|
-
function copy(a, s, t) {
|
|
181
|
-
a.forEach(m => {
|
|
182
|
-
if (s[m]) t[m] = s[m];
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
function getLastOfPath(object, path, Empty) {
|
|
186
|
-
function cleanKey(key) {
|
|
187
|
-
return key && key.indexOf('###') > -1 ? key.replace(/###/g, '.') : key;
|
|
188
|
-
}
|
|
189
|
-
function canNotTraverseDeeper() {
|
|
190
|
-
return !object || typeof object === 'string';
|
|
191
|
-
}
|
|
192
|
-
const stack = typeof path !== 'string' ? [].concat(path) : path.split('.');
|
|
193
|
-
while (stack.length > 1) {
|
|
194
|
-
if (canNotTraverseDeeper()) return {};
|
|
195
|
-
const key = cleanKey(stack.shift());
|
|
196
|
-
if (!object[key] && Empty) object[key] = new Empty();
|
|
197
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
198
|
-
object = object[key];
|
|
199
|
-
} else {
|
|
200
|
-
object = {};
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
if (canNotTraverseDeeper()) return {};
|
|
204
|
-
return {
|
|
205
|
-
obj: object,
|
|
206
|
-
k: cleanKey(stack.shift())
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
function setPath(object, path, newValue) {
|
|
210
|
-
const {
|
|
211
|
-
obj,
|
|
212
|
-
k
|
|
213
|
-
} = getLastOfPath(object, path, Object);
|
|
214
|
-
obj[k] = newValue;
|
|
215
|
-
}
|
|
216
|
-
function pushPath(object, path, newValue, concat) {
|
|
217
|
-
const {
|
|
218
|
-
obj,
|
|
219
|
-
k
|
|
220
|
-
} = getLastOfPath(object, path, Object);
|
|
221
|
-
obj[k] = obj[k] || [];
|
|
222
|
-
if (concat) obj[k] = obj[k].concat(newValue);
|
|
223
|
-
if (!concat) obj[k].push(newValue);
|
|
224
|
-
}
|
|
225
|
-
function getPath(object, path) {
|
|
226
|
-
const {
|
|
227
|
-
obj,
|
|
228
|
-
k
|
|
229
|
-
} = getLastOfPath(object, path);
|
|
230
|
-
if (!obj) return undefined;
|
|
231
|
-
return obj[k];
|
|
232
|
-
}
|
|
233
|
-
function getPathWithDefaults(data, defaultData, key) {
|
|
234
|
-
const value = getPath(data, key);
|
|
235
|
-
if (value !== undefined) {
|
|
236
|
-
return value;
|
|
237
|
-
}
|
|
238
|
-
return getPath(defaultData, key);
|
|
239
|
-
}
|
|
240
|
-
function deepExtend(target, source, overwrite) {
|
|
241
|
-
for (const prop in source) {
|
|
242
|
-
if (prop !== '__proto__' && prop !== 'constructor') {
|
|
243
|
-
if (prop in target) {
|
|
244
|
-
if (typeof target[prop] === 'string' || target[prop] instanceof String || typeof source[prop] === 'string' || source[prop] instanceof String) {
|
|
245
|
-
if (overwrite) target[prop] = source[prop];
|
|
246
|
-
} else {
|
|
247
|
-
deepExtend(target[prop], source[prop], overwrite);
|
|
248
|
-
}
|
|
249
|
-
} else {
|
|
250
|
-
target[prop] = source[prop];
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return target;
|
|
255
|
-
}
|
|
256
|
-
function regexEscape(str) {
|
|
257
|
-
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
|
|
258
|
-
}
|
|
259
|
-
var _entityMap = {
|
|
260
|
-
'&': '&',
|
|
261
|
-
'<': '<',
|
|
262
|
-
'>': '>',
|
|
263
|
-
'"': '"',
|
|
264
|
-
"'": ''',
|
|
265
|
-
'/': '/'
|
|
266
|
-
};
|
|
267
|
-
function escape(data) {
|
|
268
|
-
if (typeof data === 'string') {
|
|
269
|
-
return data.replace(/[&<>"'\/]/g, s => _entityMap[s]);
|
|
270
|
-
}
|
|
271
|
-
return data;
|
|
272
|
-
}
|
|
273
|
-
const chars = [' ', ',', '?', '!', ';'];
|
|
274
|
-
function looksLikeObjectPath(key, nsSeparator, keySeparator) {
|
|
275
|
-
nsSeparator = nsSeparator || '';
|
|
276
|
-
keySeparator = keySeparator || '';
|
|
277
|
-
const possibleChars = chars.filter(c => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
|
|
278
|
-
if (possibleChars.length === 0) return true;
|
|
279
|
-
const r = new RegExp(`(${possibleChars.map(c => c === '?' ? '\\?' : c).join('|')})`);
|
|
280
|
-
let matched = !r.test(key);
|
|
281
|
-
if (!matched) {
|
|
282
|
-
const ki = key.indexOf(keySeparator);
|
|
283
|
-
if (ki > 0 && !r.test(key.substring(0, ki))) {
|
|
284
|
-
matched = true;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
return matched;
|
|
288
|
-
}
|
|
289
|
-
function deepFind(obj, path) {
|
|
290
|
-
let keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
|
|
291
|
-
if (!obj) return undefined;
|
|
292
|
-
if (obj[path]) return obj[path];
|
|
293
|
-
const paths = path.split(keySeparator);
|
|
294
|
-
let current = obj;
|
|
295
|
-
for (let i = 0; i < paths.length; ++i) {
|
|
296
|
-
if (!current) return undefined;
|
|
297
|
-
if (typeof current[paths[i]] === 'string' && i + 1 < paths.length) {
|
|
298
|
-
return undefined;
|
|
299
|
-
}
|
|
300
|
-
if (current[paths[i]] === undefined) {
|
|
301
|
-
let j = 2;
|
|
302
|
-
let p = paths.slice(i, i + j).join(keySeparator);
|
|
303
|
-
let mix = current[p];
|
|
304
|
-
while (mix === undefined && paths.length > i + j) {
|
|
305
|
-
j++;
|
|
306
|
-
p = paths.slice(i, i + j).join(keySeparator);
|
|
307
|
-
mix = current[p];
|
|
308
|
-
}
|
|
309
|
-
if (mix === undefined) return undefined;
|
|
310
|
-
if (mix === null) return null;
|
|
311
|
-
if (path.endsWith(p)) {
|
|
312
|
-
if (typeof mix === 'string') return mix;
|
|
313
|
-
if (p && typeof mix[p] === 'string') return mix[p];
|
|
314
|
-
}
|
|
315
|
-
const joinedPath = paths.slice(i + j).join(keySeparator);
|
|
316
|
-
if (joinedPath) return deepFind(mix, joinedPath, keySeparator);
|
|
317
|
-
return undefined;
|
|
318
|
-
}
|
|
319
|
-
current = current[paths[i]];
|
|
320
|
-
}
|
|
321
|
-
return current;
|
|
322
|
-
}
|
|
323
|
-
function getCleanedCode(code) {
|
|
324
|
-
if (code && code.indexOf('_') > 0) return code.replace('_', '-');
|
|
325
|
-
return code;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
class ResourceStore extends EventEmitter {
|
|
329
|
-
constructor(data) {
|
|
330
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
331
|
-
ns: ['translation'],
|
|
332
|
-
defaultNS: 'translation'
|
|
333
|
-
};
|
|
334
|
-
super();
|
|
335
|
-
this.data = data || {};
|
|
336
|
-
this.options = options;
|
|
337
|
-
if (this.options.keySeparator === undefined) {
|
|
338
|
-
this.options.keySeparator = '.';
|
|
339
|
-
}
|
|
340
|
-
if (this.options.ignoreJSONStructure === undefined) {
|
|
341
|
-
this.options.ignoreJSONStructure = true;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
addNamespaces(ns) {
|
|
345
|
-
if (this.options.ns.indexOf(ns) < 0) {
|
|
346
|
-
this.options.ns.push(ns);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
removeNamespaces(ns) {
|
|
350
|
-
const index = this.options.ns.indexOf(ns);
|
|
351
|
-
if (index > -1) {
|
|
352
|
-
this.options.ns.splice(index, 1);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
getResource(lng, ns, key) {
|
|
356
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
357
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
358
|
-
const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
359
|
-
let path = [lng, ns];
|
|
360
|
-
if (key && typeof key !== 'string') path = path.concat(key);
|
|
361
|
-
if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
362
|
-
if (lng.indexOf('.') > -1) {
|
|
363
|
-
path = lng.split('.');
|
|
364
|
-
}
|
|
365
|
-
const result = getPath(this.data, path);
|
|
366
|
-
if (result || !ignoreJSONStructure || typeof key !== 'string') return result;
|
|
367
|
-
return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
|
|
368
|
-
}
|
|
369
|
-
addResource(lng, ns, key, value) {
|
|
370
|
-
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
371
|
-
silent: false
|
|
372
|
-
};
|
|
373
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
374
|
-
let path = [lng, ns];
|
|
375
|
-
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
376
|
-
if (lng.indexOf('.') > -1) {
|
|
377
|
-
path = lng.split('.');
|
|
378
|
-
value = ns;
|
|
379
|
-
ns = path[1];
|
|
380
|
-
}
|
|
381
|
-
this.addNamespaces(ns);
|
|
382
|
-
setPath(this.data, path, value);
|
|
383
|
-
if (!options.silent) this.emit('added', lng, ns, key, value);
|
|
384
|
-
}
|
|
385
|
-
addResources(lng, ns, resources) {
|
|
386
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
387
|
-
silent: false
|
|
388
|
-
};
|
|
389
|
-
for (const m in resources) {
|
|
390
|
-
if (typeof resources[m] === 'string' || Object.prototype.toString.apply(resources[m]) === '[object Array]') this.addResource(lng, ns, m, resources[m], {
|
|
391
|
-
silent: true
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
395
|
-
}
|
|
396
|
-
addResourceBundle(lng, ns, resources, deep, overwrite) {
|
|
397
|
-
let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
|
|
398
|
-
silent: false
|
|
399
|
-
};
|
|
400
|
-
let path = [lng, ns];
|
|
401
|
-
if (lng.indexOf('.') > -1) {
|
|
402
|
-
path = lng.split('.');
|
|
403
|
-
deep = resources;
|
|
404
|
-
resources = ns;
|
|
405
|
-
ns = path[1];
|
|
406
|
-
}
|
|
407
|
-
this.addNamespaces(ns);
|
|
408
|
-
let pack = getPath(this.data, path) || {};
|
|
409
|
-
if (deep) {
|
|
410
|
-
deepExtend(pack, resources, overwrite);
|
|
411
|
-
} else {
|
|
412
|
-
pack = {
|
|
413
|
-
...pack,
|
|
414
|
-
...resources
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
setPath(this.data, path, pack);
|
|
418
|
-
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
419
|
-
}
|
|
420
|
-
removeResourceBundle(lng, ns) {
|
|
421
|
-
if (this.hasResourceBundle(lng, ns)) {
|
|
422
|
-
delete this.data[lng][ns];
|
|
423
|
-
}
|
|
424
|
-
this.removeNamespaces(ns);
|
|
425
|
-
this.emit('removed', lng, ns);
|
|
426
|
-
}
|
|
427
|
-
hasResourceBundle(lng, ns) {
|
|
428
|
-
return this.getResource(lng, ns) !== undefined;
|
|
429
|
-
}
|
|
430
|
-
getResourceBundle(lng, ns) {
|
|
431
|
-
if (!ns) ns = this.options.defaultNS;
|
|
432
|
-
if (this.options.compatibilityAPI === 'v1') return {
|
|
433
|
-
...{},
|
|
434
|
-
...this.getResource(lng, ns)
|
|
435
|
-
};
|
|
436
|
-
return this.getResource(lng, ns);
|
|
437
|
-
}
|
|
438
|
-
getDataByLanguage(lng) {
|
|
439
|
-
return this.data[lng];
|
|
440
|
-
}
|
|
441
|
-
hasLanguageSomeTranslations(lng) {
|
|
442
|
-
const data = this.getDataByLanguage(lng);
|
|
443
|
-
const n = data && Object.keys(data) || [];
|
|
444
|
-
return !!n.find(v => data[v] && Object.keys(data[v]).length > 0);
|
|
445
|
-
}
|
|
446
|
-
toJSON() {
|
|
447
|
-
return this.data;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
var postProcessor = {
|
|
452
|
-
processors: {},
|
|
453
|
-
addPostProcessor(module) {
|
|
454
|
-
this.processors[module.name] = module;
|
|
455
|
-
},
|
|
456
|
-
handle(processors, value, key, options, translator) {
|
|
457
|
-
processors.forEach(processor => {
|
|
458
|
-
if (this.processors[processor]) value = this.processors[processor].process(value, key, options, translator);
|
|
459
|
-
});
|
|
460
|
-
return value;
|
|
461
|
-
}
|
|
462
|
-
};
|
|
463
|
-
|
|
464
|
-
const checkedLoadedFor = {};
|
|
465
|
-
class Translator extends EventEmitter {
|
|
466
|
-
constructor(services) {
|
|
467
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
468
|
-
super();
|
|
469
|
-
copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, this);
|
|
470
|
-
this.options = options;
|
|
471
|
-
if (this.options.keySeparator === undefined) {
|
|
472
|
-
this.options.keySeparator = '.';
|
|
473
|
-
}
|
|
474
|
-
this.logger = baseLogger.create('translator');
|
|
475
|
-
}
|
|
476
|
-
changeLanguage(lng) {
|
|
477
|
-
if (lng) this.language = lng;
|
|
478
|
-
}
|
|
479
|
-
exists(key) {
|
|
480
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
481
|
-
interpolation: {}
|
|
482
|
-
};
|
|
483
|
-
if (key === undefined || key === null) {
|
|
484
|
-
return false;
|
|
485
|
-
}
|
|
486
|
-
const resolved = this.resolve(key, options);
|
|
487
|
-
return resolved && resolved.res !== undefined;
|
|
488
|
-
}
|
|
489
|
-
extractFromKey(key, options) {
|
|
490
|
-
let nsSeparator = options.nsSeparator !== undefined ? options.nsSeparator : this.options.nsSeparator;
|
|
491
|
-
if (nsSeparator === undefined) nsSeparator = ':';
|
|
492
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
493
|
-
let namespaces = options.ns || this.options.defaultNS || [];
|
|
494
|
-
const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
495
|
-
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
496
|
-
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
497
|
-
const m = key.match(this.interpolator.nestingRegexp);
|
|
498
|
-
if (m && m.length > 0) {
|
|
499
|
-
return {
|
|
500
|
-
key,
|
|
501
|
-
namespaces
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
|
-
const parts = key.split(nsSeparator);
|
|
505
|
-
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
|
|
506
|
-
key = parts.join(keySeparator);
|
|
507
|
-
}
|
|
508
|
-
if (typeof namespaces === 'string') namespaces = [namespaces];
|
|
509
|
-
return {
|
|
510
|
-
key,
|
|
511
|
-
namespaces
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
translate(keys, options, lastKey) {
|
|
515
|
-
if (typeof options !== 'object' && this.options.overloadTranslationOptionHandler) {
|
|
516
|
-
options = this.options.overloadTranslationOptionHandler(arguments);
|
|
517
|
-
}
|
|
518
|
-
if (typeof options === 'object') options = {
|
|
519
|
-
...options
|
|
520
|
-
};
|
|
521
|
-
if (!options) options = {};
|
|
522
|
-
if (keys === undefined || keys === null) return '';
|
|
523
|
-
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
524
|
-
const returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
|
|
525
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
526
|
-
const {
|
|
527
|
-
key,
|
|
528
|
-
namespaces
|
|
529
|
-
} = this.extractFromKey(keys[keys.length - 1], options);
|
|
530
|
-
const namespace = namespaces[namespaces.length - 1];
|
|
531
|
-
const lng = options.lng || this.language;
|
|
532
|
-
const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
533
|
-
if (lng && lng.toLowerCase() === 'cimode') {
|
|
534
|
-
if (appendNamespaceToCIMode) {
|
|
535
|
-
const nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
536
|
-
if (returnDetails) {
|
|
537
|
-
return {
|
|
538
|
-
res: `${namespace}${nsSeparator}${key}`,
|
|
539
|
-
usedKey: key,
|
|
540
|
-
exactUsedKey: key,
|
|
541
|
-
usedLng: lng,
|
|
542
|
-
usedNS: namespace
|
|
543
|
-
};
|
|
544
|
-
}
|
|
545
|
-
return `${namespace}${nsSeparator}${key}`;
|
|
546
|
-
}
|
|
547
|
-
if (returnDetails) {
|
|
548
|
-
return {
|
|
549
|
-
res: key,
|
|
550
|
-
usedKey: key,
|
|
551
|
-
exactUsedKey: key,
|
|
552
|
-
usedLng: lng,
|
|
553
|
-
usedNS: namespace
|
|
554
|
-
};
|
|
555
|
-
}
|
|
556
|
-
return key;
|
|
557
|
-
}
|
|
558
|
-
const resolved = this.resolve(keys, options);
|
|
559
|
-
let res = resolved && resolved.res;
|
|
560
|
-
const resUsedKey = resolved && resolved.usedKey || key;
|
|
561
|
-
const resExactUsedKey = resolved && resolved.exactUsedKey || key;
|
|
562
|
-
const resType = Object.prototype.toString.apply(res);
|
|
563
|
-
const noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
|
|
564
|
-
const joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
|
|
565
|
-
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
566
|
-
const handleAsObject = typeof res !== 'string' && typeof res !== 'boolean' && typeof res !== 'number';
|
|
567
|
-
if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === 'string' && resType === '[object Array]')) {
|
|
568
|
-
if (!options.returnObjects && !this.options.returnObjects) {
|
|
569
|
-
if (!this.options.returnedObjectHandler) {
|
|
570
|
-
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
571
|
-
}
|
|
572
|
-
const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, {
|
|
573
|
-
...options,
|
|
574
|
-
ns: namespaces
|
|
575
|
-
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
576
|
-
if (returnDetails) {
|
|
577
|
-
resolved.res = r;
|
|
578
|
-
return resolved;
|
|
579
|
-
}
|
|
580
|
-
return r;
|
|
581
|
-
}
|
|
582
|
-
if (keySeparator) {
|
|
583
|
-
const resTypeIsArray = resType === '[object Array]';
|
|
584
|
-
const copy = resTypeIsArray ? [] : {};
|
|
585
|
-
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
586
|
-
for (const m in res) {
|
|
587
|
-
if (Object.prototype.hasOwnProperty.call(res, m)) {
|
|
588
|
-
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
589
|
-
copy[m] = this.translate(deepKey, {
|
|
590
|
-
...options,
|
|
591
|
-
...{
|
|
592
|
-
joinArrays: false,
|
|
593
|
-
ns: namespaces
|
|
594
|
-
}
|
|
595
|
-
});
|
|
596
|
-
if (copy[m] === deepKey) copy[m] = res[m];
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
res = copy;
|
|
600
|
-
}
|
|
601
|
-
} else if (handleAsObjectInI18nFormat && typeof joinArrays === 'string' && resType === '[object Array]') {
|
|
602
|
-
res = res.join(joinArrays);
|
|
603
|
-
if (res) res = this.extendTranslation(res, keys, options, lastKey);
|
|
604
|
-
} else {
|
|
605
|
-
let usedDefault = false;
|
|
606
|
-
let usedKey = false;
|
|
607
|
-
const needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
|
|
608
|
-
const hasDefaultValue = Translator.hasDefaultValue(options);
|
|
609
|
-
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : '';
|
|
610
|
-
const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
|
|
611
|
-
ordinal: false
|
|
612
|
-
}) : '';
|
|
613
|
-
const defaultValue = options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
|
|
614
|
-
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
615
|
-
usedDefault = true;
|
|
616
|
-
res = defaultValue;
|
|
617
|
-
}
|
|
618
|
-
if (!this.isValidLookup(res)) {
|
|
619
|
-
usedKey = true;
|
|
620
|
-
res = key;
|
|
621
|
-
}
|
|
622
|
-
const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
623
|
-
const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
|
|
624
|
-
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
625
|
-
if (usedKey || usedDefault || updateMissing) {
|
|
626
|
-
this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
|
|
627
|
-
if (keySeparator) {
|
|
628
|
-
const fk = this.resolve(key, {
|
|
629
|
-
...options,
|
|
630
|
-
keySeparator: false
|
|
631
|
-
});
|
|
632
|
-
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.');
|
|
633
|
-
}
|
|
634
|
-
let lngs = [];
|
|
635
|
-
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
|
|
636
|
-
if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
|
|
637
|
-
for (let i = 0; i < fallbackLngs.length; i++) {
|
|
638
|
-
lngs.push(fallbackLngs[i]);
|
|
639
|
-
}
|
|
640
|
-
} else if (this.options.saveMissingTo === 'all') {
|
|
641
|
-
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
|
|
642
|
-
} else {
|
|
643
|
-
lngs.push(options.lng || this.language);
|
|
644
|
-
}
|
|
645
|
-
const send = (l, k, specificDefaultValue) => {
|
|
646
|
-
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
647
|
-
if (this.options.missingKeyHandler) {
|
|
648
|
-
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
649
|
-
} else if (this.backendConnector && this.backendConnector.saveMissing) {
|
|
650
|
-
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
651
|
-
}
|
|
652
|
-
this.emit('missingKey', l, namespace, k, res);
|
|
653
|
-
};
|
|
654
|
-
if (this.options.saveMissing) {
|
|
655
|
-
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
656
|
-
lngs.forEach(language => {
|
|
657
|
-
this.pluralResolver.getSuffixes(language, options).forEach(suffix => {
|
|
658
|
-
send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
|
|
659
|
-
});
|
|
660
|
-
});
|
|
661
|
-
} else {
|
|
662
|
-
send(lngs, key, defaultValue);
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
res = this.extendTranslation(res, keys, options, resolved, lastKey);
|
|
667
|
-
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
|
|
668
|
-
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
669
|
-
if (this.options.compatibilityAPI !== 'v1') {
|
|
670
|
-
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : undefined);
|
|
671
|
-
} else {
|
|
672
|
-
res = this.options.parseMissingKeyHandler(res);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
if (returnDetails) {
|
|
677
|
-
resolved.res = res;
|
|
678
|
-
return resolved;
|
|
679
|
-
}
|
|
680
|
-
return res;
|
|
681
|
-
}
|
|
682
|
-
extendTranslation(res, key, options, resolved, lastKey) {
|
|
683
|
-
var _this = this;
|
|
684
|
-
if (this.i18nFormat && this.i18nFormat.parse) {
|
|
685
|
-
res = this.i18nFormat.parse(res, {
|
|
686
|
-
...this.options.interpolation.defaultVariables,
|
|
687
|
-
...options
|
|
688
|
-
}, resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
689
|
-
resolved
|
|
690
|
-
});
|
|
691
|
-
} else if (!options.skipInterpolation) {
|
|
692
|
-
if (options.interpolation) this.interpolator.init({
|
|
693
|
-
...options,
|
|
694
|
-
...{
|
|
695
|
-
interpolation: {
|
|
696
|
-
...this.options.interpolation,
|
|
697
|
-
...options.interpolation
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
});
|
|
701
|
-
const skipOnVariables = typeof res === 'string' && (options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
702
|
-
let nestBef;
|
|
703
|
-
if (skipOnVariables) {
|
|
704
|
-
const nb = res.match(this.interpolator.nestingRegexp);
|
|
705
|
-
nestBef = nb && nb.length;
|
|
706
|
-
}
|
|
707
|
-
let data = options.replace && typeof options.replace !== 'string' ? options.replace : options;
|
|
708
|
-
if (this.options.interpolation.defaultVariables) data = {
|
|
709
|
-
...this.options.interpolation.defaultVariables,
|
|
710
|
-
...data
|
|
711
|
-
};
|
|
712
|
-
res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
|
|
713
|
-
if (skipOnVariables) {
|
|
714
|
-
const na = res.match(this.interpolator.nestingRegexp);
|
|
715
|
-
const nestAft = na && na.length;
|
|
716
|
-
if (nestBef < nestAft) options.nest = false;
|
|
717
|
-
}
|
|
718
|
-
if (!options.lng && this.options.compatibilityAPI !== 'v1' && resolved && resolved.res) options.lng = resolved.usedLng;
|
|
719
|
-
if (options.nest !== false) res = this.interpolator.nest(res, function () {
|
|
720
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
721
|
-
args[_key] = arguments[_key];
|
|
722
|
-
}
|
|
723
|
-
if (lastKey && lastKey[0] === args[0] && !options.context) {
|
|
724
|
-
_this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
725
|
-
return null;
|
|
726
|
-
}
|
|
727
|
-
return _this.translate(...args, key);
|
|
728
|
-
}, options);
|
|
729
|
-
if (options.interpolation) this.interpolator.reset();
|
|
730
|
-
}
|
|
731
|
-
const postProcess = options.postProcess || this.options.postProcess;
|
|
732
|
-
const postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess;
|
|
733
|
-
if (res !== undefined && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
|
|
734
|
-
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
735
|
-
i18nResolved: resolved,
|
|
736
|
-
...options
|
|
737
|
-
} : options, this);
|
|
738
|
-
}
|
|
739
|
-
return res;
|
|
740
|
-
}
|
|
741
|
-
resolve(keys) {
|
|
742
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
743
|
-
let found;
|
|
744
|
-
let usedKey;
|
|
745
|
-
let exactUsedKey;
|
|
746
|
-
let usedLng;
|
|
747
|
-
let usedNS;
|
|
748
|
-
if (typeof keys === 'string') keys = [keys];
|
|
749
|
-
keys.forEach(k => {
|
|
750
|
-
if (this.isValidLookup(found)) return;
|
|
751
|
-
const extracted = this.extractFromKey(k, options);
|
|
752
|
-
const key = extracted.key;
|
|
753
|
-
usedKey = key;
|
|
754
|
-
let namespaces = extracted.namespaces;
|
|
755
|
-
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
756
|
-
const needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
|
|
757
|
-
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
|
|
758
|
-
const needsContextHandling = options.context !== undefined && (typeof options.context === 'string' || typeof options.context === 'number') && options.context !== '';
|
|
759
|
-
const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
|
|
760
|
-
namespaces.forEach(ns => {
|
|
761
|
-
if (this.isValidLookup(found)) return;
|
|
762
|
-
usedNS = ns;
|
|
763
|
-
if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils && this.utils.hasLoadedNamespace && !this.utils.hasLoadedNamespace(usedNS)) {
|
|
764
|
-
checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
765
|
-
this.logger.warn(`key "${usedKey}" for languages "${codes.join(', ')}" won't get resolved as namespace "${usedNS}" was not yet loaded`, 'This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!');
|
|
766
|
-
}
|
|
767
|
-
codes.forEach(code => {
|
|
768
|
-
if (this.isValidLookup(found)) return;
|
|
769
|
-
usedLng = code;
|
|
770
|
-
const finalKeys = [key];
|
|
771
|
-
if (this.i18nFormat && this.i18nFormat.addLookupKeys) {
|
|
772
|
-
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
|
|
773
|
-
} else {
|
|
774
|
-
let pluralSuffix;
|
|
775
|
-
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
|
|
776
|
-
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
777
|
-
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
778
|
-
if (needsPluralHandling) {
|
|
779
|
-
finalKeys.push(key + pluralSuffix);
|
|
780
|
-
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
781
|
-
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
782
|
-
}
|
|
783
|
-
if (needsZeroSuffixLookup) {
|
|
784
|
-
finalKeys.push(key + zeroSuffix);
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
if (needsContextHandling) {
|
|
788
|
-
const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
|
|
789
|
-
finalKeys.push(contextKey);
|
|
790
|
-
if (needsPluralHandling) {
|
|
791
|
-
finalKeys.push(contextKey + pluralSuffix);
|
|
792
|
-
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
793
|
-
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
794
|
-
}
|
|
795
|
-
if (needsZeroSuffixLookup) {
|
|
796
|
-
finalKeys.push(contextKey + zeroSuffix);
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
let possibleKey;
|
|
802
|
-
while (possibleKey = finalKeys.pop()) {
|
|
803
|
-
if (!this.isValidLookup(found)) {
|
|
804
|
-
exactUsedKey = possibleKey;
|
|
805
|
-
found = this.getResource(code, ns, possibleKey, options);
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
});
|
|
809
|
-
});
|
|
810
|
-
});
|
|
811
|
-
return {
|
|
812
|
-
res: found,
|
|
813
|
-
usedKey,
|
|
814
|
-
exactUsedKey,
|
|
815
|
-
usedLng,
|
|
816
|
-
usedNS
|
|
817
|
-
};
|
|
818
|
-
}
|
|
819
|
-
isValidLookup(res) {
|
|
820
|
-
return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
|
|
821
|
-
}
|
|
822
|
-
getResource(code, ns, key) {
|
|
823
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
824
|
-
if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
825
|
-
return this.resourceStore.getResource(code, ns, key, options);
|
|
826
|
-
}
|
|
827
|
-
static hasDefaultValue(options) {
|
|
828
|
-
const prefix = 'defaultValue';
|
|
829
|
-
for (const option in options) {
|
|
830
|
-
if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
|
|
831
|
-
return true;
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
return false;
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
function capitalize$1(string) {
|
|
839
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
840
|
-
}
|
|
841
|
-
class LanguageUtil {
|
|
842
|
-
constructor(options) {
|
|
843
|
-
this.options = options;
|
|
844
|
-
this.supportedLngs = this.options.supportedLngs || false;
|
|
845
|
-
this.logger = baseLogger.create('languageUtils');
|
|
846
|
-
}
|
|
847
|
-
getScriptPartFromCode(code) {
|
|
848
|
-
code = getCleanedCode(code);
|
|
849
|
-
if (!code || code.indexOf('-') < 0) return null;
|
|
850
|
-
const p = code.split('-');
|
|
851
|
-
if (p.length === 2) return null;
|
|
852
|
-
p.pop();
|
|
853
|
-
if (p[p.length - 1].toLowerCase() === 'x') return null;
|
|
854
|
-
return this.formatLanguageCode(p.join('-'));
|
|
855
|
-
}
|
|
856
|
-
getLanguagePartFromCode(code) {
|
|
857
|
-
code = getCleanedCode(code);
|
|
858
|
-
if (!code || code.indexOf('-') < 0) return code;
|
|
859
|
-
const p = code.split('-');
|
|
860
|
-
return this.formatLanguageCode(p[0]);
|
|
861
|
-
}
|
|
862
|
-
formatLanguageCode(code) {
|
|
863
|
-
if (typeof code === 'string' && code.indexOf('-') > -1) {
|
|
864
|
-
const specialCases = ['hans', 'hant', 'latn', 'cyrl', 'cans', 'mong', 'arab'];
|
|
865
|
-
let p = code.split('-');
|
|
866
|
-
if (this.options.lowerCaseLng) {
|
|
867
|
-
p = p.map(part => part.toLowerCase());
|
|
868
|
-
} else if (p.length === 2) {
|
|
869
|
-
p[0] = p[0].toLowerCase();
|
|
870
|
-
p[1] = p[1].toUpperCase();
|
|
871
|
-
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize$1(p[1].toLowerCase());
|
|
872
|
-
} else if (p.length === 3) {
|
|
873
|
-
p[0] = p[0].toLowerCase();
|
|
874
|
-
if (p[1].length === 2) p[1] = p[1].toUpperCase();
|
|
875
|
-
if (p[0] !== 'sgn' && p[2].length === 2) p[2] = p[2].toUpperCase();
|
|
876
|
-
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize$1(p[1].toLowerCase());
|
|
877
|
-
if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize$1(p[2].toLowerCase());
|
|
878
|
-
}
|
|
879
|
-
return p.join('-');
|
|
880
|
-
}
|
|
881
|
-
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
882
|
-
}
|
|
883
|
-
isSupportedCode(code) {
|
|
884
|
-
if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
|
|
885
|
-
code = this.getLanguagePartFromCode(code);
|
|
886
|
-
}
|
|
887
|
-
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
888
|
-
}
|
|
889
|
-
getBestMatchFromCodes(codes) {
|
|
890
|
-
if (!codes) return null;
|
|
891
|
-
let found;
|
|
892
|
-
codes.forEach(code => {
|
|
893
|
-
if (found) return;
|
|
894
|
-
const cleanedLng = this.formatLanguageCode(code);
|
|
895
|
-
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
896
|
-
});
|
|
897
|
-
if (!found && this.options.supportedLngs) {
|
|
898
|
-
codes.forEach(code => {
|
|
899
|
-
if (found) return;
|
|
900
|
-
const lngOnly = this.getLanguagePartFromCode(code);
|
|
901
|
-
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
902
|
-
found = this.options.supportedLngs.find(supportedLng => {
|
|
903
|
-
if (supportedLng === lngOnly) return supportedLng;
|
|
904
|
-
if (supportedLng.indexOf('-') < 0 && lngOnly.indexOf('-') < 0) return;
|
|
905
|
-
if (supportedLng.indexOf(lngOnly) === 0) return supportedLng;
|
|
906
|
-
});
|
|
907
|
-
});
|
|
908
|
-
}
|
|
909
|
-
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
910
|
-
return found;
|
|
911
|
-
}
|
|
912
|
-
getFallbackCodes(fallbacks, code) {
|
|
913
|
-
if (!fallbacks) return [];
|
|
914
|
-
if (typeof fallbacks === 'function') fallbacks = fallbacks(code);
|
|
915
|
-
if (typeof fallbacks === 'string') fallbacks = [fallbacks];
|
|
916
|
-
if (Object.prototype.toString.apply(fallbacks) === '[object Array]') return fallbacks;
|
|
917
|
-
if (!code) return fallbacks.default || [];
|
|
918
|
-
let found = fallbacks[code];
|
|
919
|
-
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
920
|
-
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
921
|
-
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
922
|
-
if (!found) found = fallbacks.default;
|
|
923
|
-
return found || [];
|
|
924
|
-
}
|
|
925
|
-
toResolveHierarchy(code, fallbackCode) {
|
|
926
|
-
const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
927
|
-
const codes = [];
|
|
928
|
-
const addCode = c => {
|
|
929
|
-
if (!c) return;
|
|
930
|
-
if (this.isSupportedCode(c)) {
|
|
931
|
-
codes.push(c);
|
|
932
|
-
} else {
|
|
933
|
-
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
934
|
-
}
|
|
935
|
-
};
|
|
936
|
-
if (typeof code === 'string' && (code.indexOf('-') > -1 || code.indexOf('_') > -1)) {
|
|
937
|
-
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
|
|
938
|
-
if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
|
|
939
|
-
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
|
|
940
|
-
} else if (typeof code === 'string') {
|
|
941
|
-
addCode(this.formatLanguageCode(code));
|
|
942
|
-
}
|
|
943
|
-
fallbackCodes.forEach(fc => {
|
|
944
|
-
if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
|
|
945
|
-
});
|
|
946
|
-
return codes;
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
let sets = [{
|
|
951
|
-
lngs: ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'gun', 'ln', 'mfe', 'mg', 'mi', 'oc', 'pt', 'pt-BR', 'tg', 'tl', 'ti', 'tr', 'uz', 'wa'],
|
|
952
|
-
nr: [1, 2],
|
|
953
|
-
fc: 1
|
|
954
|
-
}, {
|
|
955
|
-
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'],
|
|
956
|
-
nr: [1, 2],
|
|
957
|
-
fc: 2
|
|
958
|
-
}, {
|
|
959
|
-
lngs: ['ay', 'bo', 'cgg', 'fa', 'ht', 'id', 'ja', 'jbo', 'ka', 'km', 'ko', 'ky', 'lo', 'ms', 'sah', 'su', 'th', 'tt', 'ug', 'vi', 'wo', 'zh'],
|
|
960
|
-
nr: [1],
|
|
961
|
-
fc: 3
|
|
962
|
-
}, {
|
|
963
|
-
lngs: ['be', 'bs', 'cnr', 'dz', 'hr', 'ru', 'sr', 'uk'],
|
|
964
|
-
nr: [1, 2, 5],
|
|
965
|
-
fc: 4
|
|
966
|
-
}, {
|
|
967
|
-
lngs: ['ar'],
|
|
968
|
-
nr: [0, 1, 2, 3, 11, 100],
|
|
969
|
-
fc: 5
|
|
970
|
-
}, {
|
|
971
|
-
lngs: ['cs', 'sk'],
|
|
972
|
-
nr: [1, 2, 5],
|
|
973
|
-
fc: 6
|
|
974
|
-
}, {
|
|
975
|
-
lngs: ['csb', 'pl'],
|
|
976
|
-
nr: [1, 2, 5],
|
|
977
|
-
fc: 7
|
|
978
|
-
}, {
|
|
979
|
-
lngs: ['cy'],
|
|
980
|
-
nr: [1, 2, 3, 8],
|
|
981
|
-
fc: 8
|
|
982
|
-
}, {
|
|
983
|
-
lngs: ['fr'],
|
|
984
|
-
nr: [1, 2],
|
|
985
|
-
fc: 9
|
|
986
|
-
}, {
|
|
987
|
-
lngs: ['ga'],
|
|
988
|
-
nr: [1, 2, 3, 7, 11],
|
|
989
|
-
fc: 10
|
|
990
|
-
}, {
|
|
991
|
-
lngs: ['gd'],
|
|
992
|
-
nr: [1, 2, 3, 20],
|
|
993
|
-
fc: 11
|
|
994
|
-
}, {
|
|
995
|
-
lngs: ['is'],
|
|
996
|
-
nr: [1, 2],
|
|
997
|
-
fc: 12
|
|
998
|
-
}, {
|
|
999
|
-
lngs: ['jv'],
|
|
1000
|
-
nr: [0, 1],
|
|
1001
|
-
fc: 13
|
|
1002
|
-
}, {
|
|
1003
|
-
lngs: ['kw'],
|
|
1004
|
-
nr: [1, 2, 3, 4],
|
|
1005
|
-
fc: 14
|
|
1006
|
-
}, {
|
|
1007
|
-
lngs: ['lt'],
|
|
1008
|
-
nr: [1, 2, 10],
|
|
1009
|
-
fc: 15
|
|
1010
|
-
}, {
|
|
1011
|
-
lngs: ['lv'],
|
|
1012
|
-
nr: [1, 2, 0],
|
|
1013
|
-
fc: 16
|
|
1014
|
-
}, {
|
|
1015
|
-
lngs: ['mk'],
|
|
1016
|
-
nr: [1, 2],
|
|
1017
|
-
fc: 17
|
|
1018
|
-
}, {
|
|
1019
|
-
lngs: ['mnk'],
|
|
1020
|
-
nr: [0, 1, 2],
|
|
1021
|
-
fc: 18
|
|
1022
|
-
}, {
|
|
1023
|
-
lngs: ['mt'],
|
|
1024
|
-
nr: [1, 2, 11, 20],
|
|
1025
|
-
fc: 19
|
|
1026
|
-
}, {
|
|
1027
|
-
lngs: ['or'],
|
|
1028
|
-
nr: [2, 1],
|
|
1029
|
-
fc: 2
|
|
1030
|
-
}, {
|
|
1031
|
-
lngs: ['ro'],
|
|
1032
|
-
nr: [1, 2, 20],
|
|
1033
|
-
fc: 20
|
|
1034
|
-
}, {
|
|
1035
|
-
lngs: ['sl'],
|
|
1036
|
-
nr: [5, 1, 2, 3],
|
|
1037
|
-
fc: 21
|
|
1038
|
-
}, {
|
|
1039
|
-
lngs: ['he', 'iw'],
|
|
1040
|
-
nr: [1, 2, 20, 21],
|
|
1041
|
-
fc: 22
|
|
1042
|
-
}];
|
|
1043
|
-
let _rulesPluralsTypes = {
|
|
1044
|
-
1: function (n) {
|
|
1045
|
-
return Number(n > 1);
|
|
1046
|
-
},
|
|
1047
|
-
2: function (n) {
|
|
1048
|
-
return Number(n != 1);
|
|
1049
|
-
},
|
|
1050
|
-
3: function (n) {
|
|
1051
|
-
return 0;
|
|
1052
|
-
},
|
|
1053
|
-
4: function (n) {
|
|
1054
|
-
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1055
|
-
},
|
|
1056
|
-
5: function (n) {
|
|
1057
|
-
return Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5);
|
|
1058
|
-
},
|
|
1059
|
-
6: function (n) {
|
|
1060
|
-
return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2);
|
|
1061
|
-
},
|
|
1062
|
-
7: function (n) {
|
|
1063
|
-
return Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1064
|
-
},
|
|
1065
|
-
8: function (n) {
|
|
1066
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3);
|
|
1067
|
-
},
|
|
1068
|
-
9: function (n) {
|
|
1069
|
-
return Number(n >= 2);
|
|
1070
|
-
},
|
|
1071
|
-
10: function (n) {
|
|
1072
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4);
|
|
1073
|
-
},
|
|
1074
|
-
11: function (n) {
|
|
1075
|
-
return Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3);
|
|
1076
|
-
},
|
|
1077
|
-
12: function (n) {
|
|
1078
|
-
return Number(n % 10 != 1 || n % 100 == 11);
|
|
1079
|
-
},
|
|
1080
|
-
13: function (n) {
|
|
1081
|
-
return Number(n !== 0);
|
|
1082
|
-
},
|
|
1083
|
-
14: function (n) {
|
|
1084
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3);
|
|
1085
|
-
},
|
|
1086
|
-
15: function (n) {
|
|
1087
|
-
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1088
|
-
},
|
|
1089
|
-
16: function (n) {
|
|
1090
|
-
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2);
|
|
1091
|
-
},
|
|
1092
|
-
17: function (n) {
|
|
1093
|
-
return Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1);
|
|
1094
|
-
},
|
|
1095
|
-
18: function (n) {
|
|
1096
|
-
return Number(n == 0 ? 0 : n == 1 ? 1 : 2);
|
|
1097
|
-
},
|
|
1098
|
-
19: function (n) {
|
|
1099
|
-
return Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3);
|
|
1100
|
-
},
|
|
1101
|
-
20: function (n) {
|
|
1102
|
-
return Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2);
|
|
1103
|
-
},
|
|
1104
|
-
21: function (n) {
|
|
1105
|
-
return Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0);
|
|
1106
|
-
},
|
|
1107
|
-
22: function (n) {
|
|
1108
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3);
|
|
1109
|
-
}
|
|
1110
|
-
};
|
|
1111
|
-
const nonIntlVersions = ['v1', 'v2', 'v3'];
|
|
1112
|
-
const intlVersions = ['v4'];
|
|
1113
|
-
const suffixesOrder = {
|
|
1114
|
-
zero: 0,
|
|
1115
|
-
one: 1,
|
|
1116
|
-
two: 2,
|
|
1117
|
-
few: 3,
|
|
1118
|
-
many: 4,
|
|
1119
|
-
other: 5
|
|
1120
|
-
};
|
|
1121
|
-
function createRules() {
|
|
1122
|
-
const rules = {};
|
|
1123
|
-
sets.forEach(set => {
|
|
1124
|
-
set.lngs.forEach(l => {
|
|
1125
|
-
rules[l] = {
|
|
1126
|
-
numbers: set.nr,
|
|
1127
|
-
plurals: _rulesPluralsTypes[set.fc]
|
|
1128
|
-
};
|
|
1129
|
-
});
|
|
1130
|
-
});
|
|
1131
|
-
return rules;
|
|
1132
|
-
}
|
|
1133
|
-
class PluralResolver {
|
|
1134
|
-
constructor(languageUtils) {
|
|
1135
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1136
|
-
this.languageUtils = languageUtils;
|
|
1137
|
-
this.options = options;
|
|
1138
|
-
this.logger = baseLogger.create('pluralResolver');
|
|
1139
|
-
if ((!this.options.compatibilityJSON || intlVersions.includes(this.options.compatibilityJSON)) && (typeof Intl === 'undefined' || !Intl.PluralRules)) {
|
|
1140
|
-
this.options.compatibilityJSON = 'v3';
|
|
1141
|
-
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.');
|
|
1142
|
-
}
|
|
1143
|
-
this.rules = createRules();
|
|
1144
|
-
}
|
|
1145
|
-
addRule(lng, obj) {
|
|
1146
|
-
this.rules[lng] = obj;
|
|
1147
|
-
}
|
|
1148
|
-
getRule(code) {
|
|
1149
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1150
|
-
if (this.shouldUseIntlApi()) {
|
|
1151
|
-
try {
|
|
1152
|
-
return new Intl.PluralRules(getCleanedCode(code), {
|
|
1153
|
-
type: options.ordinal ? 'ordinal' : 'cardinal'
|
|
1154
|
-
});
|
|
1155
|
-
} catch {
|
|
1156
|
-
return;
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
|
|
1160
|
-
}
|
|
1161
|
-
needsPlural(code) {
|
|
1162
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1163
|
-
const rule = this.getRule(code, options);
|
|
1164
|
-
if (this.shouldUseIntlApi()) {
|
|
1165
|
-
return rule && rule.resolvedOptions().pluralCategories.length > 1;
|
|
1166
|
-
}
|
|
1167
|
-
return rule && rule.numbers.length > 1;
|
|
1168
|
-
}
|
|
1169
|
-
getPluralFormsOfKey(code, key) {
|
|
1170
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1171
|
-
return this.getSuffixes(code, options).map(suffix => `${key}${suffix}`);
|
|
1172
|
-
}
|
|
1173
|
-
getSuffixes(code) {
|
|
1174
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1175
|
-
const rule = this.getRule(code, options);
|
|
1176
|
-
if (!rule) {
|
|
1177
|
-
return [];
|
|
1178
|
-
}
|
|
1179
|
-
if (this.shouldUseIntlApi()) {
|
|
1180
|
-
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map(pluralCategory => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${pluralCategory}`);
|
|
1181
|
-
}
|
|
1182
|
-
return rule.numbers.map(number => this.getSuffix(code, number, options));
|
|
1183
|
-
}
|
|
1184
|
-
getSuffix(code, count) {
|
|
1185
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1186
|
-
const rule = this.getRule(code, options);
|
|
1187
|
-
if (rule) {
|
|
1188
|
-
if (this.shouldUseIntlApi()) {
|
|
1189
|
-
return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${rule.select(count)}`;
|
|
1190
|
-
}
|
|
1191
|
-
return this.getSuffixRetroCompatible(rule, count);
|
|
1192
|
-
}
|
|
1193
|
-
this.logger.warn(`no plural rule found for: ${code}`);
|
|
1194
|
-
return '';
|
|
1195
|
-
}
|
|
1196
|
-
getSuffixRetroCompatible(rule, count) {
|
|
1197
|
-
const idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
|
|
1198
|
-
let suffix = rule.numbers[idx];
|
|
1199
|
-
if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1200
|
-
if (suffix === 2) {
|
|
1201
|
-
suffix = 'plural';
|
|
1202
|
-
} else if (suffix === 1) {
|
|
1203
|
-
suffix = '';
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
const returnSuffix = () => this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString();
|
|
1207
|
-
if (this.options.compatibilityJSON === 'v1') {
|
|
1208
|
-
if (suffix === 1) return '';
|
|
1209
|
-
if (typeof suffix === 'number') return `_plural_${suffix.toString()}`;
|
|
1210
|
-
return returnSuffix();
|
|
1211
|
-
} else if (this.options.compatibilityJSON === 'v2') {
|
|
1212
|
-
return returnSuffix();
|
|
1213
|
-
} else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1214
|
-
return returnSuffix();
|
|
1215
|
-
}
|
|
1216
|
-
return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
|
|
1217
|
-
}
|
|
1218
|
-
shouldUseIntlApi() {
|
|
1219
|
-
return !nonIntlVersions.includes(this.options.compatibilityJSON);
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
|
|
1223
|
-
function deepFindWithDefaults(data, defaultData, key) {
|
|
1224
|
-
let keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
|
|
1225
|
-
let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
1226
|
-
let path = getPathWithDefaults(data, defaultData, key);
|
|
1227
|
-
if (!path && ignoreJSONStructure && typeof key === 'string') {
|
|
1228
|
-
path = deepFind(data, key, keySeparator);
|
|
1229
|
-
if (path === undefined) path = deepFind(defaultData, key, keySeparator);
|
|
1230
|
-
}
|
|
1231
|
-
return path;
|
|
1232
|
-
}
|
|
1233
|
-
class Interpolator {
|
|
1234
|
-
constructor() {
|
|
1235
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1236
|
-
this.logger = baseLogger.create('interpolator');
|
|
1237
|
-
this.options = options;
|
|
1238
|
-
this.format = options.interpolation && options.interpolation.format || (value => value);
|
|
1239
|
-
this.init(options);
|
|
1240
|
-
}
|
|
1241
|
-
init() {
|
|
1242
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1243
|
-
if (!options.interpolation) options.interpolation = {
|
|
1244
|
-
escapeValue: true
|
|
1245
|
-
};
|
|
1246
|
-
const iOpts = options.interpolation;
|
|
1247
|
-
this.escape = iOpts.escape !== undefined ? iOpts.escape : escape;
|
|
1248
|
-
this.escapeValue = iOpts.escapeValue !== undefined ? iOpts.escapeValue : true;
|
|
1249
|
-
this.useRawValueToEscape = iOpts.useRawValueToEscape !== undefined ? iOpts.useRawValueToEscape : false;
|
|
1250
|
-
this.prefix = iOpts.prefix ? regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{';
|
|
1251
|
-
this.suffix = iOpts.suffix ? regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}';
|
|
1252
|
-
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
|
|
1253
|
-
this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-';
|
|
1254
|
-
this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || '';
|
|
1255
|
-
this.nestingPrefix = iOpts.nestingPrefix ? regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || regexEscape('$t(');
|
|
1256
|
-
this.nestingSuffix = iOpts.nestingSuffix ? regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || regexEscape(')');
|
|
1257
|
-
this.nestingOptionsSeparator = iOpts.nestingOptionsSeparator ? iOpts.nestingOptionsSeparator : iOpts.nestingOptionsSeparator || ',';
|
|
1258
|
-
this.maxReplaces = iOpts.maxReplaces ? iOpts.maxReplaces : 1000;
|
|
1259
|
-
this.alwaysFormat = iOpts.alwaysFormat !== undefined ? iOpts.alwaysFormat : false;
|
|
1260
|
-
this.resetRegExp();
|
|
1261
|
-
}
|
|
1262
|
-
reset() {
|
|
1263
|
-
if (this.options) this.init(this.options);
|
|
1264
|
-
}
|
|
1265
|
-
resetRegExp() {
|
|
1266
|
-
const regexpStr = `${this.prefix}(.+?)${this.suffix}`;
|
|
1267
|
-
this.regexp = new RegExp(regexpStr, 'g');
|
|
1268
|
-
const regexpUnescapeStr = `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`;
|
|
1269
|
-
this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g');
|
|
1270
|
-
const nestingRegexpStr = `${this.nestingPrefix}(.+?)${this.nestingSuffix}`;
|
|
1271
|
-
this.nestingRegexp = new RegExp(nestingRegexpStr, 'g');
|
|
1272
|
-
}
|
|
1273
|
-
interpolate(str, data, lng, options) {
|
|
1274
|
-
let match;
|
|
1275
|
-
let value;
|
|
1276
|
-
let replaces;
|
|
1277
|
-
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
1278
|
-
function regexSafe(val) {
|
|
1279
|
-
return val.replace(/\$/g, '$$$$');
|
|
1280
|
-
}
|
|
1281
|
-
const handleFormat = key => {
|
|
1282
|
-
if (key.indexOf(this.formatSeparator) < 0) {
|
|
1283
|
-
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
1284
|
-
return this.alwaysFormat ? this.format(path, undefined, lng, {
|
|
1285
|
-
...options,
|
|
1286
|
-
...data,
|
|
1287
|
-
interpolationkey: key
|
|
1288
|
-
}) : path;
|
|
1289
|
-
}
|
|
1290
|
-
const p = key.split(this.formatSeparator);
|
|
1291
|
-
const k = p.shift().trim();
|
|
1292
|
-
const f = p.join(this.formatSeparator).trim();
|
|
1293
|
-
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
|
|
1294
|
-
...options,
|
|
1295
|
-
...data,
|
|
1296
|
-
interpolationkey: k
|
|
1297
|
-
});
|
|
1298
|
-
};
|
|
1299
|
-
this.resetRegExp();
|
|
1300
|
-
const missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
1301
|
-
const skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
1302
|
-
const todos = [{
|
|
1303
|
-
regex: this.regexpUnescape,
|
|
1304
|
-
safeValue: val => regexSafe(val)
|
|
1305
|
-
}, {
|
|
1306
|
-
regex: this.regexp,
|
|
1307
|
-
safeValue: val => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
|
|
1308
|
-
}];
|
|
1309
|
-
todos.forEach(todo => {
|
|
1310
|
-
replaces = 0;
|
|
1311
|
-
while (match = todo.regex.exec(str)) {
|
|
1312
|
-
const matchedVar = match[1].trim();
|
|
1313
|
-
value = handleFormat(matchedVar);
|
|
1314
|
-
if (value === undefined) {
|
|
1315
|
-
if (typeof missingInterpolationHandler === 'function') {
|
|
1316
|
-
const temp = missingInterpolationHandler(str, match, options);
|
|
1317
|
-
value = typeof temp === 'string' ? temp : '';
|
|
1318
|
-
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
|
|
1319
|
-
value = '';
|
|
1320
|
-
} else if (skipOnVariables) {
|
|
1321
|
-
value = match[0];
|
|
1322
|
-
continue;
|
|
1323
|
-
} else {
|
|
1324
|
-
this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
|
|
1325
|
-
value = '';
|
|
1326
|
-
}
|
|
1327
|
-
} else if (typeof value !== 'string' && !this.useRawValueToEscape) {
|
|
1328
|
-
value = makeString(value);
|
|
1329
|
-
}
|
|
1330
|
-
const safeValue = todo.safeValue(value);
|
|
1331
|
-
str = str.replace(match[0], safeValue);
|
|
1332
|
-
if (skipOnVariables) {
|
|
1333
|
-
todo.regex.lastIndex += value.length;
|
|
1334
|
-
todo.regex.lastIndex -= match[0].length;
|
|
1335
|
-
} else {
|
|
1336
|
-
todo.regex.lastIndex = 0;
|
|
1337
|
-
}
|
|
1338
|
-
replaces++;
|
|
1339
|
-
if (replaces >= this.maxReplaces) {
|
|
1340
|
-
break;
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
});
|
|
1344
|
-
return str;
|
|
1345
|
-
}
|
|
1346
|
-
nest(str, fc) {
|
|
1347
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1348
|
-
let match;
|
|
1349
|
-
let value;
|
|
1350
|
-
let clonedOptions;
|
|
1351
|
-
function handleHasOptions(key, inheritedOptions) {
|
|
1352
|
-
const sep = this.nestingOptionsSeparator;
|
|
1353
|
-
if (key.indexOf(sep) < 0) return key;
|
|
1354
|
-
const c = key.split(new RegExp(`${sep}[ ]*{`));
|
|
1355
|
-
let optionsString = `{${c[1]}`;
|
|
1356
|
-
key = c[0];
|
|
1357
|
-
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
1358
|
-
const matchedSingleQuotes = optionsString.match(/'/g);
|
|
1359
|
-
const matchedDoubleQuotes = optionsString.match(/"/g);
|
|
1360
|
-
if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
|
|
1361
|
-
optionsString = optionsString.replace(/'/g, '"');
|
|
1362
|
-
}
|
|
1363
|
-
try {
|
|
1364
|
-
clonedOptions = JSON.parse(optionsString);
|
|
1365
|
-
if (inheritedOptions) clonedOptions = {
|
|
1366
|
-
...inheritedOptions,
|
|
1367
|
-
...clonedOptions
|
|
1368
|
-
};
|
|
1369
|
-
} catch (e) {
|
|
1370
|
-
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
1371
|
-
return `${key}${sep}${optionsString}`;
|
|
1372
|
-
}
|
|
1373
|
-
delete clonedOptions.defaultValue;
|
|
1374
|
-
return key;
|
|
1375
|
-
}
|
|
1376
|
-
while (match = this.nestingRegexp.exec(str)) {
|
|
1377
|
-
let formatters = [];
|
|
1378
|
-
clonedOptions = {
|
|
1379
|
-
...options
|
|
1380
|
-
};
|
|
1381
|
-
clonedOptions = clonedOptions.replace && typeof clonedOptions.replace !== 'string' ? clonedOptions.replace : clonedOptions;
|
|
1382
|
-
clonedOptions.applyPostProcessor = false;
|
|
1383
|
-
delete clonedOptions.defaultValue;
|
|
1384
|
-
let doReduce = false;
|
|
1385
|
-
if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
|
|
1386
|
-
const r = match[1].split(this.formatSeparator).map(elem => elem.trim());
|
|
1387
|
-
match[1] = r.shift();
|
|
1388
|
-
formatters = r;
|
|
1389
|
-
doReduce = true;
|
|
1390
|
-
}
|
|
1391
|
-
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
1392
|
-
if (value && match[0] === str && typeof value !== 'string') return value;
|
|
1393
|
-
if (typeof value !== 'string') value = makeString(value);
|
|
1394
|
-
if (!value) {
|
|
1395
|
-
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
1396
|
-
value = '';
|
|
1397
|
-
}
|
|
1398
|
-
if (doReduce) {
|
|
1399
|
-
value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
1400
|
-
...options,
|
|
1401
|
-
interpolationkey: match[1].trim()
|
|
1402
|
-
}), value.trim());
|
|
1403
|
-
}
|
|
1404
|
-
str = str.replace(match[0], value);
|
|
1405
|
-
this.regexp.lastIndex = 0;
|
|
1406
|
-
}
|
|
1407
|
-
return str;
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
|
|
1411
|
-
function parseFormatStr(formatStr) {
|
|
1412
|
-
let formatName = formatStr.toLowerCase().trim();
|
|
1413
|
-
const formatOptions = {};
|
|
1414
|
-
if (formatStr.indexOf('(') > -1) {
|
|
1415
|
-
const p = formatStr.split('(');
|
|
1416
|
-
formatName = p[0].toLowerCase().trim();
|
|
1417
|
-
const optStr = p[1].substring(0, p[1].length - 1);
|
|
1418
|
-
if (formatName === 'currency' && optStr.indexOf(':') < 0) {
|
|
1419
|
-
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
1420
|
-
} else if (formatName === 'relativetime' && optStr.indexOf(':') < 0) {
|
|
1421
|
-
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
1422
|
-
} else {
|
|
1423
|
-
const opts = optStr.split(';');
|
|
1424
|
-
opts.forEach(opt => {
|
|
1425
|
-
if (!opt) return;
|
|
1426
|
-
const [key, ...rest] = opt.split(':');
|
|
1427
|
-
const val = rest.join(':').trim().replace(/^'+|'+$/g, '');
|
|
1428
|
-
if (!formatOptions[key.trim()]) formatOptions[key.trim()] = val;
|
|
1429
|
-
if (val === 'false') formatOptions[key.trim()] = false;
|
|
1430
|
-
if (val === 'true') formatOptions[key.trim()] = true;
|
|
1431
|
-
if (!isNaN(val)) formatOptions[key.trim()] = parseInt(val, 10);
|
|
1432
|
-
});
|
|
1433
|
-
}
|
|
1434
|
-
}
|
|
1435
|
-
return {
|
|
1436
|
-
formatName,
|
|
1437
|
-
formatOptions
|
|
1438
|
-
};
|
|
1439
|
-
}
|
|
1440
|
-
function createCachedFormatter(fn) {
|
|
1441
|
-
const cache = {};
|
|
1442
|
-
return function invokeFormatter(val, lng, options) {
|
|
1443
|
-
const key = lng + JSON.stringify(options);
|
|
1444
|
-
let formatter = cache[key];
|
|
1445
|
-
if (!formatter) {
|
|
1446
|
-
formatter = fn(getCleanedCode(lng), options);
|
|
1447
|
-
cache[key] = formatter;
|
|
1448
|
-
}
|
|
1449
|
-
return formatter(val);
|
|
1450
|
-
};
|
|
1451
|
-
}
|
|
1452
|
-
class Formatter {
|
|
1453
|
-
constructor() {
|
|
1454
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1455
|
-
this.logger = baseLogger.create('formatter');
|
|
1456
|
-
this.options = options;
|
|
1457
|
-
this.formats = {
|
|
1458
|
-
number: createCachedFormatter((lng, opt) => {
|
|
1459
|
-
const formatter = new Intl.NumberFormat(lng, {
|
|
1460
|
-
...opt
|
|
1461
|
-
});
|
|
1462
|
-
return val => formatter.format(val);
|
|
1463
|
-
}),
|
|
1464
|
-
currency: createCachedFormatter((lng, opt) => {
|
|
1465
|
-
const formatter = new Intl.NumberFormat(lng, {
|
|
1466
|
-
...opt,
|
|
1467
|
-
style: 'currency'
|
|
1468
|
-
});
|
|
1469
|
-
return val => formatter.format(val);
|
|
1470
|
-
}),
|
|
1471
|
-
datetime: createCachedFormatter((lng, opt) => {
|
|
1472
|
-
const formatter = new Intl.DateTimeFormat(lng, {
|
|
1473
|
-
...opt
|
|
1474
|
-
});
|
|
1475
|
-
return val => formatter.format(val);
|
|
1476
|
-
}),
|
|
1477
|
-
relativetime: createCachedFormatter((lng, opt) => {
|
|
1478
|
-
const formatter = new Intl.RelativeTimeFormat(lng, {
|
|
1479
|
-
...opt
|
|
1480
|
-
});
|
|
1481
|
-
return val => formatter.format(val, opt.range || 'day');
|
|
1482
|
-
}),
|
|
1483
|
-
list: createCachedFormatter((lng, opt) => {
|
|
1484
|
-
const formatter = new Intl.ListFormat(lng, {
|
|
1485
|
-
...opt
|
|
1486
|
-
});
|
|
1487
|
-
return val => formatter.format(val);
|
|
1488
|
-
})
|
|
1489
|
-
};
|
|
1490
|
-
this.init(options);
|
|
1491
|
-
}
|
|
1492
|
-
init(services) {
|
|
1493
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
1494
|
-
interpolation: {}
|
|
1495
|
-
};
|
|
1496
|
-
const iOpts = options.interpolation;
|
|
1497
|
-
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
|
|
1498
|
-
}
|
|
1499
|
-
add(name, fc) {
|
|
1500
|
-
this.formats[name.toLowerCase().trim()] = fc;
|
|
1501
|
-
}
|
|
1502
|
-
addCached(name, fc) {
|
|
1503
|
-
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
1504
|
-
}
|
|
1505
|
-
format(value, format, lng) {
|
|
1506
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1507
|
-
const formats = format.split(this.formatSeparator);
|
|
1508
|
-
const result = formats.reduce((mem, f) => {
|
|
1509
|
-
const {
|
|
1510
|
-
formatName,
|
|
1511
|
-
formatOptions
|
|
1512
|
-
} = parseFormatStr(f);
|
|
1513
|
-
if (this.formats[formatName]) {
|
|
1514
|
-
let formatted = mem;
|
|
1515
|
-
try {
|
|
1516
|
-
const valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
|
|
1517
|
-
const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
1518
|
-
formatted = this.formats[formatName](mem, l, {
|
|
1519
|
-
...formatOptions,
|
|
1520
|
-
...options,
|
|
1521
|
-
...valOptions
|
|
1522
|
-
});
|
|
1523
|
-
} catch (error) {
|
|
1524
|
-
this.logger.warn(error);
|
|
1525
|
-
}
|
|
1526
|
-
return formatted;
|
|
1527
|
-
} else {
|
|
1528
|
-
this.logger.warn(`there was no format function for ${formatName}`);
|
|
1529
|
-
}
|
|
1530
|
-
return mem;
|
|
1531
|
-
}, value);
|
|
1532
|
-
return result;
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
|
|
1536
|
-
function removePending(q, name) {
|
|
1537
|
-
if (q.pending[name] !== undefined) {
|
|
1538
|
-
delete q.pending[name];
|
|
1539
|
-
q.pendingCount--;
|
|
1540
|
-
}
|
|
1541
|
-
}
|
|
1542
|
-
class Connector extends EventEmitter {
|
|
1543
|
-
constructor(backend, store, services) {
|
|
1544
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1545
|
-
super();
|
|
1546
|
-
this.backend = backend;
|
|
1547
|
-
this.store = store;
|
|
1548
|
-
this.services = services;
|
|
1549
|
-
this.languageUtils = services.languageUtils;
|
|
1550
|
-
this.options = options;
|
|
1551
|
-
this.logger = baseLogger.create('backendConnector');
|
|
1552
|
-
this.waitingReads = [];
|
|
1553
|
-
this.maxParallelReads = options.maxParallelReads || 10;
|
|
1554
|
-
this.readingCalls = 0;
|
|
1555
|
-
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
1556
|
-
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
1557
|
-
this.state = {};
|
|
1558
|
-
this.queue = [];
|
|
1559
|
-
if (this.backend && this.backend.init) {
|
|
1560
|
-
this.backend.init(services, options.backend, options);
|
|
1561
|
-
}
|
|
1562
|
-
}
|
|
1563
|
-
queueLoad(languages, namespaces, options, callback) {
|
|
1564
|
-
const toLoad = {};
|
|
1565
|
-
const pending = {};
|
|
1566
|
-
const toLoadLanguages = {};
|
|
1567
|
-
const toLoadNamespaces = {};
|
|
1568
|
-
languages.forEach(lng => {
|
|
1569
|
-
let hasAllNamespaces = true;
|
|
1570
|
-
namespaces.forEach(ns => {
|
|
1571
|
-
const name = `${lng}|${ns}`;
|
|
1572
|
-
if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
|
|
1573
|
-
this.state[name] = 2;
|
|
1574
|
-
} else if (this.state[name] < 0) ; else if (this.state[name] === 1) {
|
|
1575
|
-
if (pending[name] === undefined) pending[name] = true;
|
|
1576
|
-
} else {
|
|
1577
|
-
this.state[name] = 1;
|
|
1578
|
-
hasAllNamespaces = false;
|
|
1579
|
-
if (pending[name] === undefined) pending[name] = true;
|
|
1580
|
-
if (toLoad[name] === undefined) toLoad[name] = true;
|
|
1581
|
-
if (toLoadNamespaces[ns] === undefined) toLoadNamespaces[ns] = true;
|
|
1582
|
-
}
|
|
1583
|
-
});
|
|
1584
|
-
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
1585
|
-
});
|
|
1586
|
-
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
1587
|
-
this.queue.push({
|
|
1588
|
-
pending,
|
|
1589
|
-
pendingCount: Object.keys(pending).length,
|
|
1590
|
-
loaded: {},
|
|
1591
|
-
errors: [],
|
|
1592
|
-
callback
|
|
1593
|
-
});
|
|
1594
|
-
}
|
|
1595
|
-
return {
|
|
1596
|
-
toLoad: Object.keys(toLoad),
|
|
1597
|
-
pending: Object.keys(pending),
|
|
1598
|
-
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
1599
|
-
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
1600
|
-
};
|
|
1601
|
-
}
|
|
1602
|
-
loaded(name, err, data) {
|
|
1603
|
-
const s = name.split('|');
|
|
1604
|
-
const lng = s[0];
|
|
1605
|
-
const ns = s[1];
|
|
1606
|
-
if (err) this.emit('failedLoading', lng, ns, err);
|
|
1607
|
-
if (data) {
|
|
1608
|
-
this.store.addResourceBundle(lng, ns, data);
|
|
1609
|
-
}
|
|
1610
|
-
this.state[name] = err ? -1 : 2;
|
|
1611
|
-
const loaded = {};
|
|
1612
|
-
this.queue.forEach(q => {
|
|
1613
|
-
pushPath(q.loaded, [lng], ns);
|
|
1614
|
-
removePending(q, name);
|
|
1615
|
-
if (err) q.errors.push(err);
|
|
1616
|
-
if (q.pendingCount === 0 && !q.done) {
|
|
1617
|
-
Object.keys(q.loaded).forEach(l => {
|
|
1618
|
-
if (!loaded[l]) loaded[l] = {};
|
|
1619
|
-
const loadedKeys = q.loaded[l];
|
|
1620
|
-
if (loadedKeys.length) {
|
|
1621
|
-
loadedKeys.forEach(n => {
|
|
1622
|
-
if (loaded[l][n] === undefined) loaded[l][n] = true;
|
|
1623
|
-
});
|
|
1624
|
-
}
|
|
1625
|
-
});
|
|
1626
|
-
q.done = true;
|
|
1627
|
-
if (q.errors.length) {
|
|
1628
|
-
q.callback(q.errors);
|
|
1629
|
-
} else {
|
|
1630
|
-
q.callback();
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
});
|
|
1634
|
-
this.emit('loaded', loaded);
|
|
1635
|
-
this.queue = this.queue.filter(q => !q.done);
|
|
1636
|
-
}
|
|
1637
|
-
read(lng, ns, fcName) {
|
|
1638
|
-
let tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
1639
|
-
let wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
|
|
1640
|
-
let callback = arguments.length > 5 ? arguments[5] : undefined;
|
|
1641
|
-
if (!lng.length) return callback(null, {});
|
|
1642
|
-
if (this.readingCalls >= this.maxParallelReads) {
|
|
1643
|
-
this.waitingReads.push({
|
|
1644
|
-
lng,
|
|
1645
|
-
ns,
|
|
1646
|
-
fcName,
|
|
1647
|
-
tried,
|
|
1648
|
-
wait,
|
|
1649
|
-
callback
|
|
1650
|
-
});
|
|
1651
|
-
return;
|
|
1652
|
-
}
|
|
1653
|
-
this.readingCalls++;
|
|
1654
|
-
const resolver = (err, data) => {
|
|
1655
|
-
this.readingCalls--;
|
|
1656
|
-
if (this.waitingReads.length > 0) {
|
|
1657
|
-
const next = this.waitingReads.shift();
|
|
1658
|
-
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
1659
|
-
}
|
|
1660
|
-
if (err && data && tried < this.maxRetries) {
|
|
1661
|
-
setTimeout(() => {
|
|
1662
|
-
this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
1663
|
-
}, wait);
|
|
1664
|
-
return;
|
|
1665
|
-
}
|
|
1666
|
-
callback(err, data);
|
|
1667
|
-
};
|
|
1668
|
-
const fc = this.backend[fcName].bind(this.backend);
|
|
1669
|
-
if (fc.length === 2) {
|
|
1670
|
-
try {
|
|
1671
|
-
const r = fc(lng, ns);
|
|
1672
|
-
if (r && typeof r.then === 'function') {
|
|
1673
|
-
r.then(data => resolver(null, data)).catch(resolver);
|
|
1674
|
-
} else {
|
|
1675
|
-
resolver(null, r);
|
|
1676
|
-
}
|
|
1677
|
-
} catch (err) {
|
|
1678
|
-
resolver(err);
|
|
1679
|
-
}
|
|
1680
|
-
return;
|
|
1681
|
-
}
|
|
1682
|
-
return fc(lng, ns, resolver);
|
|
1683
|
-
}
|
|
1684
|
-
prepareLoading(languages, namespaces) {
|
|
1685
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1686
|
-
let callback = arguments.length > 3 ? arguments[3] : undefined;
|
|
1687
|
-
if (!this.backend) {
|
|
1688
|
-
this.logger.warn('No backend was added via i18next.use. Will not load resources.');
|
|
1689
|
-
return callback && callback();
|
|
1690
|
-
}
|
|
1691
|
-
if (typeof languages === 'string') languages = this.languageUtils.toResolveHierarchy(languages);
|
|
1692
|
-
if (typeof namespaces === 'string') namespaces = [namespaces];
|
|
1693
|
-
const toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
1694
|
-
if (!toLoad.toLoad.length) {
|
|
1695
|
-
if (!toLoad.pending.length) callback();
|
|
1696
|
-
return null;
|
|
1697
|
-
}
|
|
1698
|
-
toLoad.toLoad.forEach(name => {
|
|
1699
|
-
this.loadOne(name);
|
|
1700
|
-
});
|
|
1701
|
-
}
|
|
1702
|
-
load(languages, namespaces, callback) {
|
|
1703
|
-
this.prepareLoading(languages, namespaces, {}, callback);
|
|
1704
|
-
}
|
|
1705
|
-
reload(languages, namespaces, callback) {
|
|
1706
|
-
this.prepareLoading(languages, namespaces, {
|
|
1707
|
-
reload: true
|
|
1708
|
-
}, callback);
|
|
1709
|
-
}
|
|
1710
|
-
loadOne(name) {
|
|
1711
|
-
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
1712
|
-
const s = name.split('|');
|
|
1713
|
-
const lng = s[0];
|
|
1714
|
-
const ns = s[1];
|
|
1715
|
-
this.read(lng, ns, 'read', undefined, undefined, (err, data) => {
|
|
1716
|
-
if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
1717
|
-
if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
1718
|
-
this.loaded(name, err, data);
|
|
1719
|
-
});
|
|
1720
|
-
}
|
|
1721
|
-
saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
1722
|
-
let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
1723
|
-
let clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : () => {};
|
|
1724
|
-
if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
|
|
1725
|
-
this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, 'This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!');
|
|
1726
|
-
return;
|
|
1727
|
-
}
|
|
1728
|
-
if (key === undefined || key === null || key === '') return;
|
|
1729
|
-
if (this.backend && this.backend.create) {
|
|
1730
|
-
const opts = {
|
|
1731
|
-
...options,
|
|
1732
|
-
isUpdate
|
|
1733
|
-
};
|
|
1734
|
-
const fc = this.backend.create.bind(this.backend);
|
|
1735
|
-
if (fc.length < 6) {
|
|
1736
|
-
try {
|
|
1737
|
-
let r;
|
|
1738
|
-
if (fc.length === 5) {
|
|
1739
|
-
r = fc(languages, namespace, key, fallbackValue, opts);
|
|
1740
|
-
} else {
|
|
1741
|
-
r = fc(languages, namespace, key, fallbackValue);
|
|
1742
|
-
}
|
|
1743
|
-
if (r && typeof r.then === 'function') {
|
|
1744
|
-
r.then(data => clb(null, data)).catch(clb);
|
|
1745
|
-
} else {
|
|
1746
|
-
clb(null, r);
|
|
1747
|
-
}
|
|
1748
|
-
} catch (err) {
|
|
1749
|
-
clb(err);
|
|
1750
|
-
}
|
|
1751
|
-
} else {
|
|
1752
|
-
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
1753
|
-
}
|
|
1754
|
-
}
|
|
1755
|
-
if (!languages || !languages[0]) return;
|
|
1756
|
-
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
|
|
1760
|
-
function get() {
|
|
1761
|
-
return {
|
|
1762
|
-
debug: false,
|
|
1763
|
-
initImmediate: true,
|
|
1764
|
-
ns: ['translation'],
|
|
1765
|
-
defaultNS: ['translation'],
|
|
1766
|
-
fallbackLng: ['dev'],
|
|
1767
|
-
fallbackNS: false,
|
|
1768
|
-
supportedLngs: false,
|
|
1769
|
-
nonExplicitSupportedLngs: false,
|
|
1770
|
-
load: 'all',
|
|
1771
|
-
preload: false,
|
|
1772
|
-
simplifyPluralSuffix: true,
|
|
1773
|
-
keySeparator: '.',
|
|
1774
|
-
nsSeparator: ':',
|
|
1775
|
-
pluralSeparator: '_',
|
|
1776
|
-
contextSeparator: '_',
|
|
1777
|
-
partialBundledLanguages: false,
|
|
1778
|
-
saveMissing: false,
|
|
1779
|
-
updateMissing: false,
|
|
1780
|
-
saveMissingTo: 'fallback',
|
|
1781
|
-
saveMissingPlurals: true,
|
|
1782
|
-
missingKeyHandler: false,
|
|
1783
|
-
missingInterpolationHandler: false,
|
|
1784
|
-
postProcess: false,
|
|
1785
|
-
postProcessPassResolved: false,
|
|
1786
|
-
returnNull: false,
|
|
1787
|
-
returnEmptyString: true,
|
|
1788
|
-
returnObjects: false,
|
|
1789
|
-
joinArrays: false,
|
|
1790
|
-
returnedObjectHandler: false,
|
|
1791
|
-
parseMissingKeyHandler: false,
|
|
1792
|
-
appendNamespaceToMissingKey: false,
|
|
1793
|
-
appendNamespaceToCIMode: false,
|
|
1794
|
-
overloadTranslationOptionHandler: function handle(args) {
|
|
1795
|
-
let ret = {};
|
|
1796
|
-
if (typeof args[1] === 'object') ret = args[1];
|
|
1797
|
-
if (typeof args[1] === 'string') ret.defaultValue = args[1];
|
|
1798
|
-
if (typeof args[2] === 'string') ret.tDescription = args[2];
|
|
1799
|
-
if (typeof args[2] === 'object' || typeof args[3] === 'object') {
|
|
1800
|
-
const options = args[3] || args[2];
|
|
1801
|
-
Object.keys(options).forEach(key => {
|
|
1802
|
-
ret[key] = options[key];
|
|
1803
|
-
});
|
|
1804
|
-
}
|
|
1805
|
-
return ret;
|
|
1806
|
-
},
|
|
1807
|
-
interpolation: {
|
|
1808
|
-
escapeValue: true,
|
|
1809
|
-
format: (value, format, lng, options) => value,
|
|
1810
|
-
prefix: '{{',
|
|
1811
|
-
suffix: '}}',
|
|
1812
|
-
formatSeparator: ',',
|
|
1813
|
-
unescapePrefix: '-',
|
|
1814
|
-
nestingPrefix: '$t(',
|
|
1815
|
-
nestingSuffix: ')',
|
|
1816
|
-
nestingOptionsSeparator: ',',
|
|
1817
|
-
maxReplaces: 1000,
|
|
1818
|
-
skipOnVariables: true
|
|
1819
|
-
}
|
|
1820
|
-
};
|
|
1821
|
-
}
|
|
1822
|
-
function transformOptions(options) {
|
|
1823
|
-
if (typeof options.ns === 'string') options.ns = [options.ns];
|
|
1824
|
-
if (typeof options.fallbackLng === 'string') options.fallbackLng = [options.fallbackLng];
|
|
1825
|
-
if (typeof options.fallbackNS === 'string') options.fallbackNS = [options.fallbackNS];
|
|
1826
|
-
if (options.supportedLngs && options.supportedLngs.indexOf('cimode') < 0) {
|
|
1827
|
-
options.supportedLngs = options.supportedLngs.concat(['cimode']);
|
|
1828
|
-
}
|
|
1829
|
-
return options;
|
|
1830
|
-
}
|
|
1831
|
-
|
|
1832
|
-
function noop$2() {}
|
|
1833
|
-
function bindMemberFunctions(inst) {
|
|
1834
|
-
const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
1835
|
-
mems.forEach(mem => {
|
|
1836
|
-
if (typeof inst[mem] === 'function') {
|
|
1837
|
-
inst[mem] = inst[mem].bind(inst);
|
|
1838
|
-
}
|
|
1839
|
-
});
|
|
1840
|
-
}
|
|
1841
|
-
class I18n extends EventEmitter {
|
|
1842
|
-
constructor() {
|
|
1843
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1844
|
-
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
1845
|
-
super();
|
|
1846
|
-
this.options = transformOptions(options);
|
|
1847
|
-
this.services = {};
|
|
1848
|
-
this.logger = baseLogger;
|
|
1849
|
-
this.modules = {
|
|
1850
|
-
external: []
|
|
1851
|
-
};
|
|
1852
|
-
bindMemberFunctions(this);
|
|
1853
|
-
if (callback && !this.isInitialized && !options.isClone) {
|
|
1854
|
-
if (!this.options.initImmediate) {
|
|
1855
|
-
this.init(options, callback);
|
|
1856
|
-
return this;
|
|
1857
|
-
}
|
|
1858
|
-
setTimeout(() => {
|
|
1859
|
-
this.init(options, callback);
|
|
1860
|
-
}, 0);
|
|
1861
|
-
}
|
|
1862
|
-
}
|
|
1863
|
-
init() {
|
|
1864
|
-
var _this = this;
|
|
1865
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1866
|
-
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
1867
|
-
if (typeof options === 'function') {
|
|
1868
|
-
callback = options;
|
|
1869
|
-
options = {};
|
|
1870
|
-
}
|
|
1871
|
-
if (!options.defaultNS && options.defaultNS !== false && options.ns) {
|
|
1872
|
-
if (typeof options.ns === 'string') {
|
|
1873
|
-
options.defaultNS = options.ns;
|
|
1874
|
-
} else if (options.ns.indexOf('translation') < 0) {
|
|
1875
|
-
options.defaultNS = options.ns[0];
|
|
1876
|
-
}
|
|
1877
|
-
}
|
|
1878
|
-
const defOpts = get();
|
|
1879
|
-
this.options = {
|
|
1880
|
-
...defOpts,
|
|
1881
|
-
...this.options,
|
|
1882
|
-
...transformOptions(options)
|
|
1883
|
-
};
|
|
1884
|
-
if (this.options.compatibilityAPI !== 'v1') {
|
|
1885
|
-
this.options.interpolation = {
|
|
1886
|
-
...defOpts.interpolation,
|
|
1887
|
-
...this.options.interpolation
|
|
1888
|
-
};
|
|
1889
|
-
}
|
|
1890
|
-
if (options.keySeparator !== undefined) {
|
|
1891
|
-
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
1892
|
-
}
|
|
1893
|
-
if (options.nsSeparator !== undefined) {
|
|
1894
|
-
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
1895
|
-
}
|
|
1896
|
-
function createClassOnDemand(ClassOrObject) {
|
|
1897
|
-
if (!ClassOrObject) return null;
|
|
1898
|
-
if (typeof ClassOrObject === 'function') return new ClassOrObject();
|
|
1899
|
-
return ClassOrObject;
|
|
1900
|
-
}
|
|
1901
|
-
if (!this.options.isClone) {
|
|
1902
|
-
if (this.modules.logger) {
|
|
1903
|
-
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
1904
|
-
} else {
|
|
1905
|
-
baseLogger.init(null, this.options);
|
|
1906
|
-
}
|
|
1907
|
-
let formatter;
|
|
1908
|
-
if (this.modules.formatter) {
|
|
1909
|
-
formatter = this.modules.formatter;
|
|
1910
|
-
} else if (typeof Intl !== 'undefined') {
|
|
1911
|
-
formatter = Formatter;
|
|
1912
|
-
}
|
|
1913
|
-
const lu = new LanguageUtil(this.options);
|
|
1914
|
-
this.store = new ResourceStore(this.options.resources, this.options);
|
|
1915
|
-
const s = this.services;
|
|
1916
|
-
s.logger = baseLogger;
|
|
1917
|
-
s.resourceStore = this.store;
|
|
1918
|
-
s.languageUtils = lu;
|
|
1919
|
-
s.pluralResolver = new PluralResolver(lu, {
|
|
1920
|
-
prepend: this.options.pluralSeparator,
|
|
1921
|
-
compatibilityJSON: this.options.compatibilityJSON,
|
|
1922
|
-
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
1923
|
-
});
|
|
1924
|
-
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
1925
|
-
s.formatter = createClassOnDemand(formatter);
|
|
1926
|
-
s.formatter.init(s, this.options);
|
|
1927
|
-
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
1928
|
-
}
|
|
1929
|
-
s.interpolator = new Interpolator(this.options);
|
|
1930
|
-
s.utils = {
|
|
1931
|
-
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
1932
|
-
};
|
|
1933
|
-
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
1934
|
-
s.backendConnector.on('*', function (event) {
|
|
1935
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1936
|
-
args[_key - 1] = arguments[_key];
|
|
1937
|
-
}
|
|
1938
|
-
_this.emit(event, ...args);
|
|
1939
|
-
});
|
|
1940
|
-
if (this.modules.languageDetector) {
|
|
1941
|
-
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
1942
|
-
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
1943
|
-
}
|
|
1944
|
-
if (this.modules.i18nFormat) {
|
|
1945
|
-
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
1946
|
-
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
1947
|
-
}
|
|
1948
|
-
this.translator = new Translator(this.services, this.options);
|
|
1949
|
-
this.translator.on('*', function (event) {
|
|
1950
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
1951
|
-
args[_key2 - 1] = arguments[_key2];
|
|
1952
|
-
}
|
|
1953
|
-
_this.emit(event, ...args);
|
|
1954
|
-
});
|
|
1955
|
-
this.modules.external.forEach(m => {
|
|
1956
|
-
if (m.init) m.init(this);
|
|
1957
|
-
});
|
|
1958
|
-
}
|
|
1959
|
-
this.format = this.options.interpolation.format;
|
|
1960
|
-
if (!callback) callback = noop$2;
|
|
1961
|
-
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
1962
|
-
const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
1963
|
-
if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
|
|
1964
|
-
}
|
|
1965
|
-
if (!this.services.languageDetector && !this.options.lng) {
|
|
1966
|
-
this.logger.warn('init: no languageDetector is used and no lng is defined');
|
|
1967
|
-
}
|
|
1968
|
-
const storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
|
|
1969
|
-
storeApi.forEach(fcName => {
|
|
1970
|
-
this[fcName] = function () {
|
|
1971
|
-
return _this.store[fcName](...arguments);
|
|
1972
|
-
};
|
|
1973
|
-
});
|
|
1974
|
-
const storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
|
|
1975
|
-
storeApiChained.forEach(fcName => {
|
|
1976
|
-
this[fcName] = function () {
|
|
1977
|
-
_this.store[fcName](...arguments);
|
|
1978
|
-
return _this;
|
|
1979
|
-
};
|
|
1980
|
-
});
|
|
1981
|
-
const deferred = defer();
|
|
1982
|
-
const load = () => {
|
|
1983
|
-
const finish = (err, t) => {
|
|
1984
|
-
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn('init: i18next is already initialized. You should call init just once!');
|
|
1985
|
-
this.isInitialized = true;
|
|
1986
|
-
if (!this.options.isClone) this.logger.log('initialized', this.options);
|
|
1987
|
-
this.emit('initialized', this.options);
|
|
1988
|
-
deferred.resolve(t);
|
|
1989
|
-
callback(err, t);
|
|
1990
|
-
};
|
|
1991
|
-
if (this.languages && this.options.compatibilityAPI !== 'v1' && !this.isInitialized) return finish(null, this.t.bind(this));
|
|
1992
|
-
this.changeLanguage(this.options.lng, finish);
|
|
1993
|
-
};
|
|
1994
|
-
if (this.options.resources || !this.options.initImmediate) {
|
|
1995
|
-
load();
|
|
1996
|
-
} else {
|
|
1997
|
-
setTimeout(load, 0);
|
|
1998
|
-
}
|
|
1999
|
-
return deferred;
|
|
2000
|
-
}
|
|
2001
|
-
loadResources(language) {
|
|
2002
|
-
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$2;
|
|
2003
|
-
let usedCallback = callback;
|
|
2004
|
-
const usedLng = typeof language === 'string' ? language : this.language;
|
|
2005
|
-
if (typeof language === 'function') usedCallback = language;
|
|
2006
|
-
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
2007
|
-
if (usedLng && usedLng.toLowerCase() === 'cimode') return usedCallback();
|
|
2008
|
-
const toLoad = [];
|
|
2009
|
-
const append = lng => {
|
|
2010
|
-
if (!lng) return;
|
|
2011
|
-
const lngs = this.services.languageUtils.toResolveHierarchy(lng);
|
|
2012
|
-
lngs.forEach(l => {
|
|
2013
|
-
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
|
2014
|
-
});
|
|
2015
|
-
};
|
|
2016
|
-
if (!usedLng) {
|
|
2017
|
-
const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
2018
|
-
fallbacks.forEach(l => append(l));
|
|
2019
|
-
} else {
|
|
2020
|
-
append(usedLng);
|
|
2021
|
-
}
|
|
2022
|
-
if (this.options.preload) {
|
|
2023
|
-
this.options.preload.forEach(l => append(l));
|
|
2024
|
-
}
|
|
2025
|
-
this.services.backendConnector.load(toLoad, this.options.ns, e => {
|
|
2026
|
-
if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
2027
|
-
usedCallback(e);
|
|
2028
|
-
});
|
|
2029
|
-
} else {
|
|
2030
|
-
usedCallback(null);
|
|
2031
|
-
}
|
|
2032
|
-
}
|
|
2033
|
-
reloadResources(lngs, ns, callback) {
|
|
2034
|
-
const deferred = defer();
|
|
2035
|
-
if (!lngs) lngs = this.languages;
|
|
2036
|
-
if (!ns) ns = this.options.ns;
|
|
2037
|
-
if (!callback) callback = noop$2;
|
|
2038
|
-
this.services.backendConnector.reload(lngs, ns, err => {
|
|
2039
|
-
deferred.resolve();
|
|
2040
|
-
callback(err);
|
|
2041
|
-
});
|
|
2042
|
-
return deferred;
|
|
2043
|
-
}
|
|
2044
|
-
use(module) {
|
|
2045
|
-
if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
|
|
2046
|
-
if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
|
|
2047
|
-
if (module.type === 'backend') {
|
|
2048
|
-
this.modules.backend = module;
|
|
2049
|
-
}
|
|
2050
|
-
if (module.type === 'logger' || module.log && module.warn && module.error) {
|
|
2051
|
-
this.modules.logger = module;
|
|
2052
|
-
}
|
|
2053
|
-
if (module.type === 'languageDetector') {
|
|
2054
|
-
this.modules.languageDetector = module;
|
|
2055
|
-
}
|
|
2056
|
-
if (module.type === 'i18nFormat') {
|
|
2057
|
-
this.modules.i18nFormat = module;
|
|
2058
|
-
}
|
|
2059
|
-
if (module.type === 'postProcessor') {
|
|
2060
|
-
postProcessor.addPostProcessor(module);
|
|
2061
|
-
}
|
|
2062
|
-
if (module.type === 'formatter') {
|
|
2063
|
-
this.modules.formatter = module;
|
|
2064
|
-
}
|
|
2065
|
-
if (module.type === '3rdParty') {
|
|
2066
|
-
this.modules.external.push(module);
|
|
2067
|
-
}
|
|
2068
|
-
return this;
|
|
2069
|
-
}
|
|
2070
|
-
setResolvedLanguage(l) {
|
|
2071
|
-
if (!l || !this.languages) return;
|
|
2072
|
-
if (['cimode', 'dev'].indexOf(l) > -1) return;
|
|
2073
|
-
for (let li = 0; li < this.languages.length; li++) {
|
|
2074
|
-
const lngInLngs = this.languages[li];
|
|
2075
|
-
if (['cimode', 'dev'].indexOf(lngInLngs) > -1) continue;
|
|
2076
|
-
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
2077
|
-
this.resolvedLanguage = lngInLngs;
|
|
2078
|
-
break;
|
|
2079
|
-
}
|
|
2080
|
-
}
|
|
2081
|
-
}
|
|
2082
|
-
changeLanguage(lng, callback) {
|
|
2083
|
-
var _this2 = this;
|
|
2084
|
-
this.isLanguageChangingTo = lng;
|
|
2085
|
-
const deferred = defer();
|
|
2086
|
-
this.emit('languageChanging', lng);
|
|
2087
|
-
const setLngProps = l => {
|
|
2088
|
-
this.language = l;
|
|
2089
|
-
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
2090
|
-
this.resolvedLanguage = undefined;
|
|
2091
|
-
this.setResolvedLanguage(l);
|
|
2092
|
-
};
|
|
2093
|
-
const done = (err, l) => {
|
|
2094
|
-
if (l) {
|
|
2095
|
-
setLngProps(l);
|
|
2096
|
-
this.translator.changeLanguage(l);
|
|
2097
|
-
this.isLanguageChangingTo = undefined;
|
|
2098
|
-
this.emit('languageChanged', l);
|
|
2099
|
-
this.logger.log('languageChanged', l);
|
|
2100
|
-
} else {
|
|
2101
|
-
this.isLanguageChangingTo = undefined;
|
|
2102
|
-
}
|
|
2103
|
-
deferred.resolve(function () {
|
|
2104
|
-
return _this2.t(...arguments);
|
|
2105
|
-
});
|
|
2106
|
-
if (callback) callback(err, function () {
|
|
2107
|
-
return _this2.t(...arguments);
|
|
2108
|
-
});
|
|
2109
|
-
};
|
|
2110
|
-
const setLng = lngs => {
|
|
2111
|
-
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
2112
|
-
const l = typeof lngs === 'string' ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
|
|
2113
|
-
if (l) {
|
|
2114
|
-
if (!this.language) {
|
|
2115
|
-
setLngProps(l);
|
|
2116
|
-
}
|
|
2117
|
-
if (!this.translator.language) this.translator.changeLanguage(l);
|
|
2118
|
-
if (this.services.languageDetector && this.services.languageDetector.cacheUserLanguage) this.services.languageDetector.cacheUserLanguage(l);
|
|
2119
|
-
}
|
|
2120
|
-
this.loadResources(l, err => {
|
|
2121
|
-
done(err, l);
|
|
2122
|
-
});
|
|
2123
|
-
};
|
|
2124
|
-
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
2125
|
-
setLng(this.services.languageDetector.detect());
|
|
2126
|
-
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
2127
|
-
if (this.services.languageDetector.detect.length === 0) {
|
|
2128
|
-
this.services.languageDetector.detect().then(setLng);
|
|
2129
|
-
} else {
|
|
2130
|
-
this.services.languageDetector.detect(setLng);
|
|
2131
|
-
}
|
|
2132
|
-
} else {
|
|
2133
|
-
setLng(lng);
|
|
2134
|
-
}
|
|
2135
|
-
return deferred;
|
|
2136
|
-
}
|
|
2137
|
-
getFixedT(lng, ns, keyPrefix) {
|
|
2138
|
-
var _this3 = this;
|
|
2139
|
-
const fixedT = function (key, opts) {
|
|
2140
|
-
let options;
|
|
2141
|
-
if (typeof opts !== 'object') {
|
|
2142
|
-
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
2143
|
-
rest[_key3 - 2] = arguments[_key3];
|
|
2144
|
-
}
|
|
2145
|
-
options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
2146
|
-
} else {
|
|
2147
|
-
options = {
|
|
2148
|
-
...opts
|
|
2149
|
-
};
|
|
2150
|
-
}
|
|
2151
|
-
options.lng = options.lng || fixedT.lng;
|
|
2152
|
-
options.lngs = options.lngs || fixedT.lngs;
|
|
2153
|
-
options.ns = options.ns || fixedT.ns;
|
|
2154
|
-
options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
2155
|
-
const keySeparator = _this3.options.keySeparator || '.';
|
|
2156
|
-
let resultKey;
|
|
2157
|
-
if (options.keyPrefix && Array.isArray(key)) {
|
|
2158
|
-
resultKey = key.map(k => `${options.keyPrefix}${keySeparator}${k}`);
|
|
2159
|
-
} else {
|
|
2160
|
-
resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
|
|
2161
|
-
}
|
|
2162
|
-
return _this3.t(resultKey, options);
|
|
2163
|
-
};
|
|
2164
|
-
if (typeof lng === 'string') {
|
|
2165
|
-
fixedT.lng = lng;
|
|
2166
|
-
} else {
|
|
2167
|
-
fixedT.lngs = lng;
|
|
2168
|
-
}
|
|
2169
|
-
fixedT.ns = ns;
|
|
2170
|
-
fixedT.keyPrefix = keyPrefix;
|
|
2171
|
-
return fixedT;
|
|
2172
|
-
}
|
|
2173
|
-
t() {
|
|
2174
|
-
return this.translator && this.translator.translate(...arguments);
|
|
2175
|
-
}
|
|
2176
|
-
exists() {
|
|
2177
|
-
return this.translator && this.translator.exists(...arguments);
|
|
2178
|
-
}
|
|
2179
|
-
setDefaultNamespace(ns) {
|
|
2180
|
-
this.options.defaultNS = ns;
|
|
2181
|
-
}
|
|
2182
|
-
hasLoadedNamespace(ns) {
|
|
2183
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2184
|
-
if (!this.isInitialized) {
|
|
2185
|
-
this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
|
|
2186
|
-
return false;
|
|
2187
|
-
}
|
|
2188
|
-
if (!this.languages || !this.languages.length) {
|
|
2189
|
-
this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages);
|
|
2190
|
-
return false;
|
|
2191
|
-
}
|
|
2192
|
-
const lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
2193
|
-
const fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
2194
|
-
const lastLng = this.languages[this.languages.length - 1];
|
|
2195
|
-
if (lng.toLowerCase() === 'cimode') return true;
|
|
2196
|
-
const loadNotPending = (l, n) => {
|
|
2197
|
-
const loadState = this.services.backendConnector.state[`${l}|${n}`];
|
|
2198
|
-
return loadState === -1 || loadState === 2;
|
|
2199
|
-
};
|
|
2200
|
-
if (options.precheck) {
|
|
2201
|
-
const preResult = options.precheck(this, loadNotPending);
|
|
2202
|
-
if (preResult !== undefined) return preResult;
|
|
2203
|
-
}
|
|
2204
|
-
if (this.hasResourceBundle(lng, ns)) return true;
|
|
2205
|
-
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
2206
|
-
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
2207
|
-
return false;
|
|
2208
|
-
}
|
|
2209
|
-
loadNamespaces(ns, callback) {
|
|
2210
|
-
const deferred = defer();
|
|
2211
|
-
if (!this.options.ns) {
|
|
2212
|
-
if (callback) callback();
|
|
2213
|
-
return Promise.resolve();
|
|
2214
|
-
}
|
|
2215
|
-
if (typeof ns === 'string') ns = [ns];
|
|
2216
|
-
ns.forEach(n => {
|
|
2217
|
-
if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
|
|
2218
|
-
});
|
|
2219
|
-
this.loadResources(err => {
|
|
2220
|
-
deferred.resolve();
|
|
2221
|
-
if (callback) callback(err);
|
|
2222
|
-
});
|
|
2223
|
-
return deferred;
|
|
2224
|
-
}
|
|
2225
|
-
loadLanguages(lngs, callback) {
|
|
2226
|
-
const deferred = defer();
|
|
2227
|
-
if (typeof lngs === 'string') lngs = [lngs];
|
|
2228
|
-
const preloaded = this.options.preload || [];
|
|
2229
|
-
const newLngs = lngs.filter(lng => preloaded.indexOf(lng) < 0);
|
|
2230
|
-
if (!newLngs.length) {
|
|
2231
|
-
if (callback) callback();
|
|
2232
|
-
return Promise.resolve();
|
|
2233
|
-
}
|
|
2234
|
-
this.options.preload = preloaded.concat(newLngs);
|
|
2235
|
-
this.loadResources(err => {
|
|
2236
|
-
deferred.resolve();
|
|
2237
|
-
if (callback) callback(err);
|
|
2238
|
-
});
|
|
2239
|
-
return deferred;
|
|
2240
|
-
}
|
|
2241
|
-
dir(lng) {
|
|
2242
|
-
if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
|
|
2243
|
-
if (!lng) return 'rtl';
|
|
2244
|
-
const rtlLngs = ['ar', 'shu', 'sqr', 'ssh', 'xaa', 'yhd', 'yud', 'aao', 'abh', 'abv', 'acm', 'acq', 'acw', 'acx', 'acy', 'adf', 'ads', 'aeb', 'aec', 'afb', 'ajp', 'apc', 'apd', 'arb', 'arq', 'ars', 'ary', 'arz', 'auz', 'avl', 'ayh', 'ayl', 'ayn', 'ayp', 'bbz', 'pga', 'he', 'iw', 'ps', 'pbt', 'pbu', 'pst', 'prp', 'prd', 'ug', 'ur', 'ydd', 'yds', 'yih', 'ji', 'yi', 'hbo', 'men', 'xmn', 'fa', 'jpr', 'peo', 'pes', 'prs', 'dv', 'sam', 'ckb'];
|
|
2245
|
-
const languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
|
|
2246
|
-
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
|
|
2247
|
-
}
|
|
2248
|
-
static createInstance() {
|
|
2249
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2250
|
-
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
2251
|
-
return new I18n(options, callback);
|
|
2252
|
-
}
|
|
2253
|
-
cloneInstance() {
|
|
2254
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2255
|
-
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$2;
|
|
2256
|
-
const forkResourceStore = options.forkResourceStore;
|
|
2257
|
-
if (forkResourceStore) delete options.forkResourceStore;
|
|
2258
|
-
const mergedOptions = {
|
|
2259
|
-
...this.options,
|
|
2260
|
-
...options,
|
|
2261
|
-
...{
|
|
2262
|
-
isClone: true
|
|
2263
|
-
}
|
|
2264
|
-
};
|
|
2265
|
-
const clone = new I18n(mergedOptions);
|
|
2266
|
-
if (options.debug !== undefined || options.prefix !== undefined) {
|
|
2267
|
-
clone.logger = clone.logger.clone(options);
|
|
2268
|
-
}
|
|
2269
|
-
const membersToCopy = ['store', 'services', 'language'];
|
|
2270
|
-
membersToCopy.forEach(m => {
|
|
2271
|
-
clone[m] = this[m];
|
|
2272
|
-
});
|
|
2273
|
-
clone.services = {
|
|
2274
|
-
...this.services
|
|
2275
|
-
};
|
|
2276
|
-
clone.services.utils = {
|
|
2277
|
-
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2278
|
-
};
|
|
2279
|
-
if (forkResourceStore) {
|
|
2280
|
-
clone.store = new ResourceStore(this.store.data, mergedOptions);
|
|
2281
|
-
clone.services.resourceStore = clone.store;
|
|
2282
|
-
}
|
|
2283
|
-
clone.translator = new Translator(clone.services, mergedOptions);
|
|
2284
|
-
clone.translator.on('*', function (event) {
|
|
2285
|
-
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
2286
|
-
args[_key4 - 1] = arguments[_key4];
|
|
2287
|
-
}
|
|
2288
|
-
clone.emit(event, ...args);
|
|
2289
|
-
});
|
|
2290
|
-
clone.init(mergedOptions, callback);
|
|
2291
|
-
clone.translator.options = mergedOptions;
|
|
2292
|
-
clone.translator.backendConnector.services.utils = {
|
|
2293
|
-
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2294
|
-
};
|
|
2295
|
-
return clone;
|
|
2296
|
-
}
|
|
2297
|
-
toJSON() {
|
|
2298
|
-
return {
|
|
2299
|
-
options: this.options,
|
|
2300
|
-
store: this.store,
|
|
2301
|
-
language: this.language,
|
|
2302
|
-
languages: this.languages,
|
|
2303
|
-
resolvedLanguage: this.resolvedLanguage
|
|
2304
|
-
};
|
|
2305
|
-
}
|
|
2306
|
-
}
|
|
2307
|
-
const instance = I18n.createInstance();
|
|
2308
|
-
instance.createInstance = I18n.createInstance;
|
|
2309
|
-
|
|
2310
|
-
instance.createInstance;
|
|
2311
|
-
instance.dir;
|
|
2312
|
-
instance.init;
|
|
2313
|
-
instance.loadResources;
|
|
2314
|
-
instance.reloadResources;
|
|
2315
|
-
instance.use;
|
|
2316
|
-
instance.changeLanguage;
|
|
2317
|
-
instance.getFixedT;
|
|
2318
|
-
const t$2 = instance.t;
|
|
2319
|
-
instance.exists;
|
|
2320
|
-
instance.setDefaultNamespace;
|
|
2321
|
-
instance.hasLoadedNamespace;
|
|
2322
|
-
instance.loadNamespaces;
|
|
2323
|
-
instance.loadLanguages;
|
|
2324
|
-
|
|
2325
|
-
/**
|
|
2326
|
-
* This file automatically generated from `pre-publish.js`.
|
|
2327
|
-
* Do not manually edit.
|
|
2328
|
-
*/
|
|
2329
|
-
|
|
2330
|
-
var voidElements = {
|
|
2331
|
-
"area": true,
|
|
2332
|
-
"base": true,
|
|
2333
|
-
"br": true,
|
|
2334
|
-
"col": true,
|
|
2335
|
-
"embed": true,
|
|
2336
|
-
"hr": true,
|
|
2337
|
-
"img": true,
|
|
2338
|
-
"input": true,
|
|
2339
|
-
"link": true,
|
|
2340
|
-
"meta": true,
|
|
2341
|
-
"param": true,
|
|
2342
|
-
"source": true,
|
|
2343
|
-
"track": true,
|
|
2344
|
-
"wbr": true
|
|
2345
|
-
};
|
|
2346
|
-
|
|
2347
|
-
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)},"")}};
|
|
2348
|
-
|
|
2349
|
-
function warn() {
|
|
2350
|
-
if (console && console.warn) {
|
|
2351
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2352
|
-
args[_key] = arguments[_key];
|
|
2353
|
-
}
|
|
2354
|
-
if (typeof args[0] === 'string') args[0] = `react-i18next:: ${args[0]}`;
|
|
2355
|
-
console.warn(...args);
|
|
2356
|
-
}
|
|
2357
|
-
}
|
|
2358
|
-
const alreadyWarned = {};
|
|
2359
|
-
function warnOnce() {
|
|
2360
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
2361
|
-
args[_key2] = arguments[_key2];
|
|
2362
|
-
}
|
|
2363
|
-
if (typeof args[0] === 'string' && alreadyWarned[args[0]]) return;
|
|
2364
|
-
if (typeof args[0] === 'string') alreadyWarned[args[0]] = new Date();
|
|
2365
|
-
warn(...args);
|
|
2366
|
-
}
|
|
2367
|
-
const loadedClb = (i18n, cb) => () => {
|
|
2368
|
-
if (i18n.isInitialized) {
|
|
2369
|
-
cb();
|
|
2370
|
-
} else {
|
|
2371
|
-
const initialized = () => {
|
|
2372
|
-
setTimeout(() => {
|
|
2373
|
-
i18n.off('initialized', initialized);
|
|
2374
|
-
}, 0);
|
|
2375
|
-
cb();
|
|
2376
|
-
};
|
|
2377
|
-
i18n.on('initialized', initialized);
|
|
2378
|
-
}
|
|
2379
|
-
};
|
|
2380
|
-
function loadNamespaces(i18n, ns, cb) {
|
|
2381
|
-
i18n.loadNamespaces(ns, loadedClb(i18n, cb));
|
|
2382
|
-
}
|
|
2383
|
-
function loadLanguages(i18n, lng, ns, cb) {
|
|
2384
|
-
if (typeof ns === 'string') ns = [ns];
|
|
2385
|
-
ns.forEach(n => {
|
|
2386
|
-
if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
|
|
2387
|
-
});
|
|
2388
|
-
i18n.loadLanguages(lng, loadedClb(i18n, cb));
|
|
2389
|
-
}
|
|
2390
|
-
function oldI18nextHasLoadedNamespace(ns, i18n) {
|
|
2391
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2392
|
-
const lng = i18n.languages[0];
|
|
2393
|
-
const fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
|
|
2394
|
-
const lastLng = i18n.languages[i18n.languages.length - 1];
|
|
2395
|
-
if (lng.toLowerCase() === 'cimode') return true;
|
|
2396
|
-
const loadNotPending = (l, n) => {
|
|
2397
|
-
const loadState = i18n.services.backendConnector.state[`${l}|${n}`];
|
|
2398
|
-
return loadState === -1 || loadState === 2;
|
|
2399
|
-
};
|
|
2400
|
-
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false;
|
|
2401
|
-
if (i18n.hasResourceBundle(lng, ns)) return true;
|
|
2402
|
-
if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true;
|
|
2403
|
-
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
2404
|
-
return false;
|
|
2405
|
-
}
|
|
2406
|
-
function hasLoadedNamespace(ns, i18n) {
|
|
2407
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2408
|
-
if (!i18n.languages || !i18n.languages.length) {
|
|
2409
|
-
warnOnce('i18n.languages were undefined or empty', i18n.languages);
|
|
2410
|
-
return true;
|
|
2411
|
-
}
|
|
2412
|
-
const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined;
|
|
2413
|
-
if (!isNewerI18next) {
|
|
2414
|
-
return oldI18nextHasLoadedNamespace(ns, i18n, options);
|
|
2415
|
-
}
|
|
2416
|
-
return i18n.hasLoadedNamespace(ns, {
|
|
2417
|
-
lng: options.lng,
|
|
2418
|
-
precheck: (i18nInstance, loadNotPending) => {
|
|
2419
|
-
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
|
|
2420
|
-
}
|
|
2421
|
-
});
|
|
2422
|
-
}
|
|
2423
|
-
|
|
2424
|
-
const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
|
|
2425
|
-
const htmlEntities = {
|
|
2426
|
-
'&': '&',
|
|
2427
|
-
'&': '&',
|
|
2428
|
-
'<': '<',
|
|
2429
|
-
'<': '<',
|
|
2430
|
-
'>': '>',
|
|
2431
|
-
'>': '>',
|
|
2432
|
-
''': "'",
|
|
2433
|
-
''': "'",
|
|
2434
|
-
'"': '"',
|
|
2435
|
-
'"': '"',
|
|
2436
|
-
' ': ' ',
|
|
2437
|
-
' ': ' ',
|
|
2438
|
-
'©': '©',
|
|
2439
|
-
'©': '©',
|
|
2440
|
-
'®': '®',
|
|
2441
|
-
'®': '®',
|
|
2442
|
-
'…': '…',
|
|
2443
|
-
'…': '…',
|
|
2444
|
-
'/': '/',
|
|
2445
|
-
'/': '/'
|
|
2446
|
-
};
|
|
2447
|
-
const unescapeHtmlEntity = m => htmlEntities[m];
|
|
2448
|
-
const unescape = text => text.replace(matchHtmlEntity, unescapeHtmlEntity);
|
|
2449
|
-
|
|
2450
|
-
let defaultOptions = {
|
|
2451
|
-
bindI18n: 'languageChanged',
|
|
2452
|
-
bindI18nStore: '',
|
|
2453
|
-
transEmptyNodeValue: '',
|
|
2454
|
-
transSupportBasicHtmlNodes: true,
|
|
2455
|
-
transWrapTextNodes: '',
|
|
2456
|
-
transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
|
|
2457
|
-
useSuspense: true,
|
|
2458
|
-
unescape
|
|
2459
|
-
};
|
|
2460
|
-
function setDefaults() {
|
|
2461
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2462
|
-
defaultOptions = {
|
|
2463
|
-
...defaultOptions,
|
|
2464
|
-
...options
|
|
2465
|
-
};
|
|
2466
|
-
}
|
|
2467
|
-
function getDefaults() {
|
|
2468
|
-
return defaultOptions;
|
|
2469
|
-
}
|
|
2470
|
-
|
|
2471
|
-
let i18nInstance;
|
|
2472
|
-
function setI18n(instance) {
|
|
2473
|
-
i18nInstance = instance;
|
|
2474
|
-
}
|
|
2475
|
-
function getI18n() {
|
|
2476
|
-
return i18nInstance;
|
|
2477
|
-
}
|
|
2478
|
-
|
|
2479
|
-
function hasChildren(node, checkLength) {
|
|
2480
|
-
if (!node) return false;
|
|
2481
|
-
const base = node.props ? node.props.children : node.children;
|
|
2482
|
-
if (checkLength) return base.length > 0;
|
|
2483
|
-
return !!base;
|
|
2484
|
-
}
|
|
2485
|
-
function getChildren(node) {
|
|
2486
|
-
if (!node) return [];
|
|
2487
|
-
return node.props ? node.props.children : node.children;
|
|
2488
|
-
}
|
|
2489
|
-
function hasValidReactChildren(children) {
|
|
2490
|
-
if (Object.prototype.toString.call(children) !== '[object Array]') return false;
|
|
2491
|
-
return children.every(child => React.isValidElement(child));
|
|
2492
|
-
}
|
|
2493
|
-
function getAsArray(data) {
|
|
2494
|
-
return Array.isArray(data) ? data : [data];
|
|
2495
|
-
}
|
|
2496
|
-
function mergeProps(source, target) {
|
|
2497
|
-
const newTarget = {
|
|
2498
|
-
...target
|
|
2499
|
-
};
|
|
2500
|
-
newTarget.props = Object.assign(source.props, target.props);
|
|
2501
|
-
return newTarget;
|
|
2502
|
-
}
|
|
2503
|
-
function nodesToString(children, i18nOptions) {
|
|
2504
|
-
if (!children) return '';
|
|
2505
|
-
let stringNode = '';
|
|
2506
|
-
const childrenArray = getAsArray(children);
|
|
2507
|
-
const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : [];
|
|
2508
|
-
childrenArray.forEach((child, childIndex) => {
|
|
2509
|
-
if (typeof child === 'string') {
|
|
2510
|
-
stringNode += `${child}`;
|
|
2511
|
-
} else if (React.isValidElement(child)) {
|
|
2512
|
-
const childPropsCount = Object.keys(child.props).length;
|
|
2513
|
-
const shouldKeepChild = keepArray.indexOf(child.type) > -1;
|
|
2514
|
-
const childChildren = child.props.children;
|
|
2515
|
-
if (!childChildren && shouldKeepChild && childPropsCount === 0) {
|
|
2516
|
-
stringNode += `<${child.type}/>`;
|
|
2517
|
-
} else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
|
|
2518
|
-
stringNode += `<${childIndex}></${childIndex}>`;
|
|
2519
|
-
} else if (child.props.i18nIsDynamicList) {
|
|
2520
|
-
stringNode += `<${childIndex}></${childIndex}>`;
|
|
2521
|
-
} else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
|
|
2522
|
-
stringNode += `<${child.type}>${childChildren}</${child.type}>`;
|
|
2523
|
-
} else {
|
|
2524
|
-
const content = nodesToString(childChildren, i18nOptions);
|
|
2525
|
-
stringNode += `<${childIndex}>${content}</${childIndex}>`;
|
|
2526
|
-
}
|
|
2527
|
-
} else if (child === null) {
|
|
2528
|
-
warn(`Trans: the passed in value is invalid - seems you passed in a null child.`);
|
|
2529
|
-
} else if (typeof child === 'object') {
|
|
2530
|
-
const {
|
|
2531
|
-
format,
|
|
2532
|
-
...clone
|
|
2533
|
-
} = child;
|
|
2534
|
-
const keys = Object.keys(clone);
|
|
2535
|
-
if (keys.length === 1) {
|
|
2536
|
-
const value = format ? `${keys[0]}, ${format}` : keys[0];
|
|
2537
|
-
stringNode += `{{${value}}}`;
|
|
2538
|
-
} else {
|
|
2539
|
-
warn(`react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child);
|
|
2540
|
-
}
|
|
2541
|
-
} else {
|
|
2542
|
-
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);
|
|
2543
|
-
}
|
|
2544
|
-
});
|
|
2545
|
-
return stringNode;
|
|
2546
|
-
}
|
|
2547
|
-
function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) {
|
|
2548
|
-
if (targetString === '') return [];
|
|
2549
|
-
const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
2550
|
-
const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString);
|
|
2551
|
-
if (!children && !emptyChildrenButNeedsHandling) return [targetString];
|
|
2552
|
-
const data = {};
|
|
2553
|
-
function getData(childs) {
|
|
2554
|
-
const childrenArray = getAsArray(childs);
|
|
2555
|
-
childrenArray.forEach(child => {
|
|
2556
|
-
if (typeof child === 'string') return;
|
|
2557
|
-
if (hasChildren(child)) getData(getChildren(child));else if (typeof child === 'object' && !React.isValidElement(child)) Object.assign(data, child);
|
|
2558
|
-
});
|
|
2559
|
-
}
|
|
2560
|
-
getData(children);
|
|
2561
|
-
const ast = c.parse(`<0>${targetString}</0>`);
|
|
2562
|
-
const opts = {
|
|
2563
|
-
...data,
|
|
2564
|
-
...combinedTOpts
|
|
2565
|
-
};
|
|
2566
|
-
function renderInner(child, node, rootReactNode) {
|
|
2567
|
-
const childs = getChildren(child);
|
|
2568
|
-
const mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
2569
|
-
return hasValidReactChildren(childs) && mappedChildren.length === 0 ? childs : mappedChildren;
|
|
2570
|
-
}
|
|
2571
|
-
function pushTranslatedJSX(child, inner, mem, i, isVoid) {
|
|
2572
|
-
if (child.dummy) child.children = inner;
|
|
2573
|
-
mem.push(React.cloneElement(child, {
|
|
2574
|
-
...child.props,
|
|
2575
|
-
key: i
|
|
2576
|
-
}, isVoid ? undefined : inner));
|
|
2577
|
-
}
|
|
2578
|
-
function mapAST(reactNode, astNode, rootReactNode) {
|
|
2579
|
-
const reactNodes = getAsArray(reactNode);
|
|
2580
|
-
const astNodes = getAsArray(astNode);
|
|
2581
|
-
return astNodes.reduce((mem, node, i) => {
|
|
2582
|
-
const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
2583
|
-
if (node.type === 'tag') {
|
|
2584
|
-
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
2585
|
-
if (!tmp && rootReactNode.length === 1 && rootReactNode[0][node.name]) tmp = rootReactNode[0][node.name];
|
|
2586
|
-
if (!tmp) tmp = {};
|
|
2587
|
-
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
2588
|
-
props: node.attrs
|
|
2589
|
-
}, tmp) : tmp;
|
|
2590
|
-
const isElement = React.isValidElement(child);
|
|
2591
|
-
const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
2592
|
-
const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && typeof child === 'object' && child.dummy && !isElement;
|
|
2593
|
-
const isKnownComponent = typeof children === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name);
|
|
2594
|
-
if (typeof child === 'string') {
|
|
2595
|
-
const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
2596
|
-
mem.push(value);
|
|
2597
|
-
} else if (hasChildren(child) || isValidTranslationWithChildren) {
|
|
2598
|
-
const inner = renderInner(child, node, rootReactNode);
|
|
2599
|
-
pushTranslatedJSX(child, inner, mem, i);
|
|
2600
|
-
} else if (isEmptyTransWithHTML) {
|
|
2601
|
-
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
2602
|
-
mem.push(React.cloneElement(child, {
|
|
2603
|
-
...child.props,
|
|
2604
|
-
key: i
|
|
2605
|
-
}, inner));
|
|
2606
|
-
} else if (Number.isNaN(parseFloat(node.name))) {
|
|
2607
|
-
if (isKnownComponent) {
|
|
2608
|
-
const inner = renderInner(child, node, rootReactNode);
|
|
2609
|
-
pushTranslatedJSX(child, inner, mem, i, node.voidElement);
|
|
2610
|
-
} else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
|
|
2611
|
-
if (node.voidElement) {
|
|
2612
|
-
mem.push(React.createElement(node.name, {
|
|
2613
|
-
key: `${node.name}-${i}`
|
|
2614
|
-
}));
|
|
2615
|
-
} else {
|
|
2616
|
-
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
2617
|
-
mem.push(React.createElement(node.name, {
|
|
2618
|
-
key: `${node.name}-${i}`
|
|
2619
|
-
}, inner));
|
|
2620
|
-
}
|
|
2621
|
-
} else if (node.voidElement) {
|
|
2622
|
-
mem.push(`<${node.name} />`);
|
|
2623
|
-
} else {
|
|
2624
|
-
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
2625
|
-
mem.push(`<${node.name}>${inner}</${node.name}>`);
|
|
2626
|
-
}
|
|
2627
|
-
} else if (typeof child === 'object' && !isElement) {
|
|
2628
|
-
const content = node.children[0] ? translationContent : null;
|
|
2629
|
-
if (content) mem.push(content);
|
|
2630
|
-
} else if (node.children.length === 1 && translationContent) {
|
|
2631
|
-
mem.push(React.cloneElement(child, {
|
|
2632
|
-
...child.props,
|
|
2633
|
-
key: i
|
|
2634
|
-
}, translationContent));
|
|
2635
|
-
} else {
|
|
2636
|
-
mem.push(React.cloneElement(child, {
|
|
2637
|
-
...child.props,
|
|
2638
|
-
key: i
|
|
2639
|
-
}));
|
|
2640
|
-
}
|
|
2641
|
-
} else if (node.type === 'text') {
|
|
2642
|
-
const wrapTextNodes = i18nOptions.transWrapTextNodes;
|
|
2643
|
-
const content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
|
|
2644
|
-
if (wrapTextNodes) {
|
|
2645
|
-
mem.push(React.createElement(wrapTextNodes, {
|
|
2646
|
-
key: `${node.name}-${i}`
|
|
2647
|
-
}, content));
|
|
2648
|
-
} else {
|
|
2649
|
-
mem.push(content);
|
|
2650
|
-
}
|
|
2651
|
-
}
|
|
2652
|
-
return mem;
|
|
2653
|
-
}, []);
|
|
2654
|
-
}
|
|
2655
|
-
const result = mapAST([{
|
|
2656
|
-
dummy: true,
|
|
2657
|
-
children: children || []
|
|
2658
|
-
}], ast, getAsArray(children || []));
|
|
2659
|
-
return getChildren(result[0]);
|
|
2660
|
-
}
|
|
2661
|
-
function Trans$1(_ref) {
|
|
2662
|
-
let {
|
|
2663
|
-
children,
|
|
2664
|
-
count,
|
|
2665
|
-
parent,
|
|
2666
|
-
i18nKey,
|
|
2667
|
-
context,
|
|
2668
|
-
tOptions = {},
|
|
2669
|
-
values,
|
|
2670
|
-
defaults,
|
|
2671
|
-
components,
|
|
2672
|
-
ns,
|
|
2673
|
-
i18n: i18nFromProps,
|
|
2674
|
-
t: tFromProps,
|
|
2675
|
-
shouldUnescape,
|
|
2676
|
-
...additionalProps
|
|
2677
|
-
} = _ref;
|
|
2678
|
-
const i18n = i18nFromProps || getI18n();
|
|
2679
|
-
if (!i18n) {
|
|
2680
|
-
warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
|
|
2681
|
-
return children;
|
|
2682
|
-
}
|
|
2683
|
-
const t = tFromProps || i18n.t.bind(i18n) || (k => k);
|
|
2684
|
-
if (context) tOptions.context = context;
|
|
2685
|
-
const reactI18nextOptions = {
|
|
2686
|
-
...getDefaults(),
|
|
2687
|
-
...(i18n.options && i18n.options.react)
|
|
2688
|
-
};
|
|
2689
|
-
let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS;
|
|
2690
|
-
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
2691
|
-
const defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
|
|
2692
|
-
const {
|
|
2693
|
-
hashTransKey
|
|
2694
|
-
} = reactI18nextOptions;
|
|
2695
|
-
const key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
|
|
2696
|
-
const interpolationOverride = values ? tOptions.interpolation : {
|
|
2697
|
-
interpolation: {
|
|
2698
|
-
...tOptions.interpolation,
|
|
2699
|
-
prefix: '#$?',
|
|
2700
|
-
suffix: '?$#'
|
|
2701
|
-
}
|
|
2702
|
-
};
|
|
2703
|
-
const combinedTOpts = {
|
|
2704
|
-
...tOptions,
|
|
2705
|
-
count,
|
|
2706
|
-
...values,
|
|
2707
|
-
...interpolationOverride,
|
|
2708
|
-
defaultValue,
|
|
2709
|
-
ns: namespaces
|
|
2710
|
-
};
|
|
2711
|
-
const translation = key ? t(key, combinedTOpts) : defaultValue;
|
|
2712
|
-
const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
|
|
2713
|
-
const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
|
|
2714
|
-
return useAsParent ? React.createElement(useAsParent, additionalProps, content) : content;
|
|
2715
|
-
}
|
|
2716
|
-
|
|
2717
|
-
const initReactI18next = {
|
|
2718
|
-
type: '3rdParty',
|
|
2719
|
-
init(instance) {
|
|
2720
|
-
setDefaults(instance.options.react);
|
|
2721
|
-
setI18n(instance);
|
|
2722
|
-
}
|
|
2723
|
-
};
|
|
2724
|
-
|
|
2725
|
-
const I18nContext = React.createContext();
|
|
2726
|
-
class ReportNamespaces {
|
|
2727
|
-
constructor() {
|
|
2728
|
-
this.usedNamespaces = {};
|
|
2729
|
-
}
|
|
2730
|
-
addUsedNamespaces(namespaces) {
|
|
2731
|
-
namespaces.forEach(ns => {
|
|
2732
|
-
if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
|
|
2733
|
-
});
|
|
2734
|
-
}
|
|
2735
|
-
getUsedNamespaces() {
|
|
2736
|
-
return Object.keys(this.usedNamespaces);
|
|
2737
|
-
}
|
|
2738
|
-
}
|
|
2739
|
-
|
|
2740
|
-
function Trans(_ref) {
|
|
2741
|
-
let {
|
|
2742
|
-
children,
|
|
2743
|
-
count,
|
|
2744
|
-
parent,
|
|
2745
|
-
i18nKey,
|
|
2746
|
-
context,
|
|
2747
|
-
tOptions = {},
|
|
2748
|
-
values,
|
|
2749
|
-
defaults,
|
|
2750
|
-
components,
|
|
2751
|
-
ns,
|
|
2752
|
-
i18n: i18nFromProps,
|
|
2753
|
-
t: tFromProps,
|
|
2754
|
-
shouldUnescape,
|
|
2755
|
-
...additionalProps
|
|
2756
|
-
} = _ref;
|
|
2757
|
-
const {
|
|
2758
|
-
i18n: i18nFromContext,
|
|
2759
|
-
defaultNS: defaultNSFromContext
|
|
2760
|
-
} = React.useContext(I18nContext) || {};
|
|
2761
|
-
const i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
2762
|
-
const t = tFromProps || i18n && i18n.t.bind(i18n);
|
|
2763
|
-
return Trans$1({
|
|
2764
|
-
children,
|
|
2765
|
-
count,
|
|
2766
|
-
parent,
|
|
2767
|
-
i18nKey,
|
|
2768
|
-
context,
|
|
2769
|
-
tOptions,
|
|
2770
|
-
values,
|
|
2771
|
-
defaults,
|
|
2772
|
-
components,
|
|
2773
|
-
ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS,
|
|
2774
|
-
i18n,
|
|
2775
|
-
t: tFromProps,
|
|
2776
|
-
shouldUnescape,
|
|
2777
|
-
...additionalProps
|
|
2778
|
-
});
|
|
2779
|
-
}
|
|
2780
|
-
|
|
2781
|
-
const usePrevious = (value, ignore) => {
|
|
2782
|
-
const ref = React.useRef();
|
|
2783
|
-
React.useEffect(() => {
|
|
2784
|
-
ref.current = ignore ? ref.current : value;
|
|
2785
|
-
}, [value, ignore]);
|
|
2786
|
-
return ref.current;
|
|
2787
|
-
};
|
|
2788
|
-
function useTranslation(ns) {
|
|
2789
|
-
let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2790
|
-
const {
|
|
2791
|
-
i18n: i18nFromProps
|
|
2792
|
-
} = props;
|
|
2793
|
-
const {
|
|
2794
|
-
i18n: i18nFromContext,
|
|
2795
|
-
defaultNS: defaultNSFromContext
|
|
2796
|
-
} = React.useContext(I18nContext) || {};
|
|
2797
|
-
const i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
2798
|
-
if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
|
|
2799
|
-
if (!i18n) {
|
|
2800
|
-
warnOnce('You will need to pass in an i18next instance by using initReactI18next');
|
|
2801
|
-
const notReadyT = (k, optsOrDefaultValue) => {
|
|
2802
|
-
if (typeof optsOrDefaultValue === 'string') return optsOrDefaultValue;
|
|
2803
|
-
if (optsOrDefaultValue && typeof optsOrDefaultValue === 'object' && typeof optsOrDefaultValue.defaultValue === 'string') return optsOrDefaultValue.defaultValue;
|
|
2804
|
-
return Array.isArray(k) ? k[k.length - 1] : k;
|
|
2805
|
-
};
|
|
2806
|
-
const retNotReady = [notReadyT, {}, false];
|
|
2807
|
-
retNotReady.t = notReadyT;
|
|
2808
|
-
retNotReady.i18n = {};
|
|
2809
|
-
retNotReady.ready = false;
|
|
2810
|
-
return retNotReady;
|
|
2811
|
-
}
|
|
2812
|
-
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.');
|
|
2813
|
-
const i18nOptions = {
|
|
2814
|
-
...getDefaults(),
|
|
2815
|
-
...i18n.options.react,
|
|
2816
|
-
...props
|
|
2817
|
-
};
|
|
2818
|
-
const {
|
|
2819
|
-
useSuspense,
|
|
2820
|
-
keyPrefix
|
|
2821
|
-
} = i18nOptions;
|
|
2822
|
-
let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
|
|
2823
|
-
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
2824
|
-
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
|
|
2825
|
-
const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions));
|
|
2826
|
-
function getT() {
|
|
2827
|
-
return i18n.getFixedT(props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
|
|
2828
|
-
}
|
|
2829
|
-
const [t, setT] = React.useState(getT);
|
|
2830
|
-
let joinedNS = namespaces.join();
|
|
2831
|
-
if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
|
|
2832
|
-
const previousJoinedNS = usePrevious(joinedNS);
|
|
2833
|
-
const isMounted = React.useRef(true);
|
|
2834
|
-
React.useEffect(() => {
|
|
2835
|
-
const {
|
|
2836
|
-
bindI18n,
|
|
2837
|
-
bindI18nStore
|
|
2838
|
-
} = i18nOptions;
|
|
2839
|
-
isMounted.current = true;
|
|
2840
|
-
if (!ready && !useSuspense) {
|
|
2841
|
-
if (props.lng) {
|
|
2842
|
-
loadLanguages(i18n, props.lng, namespaces, () => {
|
|
2843
|
-
if (isMounted.current) setT(getT);
|
|
2844
|
-
});
|
|
2845
|
-
} else {
|
|
2846
|
-
loadNamespaces(i18n, namespaces, () => {
|
|
2847
|
-
if (isMounted.current) setT(getT);
|
|
2848
|
-
});
|
|
2849
|
-
}
|
|
2850
|
-
}
|
|
2851
|
-
if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
|
|
2852
|
-
setT(getT);
|
|
2853
|
-
}
|
|
2854
|
-
function boundReset() {
|
|
2855
|
-
if (isMounted.current) setT(getT);
|
|
2856
|
-
}
|
|
2857
|
-
if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
|
|
2858
|
-
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
|
|
2859
|
-
return () => {
|
|
2860
|
-
isMounted.current = false;
|
|
2861
|
-
if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset));
|
|
2862
|
-
if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
|
|
2863
|
-
};
|
|
2864
|
-
}, [i18n, joinedNS]);
|
|
2865
|
-
const isInitial = React.useRef(true);
|
|
2866
|
-
React.useEffect(() => {
|
|
2867
|
-
if (isMounted.current && !isInitial.current) {
|
|
2868
|
-
setT(getT);
|
|
2869
|
-
}
|
|
2870
|
-
isInitial.current = false;
|
|
2871
|
-
}, [i18n, keyPrefix]);
|
|
2872
|
-
const ret = [t, i18n, ready];
|
|
2873
|
-
ret.t = t;
|
|
2874
|
-
ret.i18n = i18n;
|
|
2875
|
-
ret.ready = ready;
|
|
2876
|
-
if (ready) return ret;
|
|
2877
|
-
if (!ready && !useSuspense) return ret;
|
|
2878
|
-
throw new Promise(resolve => {
|
|
2879
|
-
if (props.lng) {
|
|
2880
|
-
loadLanguages(i18n, props.lng, namespaces, () => resolve());
|
|
2881
|
-
} else {
|
|
2882
|
-
loadNamespaces(i18n, namespaces, () => resolve());
|
|
2883
|
-
}
|
|
2884
|
-
});
|
|
2885
|
-
}
|
|
2886
|
-
|
|
2887
|
-
var neetoFilters = {
|
|
2888
|
-
common: {
|
|
2889
|
-
clearFilters: "Clear filters",
|
|
2890
|
-
columns: "Columns",
|
|
2891
|
-
"delete": "Delete",
|
|
2892
|
-
done: "Done",
|
|
2893
|
-
filter: "Filter",
|
|
2894
|
-
filters: "Filters",
|
|
2895
|
-
no: "No",
|
|
2896
|
-
proceed: "Proceed",
|
|
2897
|
-
rename: "Rename",
|
|
2898
|
-
segments: "Segments",
|
|
2899
|
-
userCount: "{{count}} Users",
|
|
2900
|
-
yes: "Yes",
|
|
2901
|
-
update: "Update"
|
|
2902
|
-
},
|
|
2903
|
-
messages: {
|
|
2904
|
-
enterResource: "Enter {{resource}}",
|
|
2905
|
-
noResourcesFound: "No {{resources}} found",
|
|
2906
|
-
searchResources: "Search {{resources}}",
|
|
2907
|
-
selectResource: "Select {{resource}}",
|
|
2908
|
-
selectOption: "Select an option"
|
|
2909
|
-
},
|
|
2910
|
-
rules: {
|
|
2911
|
-
contains: "Contains",
|
|
2912
|
-
doesNotContain: "Does not contain",
|
|
2913
|
-
exactly: "Exactly",
|
|
2914
|
-
notExactly: "Not exactly",
|
|
2915
|
-
startsWith: "Starts with",
|
|
2916
|
-
doesNotStartWith: "Does not start with",
|
|
2917
|
-
endsWith: "Ends with",
|
|
2918
|
-
doesNotEndWith: "Does not end with",
|
|
2919
|
-
greaterThan: "Greater than",
|
|
2920
|
-
lessThan: "Less than"
|
|
2921
|
-
},
|
|
2922
|
-
errors: {
|
|
2923
|
-
cannotPassMultipleModels: "Cannot pass multiple Models except for keyword searching"
|
|
2924
|
-
},
|
|
2925
|
-
shortcuts: {
|
|
2926
|
-
deleteBlock: "Delete block",
|
|
2927
|
-
openFilterPane: "Open filter pane",
|
|
2928
|
-
closePane: "Close pane"
|
|
2929
|
-
},
|
|
2930
|
-
segments: {
|
|
2931
|
-
addNewSegment: "Add new segment",
|
|
2932
|
-
deleteAlertMessage: "You are permanently deleting the segment <strong>{{entity}}</strong>. This can't be undone.",
|
|
2933
|
-
deleteAlertTitle: "Delete segment?",
|
|
2934
|
-
manageSegments: "Manage segments",
|
|
2935
|
-
name: "Segment name",
|
|
2936
|
-
noSegmentsFound: "No segments found",
|
|
2937
|
-
saveSegment: "Save segment",
|
|
2938
|
-
saveAsSegment: "Save as segment",
|
|
2939
|
-
saveAsNewSegment: "Save as new segment",
|
|
2940
|
-
searchSegments: "Search segments",
|
|
2941
|
-
segmentName: "Segment name",
|
|
2942
|
-
showLess: "See less",
|
|
2943
|
-
showMoreNumbers: "See {{entity}} more",
|
|
2944
|
-
updateSegment: "Update segment?",
|
|
2945
|
-
updateSegmentMessage: "You are trying to update the current segment."
|
|
2946
|
-
},
|
|
2947
|
-
labels: {
|
|
2948
|
-
keyword: "Keyword"
|
|
2949
|
-
}
|
|
2950
|
-
};
|
|
2951
|
-
var en = {
|
|
2952
|
-
neetoFilters: neetoFilters
|
|
2953
|
-
};
|
|
2954
|
-
|
|
2955
|
-
instance.use(initReactI18next).init({
|
|
2956
|
-
resources: {
|
|
2957
|
-
en: {
|
|
2958
|
-
translation: en
|
|
2959
|
-
}
|
|
2960
|
-
},
|
|
2961
|
-
fallbackLng: "en"
|
|
2962
|
-
});
|
|
2963
|
-
|
|
2964
58
|
function _arrayLikeToArray$1(arr, len) {
|
|
2965
59
|
if (len == null || len > arr.length) len = arr.length;
|
|
2966
60
|
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
@@ -3183,15 +277,15 @@ var filterBy = /*#__PURE__*/ramda.curry(function (pattern, array) {
|
|
|
3183
277
|
var SHORTCUTS = {
|
|
3184
278
|
closePane: {
|
|
3185
279
|
sequence: "escape",
|
|
3186
|
-
description: t
|
|
280
|
+
description: i18next.t("neetoFilters.shortcuts.closePane")
|
|
3187
281
|
},
|
|
3188
282
|
deleteBlock: {
|
|
3189
283
|
sequence: "backspace",
|
|
3190
|
-
description: t
|
|
284
|
+
description: i18next.t("neetoFilters.shortcuts.deleteBlock")
|
|
3191
285
|
},
|
|
3192
286
|
openFilterPane: {
|
|
3193
287
|
sequence: "enter",
|
|
3194
|
-
description: t
|
|
288
|
+
description: i18next.t("neetoFilters.shortcuts.openFilterPane")
|
|
3195
289
|
}
|
|
3196
290
|
};
|
|
3197
291
|
|
|
@@ -3279,48 +373,48 @@ var DATE_RULES = {
|
|
|
3279
373
|
};
|
|
3280
374
|
|
|
3281
375
|
var NUMBER_RULES = [{
|
|
3282
|
-
label: t
|
|
376
|
+
label: i18next.t("neetoFilters.rules.exactly"),
|
|
3283
377
|
value: "is"
|
|
3284
378
|
}, {
|
|
3285
|
-
label: t
|
|
379
|
+
label: i18next.t("neetoFilters.rules.notExactly"),
|
|
3286
380
|
value: "is_not"
|
|
3287
381
|
}, {
|
|
3288
|
-
label: t
|
|
382
|
+
label: i18next.t("neetoFilters.rules.greaterThan"),
|
|
3289
383
|
value: "greater_than"
|
|
3290
384
|
}, {
|
|
3291
|
-
label: t
|
|
385
|
+
label: i18next.t("neetoFilters.rules.lessThan"),
|
|
3292
386
|
value: "less_than"
|
|
3293
387
|
}];
|
|
3294
388
|
var TEXT_RULES = [{
|
|
3295
|
-
label: t
|
|
389
|
+
label: i18next.t("neetoFilters.rules.contains"),
|
|
3296
390
|
value: "contains"
|
|
3297
391
|
}, {
|
|
3298
|
-
label: t
|
|
392
|
+
label: i18next.t("neetoFilters.rules.doesNotContain"),
|
|
3299
393
|
value: "does_not_contain"
|
|
3300
394
|
}, {
|
|
3301
|
-
label: t
|
|
395
|
+
label: i18next.t("neetoFilters.rules.exactly"),
|
|
3302
396
|
value: "is"
|
|
3303
397
|
}, {
|
|
3304
|
-
label: t
|
|
398
|
+
label: i18next.t("neetoFilters.rules.notExactly"),
|
|
3305
399
|
value: "is_not"
|
|
3306
400
|
}, {
|
|
3307
|
-
label: t
|
|
401
|
+
label: i18next.t("neetoFilters.rules.startsWith"),
|
|
3308
402
|
value: "starts_with"
|
|
3309
403
|
}, {
|
|
3310
|
-
label: t
|
|
404
|
+
label: i18next.t("neetoFilters.rules.doesNotStartWith"),
|
|
3311
405
|
value: "does_not_start_with"
|
|
3312
406
|
}, {
|
|
3313
|
-
label: t
|
|
407
|
+
label: i18next.t("neetoFilters.rules.endsWith"),
|
|
3314
408
|
value: "ends_with"
|
|
3315
409
|
}, {
|
|
3316
|
-
label: t
|
|
410
|
+
label: i18next.t("neetoFilters.rules.doesNotEndWith"),
|
|
3317
411
|
value: "does_not_end_with"
|
|
3318
412
|
}];
|
|
3319
413
|
var DEFAULT_BOOLEAN_OPTIONS = [{
|
|
3320
|
-
label: t
|
|
414
|
+
label: i18next.t("neetoFilters.common.yes"),
|
|
3321
415
|
value: "true"
|
|
3322
416
|
}, {
|
|
3323
|
-
label: t
|
|
417
|
+
label: i18next.t("neetoFilters.common.no"),
|
|
3324
418
|
value: "false"
|
|
3325
419
|
}];
|
|
3326
420
|
|
|
@@ -3700,7 +794,7 @@ var buildFiltersPayload = function buildFiltersPayload(filters) {
|
|
|
3700
794
|
defaultType = _filterPayload$defaul === void 0 ? filterPayload.type : _filterPayload$defaul,
|
|
3701
795
|
value = filterPayload.value;
|
|
3702
796
|
if (isMultiModelFilter(filterPayload)) {
|
|
3703
|
-
throw
|
|
797
|
+
throw i18next__default["default"].t("neetoFilters.errors.cannotPassMultipleModels");
|
|
3704
798
|
}
|
|
3705
799
|
if (isDate(defaultType)) {
|
|
3706
800
|
return ramda.mergeRight(filterPayload, buildDatePayload(value));
|
|
@@ -3734,7 +828,7 @@ var buildSegmentsPayload = function buildSegmentsPayload(filters) {
|
|
|
3734
828
|
defaultType = _filterPayload$defaul2 === void 0 ? filterPayload.type : _filterPayload$defaul2,
|
|
3735
829
|
value = filterPayload.value;
|
|
3736
830
|
if (filter.key !== "keyword" && isMultiModelFilter(filterPayload)) {
|
|
3737
|
-
throw
|
|
831
|
+
throw i18next__default["default"].t("neetoFilters.errors.cannotPassMultipleModels");
|
|
3738
832
|
}
|
|
3739
833
|
if (isMulti(defaultType)) {
|
|
3740
834
|
return ramda.mergeRight(filterPayload, {
|
|
@@ -3880,6 +974,9 @@ var buildUrlFromFilters = function buildUrlFromFilters(_ref16) {
|
|
|
3880
974
|
columns: columns
|
|
3881
975
|
});
|
|
3882
976
|
});
|
|
977
|
+
if (ramda.isEmpty(ramda.omit(["segmentId"], searchParams))) {
|
|
978
|
+
delete searchParams["segmentId"];
|
|
979
|
+
}
|
|
3883
980
|
return new URLSearchParams(searchParams).toString();
|
|
3884
981
|
};
|
|
3885
982
|
var createUrlParamStringForSegments = function createUrlParamStringForSegments(_ref18) {
|
|
@@ -4234,7 +1331,7 @@ var Segment = function Segment(_ref) {
|
|
|
4234
1331
|
isUpdateAlertOpen = _useState4[0],
|
|
4235
1332
|
setIsUpdateAlertOpen = _useState4[1];
|
|
4236
1333
|
var inputRef = React.useRef(null);
|
|
4237
|
-
var _useTranslation = useTranslation(),
|
|
1334
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
4238
1335
|
t = _useTranslation.t;
|
|
4239
1336
|
var history = reactRouterDom.useHistory();
|
|
4240
1337
|
var filtersPayload = buildSegmentsPayload(filters, childrenKeys);
|
|
@@ -4246,10 +1343,12 @@ var Segment = function Segment(_ref) {
|
|
|
4246
1343
|
_useShowSegment$data = _useShowSegment.data,
|
|
4247
1344
|
selectedSegment = _useShowSegment$data === void 0 ? {} : _useShowSegment$data;
|
|
4248
1345
|
var _useCreateSegment = useCreateSegment(),
|
|
4249
|
-
createSegment = _useCreateSegment.mutate
|
|
1346
|
+
createSegment = _useCreateSegment.mutate,
|
|
1347
|
+
isCreating = _useCreateSegment.isLoading;
|
|
4250
1348
|
var _useUpdateSegment = useUpdateSegment(),
|
|
4251
1349
|
updateSegment = _useUpdateSegment.mutate,
|
|
4252
1350
|
isUpdating = _useUpdateSegment.isLoading;
|
|
1351
|
+
var isSubmitting = isCreating || isUpdating;
|
|
4253
1352
|
var handleUpdate = function handleUpdate() {
|
|
4254
1353
|
return updateSegment({
|
|
4255
1354
|
id: segmentId,
|
|
@@ -4342,6 +1441,10 @@ var Segment = function Segment(_ref) {
|
|
|
4342
1441
|
return setIsSavePaneOpen(false);
|
|
4343
1442
|
},
|
|
4344
1443
|
disabled: false
|
|
1444
|
+
},
|
|
1445
|
+
submitButtonProps: {
|
|
1446
|
+
disabled: isSubmitting,
|
|
1447
|
+
loading: isSubmitting
|
|
4345
1448
|
}
|
|
4346
1449
|
})))), /*#__PURE__*/React__default["default"].createElement(neetoui.Alert, {
|
|
4347
1450
|
isOpen: isUpdateAlertOpen,
|
|
@@ -4373,7 +1476,7 @@ var Bar = function Bar(_ref) {
|
|
|
4373
1476
|
setIsPaneOpen = _ref$setIsPaneOpen === void 0 ? ramda.identity : _ref$setIsPaneOpen,
|
|
4374
1477
|
_ref$childrenKeys = _ref.childrenKeys,
|
|
4375
1478
|
childrenKeys = _ref$childrenKeys === void 0 ? [] : _ref$childrenKeys;
|
|
4376
|
-
var _useTranslation = useTranslation(),
|
|
1479
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
4377
1480
|
t = _useTranslation.t;
|
|
4378
1481
|
var initialRenderRef = React.useRef(true);
|
|
4379
1482
|
var searchParams = new URLSearchParams(window.location.search);
|
|
@@ -7140,7 +4243,7 @@ var Boolean = function Boolean(_ref) {
|
|
|
7140
4243
|
filter: filter,
|
|
7141
4244
|
options: options
|
|
7142
4245
|
});
|
|
7143
|
-
var _useTranslation = useTranslation(),
|
|
4246
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
7144
4247
|
t = _useTranslation.t;
|
|
7145
4248
|
var handleChange = function handleChange(option) {
|
|
7146
4249
|
if (ramda.isEmpty(option) || ramda.isNil(option)) {
|
|
@@ -7181,7 +4284,7 @@ var Datetime = function Datetime(_ref) {
|
|
|
7181
4284
|
_useState2 = _slicedToArray(_useState, 2),
|
|
7182
4285
|
selectedRule = _useState2[0],
|
|
7183
4286
|
setSelectedRule = _useState2[1];
|
|
7184
|
-
var _useTranslation = useTranslation(),
|
|
4287
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
7185
4288
|
t = _useTranslation.t;
|
|
7186
4289
|
var key = column.key,
|
|
7187
4290
|
_column$defaultType = column.defaultType,
|
|
@@ -7275,7 +4378,7 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
7275
4378
|
filter: filter,
|
|
7276
4379
|
options: options
|
|
7277
4380
|
});
|
|
7278
|
-
var _useTranslation = useTranslation(),
|
|
4381
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
7279
4382
|
t = _useTranslation.t;
|
|
7280
4383
|
var handleChange = function handleChange(option) {
|
|
7281
4384
|
if (ramda.isEmpty(option) || ramda.isNil(option)) {
|
|
@@ -7501,7 +4604,7 @@ var Text = function Text(_ref) {
|
|
|
7501
4604
|
selectedRule = _useState4[0],
|
|
7502
4605
|
setSelectedRule = _useState4[1];
|
|
7503
4606
|
var debouncedInputValue = reactUtils.useDebounce(inputValue);
|
|
7504
|
-
var _useTranslation = useTranslation(),
|
|
4607
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
7505
4608
|
t = _useTranslation.t;
|
|
7506
4609
|
var handleUpdateAndApplyFilter = function handleUpdateAndApplyFilter() {
|
|
7507
4610
|
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : debouncedInputValue;
|
|
@@ -7579,7 +4682,7 @@ var Time = function Time(_ref) {
|
|
|
7579
4682
|
var otherProps = getOtherProps(column);
|
|
7580
4683
|
var value = buildSingleTimeValue(filter);
|
|
7581
4684
|
var isCustomTimeRangeShown = filter && isCustomTimeRange(filter.value);
|
|
7582
|
-
var _useTranslation = useTranslation(),
|
|
4685
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
7583
4686
|
t = _useTranslation.t;
|
|
7584
4687
|
var handleChange = function handleChange(option) {
|
|
7585
4688
|
if (ramda.isEmpty(option) || ramda.isNil(option)) {
|
|
@@ -7736,7 +4839,7 @@ var Pane = function Pane(_ref) {
|
|
|
7736
4839
|
searchTerm = _useState2[0],
|
|
7737
4840
|
setSearchTerm = _useState2[1];
|
|
7738
4841
|
var history = reactRouterDom.useHistory();
|
|
7739
|
-
var _useTranslation = useTranslation(),
|
|
4842
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
7740
4843
|
t = _useTranslation.t;
|
|
7741
4844
|
columns = React.useMemo(function () {
|
|
7742
4845
|
return getColumnsWithStandardizedType(columns);
|
|
@@ -7936,7 +5039,7 @@ var DeleteAlert = function DeleteAlert(_ref) {
|
|
|
7936
5039
|
onClose = _ref.onClose,
|
|
7937
5040
|
segment = _ref.segment,
|
|
7938
5041
|
columns = _ref.columns;
|
|
7939
|
-
var _useTranslation = useTranslation(),
|
|
5042
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
7940
5043
|
t = _useTranslation.t;
|
|
7941
5044
|
var history = reactRouterDom.useHistory();
|
|
7942
5045
|
var _getQueryParams = utils.getQueryParams(),
|
|
@@ -7966,7 +5069,7 @@ var DeleteAlert = function DeleteAlert(_ref) {
|
|
|
7966
5069
|
isSubmitting: isDeleting,
|
|
7967
5070
|
submitButtonLabel: t("neetoFilters.common.delete"),
|
|
7968
5071
|
title: t("neetoFilters.segments.deleteAlertTitle"),
|
|
7969
|
-
message: /*#__PURE__*/React__default["default"].createElement(Trans, {
|
|
5072
|
+
message: /*#__PURE__*/React__default["default"].createElement(reactI18next.Trans, {
|
|
7970
5073
|
i18nKey: "neetoFilters.segments.deleteAlertMessage",
|
|
7971
5074
|
values: {
|
|
7972
5075
|
entity: segment.name
|
|
@@ -7987,7 +5090,7 @@ var Card = function Card(_ref) {
|
|
|
7987
5090
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
7988
5091
|
isDeleteAlertOpen = _useState4[0],
|
|
7989
5092
|
setIsDeleteAlertOpen = _useState4[1];
|
|
7990
|
-
var _useTranslation = useTranslation(),
|
|
5093
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
7991
5094
|
t = _useTranslation.t;
|
|
7992
5095
|
var Menu = neetoui.Dropdown.Menu,
|
|
7993
5096
|
MenuItem = neetoui.Dropdown.MenuItem;
|
|
@@ -8074,7 +5177,7 @@ var ManagePane = function ManagePane(_ref) {
|
|
|
8074
5177
|
searchTerm = _useState2[0],
|
|
8075
5178
|
setSearchTerm = _useState2[1];
|
|
8076
5179
|
var inputRef = React.useRef(null);
|
|
8077
|
-
var _useTranslation = useTranslation(),
|
|
5180
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
8078
5181
|
t = _useTranslation.t;
|
|
8079
5182
|
var debouncedSearchTerm = reactUtils.useDebounce(searchTerm);
|
|
8080
5183
|
var _useFetchSegments = useFetchSegments({
|
|
@@ -8117,7 +5220,7 @@ var ManagePane = function ManagePane(_ref) {
|
|
|
8117
5220
|
}))));
|
|
8118
5221
|
};
|
|
8119
5222
|
|
|
8120
|
-
var ITEMS_MAX_COUNT =
|
|
5223
|
+
var ITEMS_MAX_COUNT = 20;
|
|
8121
5224
|
|
|
8122
5225
|
var MenuBlocks = function MenuBlocks(_ref) {
|
|
8123
5226
|
var entity = _ref.entity,
|
|
@@ -8129,7 +5232,7 @@ var MenuBlocks = function MenuBlocks(_ref) {
|
|
|
8129
5232
|
setShowAll = _useState2[1];
|
|
8130
5233
|
var location = reactRouterDom.useLocation();
|
|
8131
5234
|
var history = reactRouterDom.useHistory();
|
|
8132
|
-
var _useTranslation = useTranslation(),
|
|
5235
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
8133
5236
|
t = _useTranslation.t;
|
|
8134
5237
|
var _Object$fromEntries = Object.fromEntries(new URLSearchParams(location.search)),
|
|
8135
5238
|
segmentId = _Object$fromEntries.segmentId;
|
|
@@ -8211,7 +5314,7 @@ var Segments = function Segments(_ref) {
|
|
|
8211
5314
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
8212
5315
|
isSegmentsPaneOpen = _useState6[0],
|
|
8213
5316
|
setIsSegmentsPaneOpen = _useState6[1];
|
|
8214
|
-
var _useTranslation = useTranslation(),
|
|
5317
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
8215
5318
|
t = _useTranslation.t;
|
|
8216
5319
|
var debouncedSearchTerm = reactUtils.useDebounce(searchTerm);
|
|
8217
5320
|
var iconProps = [{
|
|
@@ -8272,7 +5375,75 @@ var Segments = function Segments(_ref) {
|
|
|
8272
5375
|
};
|
|
8273
5376
|
var index = /*#__PURE__*/React__default["default"].memo(Segments);
|
|
8274
5377
|
|
|
8275
|
-
|
|
5378
|
+
var neetoFilters = {
|
|
5379
|
+
common: {
|
|
5380
|
+
clearFilters: "Clear filters",
|
|
5381
|
+
columns: "Columns",
|
|
5382
|
+
"delete": "Delete",
|
|
5383
|
+
done: "Done",
|
|
5384
|
+
filter: "Filter",
|
|
5385
|
+
filters: "Filters",
|
|
5386
|
+
no: "No",
|
|
5387
|
+
proceed: "Proceed",
|
|
5388
|
+
rename: "Rename",
|
|
5389
|
+
segments: "Segments",
|
|
5390
|
+
userCount: "{{count}} Users",
|
|
5391
|
+
yes: "Yes",
|
|
5392
|
+
update: "Update"
|
|
5393
|
+
},
|
|
5394
|
+
messages: {
|
|
5395
|
+
enterResource: "Enter {{resource}}",
|
|
5396
|
+
noResourcesFound: "No {{resources}} found",
|
|
5397
|
+
searchResources: "Search {{resources}}",
|
|
5398
|
+
selectResource: "Select {{resource}}",
|
|
5399
|
+
selectOption: "Select an option"
|
|
5400
|
+
},
|
|
5401
|
+
rules: {
|
|
5402
|
+
contains: "Contains",
|
|
5403
|
+
doesNotContain: "Does not contain",
|
|
5404
|
+
exactly: "Exactly",
|
|
5405
|
+
notExactly: "Not exactly",
|
|
5406
|
+
startsWith: "Starts with",
|
|
5407
|
+
doesNotStartWith: "Does not start with",
|
|
5408
|
+
endsWith: "Ends with",
|
|
5409
|
+
doesNotEndWith: "Does not end with",
|
|
5410
|
+
greaterThan: "Greater than",
|
|
5411
|
+
lessThan: "Less than"
|
|
5412
|
+
},
|
|
5413
|
+
errors: {
|
|
5414
|
+
cannotPassMultipleModels: "Cannot pass multiple Models except for keyword searching"
|
|
5415
|
+
},
|
|
5416
|
+
shortcuts: {
|
|
5417
|
+
deleteBlock: "Delete block",
|
|
5418
|
+
openFilterPane: "Open filter pane",
|
|
5419
|
+
closePane: "Close pane"
|
|
5420
|
+
},
|
|
5421
|
+
segments: {
|
|
5422
|
+
addNewSegment: "Add new segment",
|
|
5423
|
+
deleteAlertMessage: "You are permanently deleting the segment <strong>{{entity}}</strong>. This can't be undone.",
|
|
5424
|
+
deleteAlertTitle: "Delete segment?",
|
|
5425
|
+
manageSegments: "Manage segments",
|
|
5426
|
+
name: "Segment name",
|
|
5427
|
+
noSegmentsFound: "No segments found",
|
|
5428
|
+
saveSegment: "Save segment",
|
|
5429
|
+
saveAsSegment: "Save as segment",
|
|
5430
|
+
saveAsNewSegment: "Save as new segment",
|
|
5431
|
+
searchSegments: "Search segments",
|
|
5432
|
+
segmentName: "Segment name",
|
|
5433
|
+
showLess: "See less",
|
|
5434
|
+
showMoreNumbers: "See {{entity}} more",
|
|
5435
|
+
updateSegment: "Update segment?",
|
|
5436
|
+
updateSegmentMessage: "You are trying to update the current segment."
|
|
5437
|
+
},
|
|
5438
|
+
labels: {
|
|
5439
|
+
keyword: "Keyword"
|
|
5440
|
+
}
|
|
5441
|
+
};
|
|
5442
|
+
var en = {
|
|
5443
|
+
neetoFilters: neetoFilters
|
|
5444
|
+
};
|
|
5445
|
+
|
|
5446
|
+
i18next__default["default"].use(reactI18next.initReactI18next).init({
|
|
8276
5447
|
resources: {
|
|
8277
5448
|
en: {
|
|
8278
5449
|
translation: en
|