@bigbinary/neeto-filters-frontend 2.14.1 → 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 +175 -3008
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +161 -2995
- 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.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useState, useRef, useEffect, useTransition, useMemo } from 'react';
|
|
2
2
|
import classnames from 'classnames';
|
|
3
3
|
import { curryN, isNil, complement, curry, isEmpty, either, groupBy, anyPass, any, toLower, mergeLeft, identity, omit, mergeRight, toPairs, concat, pluck, has as has$1, equals, pick, modify, prop, isNotNil, append, last, not } from 'ramda';
|
|
4
4
|
import { Tooltip, Typography, Dropdown as Dropdown$2, Button, Pane as Pane$1, Alert, Select, DatePicker, TimePicker, Input as Input$1, Accordion, Spinner } from '@bigbinary/neetoui';
|
|
5
|
+
import { useTranslation, Trans, initReactI18next } from 'react-i18next';
|
|
5
6
|
import { useHistory, useLocation } from 'react-router-dom';
|
|
6
7
|
import { useHotKeys, useMutationWithInvalidation, useDebounce, withT } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
7
8
|
import { Close, Search, Check, MenuHorizontal, Down, Settings } from '@bigbinary/neeto-icons';
|
|
9
|
+
import i18next, { t as t$1 } from 'i18next';
|
|
8
10
|
import dayjs from 'dayjs';
|
|
9
11
|
import { getQueryParams, dateFormat } from '@bigbinary/neeto-commons-frontend/utils';
|
|
10
12
|
import * as yup from 'yup';
|
|
@@ -17,2919 +19,6 @@ import axios from 'axios';
|
|
|
17
19
|
import ReactDOM, { createPortal } from 'react-dom';
|
|
18
20
|
import MenuBar from '@bigbinary/neeto-molecules/MenuBar';
|
|
19
21
|
|
|
20
|
-
const consoleLogger = {
|
|
21
|
-
type: 'logger',
|
|
22
|
-
log(args) {
|
|
23
|
-
this.output('log', args);
|
|
24
|
-
},
|
|
25
|
-
warn(args) {
|
|
26
|
-
this.output('warn', args);
|
|
27
|
-
},
|
|
28
|
-
error(args) {
|
|
29
|
-
this.output('error', args);
|
|
30
|
-
},
|
|
31
|
-
output(type, args) {
|
|
32
|
-
if (console && console[type]) console[type].apply(console, args);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
class Logger {
|
|
36
|
-
constructor(concreteLogger) {
|
|
37
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
38
|
-
this.init(concreteLogger, options);
|
|
39
|
-
}
|
|
40
|
-
init(concreteLogger) {
|
|
41
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
42
|
-
this.prefix = options.prefix || 'i18next:';
|
|
43
|
-
this.logger = concreteLogger || consoleLogger;
|
|
44
|
-
this.options = options;
|
|
45
|
-
this.debug = options.debug;
|
|
46
|
-
}
|
|
47
|
-
log() {
|
|
48
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
49
|
-
args[_key] = arguments[_key];
|
|
50
|
-
}
|
|
51
|
-
return this.forward(args, 'log', '', true);
|
|
52
|
-
}
|
|
53
|
-
warn() {
|
|
54
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
55
|
-
args[_key2] = arguments[_key2];
|
|
56
|
-
}
|
|
57
|
-
return this.forward(args, 'warn', '', true);
|
|
58
|
-
}
|
|
59
|
-
error() {
|
|
60
|
-
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
61
|
-
args[_key3] = arguments[_key3];
|
|
62
|
-
}
|
|
63
|
-
return this.forward(args, 'error', '');
|
|
64
|
-
}
|
|
65
|
-
deprecate() {
|
|
66
|
-
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
67
|
-
args[_key4] = arguments[_key4];
|
|
68
|
-
}
|
|
69
|
-
return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
|
|
70
|
-
}
|
|
71
|
-
forward(args, lvl, prefix, debugOnly) {
|
|
72
|
-
if (debugOnly && !this.debug) return null;
|
|
73
|
-
if (typeof args[0] === 'string') args[0] = `${prefix}${this.prefix} ${args[0]}`;
|
|
74
|
-
return this.logger[lvl](args);
|
|
75
|
-
}
|
|
76
|
-
create(moduleName) {
|
|
77
|
-
return new Logger(this.logger, {
|
|
78
|
-
...{
|
|
79
|
-
prefix: `${this.prefix}:${moduleName}:`
|
|
80
|
-
},
|
|
81
|
-
...this.options
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
clone(options) {
|
|
85
|
-
options = options || this.options;
|
|
86
|
-
options.prefix = options.prefix || this.prefix;
|
|
87
|
-
return new Logger(this.logger, options);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
var baseLogger = new Logger();
|
|
91
|
-
|
|
92
|
-
class EventEmitter {
|
|
93
|
-
constructor() {
|
|
94
|
-
this.observers = {};
|
|
95
|
-
}
|
|
96
|
-
on(events, listener) {
|
|
97
|
-
events.split(' ').forEach(event => {
|
|
98
|
-
this.observers[event] = this.observers[event] || [];
|
|
99
|
-
this.observers[event].push(listener);
|
|
100
|
-
});
|
|
101
|
-
return this;
|
|
102
|
-
}
|
|
103
|
-
off(event, listener) {
|
|
104
|
-
if (!this.observers[event]) return;
|
|
105
|
-
if (!listener) {
|
|
106
|
-
delete this.observers[event];
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
this.observers[event] = this.observers[event].filter(l => l !== listener);
|
|
110
|
-
}
|
|
111
|
-
emit(event) {
|
|
112
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
113
|
-
args[_key - 1] = arguments[_key];
|
|
114
|
-
}
|
|
115
|
-
if (this.observers[event]) {
|
|
116
|
-
const cloned = [].concat(this.observers[event]);
|
|
117
|
-
cloned.forEach(observer => {
|
|
118
|
-
observer(...args);
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
if (this.observers['*']) {
|
|
122
|
-
const cloned = [].concat(this.observers['*']);
|
|
123
|
-
cloned.forEach(observer => {
|
|
124
|
-
observer.apply(observer, [event, ...args]);
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function defer() {
|
|
131
|
-
let res;
|
|
132
|
-
let rej;
|
|
133
|
-
const promise = new Promise((resolve, reject) => {
|
|
134
|
-
res = resolve;
|
|
135
|
-
rej = reject;
|
|
136
|
-
});
|
|
137
|
-
promise.resolve = res;
|
|
138
|
-
promise.reject = rej;
|
|
139
|
-
return promise;
|
|
140
|
-
}
|
|
141
|
-
function makeString(object) {
|
|
142
|
-
if (object == null) return '';
|
|
143
|
-
return '' + object;
|
|
144
|
-
}
|
|
145
|
-
function copy(a, s, t) {
|
|
146
|
-
a.forEach(m => {
|
|
147
|
-
if (s[m]) t[m] = s[m];
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
function getLastOfPath(object, path, Empty) {
|
|
151
|
-
function cleanKey(key) {
|
|
152
|
-
return key && key.indexOf('###') > -1 ? key.replace(/###/g, '.') : key;
|
|
153
|
-
}
|
|
154
|
-
function canNotTraverseDeeper() {
|
|
155
|
-
return !object || typeof object === 'string';
|
|
156
|
-
}
|
|
157
|
-
const stack = typeof path !== 'string' ? [].concat(path) : path.split('.');
|
|
158
|
-
while (stack.length > 1) {
|
|
159
|
-
if (canNotTraverseDeeper()) return {};
|
|
160
|
-
const key = cleanKey(stack.shift());
|
|
161
|
-
if (!object[key] && Empty) object[key] = new Empty();
|
|
162
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
163
|
-
object = object[key];
|
|
164
|
-
} else {
|
|
165
|
-
object = {};
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (canNotTraverseDeeper()) return {};
|
|
169
|
-
return {
|
|
170
|
-
obj: object,
|
|
171
|
-
k: cleanKey(stack.shift())
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
function setPath(object, path, newValue) {
|
|
175
|
-
const {
|
|
176
|
-
obj,
|
|
177
|
-
k
|
|
178
|
-
} = getLastOfPath(object, path, Object);
|
|
179
|
-
obj[k] = newValue;
|
|
180
|
-
}
|
|
181
|
-
function pushPath(object, path, newValue, concat) {
|
|
182
|
-
const {
|
|
183
|
-
obj,
|
|
184
|
-
k
|
|
185
|
-
} = getLastOfPath(object, path, Object);
|
|
186
|
-
obj[k] = obj[k] || [];
|
|
187
|
-
if (concat) obj[k] = obj[k].concat(newValue);
|
|
188
|
-
if (!concat) obj[k].push(newValue);
|
|
189
|
-
}
|
|
190
|
-
function getPath(object, path) {
|
|
191
|
-
const {
|
|
192
|
-
obj,
|
|
193
|
-
k
|
|
194
|
-
} = getLastOfPath(object, path);
|
|
195
|
-
if (!obj) return undefined;
|
|
196
|
-
return obj[k];
|
|
197
|
-
}
|
|
198
|
-
function getPathWithDefaults(data, defaultData, key) {
|
|
199
|
-
const value = getPath(data, key);
|
|
200
|
-
if (value !== undefined) {
|
|
201
|
-
return value;
|
|
202
|
-
}
|
|
203
|
-
return getPath(defaultData, key);
|
|
204
|
-
}
|
|
205
|
-
function deepExtend(target, source, overwrite) {
|
|
206
|
-
for (const prop in source) {
|
|
207
|
-
if (prop !== '__proto__' && prop !== 'constructor') {
|
|
208
|
-
if (prop in target) {
|
|
209
|
-
if (typeof target[prop] === 'string' || target[prop] instanceof String || typeof source[prop] === 'string' || source[prop] instanceof String) {
|
|
210
|
-
if (overwrite) target[prop] = source[prop];
|
|
211
|
-
} else {
|
|
212
|
-
deepExtend(target[prop], source[prop], overwrite);
|
|
213
|
-
}
|
|
214
|
-
} else {
|
|
215
|
-
target[prop] = source[prop];
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
return target;
|
|
220
|
-
}
|
|
221
|
-
function regexEscape(str) {
|
|
222
|
-
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
|
|
223
|
-
}
|
|
224
|
-
var _entityMap = {
|
|
225
|
-
'&': '&',
|
|
226
|
-
'<': '<',
|
|
227
|
-
'>': '>',
|
|
228
|
-
'"': '"',
|
|
229
|
-
"'": ''',
|
|
230
|
-
'/': '/'
|
|
231
|
-
};
|
|
232
|
-
function escape(data) {
|
|
233
|
-
if (typeof data === 'string') {
|
|
234
|
-
return data.replace(/[&<>"'\/]/g, s => _entityMap[s]);
|
|
235
|
-
}
|
|
236
|
-
return data;
|
|
237
|
-
}
|
|
238
|
-
const chars = [' ', ',', '?', '!', ';'];
|
|
239
|
-
function looksLikeObjectPath(key, nsSeparator, keySeparator) {
|
|
240
|
-
nsSeparator = nsSeparator || '';
|
|
241
|
-
keySeparator = keySeparator || '';
|
|
242
|
-
const possibleChars = chars.filter(c => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
|
|
243
|
-
if (possibleChars.length === 0) return true;
|
|
244
|
-
const r = new RegExp(`(${possibleChars.map(c => c === '?' ? '\\?' : c).join('|')})`);
|
|
245
|
-
let matched = !r.test(key);
|
|
246
|
-
if (!matched) {
|
|
247
|
-
const ki = key.indexOf(keySeparator);
|
|
248
|
-
if (ki > 0 && !r.test(key.substring(0, ki))) {
|
|
249
|
-
matched = true;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return matched;
|
|
253
|
-
}
|
|
254
|
-
function deepFind(obj, path) {
|
|
255
|
-
let keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
|
|
256
|
-
if (!obj) return undefined;
|
|
257
|
-
if (obj[path]) return obj[path];
|
|
258
|
-
const paths = path.split(keySeparator);
|
|
259
|
-
let current = obj;
|
|
260
|
-
for (let i = 0; i < paths.length; ++i) {
|
|
261
|
-
if (!current) return undefined;
|
|
262
|
-
if (typeof current[paths[i]] === 'string' && i + 1 < paths.length) {
|
|
263
|
-
return undefined;
|
|
264
|
-
}
|
|
265
|
-
if (current[paths[i]] === undefined) {
|
|
266
|
-
let j = 2;
|
|
267
|
-
let p = paths.slice(i, i + j).join(keySeparator);
|
|
268
|
-
let mix = current[p];
|
|
269
|
-
while (mix === undefined && paths.length > i + j) {
|
|
270
|
-
j++;
|
|
271
|
-
p = paths.slice(i, i + j).join(keySeparator);
|
|
272
|
-
mix = current[p];
|
|
273
|
-
}
|
|
274
|
-
if (mix === undefined) return undefined;
|
|
275
|
-
if (mix === null) return null;
|
|
276
|
-
if (path.endsWith(p)) {
|
|
277
|
-
if (typeof mix === 'string') return mix;
|
|
278
|
-
if (p && typeof mix[p] === 'string') return mix[p];
|
|
279
|
-
}
|
|
280
|
-
const joinedPath = paths.slice(i + j).join(keySeparator);
|
|
281
|
-
if (joinedPath) return deepFind(mix, joinedPath, keySeparator);
|
|
282
|
-
return undefined;
|
|
283
|
-
}
|
|
284
|
-
current = current[paths[i]];
|
|
285
|
-
}
|
|
286
|
-
return current;
|
|
287
|
-
}
|
|
288
|
-
function getCleanedCode(code) {
|
|
289
|
-
if (code && code.indexOf('_') > 0) return code.replace('_', '-');
|
|
290
|
-
return code;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
class ResourceStore extends EventEmitter {
|
|
294
|
-
constructor(data) {
|
|
295
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
296
|
-
ns: ['translation'],
|
|
297
|
-
defaultNS: 'translation'
|
|
298
|
-
};
|
|
299
|
-
super();
|
|
300
|
-
this.data = data || {};
|
|
301
|
-
this.options = options;
|
|
302
|
-
if (this.options.keySeparator === undefined) {
|
|
303
|
-
this.options.keySeparator = '.';
|
|
304
|
-
}
|
|
305
|
-
if (this.options.ignoreJSONStructure === undefined) {
|
|
306
|
-
this.options.ignoreJSONStructure = true;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
addNamespaces(ns) {
|
|
310
|
-
if (this.options.ns.indexOf(ns) < 0) {
|
|
311
|
-
this.options.ns.push(ns);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
removeNamespaces(ns) {
|
|
315
|
-
const index = this.options.ns.indexOf(ns);
|
|
316
|
-
if (index > -1) {
|
|
317
|
-
this.options.ns.splice(index, 1);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
getResource(lng, ns, key) {
|
|
321
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
322
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
323
|
-
const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
324
|
-
let path = [lng, ns];
|
|
325
|
-
if (key && typeof key !== 'string') path = path.concat(key);
|
|
326
|
-
if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
327
|
-
if (lng.indexOf('.') > -1) {
|
|
328
|
-
path = lng.split('.');
|
|
329
|
-
}
|
|
330
|
-
const result = getPath(this.data, path);
|
|
331
|
-
if (result || !ignoreJSONStructure || typeof key !== 'string') return result;
|
|
332
|
-
return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
|
|
333
|
-
}
|
|
334
|
-
addResource(lng, ns, key, value) {
|
|
335
|
-
let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
336
|
-
silent: false
|
|
337
|
-
};
|
|
338
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
339
|
-
let path = [lng, ns];
|
|
340
|
-
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
341
|
-
if (lng.indexOf('.') > -1) {
|
|
342
|
-
path = lng.split('.');
|
|
343
|
-
value = ns;
|
|
344
|
-
ns = path[1];
|
|
345
|
-
}
|
|
346
|
-
this.addNamespaces(ns);
|
|
347
|
-
setPath(this.data, path, value);
|
|
348
|
-
if (!options.silent) this.emit('added', lng, ns, key, value);
|
|
349
|
-
}
|
|
350
|
-
addResources(lng, ns, resources) {
|
|
351
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
352
|
-
silent: false
|
|
353
|
-
};
|
|
354
|
-
for (const m in resources) {
|
|
355
|
-
if (typeof resources[m] === 'string' || Object.prototype.toString.apply(resources[m]) === '[object Array]') this.addResource(lng, ns, m, resources[m], {
|
|
356
|
-
silent: true
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
360
|
-
}
|
|
361
|
-
addResourceBundle(lng, ns, resources, deep, overwrite) {
|
|
362
|
-
let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
|
|
363
|
-
silent: false
|
|
364
|
-
};
|
|
365
|
-
let path = [lng, ns];
|
|
366
|
-
if (lng.indexOf('.') > -1) {
|
|
367
|
-
path = lng.split('.');
|
|
368
|
-
deep = resources;
|
|
369
|
-
resources = ns;
|
|
370
|
-
ns = path[1];
|
|
371
|
-
}
|
|
372
|
-
this.addNamespaces(ns);
|
|
373
|
-
let pack = getPath(this.data, path) || {};
|
|
374
|
-
if (deep) {
|
|
375
|
-
deepExtend(pack, resources, overwrite);
|
|
376
|
-
} else {
|
|
377
|
-
pack = {
|
|
378
|
-
...pack,
|
|
379
|
-
...resources
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
setPath(this.data, path, pack);
|
|
383
|
-
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
384
|
-
}
|
|
385
|
-
removeResourceBundle(lng, ns) {
|
|
386
|
-
if (this.hasResourceBundle(lng, ns)) {
|
|
387
|
-
delete this.data[lng][ns];
|
|
388
|
-
}
|
|
389
|
-
this.removeNamespaces(ns);
|
|
390
|
-
this.emit('removed', lng, ns);
|
|
391
|
-
}
|
|
392
|
-
hasResourceBundle(lng, ns) {
|
|
393
|
-
return this.getResource(lng, ns) !== undefined;
|
|
394
|
-
}
|
|
395
|
-
getResourceBundle(lng, ns) {
|
|
396
|
-
if (!ns) ns = this.options.defaultNS;
|
|
397
|
-
if (this.options.compatibilityAPI === 'v1') return {
|
|
398
|
-
...{},
|
|
399
|
-
...this.getResource(lng, ns)
|
|
400
|
-
};
|
|
401
|
-
return this.getResource(lng, ns);
|
|
402
|
-
}
|
|
403
|
-
getDataByLanguage(lng) {
|
|
404
|
-
return this.data[lng];
|
|
405
|
-
}
|
|
406
|
-
hasLanguageSomeTranslations(lng) {
|
|
407
|
-
const data = this.getDataByLanguage(lng);
|
|
408
|
-
const n = data && Object.keys(data) || [];
|
|
409
|
-
return !!n.find(v => data[v] && Object.keys(data[v]).length > 0);
|
|
410
|
-
}
|
|
411
|
-
toJSON() {
|
|
412
|
-
return this.data;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
var postProcessor = {
|
|
417
|
-
processors: {},
|
|
418
|
-
addPostProcessor(module) {
|
|
419
|
-
this.processors[module.name] = module;
|
|
420
|
-
},
|
|
421
|
-
handle(processors, value, key, options, translator) {
|
|
422
|
-
processors.forEach(processor => {
|
|
423
|
-
if (this.processors[processor]) value = this.processors[processor].process(value, key, options, translator);
|
|
424
|
-
});
|
|
425
|
-
return value;
|
|
426
|
-
}
|
|
427
|
-
};
|
|
428
|
-
|
|
429
|
-
const checkedLoadedFor = {};
|
|
430
|
-
class Translator extends EventEmitter {
|
|
431
|
-
constructor(services) {
|
|
432
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
433
|
-
super();
|
|
434
|
-
copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, this);
|
|
435
|
-
this.options = options;
|
|
436
|
-
if (this.options.keySeparator === undefined) {
|
|
437
|
-
this.options.keySeparator = '.';
|
|
438
|
-
}
|
|
439
|
-
this.logger = baseLogger.create('translator');
|
|
440
|
-
}
|
|
441
|
-
changeLanguage(lng) {
|
|
442
|
-
if (lng) this.language = lng;
|
|
443
|
-
}
|
|
444
|
-
exists(key) {
|
|
445
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
446
|
-
interpolation: {}
|
|
447
|
-
};
|
|
448
|
-
if (key === undefined || key === null) {
|
|
449
|
-
return false;
|
|
450
|
-
}
|
|
451
|
-
const resolved = this.resolve(key, options);
|
|
452
|
-
return resolved && resolved.res !== undefined;
|
|
453
|
-
}
|
|
454
|
-
extractFromKey(key, options) {
|
|
455
|
-
let nsSeparator = options.nsSeparator !== undefined ? options.nsSeparator : this.options.nsSeparator;
|
|
456
|
-
if (nsSeparator === undefined) nsSeparator = ':';
|
|
457
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
458
|
-
let namespaces = options.ns || this.options.defaultNS || [];
|
|
459
|
-
const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
460
|
-
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
461
|
-
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
462
|
-
const m = key.match(this.interpolator.nestingRegexp);
|
|
463
|
-
if (m && m.length > 0) {
|
|
464
|
-
return {
|
|
465
|
-
key,
|
|
466
|
-
namespaces
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
const parts = key.split(nsSeparator);
|
|
470
|
-
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
|
|
471
|
-
key = parts.join(keySeparator);
|
|
472
|
-
}
|
|
473
|
-
if (typeof namespaces === 'string') namespaces = [namespaces];
|
|
474
|
-
return {
|
|
475
|
-
key,
|
|
476
|
-
namespaces
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
|
-
translate(keys, options, lastKey) {
|
|
480
|
-
if (typeof options !== 'object' && this.options.overloadTranslationOptionHandler) {
|
|
481
|
-
options = this.options.overloadTranslationOptionHandler(arguments);
|
|
482
|
-
}
|
|
483
|
-
if (typeof options === 'object') options = {
|
|
484
|
-
...options
|
|
485
|
-
};
|
|
486
|
-
if (!options) options = {};
|
|
487
|
-
if (keys === undefined || keys === null) return '';
|
|
488
|
-
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
489
|
-
const returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
|
|
490
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
491
|
-
const {
|
|
492
|
-
key,
|
|
493
|
-
namespaces
|
|
494
|
-
} = this.extractFromKey(keys[keys.length - 1], options);
|
|
495
|
-
const namespace = namespaces[namespaces.length - 1];
|
|
496
|
-
const lng = options.lng || this.language;
|
|
497
|
-
const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
498
|
-
if (lng && lng.toLowerCase() === 'cimode') {
|
|
499
|
-
if (appendNamespaceToCIMode) {
|
|
500
|
-
const nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
501
|
-
if (returnDetails) {
|
|
502
|
-
return {
|
|
503
|
-
res: `${namespace}${nsSeparator}${key}`,
|
|
504
|
-
usedKey: key,
|
|
505
|
-
exactUsedKey: key,
|
|
506
|
-
usedLng: lng,
|
|
507
|
-
usedNS: namespace
|
|
508
|
-
};
|
|
509
|
-
}
|
|
510
|
-
return `${namespace}${nsSeparator}${key}`;
|
|
511
|
-
}
|
|
512
|
-
if (returnDetails) {
|
|
513
|
-
return {
|
|
514
|
-
res: key,
|
|
515
|
-
usedKey: key,
|
|
516
|
-
exactUsedKey: key,
|
|
517
|
-
usedLng: lng,
|
|
518
|
-
usedNS: namespace
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
return key;
|
|
522
|
-
}
|
|
523
|
-
const resolved = this.resolve(keys, options);
|
|
524
|
-
let res = resolved && resolved.res;
|
|
525
|
-
const resUsedKey = resolved && resolved.usedKey || key;
|
|
526
|
-
const resExactUsedKey = resolved && resolved.exactUsedKey || key;
|
|
527
|
-
const resType = Object.prototype.toString.apply(res);
|
|
528
|
-
const noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
|
|
529
|
-
const joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
|
|
530
|
-
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
531
|
-
const handleAsObject = typeof res !== 'string' && typeof res !== 'boolean' && typeof res !== 'number';
|
|
532
|
-
if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === 'string' && resType === '[object Array]')) {
|
|
533
|
-
if (!options.returnObjects && !this.options.returnObjects) {
|
|
534
|
-
if (!this.options.returnedObjectHandler) {
|
|
535
|
-
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
536
|
-
}
|
|
537
|
-
const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, {
|
|
538
|
-
...options,
|
|
539
|
-
ns: namespaces
|
|
540
|
-
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
541
|
-
if (returnDetails) {
|
|
542
|
-
resolved.res = r;
|
|
543
|
-
return resolved;
|
|
544
|
-
}
|
|
545
|
-
return r;
|
|
546
|
-
}
|
|
547
|
-
if (keySeparator) {
|
|
548
|
-
const resTypeIsArray = resType === '[object Array]';
|
|
549
|
-
const copy = resTypeIsArray ? [] : {};
|
|
550
|
-
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
551
|
-
for (const m in res) {
|
|
552
|
-
if (Object.prototype.hasOwnProperty.call(res, m)) {
|
|
553
|
-
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
554
|
-
copy[m] = this.translate(deepKey, {
|
|
555
|
-
...options,
|
|
556
|
-
...{
|
|
557
|
-
joinArrays: false,
|
|
558
|
-
ns: namespaces
|
|
559
|
-
}
|
|
560
|
-
});
|
|
561
|
-
if (copy[m] === deepKey) copy[m] = res[m];
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
res = copy;
|
|
565
|
-
}
|
|
566
|
-
} else if (handleAsObjectInI18nFormat && typeof joinArrays === 'string' && resType === '[object Array]') {
|
|
567
|
-
res = res.join(joinArrays);
|
|
568
|
-
if (res) res = this.extendTranslation(res, keys, options, lastKey);
|
|
569
|
-
} else {
|
|
570
|
-
let usedDefault = false;
|
|
571
|
-
let usedKey = false;
|
|
572
|
-
const needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
|
|
573
|
-
const hasDefaultValue = Translator.hasDefaultValue(options);
|
|
574
|
-
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : '';
|
|
575
|
-
const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
|
|
576
|
-
ordinal: false
|
|
577
|
-
}) : '';
|
|
578
|
-
const defaultValue = options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
|
|
579
|
-
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
580
|
-
usedDefault = true;
|
|
581
|
-
res = defaultValue;
|
|
582
|
-
}
|
|
583
|
-
if (!this.isValidLookup(res)) {
|
|
584
|
-
usedKey = true;
|
|
585
|
-
res = key;
|
|
586
|
-
}
|
|
587
|
-
const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
588
|
-
const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
|
|
589
|
-
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
590
|
-
if (usedKey || usedDefault || updateMissing) {
|
|
591
|
-
this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
|
|
592
|
-
if (keySeparator) {
|
|
593
|
-
const fk = this.resolve(key, {
|
|
594
|
-
...options,
|
|
595
|
-
keySeparator: false
|
|
596
|
-
});
|
|
597
|
-
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.');
|
|
598
|
-
}
|
|
599
|
-
let lngs = [];
|
|
600
|
-
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
|
|
601
|
-
if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
|
|
602
|
-
for (let i = 0; i < fallbackLngs.length; i++) {
|
|
603
|
-
lngs.push(fallbackLngs[i]);
|
|
604
|
-
}
|
|
605
|
-
} else if (this.options.saveMissingTo === 'all') {
|
|
606
|
-
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
|
|
607
|
-
} else {
|
|
608
|
-
lngs.push(options.lng || this.language);
|
|
609
|
-
}
|
|
610
|
-
const send = (l, k, specificDefaultValue) => {
|
|
611
|
-
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
612
|
-
if (this.options.missingKeyHandler) {
|
|
613
|
-
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
614
|
-
} else if (this.backendConnector && this.backendConnector.saveMissing) {
|
|
615
|
-
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
616
|
-
}
|
|
617
|
-
this.emit('missingKey', l, namespace, k, res);
|
|
618
|
-
};
|
|
619
|
-
if (this.options.saveMissing) {
|
|
620
|
-
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
621
|
-
lngs.forEach(language => {
|
|
622
|
-
this.pluralResolver.getSuffixes(language, options).forEach(suffix => {
|
|
623
|
-
send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
|
|
624
|
-
});
|
|
625
|
-
});
|
|
626
|
-
} else {
|
|
627
|
-
send(lngs, key, defaultValue);
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
res = this.extendTranslation(res, keys, options, resolved, lastKey);
|
|
632
|
-
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
|
|
633
|
-
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
634
|
-
if (this.options.compatibilityAPI !== 'v1') {
|
|
635
|
-
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : undefined);
|
|
636
|
-
} else {
|
|
637
|
-
res = this.options.parseMissingKeyHandler(res);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
if (returnDetails) {
|
|
642
|
-
resolved.res = res;
|
|
643
|
-
return resolved;
|
|
644
|
-
}
|
|
645
|
-
return res;
|
|
646
|
-
}
|
|
647
|
-
extendTranslation(res, key, options, resolved, lastKey) {
|
|
648
|
-
var _this = this;
|
|
649
|
-
if (this.i18nFormat && this.i18nFormat.parse) {
|
|
650
|
-
res = this.i18nFormat.parse(res, {
|
|
651
|
-
...this.options.interpolation.defaultVariables,
|
|
652
|
-
...options
|
|
653
|
-
}, resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
654
|
-
resolved
|
|
655
|
-
});
|
|
656
|
-
} else if (!options.skipInterpolation) {
|
|
657
|
-
if (options.interpolation) this.interpolator.init({
|
|
658
|
-
...options,
|
|
659
|
-
...{
|
|
660
|
-
interpolation: {
|
|
661
|
-
...this.options.interpolation,
|
|
662
|
-
...options.interpolation
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
});
|
|
666
|
-
const skipOnVariables = typeof res === 'string' && (options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
667
|
-
let nestBef;
|
|
668
|
-
if (skipOnVariables) {
|
|
669
|
-
const nb = res.match(this.interpolator.nestingRegexp);
|
|
670
|
-
nestBef = nb && nb.length;
|
|
671
|
-
}
|
|
672
|
-
let data = options.replace && typeof options.replace !== 'string' ? options.replace : options;
|
|
673
|
-
if (this.options.interpolation.defaultVariables) data = {
|
|
674
|
-
...this.options.interpolation.defaultVariables,
|
|
675
|
-
...data
|
|
676
|
-
};
|
|
677
|
-
res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
|
|
678
|
-
if (skipOnVariables) {
|
|
679
|
-
const na = res.match(this.interpolator.nestingRegexp);
|
|
680
|
-
const nestAft = na && na.length;
|
|
681
|
-
if (nestBef < nestAft) options.nest = false;
|
|
682
|
-
}
|
|
683
|
-
if (!options.lng && this.options.compatibilityAPI !== 'v1' && resolved && resolved.res) options.lng = resolved.usedLng;
|
|
684
|
-
if (options.nest !== false) res = this.interpolator.nest(res, function () {
|
|
685
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
686
|
-
args[_key] = arguments[_key];
|
|
687
|
-
}
|
|
688
|
-
if (lastKey && lastKey[0] === args[0] && !options.context) {
|
|
689
|
-
_this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
690
|
-
return null;
|
|
691
|
-
}
|
|
692
|
-
return _this.translate(...args, key);
|
|
693
|
-
}, options);
|
|
694
|
-
if (options.interpolation) this.interpolator.reset();
|
|
695
|
-
}
|
|
696
|
-
const postProcess = options.postProcess || this.options.postProcess;
|
|
697
|
-
const postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess;
|
|
698
|
-
if (res !== undefined && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
|
|
699
|
-
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
700
|
-
i18nResolved: resolved,
|
|
701
|
-
...options
|
|
702
|
-
} : options, this);
|
|
703
|
-
}
|
|
704
|
-
return res;
|
|
705
|
-
}
|
|
706
|
-
resolve(keys) {
|
|
707
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
708
|
-
let found;
|
|
709
|
-
let usedKey;
|
|
710
|
-
let exactUsedKey;
|
|
711
|
-
let usedLng;
|
|
712
|
-
let usedNS;
|
|
713
|
-
if (typeof keys === 'string') keys = [keys];
|
|
714
|
-
keys.forEach(k => {
|
|
715
|
-
if (this.isValidLookup(found)) return;
|
|
716
|
-
const extracted = this.extractFromKey(k, options);
|
|
717
|
-
const key = extracted.key;
|
|
718
|
-
usedKey = key;
|
|
719
|
-
let namespaces = extracted.namespaces;
|
|
720
|
-
if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
|
|
721
|
-
const needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
|
|
722
|
-
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
|
|
723
|
-
const needsContextHandling = options.context !== undefined && (typeof options.context === 'string' || typeof options.context === 'number') && options.context !== '';
|
|
724
|
-
const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
|
|
725
|
-
namespaces.forEach(ns => {
|
|
726
|
-
if (this.isValidLookup(found)) return;
|
|
727
|
-
usedNS = ns;
|
|
728
|
-
if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils && this.utils.hasLoadedNamespace && !this.utils.hasLoadedNamespace(usedNS)) {
|
|
729
|
-
checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
730
|
-
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!!!');
|
|
731
|
-
}
|
|
732
|
-
codes.forEach(code => {
|
|
733
|
-
if (this.isValidLookup(found)) return;
|
|
734
|
-
usedLng = code;
|
|
735
|
-
const finalKeys = [key];
|
|
736
|
-
if (this.i18nFormat && this.i18nFormat.addLookupKeys) {
|
|
737
|
-
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
|
|
738
|
-
} else {
|
|
739
|
-
let pluralSuffix;
|
|
740
|
-
if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
|
|
741
|
-
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
742
|
-
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
743
|
-
if (needsPluralHandling) {
|
|
744
|
-
finalKeys.push(key + pluralSuffix);
|
|
745
|
-
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
746
|
-
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
747
|
-
}
|
|
748
|
-
if (needsZeroSuffixLookup) {
|
|
749
|
-
finalKeys.push(key + zeroSuffix);
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
if (needsContextHandling) {
|
|
753
|
-
const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
|
|
754
|
-
finalKeys.push(contextKey);
|
|
755
|
-
if (needsPluralHandling) {
|
|
756
|
-
finalKeys.push(contextKey + pluralSuffix);
|
|
757
|
-
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
758
|
-
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
759
|
-
}
|
|
760
|
-
if (needsZeroSuffixLookup) {
|
|
761
|
-
finalKeys.push(contextKey + zeroSuffix);
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
let possibleKey;
|
|
767
|
-
while (possibleKey = finalKeys.pop()) {
|
|
768
|
-
if (!this.isValidLookup(found)) {
|
|
769
|
-
exactUsedKey = possibleKey;
|
|
770
|
-
found = this.getResource(code, ns, possibleKey, options);
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
});
|
|
774
|
-
});
|
|
775
|
-
});
|
|
776
|
-
return {
|
|
777
|
-
res: found,
|
|
778
|
-
usedKey,
|
|
779
|
-
exactUsedKey,
|
|
780
|
-
usedLng,
|
|
781
|
-
usedNS
|
|
782
|
-
};
|
|
783
|
-
}
|
|
784
|
-
isValidLookup(res) {
|
|
785
|
-
return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
|
|
786
|
-
}
|
|
787
|
-
getResource(code, ns, key) {
|
|
788
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
789
|
-
if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
790
|
-
return this.resourceStore.getResource(code, ns, key, options);
|
|
791
|
-
}
|
|
792
|
-
static hasDefaultValue(options) {
|
|
793
|
-
const prefix = 'defaultValue';
|
|
794
|
-
for (const option in options) {
|
|
795
|
-
if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
|
|
796
|
-
return true;
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
return false;
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
function capitalize$1(string) {
|
|
804
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
805
|
-
}
|
|
806
|
-
class LanguageUtil {
|
|
807
|
-
constructor(options) {
|
|
808
|
-
this.options = options;
|
|
809
|
-
this.supportedLngs = this.options.supportedLngs || false;
|
|
810
|
-
this.logger = baseLogger.create('languageUtils');
|
|
811
|
-
}
|
|
812
|
-
getScriptPartFromCode(code) {
|
|
813
|
-
code = getCleanedCode(code);
|
|
814
|
-
if (!code || code.indexOf('-') < 0) return null;
|
|
815
|
-
const p = code.split('-');
|
|
816
|
-
if (p.length === 2) return null;
|
|
817
|
-
p.pop();
|
|
818
|
-
if (p[p.length - 1].toLowerCase() === 'x') return null;
|
|
819
|
-
return this.formatLanguageCode(p.join('-'));
|
|
820
|
-
}
|
|
821
|
-
getLanguagePartFromCode(code) {
|
|
822
|
-
code = getCleanedCode(code);
|
|
823
|
-
if (!code || code.indexOf('-') < 0) return code;
|
|
824
|
-
const p = code.split('-');
|
|
825
|
-
return this.formatLanguageCode(p[0]);
|
|
826
|
-
}
|
|
827
|
-
formatLanguageCode(code) {
|
|
828
|
-
if (typeof code === 'string' && code.indexOf('-') > -1) {
|
|
829
|
-
const specialCases = ['hans', 'hant', 'latn', 'cyrl', 'cans', 'mong', 'arab'];
|
|
830
|
-
let p = code.split('-');
|
|
831
|
-
if (this.options.lowerCaseLng) {
|
|
832
|
-
p = p.map(part => part.toLowerCase());
|
|
833
|
-
} else if (p.length === 2) {
|
|
834
|
-
p[0] = p[0].toLowerCase();
|
|
835
|
-
p[1] = p[1].toUpperCase();
|
|
836
|
-
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize$1(p[1].toLowerCase());
|
|
837
|
-
} else if (p.length === 3) {
|
|
838
|
-
p[0] = p[0].toLowerCase();
|
|
839
|
-
if (p[1].length === 2) p[1] = p[1].toUpperCase();
|
|
840
|
-
if (p[0] !== 'sgn' && p[2].length === 2) p[2] = p[2].toUpperCase();
|
|
841
|
-
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize$1(p[1].toLowerCase());
|
|
842
|
-
if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize$1(p[2].toLowerCase());
|
|
843
|
-
}
|
|
844
|
-
return p.join('-');
|
|
845
|
-
}
|
|
846
|
-
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
847
|
-
}
|
|
848
|
-
isSupportedCode(code) {
|
|
849
|
-
if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
|
|
850
|
-
code = this.getLanguagePartFromCode(code);
|
|
851
|
-
}
|
|
852
|
-
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
853
|
-
}
|
|
854
|
-
getBestMatchFromCodes(codes) {
|
|
855
|
-
if (!codes) return null;
|
|
856
|
-
let found;
|
|
857
|
-
codes.forEach(code => {
|
|
858
|
-
if (found) return;
|
|
859
|
-
const cleanedLng = this.formatLanguageCode(code);
|
|
860
|
-
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
861
|
-
});
|
|
862
|
-
if (!found && this.options.supportedLngs) {
|
|
863
|
-
codes.forEach(code => {
|
|
864
|
-
if (found) return;
|
|
865
|
-
const lngOnly = this.getLanguagePartFromCode(code);
|
|
866
|
-
if (this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
867
|
-
found = this.options.supportedLngs.find(supportedLng => {
|
|
868
|
-
if (supportedLng === lngOnly) return supportedLng;
|
|
869
|
-
if (supportedLng.indexOf('-') < 0 && lngOnly.indexOf('-') < 0) return;
|
|
870
|
-
if (supportedLng.indexOf(lngOnly) === 0) return supportedLng;
|
|
871
|
-
});
|
|
872
|
-
});
|
|
873
|
-
}
|
|
874
|
-
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
875
|
-
return found;
|
|
876
|
-
}
|
|
877
|
-
getFallbackCodes(fallbacks, code) {
|
|
878
|
-
if (!fallbacks) return [];
|
|
879
|
-
if (typeof fallbacks === 'function') fallbacks = fallbacks(code);
|
|
880
|
-
if (typeof fallbacks === 'string') fallbacks = [fallbacks];
|
|
881
|
-
if (Object.prototype.toString.apply(fallbacks) === '[object Array]') return fallbacks;
|
|
882
|
-
if (!code) return fallbacks.default || [];
|
|
883
|
-
let found = fallbacks[code];
|
|
884
|
-
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
885
|
-
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
886
|
-
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
887
|
-
if (!found) found = fallbacks.default;
|
|
888
|
-
return found || [];
|
|
889
|
-
}
|
|
890
|
-
toResolveHierarchy(code, fallbackCode) {
|
|
891
|
-
const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
892
|
-
const codes = [];
|
|
893
|
-
const addCode = c => {
|
|
894
|
-
if (!c) return;
|
|
895
|
-
if (this.isSupportedCode(c)) {
|
|
896
|
-
codes.push(c);
|
|
897
|
-
} else {
|
|
898
|
-
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
899
|
-
}
|
|
900
|
-
};
|
|
901
|
-
if (typeof code === 'string' && (code.indexOf('-') > -1 || code.indexOf('_') > -1)) {
|
|
902
|
-
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
|
|
903
|
-
if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
|
|
904
|
-
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
|
|
905
|
-
} else if (typeof code === 'string') {
|
|
906
|
-
addCode(this.formatLanguageCode(code));
|
|
907
|
-
}
|
|
908
|
-
fallbackCodes.forEach(fc => {
|
|
909
|
-
if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
|
|
910
|
-
});
|
|
911
|
-
return codes;
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
let sets = [{
|
|
916
|
-
lngs: ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'gun', 'ln', 'mfe', 'mg', 'mi', 'oc', 'pt', 'pt-BR', 'tg', 'tl', 'ti', 'tr', 'uz', 'wa'],
|
|
917
|
-
nr: [1, 2],
|
|
918
|
-
fc: 1
|
|
919
|
-
}, {
|
|
920
|
-
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'],
|
|
921
|
-
nr: [1, 2],
|
|
922
|
-
fc: 2
|
|
923
|
-
}, {
|
|
924
|
-
lngs: ['ay', 'bo', 'cgg', 'fa', 'ht', 'id', 'ja', 'jbo', 'ka', 'km', 'ko', 'ky', 'lo', 'ms', 'sah', 'su', 'th', 'tt', 'ug', 'vi', 'wo', 'zh'],
|
|
925
|
-
nr: [1],
|
|
926
|
-
fc: 3
|
|
927
|
-
}, {
|
|
928
|
-
lngs: ['be', 'bs', 'cnr', 'dz', 'hr', 'ru', 'sr', 'uk'],
|
|
929
|
-
nr: [1, 2, 5],
|
|
930
|
-
fc: 4
|
|
931
|
-
}, {
|
|
932
|
-
lngs: ['ar'],
|
|
933
|
-
nr: [0, 1, 2, 3, 11, 100],
|
|
934
|
-
fc: 5
|
|
935
|
-
}, {
|
|
936
|
-
lngs: ['cs', 'sk'],
|
|
937
|
-
nr: [1, 2, 5],
|
|
938
|
-
fc: 6
|
|
939
|
-
}, {
|
|
940
|
-
lngs: ['csb', 'pl'],
|
|
941
|
-
nr: [1, 2, 5],
|
|
942
|
-
fc: 7
|
|
943
|
-
}, {
|
|
944
|
-
lngs: ['cy'],
|
|
945
|
-
nr: [1, 2, 3, 8],
|
|
946
|
-
fc: 8
|
|
947
|
-
}, {
|
|
948
|
-
lngs: ['fr'],
|
|
949
|
-
nr: [1, 2],
|
|
950
|
-
fc: 9
|
|
951
|
-
}, {
|
|
952
|
-
lngs: ['ga'],
|
|
953
|
-
nr: [1, 2, 3, 7, 11],
|
|
954
|
-
fc: 10
|
|
955
|
-
}, {
|
|
956
|
-
lngs: ['gd'],
|
|
957
|
-
nr: [1, 2, 3, 20],
|
|
958
|
-
fc: 11
|
|
959
|
-
}, {
|
|
960
|
-
lngs: ['is'],
|
|
961
|
-
nr: [1, 2],
|
|
962
|
-
fc: 12
|
|
963
|
-
}, {
|
|
964
|
-
lngs: ['jv'],
|
|
965
|
-
nr: [0, 1],
|
|
966
|
-
fc: 13
|
|
967
|
-
}, {
|
|
968
|
-
lngs: ['kw'],
|
|
969
|
-
nr: [1, 2, 3, 4],
|
|
970
|
-
fc: 14
|
|
971
|
-
}, {
|
|
972
|
-
lngs: ['lt'],
|
|
973
|
-
nr: [1, 2, 10],
|
|
974
|
-
fc: 15
|
|
975
|
-
}, {
|
|
976
|
-
lngs: ['lv'],
|
|
977
|
-
nr: [1, 2, 0],
|
|
978
|
-
fc: 16
|
|
979
|
-
}, {
|
|
980
|
-
lngs: ['mk'],
|
|
981
|
-
nr: [1, 2],
|
|
982
|
-
fc: 17
|
|
983
|
-
}, {
|
|
984
|
-
lngs: ['mnk'],
|
|
985
|
-
nr: [0, 1, 2],
|
|
986
|
-
fc: 18
|
|
987
|
-
}, {
|
|
988
|
-
lngs: ['mt'],
|
|
989
|
-
nr: [1, 2, 11, 20],
|
|
990
|
-
fc: 19
|
|
991
|
-
}, {
|
|
992
|
-
lngs: ['or'],
|
|
993
|
-
nr: [2, 1],
|
|
994
|
-
fc: 2
|
|
995
|
-
}, {
|
|
996
|
-
lngs: ['ro'],
|
|
997
|
-
nr: [1, 2, 20],
|
|
998
|
-
fc: 20
|
|
999
|
-
}, {
|
|
1000
|
-
lngs: ['sl'],
|
|
1001
|
-
nr: [5, 1, 2, 3],
|
|
1002
|
-
fc: 21
|
|
1003
|
-
}, {
|
|
1004
|
-
lngs: ['he', 'iw'],
|
|
1005
|
-
nr: [1, 2, 20, 21],
|
|
1006
|
-
fc: 22
|
|
1007
|
-
}];
|
|
1008
|
-
let _rulesPluralsTypes = {
|
|
1009
|
-
1: function (n) {
|
|
1010
|
-
return Number(n > 1);
|
|
1011
|
-
},
|
|
1012
|
-
2: function (n) {
|
|
1013
|
-
return Number(n != 1);
|
|
1014
|
-
},
|
|
1015
|
-
3: function (n) {
|
|
1016
|
-
return 0;
|
|
1017
|
-
},
|
|
1018
|
-
4: function (n) {
|
|
1019
|
-
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1020
|
-
},
|
|
1021
|
-
5: function (n) {
|
|
1022
|
-
return Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5);
|
|
1023
|
-
},
|
|
1024
|
-
6: function (n) {
|
|
1025
|
-
return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2);
|
|
1026
|
-
},
|
|
1027
|
-
7: function (n) {
|
|
1028
|
-
return Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1029
|
-
},
|
|
1030
|
-
8: function (n) {
|
|
1031
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3);
|
|
1032
|
-
},
|
|
1033
|
-
9: function (n) {
|
|
1034
|
-
return Number(n >= 2);
|
|
1035
|
-
},
|
|
1036
|
-
10: function (n) {
|
|
1037
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4);
|
|
1038
|
-
},
|
|
1039
|
-
11: function (n) {
|
|
1040
|
-
return Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3);
|
|
1041
|
-
},
|
|
1042
|
-
12: function (n) {
|
|
1043
|
-
return Number(n % 10 != 1 || n % 100 == 11);
|
|
1044
|
-
},
|
|
1045
|
-
13: function (n) {
|
|
1046
|
-
return Number(n !== 0);
|
|
1047
|
-
},
|
|
1048
|
-
14: function (n) {
|
|
1049
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3);
|
|
1050
|
-
},
|
|
1051
|
-
15: function (n) {
|
|
1052
|
-
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1053
|
-
},
|
|
1054
|
-
16: function (n) {
|
|
1055
|
-
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2);
|
|
1056
|
-
},
|
|
1057
|
-
17: function (n) {
|
|
1058
|
-
return Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1);
|
|
1059
|
-
},
|
|
1060
|
-
18: function (n) {
|
|
1061
|
-
return Number(n == 0 ? 0 : n == 1 ? 1 : 2);
|
|
1062
|
-
},
|
|
1063
|
-
19: function (n) {
|
|
1064
|
-
return Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3);
|
|
1065
|
-
},
|
|
1066
|
-
20: function (n) {
|
|
1067
|
-
return Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2);
|
|
1068
|
-
},
|
|
1069
|
-
21: function (n) {
|
|
1070
|
-
return Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0);
|
|
1071
|
-
},
|
|
1072
|
-
22: function (n) {
|
|
1073
|
-
return Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3);
|
|
1074
|
-
}
|
|
1075
|
-
};
|
|
1076
|
-
const nonIntlVersions = ['v1', 'v2', 'v3'];
|
|
1077
|
-
const intlVersions = ['v4'];
|
|
1078
|
-
const suffixesOrder = {
|
|
1079
|
-
zero: 0,
|
|
1080
|
-
one: 1,
|
|
1081
|
-
two: 2,
|
|
1082
|
-
few: 3,
|
|
1083
|
-
many: 4,
|
|
1084
|
-
other: 5
|
|
1085
|
-
};
|
|
1086
|
-
function createRules() {
|
|
1087
|
-
const rules = {};
|
|
1088
|
-
sets.forEach(set => {
|
|
1089
|
-
set.lngs.forEach(l => {
|
|
1090
|
-
rules[l] = {
|
|
1091
|
-
numbers: set.nr,
|
|
1092
|
-
plurals: _rulesPluralsTypes[set.fc]
|
|
1093
|
-
};
|
|
1094
|
-
});
|
|
1095
|
-
});
|
|
1096
|
-
return rules;
|
|
1097
|
-
}
|
|
1098
|
-
class PluralResolver {
|
|
1099
|
-
constructor(languageUtils) {
|
|
1100
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1101
|
-
this.languageUtils = languageUtils;
|
|
1102
|
-
this.options = options;
|
|
1103
|
-
this.logger = baseLogger.create('pluralResolver');
|
|
1104
|
-
if ((!this.options.compatibilityJSON || intlVersions.includes(this.options.compatibilityJSON)) && (typeof Intl === 'undefined' || !Intl.PluralRules)) {
|
|
1105
|
-
this.options.compatibilityJSON = 'v3';
|
|
1106
|
-
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.');
|
|
1107
|
-
}
|
|
1108
|
-
this.rules = createRules();
|
|
1109
|
-
}
|
|
1110
|
-
addRule(lng, obj) {
|
|
1111
|
-
this.rules[lng] = obj;
|
|
1112
|
-
}
|
|
1113
|
-
getRule(code) {
|
|
1114
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1115
|
-
if (this.shouldUseIntlApi()) {
|
|
1116
|
-
try {
|
|
1117
|
-
return new Intl.PluralRules(getCleanedCode(code), {
|
|
1118
|
-
type: options.ordinal ? 'ordinal' : 'cardinal'
|
|
1119
|
-
});
|
|
1120
|
-
} catch {
|
|
1121
|
-
return;
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
|
|
1125
|
-
}
|
|
1126
|
-
needsPlural(code) {
|
|
1127
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1128
|
-
const rule = this.getRule(code, options);
|
|
1129
|
-
if (this.shouldUseIntlApi()) {
|
|
1130
|
-
return rule && rule.resolvedOptions().pluralCategories.length > 1;
|
|
1131
|
-
}
|
|
1132
|
-
return rule && rule.numbers.length > 1;
|
|
1133
|
-
}
|
|
1134
|
-
getPluralFormsOfKey(code, key) {
|
|
1135
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1136
|
-
return this.getSuffixes(code, options).map(suffix => `${key}${suffix}`);
|
|
1137
|
-
}
|
|
1138
|
-
getSuffixes(code) {
|
|
1139
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1140
|
-
const rule = this.getRule(code, options);
|
|
1141
|
-
if (!rule) {
|
|
1142
|
-
return [];
|
|
1143
|
-
}
|
|
1144
|
-
if (this.shouldUseIntlApi()) {
|
|
1145
|
-
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map(pluralCategory => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${pluralCategory}`);
|
|
1146
|
-
}
|
|
1147
|
-
return rule.numbers.map(number => this.getSuffix(code, number, options));
|
|
1148
|
-
}
|
|
1149
|
-
getSuffix(code, count) {
|
|
1150
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1151
|
-
const rule = this.getRule(code, options);
|
|
1152
|
-
if (rule) {
|
|
1153
|
-
if (this.shouldUseIntlApi()) {
|
|
1154
|
-
return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ''}${rule.select(count)}`;
|
|
1155
|
-
}
|
|
1156
|
-
return this.getSuffixRetroCompatible(rule, count);
|
|
1157
|
-
}
|
|
1158
|
-
this.logger.warn(`no plural rule found for: ${code}`);
|
|
1159
|
-
return '';
|
|
1160
|
-
}
|
|
1161
|
-
getSuffixRetroCompatible(rule, count) {
|
|
1162
|
-
const idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
|
|
1163
|
-
let suffix = rule.numbers[idx];
|
|
1164
|
-
if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1165
|
-
if (suffix === 2) {
|
|
1166
|
-
suffix = 'plural';
|
|
1167
|
-
} else if (suffix === 1) {
|
|
1168
|
-
suffix = '';
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
const returnSuffix = () => this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString();
|
|
1172
|
-
if (this.options.compatibilityJSON === 'v1') {
|
|
1173
|
-
if (suffix === 1) return '';
|
|
1174
|
-
if (typeof suffix === 'number') return `_plural_${suffix.toString()}`;
|
|
1175
|
-
return returnSuffix();
|
|
1176
|
-
} else if (this.options.compatibilityJSON === 'v2') {
|
|
1177
|
-
return returnSuffix();
|
|
1178
|
-
} else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1179
|
-
return returnSuffix();
|
|
1180
|
-
}
|
|
1181
|
-
return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
|
|
1182
|
-
}
|
|
1183
|
-
shouldUseIntlApi() {
|
|
1184
|
-
return !nonIntlVersions.includes(this.options.compatibilityJSON);
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
function deepFindWithDefaults(data, defaultData, key) {
|
|
1189
|
-
let keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
|
|
1190
|
-
let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
1191
|
-
let path = getPathWithDefaults(data, defaultData, key);
|
|
1192
|
-
if (!path && ignoreJSONStructure && typeof key === 'string') {
|
|
1193
|
-
path = deepFind(data, key, keySeparator);
|
|
1194
|
-
if (path === undefined) path = deepFind(defaultData, key, keySeparator);
|
|
1195
|
-
}
|
|
1196
|
-
return path;
|
|
1197
|
-
}
|
|
1198
|
-
class Interpolator {
|
|
1199
|
-
constructor() {
|
|
1200
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1201
|
-
this.logger = baseLogger.create('interpolator');
|
|
1202
|
-
this.options = options;
|
|
1203
|
-
this.format = options.interpolation && options.interpolation.format || (value => value);
|
|
1204
|
-
this.init(options);
|
|
1205
|
-
}
|
|
1206
|
-
init() {
|
|
1207
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1208
|
-
if (!options.interpolation) options.interpolation = {
|
|
1209
|
-
escapeValue: true
|
|
1210
|
-
};
|
|
1211
|
-
const iOpts = options.interpolation;
|
|
1212
|
-
this.escape = iOpts.escape !== undefined ? iOpts.escape : escape;
|
|
1213
|
-
this.escapeValue = iOpts.escapeValue !== undefined ? iOpts.escapeValue : true;
|
|
1214
|
-
this.useRawValueToEscape = iOpts.useRawValueToEscape !== undefined ? iOpts.useRawValueToEscape : false;
|
|
1215
|
-
this.prefix = iOpts.prefix ? regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{';
|
|
1216
|
-
this.suffix = iOpts.suffix ? regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}';
|
|
1217
|
-
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
|
|
1218
|
-
this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-';
|
|
1219
|
-
this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || '';
|
|
1220
|
-
this.nestingPrefix = iOpts.nestingPrefix ? regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || regexEscape('$t(');
|
|
1221
|
-
this.nestingSuffix = iOpts.nestingSuffix ? regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || regexEscape(')');
|
|
1222
|
-
this.nestingOptionsSeparator = iOpts.nestingOptionsSeparator ? iOpts.nestingOptionsSeparator : iOpts.nestingOptionsSeparator || ',';
|
|
1223
|
-
this.maxReplaces = iOpts.maxReplaces ? iOpts.maxReplaces : 1000;
|
|
1224
|
-
this.alwaysFormat = iOpts.alwaysFormat !== undefined ? iOpts.alwaysFormat : false;
|
|
1225
|
-
this.resetRegExp();
|
|
1226
|
-
}
|
|
1227
|
-
reset() {
|
|
1228
|
-
if (this.options) this.init(this.options);
|
|
1229
|
-
}
|
|
1230
|
-
resetRegExp() {
|
|
1231
|
-
const regexpStr = `${this.prefix}(.+?)${this.suffix}`;
|
|
1232
|
-
this.regexp = new RegExp(regexpStr, 'g');
|
|
1233
|
-
const regexpUnescapeStr = `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`;
|
|
1234
|
-
this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g');
|
|
1235
|
-
const nestingRegexpStr = `${this.nestingPrefix}(.+?)${this.nestingSuffix}`;
|
|
1236
|
-
this.nestingRegexp = new RegExp(nestingRegexpStr, 'g');
|
|
1237
|
-
}
|
|
1238
|
-
interpolate(str, data, lng, options) {
|
|
1239
|
-
let match;
|
|
1240
|
-
let value;
|
|
1241
|
-
let replaces;
|
|
1242
|
-
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
1243
|
-
function regexSafe(val) {
|
|
1244
|
-
return val.replace(/\$/g, '$$$$');
|
|
1245
|
-
}
|
|
1246
|
-
const handleFormat = key => {
|
|
1247
|
-
if (key.indexOf(this.formatSeparator) < 0) {
|
|
1248
|
-
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
1249
|
-
return this.alwaysFormat ? this.format(path, undefined, lng, {
|
|
1250
|
-
...options,
|
|
1251
|
-
...data,
|
|
1252
|
-
interpolationkey: key
|
|
1253
|
-
}) : path;
|
|
1254
|
-
}
|
|
1255
|
-
const p = key.split(this.formatSeparator);
|
|
1256
|
-
const k = p.shift().trim();
|
|
1257
|
-
const f = p.join(this.formatSeparator).trim();
|
|
1258
|
-
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
|
|
1259
|
-
...options,
|
|
1260
|
-
...data,
|
|
1261
|
-
interpolationkey: k
|
|
1262
|
-
});
|
|
1263
|
-
};
|
|
1264
|
-
this.resetRegExp();
|
|
1265
|
-
const missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
1266
|
-
const skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
1267
|
-
const todos = [{
|
|
1268
|
-
regex: this.regexpUnescape,
|
|
1269
|
-
safeValue: val => regexSafe(val)
|
|
1270
|
-
}, {
|
|
1271
|
-
regex: this.regexp,
|
|
1272
|
-
safeValue: val => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
|
|
1273
|
-
}];
|
|
1274
|
-
todos.forEach(todo => {
|
|
1275
|
-
replaces = 0;
|
|
1276
|
-
while (match = todo.regex.exec(str)) {
|
|
1277
|
-
const matchedVar = match[1].trim();
|
|
1278
|
-
value = handleFormat(matchedVar);
|
|
1279
|
-
if (value === undefined) {
|
|
1280
|
-
if (typeof missingInterpolationHandler === 'function') {
|
|
1281
|
-
const temp = missingInterpolationHandler(str, match, options);
|
|
1282
|
-
value = typeof temp === 'string' ? temp : '';
|
|
1283
|
-
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
|
|
1284
|
-
value = '';
|
|
1285
|
-
} else if (skipOnVariables) {
|
|
1286
|
-
value = match[0];
|
|
1287
|
-
continue;
|
|
1288
|
-
} else {
|
|
1289
|
-
this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
|
|
1290
|
-
value = '';
|
|
1291
|
-
}
|
|
1292
|
-
} else if (typeof value !== 'string' && !this.useRawValueToEscape) {
|
|
1293
|
-
value = makeString(value);
|
|
1294
|
-
}
|
|
1295
|
-
const safeValue = todo.safeValue(value);
|
|
1296
|
-
str = str.replace(match[0], safeValue);
|
|
1297
|
-
if (skipOnVariables) {
|
|
1298
|
-
todo.regex.lastIndex += value.length;
|
|
1299
|
-
todo.regex.lastIndex -= match[0].length;
|
|
1300
|
-
} else {
|
|
1301
|
-
todo.regex.lastIndex = 0;
|
|
1302
|
-
}
|
|
1303
|
-
replaces++;
|
|
1304
|
-
if (replaces >= this.maxReplaces) {
|
|
1305
|
-
break;
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
});
|
|
1309
|
-
return str;
|
|
1310
|
-
}
|
|
1311
|
-
nest(str, fc) {
|
|
1312
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1313
|
-
let match;
|
|
1314
|
-
let value;
|
|
1315
|
-
let clonedOptions;
|
|
1316
|
-
function handleHasOptions(key, inheritedOptions) {
|
|
1317
|
-
const sep = this.nestingOptionsSeparator;
|
|
1318
|
-
if (key.indexOf(sep) < 0) return key;
|
|
1319
|
-
const c = key.split(new RegExp(`${sep}[ ]*{`));
|
|
1320
|
-
let optionsString = `{${c[1]}`;
|
|
1321
|
-
key = c[0];
|
|
1322
|
-
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
1323
|
-
const matchedSingleQuotes = optionsString.match(/'/g);
|
|
1324
|
-
const matchedDoubleQuotes = optionsString.match(/"/g);
|
|
1325
|
-
if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
|
|
1326
|
-
optionsString = optionsString.replace(/'/g, '"');
|
|
1327
|
-
}
|
|
1328
|
-
try {
|
|
1329
|
-
clonedOptions = JSON.parse(optionsString);
|
|
1330
|
-
if (inheritedOptions) clonedOptions = {
|
|
1331
|
-
...inheritedOptions,
|
|
1332
|
-
...clonedOptions
|
|
1333
|
-
};
|
|
1334
|
-
} catch (e) {
|
|
1335
|
-
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
1336
|
-
return `${key}${sep}${optionsString}`;
|
|
1337
|
-
}
|
|
1338
|
-
delete clonedOptions.defaultValue;
|
|
1339
|
-
return key;
|
|
1340
|
-
}
|
|
1341
|
-
while (match = this.nestingRegexp.exec(str)) {
|
|
1342
|
-
let formatters = [];
|
|
1343
|
-
clonedOptions = {
|
|
1344
|
-
...options
|
|
1345
|
-
};
|
|
1346
|
-
clonedOptions = clonedOptions.replace && typeof clonedOptions.replace !== 'string' ? clonedOptions.replace : clonedOptions;
|
|
1347
|
-
clonedOptions.applyPostProcessor = false;
|
|
1348
|
-
delete clonedOptions.defaultValue;
|
|
1349
|
-
let doReduce = false;
|
|
1350
|
-
if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
|
|
1351
|
-
const r = match[1].split(this.formatSeparator).map(elem => elem.trim());
|
|
1352
|
-
match[1] = r.shift();
|
|
1353
|
-
formatters = r;
|
|
1354
|
-
doReduce = true;
|
|
1355
|
-
}
|
|
1356
|
-
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
1357
|
-
if (value && match[0] === str && typeof value !== 'string') return value;
|
|
1358
|
-
if (typeof value !== 'string') value = makeString(value);
|
|
1359
|
-
if (!value) {
|
|
1360
|
-
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
1361
|
-
value = '';
|
|
1362
|
-
}
|
|
1363
|
-
if (doReduce) {
|
|
1364
|
-
value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
1365
|
-
...options,
|
|
1366
|
-
interpolationkey: match[1].trim()
|
|
1367
|
-
}), value.trim());
|
|
1368
|
-
}
|
|
1369
|
-
str = str.replace(match[0], value);
|
|
1370
|
-
this.regexp.lastIndex = 0;
|
|
1371
|
-
}
|
|
1372
|
-
return str;
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
|
-
function parseFormatStr(formatStr) {
|
|
1377
|
-
let formatName = formatStr.toLowerCase().trim();
|
|
1378
|
-
const formatOptions = {};
|
|
1379
|
-
if (formatStr.indexOf('(') > -1) {
|
|
1380
|
-
const p = formatStr.split('(');
|
|
1381
|
-
formatName = p[0].toLowerCase().trim();
|
|
1382
|
-
const optStr = p[1].substring(0, p[1].length - 1);
|
|
1383
|
-
if (formatName === 'currency' && optStr.indexOf(':') < 0) {
|
|
1384
|
-
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
1385
|
-
} else if (formatName === 'relativetime' && optStr.indexOf(':') < 0) {
|
|
1386
|
-
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
1387
|
-
} else {
|
|
1388
|
-
const opts = optStr.split(';');
|
|
1389
|
-
opts.forEach(opt => {
|
|
1390
|
-
if (!opt) return;
|
|
1391
|
-
const [key, ...rest] = opt.split(':');
|
|
1392
|
-
const val = rest.join(':').trim().replace(/^'+|'+$/g, '');
|
|
1393
|
-
if (!formatOptions[key.trim()]) formatOptions[key.trim()] = val;
|
|
1394
|
-
if (val === 'false') formatOptions[key.trim()] = false;
|
|
1395
|
-
if (val === 'true') formatOptions[key.trim()] = true;
|
|
1396
|
-
if (!isNaN(val)) formatOptions[key.trim()] = parseInt(val, 10);
|
|
1397
|
-
});
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
return {
|
|
1401
|
-
formatName,
|
|
1402
|
-
formatOptions
|
|
1403
|
-
};
|
|
1404
|
-
}
|
|
1405
|
-
function createCachedFormatter(fn) {
|
|
1406
|
-
const cache = {};
|
|
1407
|
-
return function invokeFormatter(val, lng, options) {
|
|
1408
|
-
const key = lng + JSON.stringify(options);
|
|
1409
|
-
let formatter = cache[key];
|
|
1410
|
-
if (!formatter) {
|
|
1411
|
-
formatter = fn(getCleanedCode(lng), options);
|
|
1412
|
-
cache[key] = formatter;
|
|
1413
|
-
}
|
|
1414
|
-
return formatter(val);
|
|
1415
|
-
};
|
|
1416
|
-
}
|
|
1417
|
-
class Formatter {
|
|
1418
|
-
constructor() {
|
|
1419
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1420
|
-
this.logger = baseLogger.create('formatter');
|
|
1421
|
-
this.options = options;
|
|
1422
|
-
this.formats = {
|
|
1423
|
-
number: createCachedFormatter((lng, opt) => {
|
|
1424
|
-
const formatter = new Intl.NumberFormat(lng, {
|
|
1425
|
-
...opt
|
|
1426
|
-
});
|
|
1427
|
-
return val => formatter.format(val);
|
|
1428
|
-
}),
|
|
1429
|
-
currency: createCachedFormatter((lng, opt) => {
|
|
1430
|
-
const formatter = new Intl.NumberFormat(lng, {
|
|
1431
|
-
...opt,
|
|
1432
|
-
style: 'currency'
|
|
1433
|
-
});
|
|
1434
|
-
return val => formatter.format(val);
|
|
1435
|
-
}),
|
|
1436
|
-
datetime: createCachedFormatter((lng, opt) => {
|
|
1437
|
-
const formatter = new Intl.DateTimeFormat(lng, {
|
|
1438
|
-
...opt
|
|
1439
|
-
});
|
|
1440
|
-
return val => formatter.format(val);
|
|
1441
|
-
}),
|
|
1442
|
-
relativetime: createCachedFormatter((lng, opt) => {
|
|
1443
|
-
const formatter = new Intl.RelativeTimeFormat(lng, {
|
|
1444
|
-
...opt
|
|
1445
|
-
});
|
|
1446
|
-
return val => formatter.format(val, opt.range || 'day');
|
|
1447
|
-
}),
|
|
1448
|
-
list: createCachedFormatter((lng, opt) => {
|
|
1449
|
-
const formatter = new Intl.ListFormat(lng, {
|
|
1450
|
-
...opt
|
|
1451
|
-
});
|
|
1452
|
-
return val => formatter.format(val);
|
|
1453
|
-
})
|
|
1454
|
-
};
|
|
1455
|
-
this.init(options);
|
|
1456
|
-
}
|
|
1457
|
-
init(services) {
|
|
1458
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
1459
|
-
interpolation: {}
|
|
1460
|
-
};
|
|
1461
|
-
const iOpts = options.interpolation;
|
|
1462
|
-
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
|
|
1463
|
-
}
|
|
1464
|
-
add(name, fc) {
|
|
1465
|
-
this.formats[name.toLowerCase().trim()] = fc;
|
|
1466
|
-
}
|
|
1467
|
-
addCached(name, fc) {
|
|
1468
|
-
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
1469
|
-
}
|
|
1470
|
-
format(value, format, lng) {
|
|
1471
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1472
|
-
const formats = format.split(this.formatSeparator);
|
|
1473
|
-
const result = formats.reduce((mem, f) => {
|
|
1474
|
-
const {
|
|
1475
|
-
formatName,
|
|
1476
|
-
formatOptions
|
|
1477
|
-
} = parseFormatStr(f);
|
|
1478
|
-
if (this.formats[formatName]) {
|
|
1479
|
-
let formatted = mem;
|
|
1480
|
-
try {
|
|
1481
|
-
const valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
|
|
1482
|
-
const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
1483
|
-
formatted = this.formats[formatName](mem, l, {
|
|
1484
|
-
...formatOptions,
|
|
1485
|
-
...options,
|
|
1486
|
-
...valOptions
|
|
1487
|
-
});
|
|
1488
|
-
} catch (error) {
|
|
1489
|
-
this.logger.warn(error);
|
|
1490
|
-
}
|
|
1491
|
-
return formatted;
|
|
1492
|
-
} else {
|
|
1493
|
-
this.logger.warn(`there was no format function for ${formatName}`);
|
|
1494
|
-
}
|
|
1495
|
-
return mem;
|
|
1496
|
-
}, value);
|
|
1497
|
-
return result;
|
|
1498
|
-
}
|
|
1499
|
-
}
|
|
1500
|
-
|
|
1501
|
-
function removePending(q, name) {
|
|
1502
|
-
if (q.pending[name] !== undefined) {
|
|
1503
|
-
delete q.pending[name];
|
|
1504
|
-
q.pendingCount--;
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
class Connector extends EventEmitter {
|
|
1508
|
-
constructor(backend, store, services) {
|
|
1509
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1510
|
-
super();
|
|
1511
|
-
this.backend = backend;
|
|
1512
|
-
this.store = store;
|
|
1513
|
-
this.services = services;
|
|
1514
|
-
this.languageUtils = services.languageUtils;
|
|
1515
|
-
this.options = options;
|
|
1516
|
-
this.logger = baseLogger.create('backendConnector');
|
|
1517
|
-
this.waitingReads = [];
|
|
1518
|
-
this.maxParallelReads = options.maxParallelReads || 10;
|
|
1519
|
-
this.readingCalls = 0;
|
|
1520
|
-
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
1521
|
-
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
1522
|
-
this.state = {};
|
|
1523
|
-
this.queue = [];
|
|
1524
|
-
if (this.backend && this.backend.init) {
|
|
1525
|
-
this.backend.init(services, options.backend, options);
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
queueLoad(languages, namespaces, options, callback) {
|
|
1529
|
-
const toLoad = {};
|
|
1530
|
-
const pending = {};
|
|
1531
|
-
const toLoadLanguages = {};
|
|
1532
|
-
const toLoadNamespaces = {};
|
|
1533
|
-
languages.forEach(lng => {
|
|
1534
|
-
let hasAllNamespaces = true;
|
|
1535
|
-
namespaces.forEach(ns => {
|
|
1536
|
-
const name = `${lng}|${ns}`;
|
|
1537
|
-
if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
|
|
1538
|
-
this.state[name] = 2;
|
|
1539
|
-
} else if (this.state[name] < 0) ; else if (this.state[name] === 1) {
|
|
1540
|
-
if (pending[name] === undefined) pending[name] = true;
|
|
1541
|
-
} else {
|
|
1542
|
-
this.state[name] = 1;
|
|
1543
|
-
hasAllNamespaces = false;
|
|
1544
|
-
if (pending[name] === undefined) pending[name] = true;
|
|
1545
|
-
if (toLoad[name] === undefined) toLoad[name] = true;
|
|
1546
|
-
if (toLoadNamespaces[ns] === undefined) toLoadNamespaces[ns] = true;
|
|
1547
|
-
}
|
|
1548
|
-
});
|
|
1549
|
-
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
1550
|
-
});
|
|
1551
|
-
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
1552
|
-
this.queue.push({
|
|
1553
|
-
pending,
|
|
1554
|
-
pendingCount: Object.keys(pending).length,
|
|
1555
|
-
loaded: {},
|
|
1556
|
-
errors: [],
|
|
1557
|
-
callback
|
|
1558
|
-
});
|
|
1559
|
-
}
|
|
1560
|
-
return {
|
|
1561
|
-
toLoad: Object.keys(toLoad),
|
|
1562
|
-
pending: Object.keys(pending),
|
|
1563
|
-
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
1564
|
-
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
1565
|
-
};
|
|
1566
|
-
}
|
|
1567
|
-
loaded(name, err, data) {
|
|
1568
|
-
const s = name.split('|');
|
|
1569
|
-
const lng = s[0];
|
|
1570
|
-
const ns = s[1];
|
|
1571
|
-
if (err) this.emit('failedLoading', lng, ns, err);
|
|
1572
|
-
if (data) {
|
|
1573
|
-
this.store.addResourceBundle(lng, ns, data);
|
|
1574
|
-
}
|
|
1575
|
-
this.state[name] = err ? -1 : 2;
|
|
1576
|
-
const loaded = {};
|
|
1577
|
-
this.queue.forEach(q => {
|
|
1578
|
-
pushPath(q.loaded, [lng], ns);
|
|
1579
|
-
removePending(q, name);
|
|
1580
|
-
if (err) q.errors.push(err);
|
|
1581
|
-
if (q.pendingCount === 0 && !q.done) {
|
|
1582
|
-
Object.keys(q.loaded).forEach(l => {
|
|
1583
|
-
if (!loaded[l]) loaded[l] = {};
|
|
1584
|
-
const loadedKeys = q.loaded[l];
|
|
1585
|
-
if (loadedKeys.length) {
|
|
1586
|
-
loadedKeys.forEach(n => {
|
|
1587
|
-
if (loaded[l][n] === undefined) loaded[l][n] = true;
|
|
1588
|
-
});
|
|
1589
|
-
}
|
|
1590
|
-
});
|
|
1591
|
-
q.done = true;
|
|
1592
|
-
if (q.errors.length) {
|
|
1593
|
-
q.callback(q.errors);
|
|
1594
|
-
} else {
|
|
1595
|
-
q.callback();
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
});
|
|
1599
|
-
this.emit('loaded', loaded);
|
|
1600
|
-
this.queue = this.queue.filter(q => !q.done);
|
|
1601
|
-
}
|
|
1602
|
-
read(lng, ns, fcName) {
|
|
1603
|
-
let tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
1604
|
-
let wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
|
|
1605
|
-
let callback = arguments.length > 5 ? arguments[5] : undefined;
|
|
1606
|
-
if (!lng.length) return callback(null, {});
|
|
1607
|
-
if (this.readingCalls >= this.maxParallelReads) {
|
|
1608
|
-
this.waitingReads.push({
|
|
1609
|
-
lng,
|
|
1610
|
-
ns,
|
|
1611
|
-
fcName,
|
|
1612
|
-
tried,
|
|
1613
|
-
wait,
|
|
1614
|
-
callback
|
|
1615
|
-
});
|
|
1616
|
-
return;
|
|
1617
|
-
}
|
|
1618
|
-
this.readingCalls++;
|
|
1619
|
-
const resolver = (err, data) => {
|
|
1620
|
-
this.readingCalls--;
|
|
1621
|
-
if (this.waitingReads.length > 0) {
|
|
1622
|
-
const next = this.waitingReads.shift();
|
|
1623
|
-
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
1624
|
-
}
|
|
1625
|
-
if (err && data && tried < this.maxRetries) {
|
|
1626
|
-
setTimeout(() => {
|
|
1627
|
-
this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
1628
|
-
}, wait);
|
|
1629
|
-
return;
|
|
1630
|
-
}
|
|
1631
|
-
callback(err, data);
|
|
1632
|
-
};
|
|
1633
|
-
const fc = this.backend[fcName].bind(this.backend);
|
|
1634
|
-
if (fc.length === 2) {
|
|
1635
|
-
try {
|
|
1636
|
-
const r = fc(lng, ns);
|
|
1637
|
-
if (r && typeof r.then === 'function') {
|
|
1638
|
-
r.then(data => resolver(null, data)).catch(resolver);
|
|
1639
|
-
} else {
|
|
1640
|
-
resolver(null, r);
|
|
1641
|
-
}
|
|
1642
|
-
} catch (err) {
|
|
1643
|
-
resolver(err);
|
|
1644
|
-
}
|
|
1645
|
-
return;
|
|
1646
|
-
}
|
|
1647
|
-
return fc(lng, ns, resolver);
|
|
1648
|
-
}
|
|
1649
|
-
prepareLoading(languages, namespaces) {
|
|
1650
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1651
|
-
let callback = arguments.length > 3 ? arguments[3] : undefined;
|
|
1652
|
-
if (!this.backend) {
|
|
1653
|
-
this.logger.warn('No backend was added via i18next.use. Will not load resources.');
|
|
1654
|
-
return callback && callback();
|
|
1655
|
-
}
|
|
1656
|
-
if (typeof languages === 'string') languages = this.languageUtils.toResolveHierarchy(languages);
|
|
1657
|
-
if (typeof namespaces === 'string') namespaces = [namespaces];
|
|
1658
|
-
const toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
1659
|
-
if (!toLoad.toLoad.length) {
|
|
1660
|
-
if (!toLoad.pending.length) callback();
|
|
1661
|
-
return null;
|
|
1662
|
-
}
|
|
1663
|
-
toLoad.toLoad.forEach(name => {
|
|
1664
|
-
this.loadOne(name);
|
|
1665
|
-
});
|
|
1666
|
-
}
|
|
1667
|
-
load(languages, namespaces, callback) {
|
|
1668
|
-
this.prepareLoading(languages, namespaces, {}, callback);
|
|
1669
|
-
}
|
|
1670
|
-
reload(languages, namespaces, callback) {
|
|
1671
|
-
this.prepareLoading(languages, namespaces, {
|
|
1672
|
-
reload: true
|
|
1673
|
-
}, callback);
|
|
1674
|
-
}
|
|
1675
|
-
loadOne(name) {
|
|
1676
|
-
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
1677
|
-
const s = name.split('|');
|
|
1678
|
-
const lng = s[0];
|
|
1679
|
-
const ns = s[1];
|
|
1680
|
-
this.read(lng, ns, 'read', undefined, undefined, (err, data) => {
|
|
1681
|
-
if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
1682
|
-
if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
1683
|
-
this.loaded(name, err, data);
|
|
1684
|
-
});
|
|
1685
|
-
}
|
|
1686
|
-
saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
1687
|
-
let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
1688
|
-
let clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : () => {};
|
|
1689
|
-
if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
|
|
1690
|
-
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!!!');
|
|
1691
|
-
return;
|
|
1692
|
-
}
|
|
1693
|
-
if (key === undefined || key === null || key === '') return;
|
|
1694
|
-
if (this.backend && this.backend.create) {
|
|
1695
|
-
const opts = {
|
|
1696
|
-
...options,
|
|
1697
|
-
isUpdate
|
|
1698
|
-
};
|
|
1699
|
-
const fc = this.backend.create.bind(this.backend);
|
|
1700
|
-
if (fc.length < 6) {
|
|
1701
|
-
try {
|
|
1702
|
-
let r;
|
|
1703
|
-
if (fc.length === 5) {
|
|
1704
|
-
r = fc(languages, namespace, key, fallbackValue, opts);
|
|
1705
|
-
} else {
|
|
1706
|
-
r = fc(languages, namespace, key, fallbackValue);
|
|
1707
|
-
}
|
|
1708
|
-
if (r && typeof r.then === 'function') {
|
|
1709
|
-
r.then(data => clb(null, data)).catch(clb);
|
|
1710
|
-
} else {
|
|
1711
|
-
clb(null, r);
|
|
1712
|
-
}
|
|
1713
|
-
} catch (err) {
|
|
1714
|
-
clb(err);
|
|
1715
|
-
}
|
|
1716
|
-
} else {
|
|
1717
|
-
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
if (!languages || !languages[0]) return;
|
|
1721
|
-
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
|
-
|
|
1725
|
-
function get() {
|
|
1726
|
-
return {
|
|
1727
|
-
debug: false,
|
|
1728
|
-
initImmediate: true,
|
|
1729
|
-
ns: ['translation'],
|
|
1730
|
-
defaultNS: ['translation'],
|
|
1731
|
-
fallbackLng: ['dev'],
|
|
1732
|
-
fallbackNS: false,
|
|
1733
|
-
supportedLngs: false,
|
|
1734
|
-
nonExplicitSupportedLngs: false,
|
|
1735
|
-
load: 'all',
|
|
1736
|
-
preload: false,
|
|
1737
|
-
simplifyPluralSuffix: true,
|
|
1738
|
-
keySeparator: '.',
|
|
1739
|
-
nsSeparator: ':',
|
|
1740
|
-
pluralSeparator: '_',
|
|
1741
|
-
contextSeparator: '_',
|
|
1742
|
-
partialBundledLanguages: false,
|
|
1743
|
-
saveMissing: false,
|
|
1744
|
-
updateMissing: false,
|
|
1745
|
-
saveMissingTo: 'fallback',
|
|
1746
|
-
saveMissingPlurals: true,
|
|
1747
|
-
missingKeyHandler: false,
|
|
1748
|
-
missingInterpolationHandler: false,
|
|
1749
|
-
postProcess: false,
|
|
1750
|
-
postProcessPassResolved: false,
|
|
1751
|
-
returnNull: false,
|
|
1752
|
-
returnEmptyString: true,
|
|
1753
|
-
returnObjects: false,
|
|
1754
|
-
joinArrays: false,
|
|
1755
|
-
returnedObjectHandler: false,
|
|
1756
|
-
parseMissingKeyHandler: false,
|
|
1757
|
-
appendNamespaceToMissingKey: false,
|
|
1758
|
-
appendNamespaceToCIMode: false,
|
|
1759
|
-
overloadTranslationOptionHandler: function handle(args) {
|
|
1760
|
-
let ret = {};
|
|
1761
|
-
if (typeof args[1] === 'object') ret = args[1];
|
|
1762
|
-
if (typeof args[1] === 'string') ret.defaultValue = args[1];
|
|
1763
|
-
if (typeof args[2] === 'string') ret.tDescription = args[2];
|
|
1764
|
-
if (typeof args[2] === 'object' || typeof args[3] === 'object') {
|
|
1765
|
-
const options = args[3] || args[2];
|
|
1766
|
-
Object.keys(options).forEach(key => {
|
|
1767
|
-
ret[key] = options[key];
|
|
1768
|
-
});
|
|
1769
|
-
}
|
|
1770
|
-
return ret;
|
|
1771
|
-
},
|
|
1772
|
-
interpolation: {
|
|
1773
|
-
escapeValue: true,
|
|
1774
|
-
format: (value, format, lng, options) => value,
|
|
1775
|
-
prefix: '{{',
|
|
1776
|
-
suffix: '}}',
|
|
1777
|
-
formatSeparator: ',',
|
|
1778
|
-
unescapePrefix: '-',
|
|
1779
|
-
nestingPrefix: '$t(',
|
|
1780
|
-
nestingSuffix: ')',
|
|
1781
|
-
nestingOptionsSeparator: ',',
|
|
1782
|
-
maxReplaces: 1000,
|
|
1783
|
-
skipOnVariables: true
|
|
1784
|
-
}
|
|
1785
|
-
};
|
|
1786
|
-
}
|
|
1787
|
-
function transformOptions(options) {
|
|
1788
|
-
if (typeof options.ns === 'string') options.ns = [options.ns];
|
|
1789
|
-
if (typeof options.fallbackLng === 'string') options.fallbackLng = [options.fallbackLng];
|
|
1790
|
-
if (typeof options.fallbackNS === 'string') options.fallbackNS = [options.fallbackNS];
|
|
1791
|
-
if (options.supportedLngs && options.supportedLngs.indexOf('cimode') < 0) {
|
|
1792
|
-
options.supportedLngs = options.supportedLngs.concat(['cimode']);
|
|
1793
|
-
}
|
|
1794
|
-
return options;
|
|
1795
|
-
}
|
|
1796
|
-
|
|
1797
|
-
function noop$2() {}
|
|
1798
|
-
function bindMemberFunctions(inst) {
|
|
1799
|
-
const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
1800
|
-
mems.forEach(mem => {
|
|
1801
|
-
if (typeof inst[mem] === 'function') {
|
|
1802
|
-
inst[mem] = inst[mem].bind(inst);
|
|
1803
|
-
}
|
|
1804
|
-
});
|
|
1805
|
-
}
|
|
1806
|
-
class I18n extends EventEmitter {
|
|
1807
|
-
constructor() {
|
|
1808
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1809
|
-
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
1810
|
-
super();
|
|
1811
|
-
this.options = transformOptions(options);
|
|
1812
|
-
this.services = {};
|
|
1813
|
-
this.logger = baseLogger;
|
|
1814
|
-
this.modules = {
|
|
1815
|
-
external: []
|
|
1816
|
-
};
|
|
1817
|
-
bindMemberFunctions(this);
|
|
1818
|
-
if (callback && !this.isInitialized && !options.isClone) {
|
|
1819
|
-
if (!this.options.initImmediate) {
|
|
1820
|
-
this.init(options, callback);
|
|
1821
|
-
return this;
|
|
1822
|
-
}
|
|
1823
|
-
setTimeout(() => {
|
|
1824
|
-
this.init(options, callback);
|
|
1825
|
-
}, 0);
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
init() {
|
|
1829
|
-
var _this = this;
|
|
1830
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1831
|
-
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
1832
|
-
if (typeof options === 'function') {
|
|
1833
|
-
callback = options;
|
|
1834
|
-
options = {};
|
|
1835
|
-
}
|
|
1836
|
-
if (!options.defaultNS && options.defaultNS !== false && options.ns) {
|
|
1837
|
-
if (typeof options.ns === 'string') {
|
|
1838
|
-
options.defaultNS = options.ns;
|
|
1839
|
-
} else if (options.ns.indexOf('translation') < 0) {
|
|
1840
|
-
options.defaultNS = options.ns[0];
|
|
1841
|
-
}
|
|
1842
|
-
}
|
|
1843
|
-
const defOpts = get();
|
|
1844
|
-
this.options = {
|
|
1845
|
-
...defOpts,
|
|
1846
|
-
...this.options,
|
|
1847
|
-
...transformOptions(options)
|
|
1848
|
-
};
|
|
1849
|
-
if (this.options.compatibilityAPI !== 'v1') {
|
|
1850
|
-
this.options.interpolation = {
|
|
1851
|
-
...defOpts.interpolation,
|
|
1852
|
-
...this.options.interpolation
|
|
1853
|
-
};
|
|
1854
|
-
}
|
|
1855
|
-
if (options.keySeparator !== undefined) {
|
|
1856
|
-
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
1857
|
-
}
|
|
1858
|
-
if (options.nsSeparator !== undefined) {
|
|
1859
|
-
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
1860
|
-
}
|
|
1861
|
-
function createClassOnDemand(ClassOrObject) {
|
|
1862
|
-
if (!ClassOrObject) return null;
|
|
1863
|
-
if (typeof ClassOrObject === 'function') return new ClassOrObject();
|
|
1864
|
-
return ClassOrObject;
|
|
1865
|
-
}
|
|
1866
|
-
if (!this.options.isClone) {
|
|
1867
|
-
if (this.modules.logger) {
|
|
1868
|
-
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
1869
|
-
} else {
|
|
1870
|
-
baseLogger.init(null, this.options);
|
|
1871
|
-
}
|
|
1872
|
-
let formatter;
|
|
1873
|
-
if (this.modules.formatter) {
|
|
1874
|
-
formatter = this.modules.formatter;
|
|
1875
|
-
} else if (typeof Intl !== 'undefined') {
|
|
1876
|
-
formatter = Formatter;
|
|
1877
|
-
}
|
|
1878
|
-
const lu = new LanguageUtil(this.options);
|
|
1879
|
-
this.store = new ResourceStore(this.options.resources, this.options);
|
|
1880
|
-
const s = this.services;
|
|
1881
|
-
s.logger = baseLogger;
|
|
1882
|
-
s.resourceStore = this.store;
|
|
1883
|
-
s.languageUtils = lu;
|
|
1884
|
-
s.pluralResolver = new PluralResolver(lu, {
|
|
1885
|
-
prepend: this.options.pluralSeparator,
|
|
1886
|
-
compatibilityJSON: this.options.compatibilityJSON,
|
|
1887
|
-
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
1888
|
-
});
|
|
1889
|
-
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
1890
|
-
s.formatter = createClassOnDemand(formatter);
|
|
1891
|
-
s.formatter.init(s, this.options);
|
|
1892
|
-
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
1893
|
-
}
|
|
1894
|
-
s.interpolator = new Interpolator(this.options);
|
|
1895
|
-
s.utils = {
|
|
1896
|
-
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
1897
|
-
};
|
|
1898
|
-
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
1899
|
-
s.backendConnector.on('*', function (event) {
|
|
1900
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1901
|
-
args[_key - 1] = arguments[_key];
|
|
1902
|
-
}
|
|
1903
|
-
_this.emit(event, ...args);
|
|
1904
|
-
});
|
|
1905
|
-
if (this.modules.languageDetector) {
|
|
1906
|
-
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
1907
|
-
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
1908
|
-
}
|
|
1909
|
-
if (this.modules.i18nFormat) {
|
|
1910
|
-
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
1911
|
-
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
1912
|
-
}
|
|
1913
|
-
this.translator = new Translator(this.services, this.options);
|
|
1914
|
-
this.translator.on('*', function (event) {
|
|
1915
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
1916
|
-
args[_key2 - 1] = arguments[_key2];
|
|
1917
|
-
}
|
|
1918
|
-
_this.emit(event, ...args);
|
|
1919
|
-
});
|
|
1920
|
-
this.modules.external.forEach(m => {
|
|
1921
|
-
if (m.init) m.init(this);
|
|
1922
|
-
});
|
|
1923
|
-
}
|
|
1924
|
-
this.format = this.options.interpolation.format;
|
|
1925
|
-
if (!callback) callback = noop$2;
|
|
1926
|
-
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
1927
|
-
const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
1928
|
-
if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
|
|
1929
|
-
}
|
|
1930
|
-
if (!this.services.languageDetector && !this.options.lng) {
|
|
1931
|
-
this.logger.warn('init: no languageDetector is used and no lng is defined');
|
|
1932
|
-
}
|
|
1933
|
-
const storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
|
|
1934
|
-
storeApi.forEach(fcName => {
|
|
1935
|
-
this[fcName] = function () {
|
|
1936
|
-
return _this.store[fcName](...arguments);
|
|
1937
|
-
};
|
|
1938
|
-
});
|
|
1939
|
-
const storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
|
|
1940
|
-
storeApiChained.forEach(fcName => {
|
|
1941
|
-
this[fcName] = function () {
|
|
1942
|
-
_this.store[fcName](...arguments);
|
|
1943
|
-
return _this;
|
|
1944
|
-
};
|
|
1945
|
-
});
|
|
1946
|
-
const deferred = defer();
|
|
1947
|
-
const load = () => {
|
|
1948
|
-
const finish = (err, t) => {
|
|
1949
|
-
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn('init: i18next is already initialized. You should call init just once!');
|
|
1950
|
-
this.isInitialized = true;
|
|
1951
|
-
if (!this.options.isClone) this.logger.log('initialized', this.options);
|
|
1952
|
-
this.emit('initialized', this.options);
|
|
1953
|
-
deferred.resolve(t);
|
|
1954
|
-
callback(err, t);
|
|
1955
|
-
};
|
|
1956
|
-
if (this.languages && this.options.compatibilityAPI !== 'v1' && !this.isInitialized) return finish(null, this.t.bind(this));
|
|
1957
|
-
this.changeLanguage(this.options.lng, finish);
|
|
1958
|
-
};
|
|
1959
|
-
if (this.options.resources || !this.options.initImmediate) {
|
|
1960
|
-
load();
|
|
1961
|
-
} else {
|
|
1962
|
-
setTimeout(load, 0);
|
|
1963
|
-
}
|
|
1964
|
-
return deferred;
|
|
1965
|
-
}
|
|
1966
|
-
loadResources(language) {
|
|
1967
|
-
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$2;
|
|
1968
|
-
let usedCallback = callback;
|
|
1969
|
-
const usedLng = typeof language === 'string' ? language : this.language;
|
|
1970
|
-
if (typeof language === 'function') usedCallback = language;
|
|
1971
|
-
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
1972
|
-
if (usedLng && usedLng.toLowerCase() === 'cimode') return usedCallback();
|
|
1973
|
-
const toLoad = [];
|
|
1974
|
-
const append = lng => {
|
|
1975
|
-
if (!lng) return;
|
|
1976
|
-
const lngs = this.services.languageUtils.toResolveHierarchy(lng);
|
|
1977
|
-
lngs.forEach(l => {
|
|
1978
|
-
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
|
1979
|
-
});
|
|
1980
|
-
};
|
|
1981
|
-
if (!usedLng) {
|
|
1982
|
-
const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
1983
|
-
fallbacks.forEach(l => append(l));
|
|
1984
|
-
} else {
|
|
1985
|
-
append(usedLng);
|
|
1986
|
-
}
|
|
1987
|
-
if (this.options.preload) {
|
|
1988
|
-
this.options.preload.forEach(l => append(l));
|
|
1989
|
-
}
|
|
1990
|
-
this.services.backendConnector.load(toLoad, this.options.ns, e => {
|
|
1991
|
-
if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
1992
|
-
usedCallback(e);
|
|
1993
|
-
});
|
|
1994
|
-
} else {
|
|
1995
|
-
usedCallback(null);
|
|
1996
|
-
}
|
|
1997
|
-
}
|
|
1998
|
-
reloadResources(lngs, ns, callback) {
|
|
1999
|
-
const deferred = defer();
|
|
2000
|
-
if (!lngs) lngs = this.languages;
|
|
2001
|
-
if (!ns) ns = this.options.ns;
|
|
2002
|
-
if (!callback) callback = noop$2;
|
|
2003
|
-
this.services.backendConnector.reload(lngs, ns, err => {
|
|
2004
|
-
deferred.resolve();
|
|
2005
|
-
callback(err);
|
|
2006
|
-
});
|
|
2007
|
-
return deferred;
|
|
2008
|
-
}
|
|
2009
|
-
use(module) {
|
|
2010
|
-
if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
|
|
2011
|
-
if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
|
|
2012
|
-
if (module.type === 'backend') {
|
|
2013
|
-
this.modules.backend = module;
|
|
2014
|
-
}
|
|
2015
|
-
if (module.type === 'logger' || module.log && module.warn && module.error) {
|
|
2016
|
-
this.modules.logger = module;
|
|
2017
|
-
}
|
|
2018
|
-
if (module.type === 'languageDetector') {
|
|
2019
|
-
this.modules.languageDetector = module;
|
|
2020
|
-
}
|
|
2021
|
-
if (module.type === 'i18nFormat') {
|
|
2022
|
-
this.modules.i18nFormat = module;
|
|
2023
|
-
}
|
|
2024
|
-
if (module.type === 'postProcessor') {
|
|
2025
|
-
postProcessor.addPostProcessor(module);
|
|
2026
|
-
}
|
|
2027
|
-
if (module.type === 'formatter') {
|
|
2028
|
-
this.modules.formatter = module;
|
|
2029
|
-
}
|
|
2030
|
-
if (module.type === '3rdParty') {
|
|
2031
|
-
this.modules.external.push(module);
|
|
2032
|
-
}
|
|
2033
|
-
return this;
|
|
2034
|
-
}
|
|
2035
|
-
setResolvedLanguage(l) {
|
|
2036
|
-
if (!l || !this.languages) return;
|
|
2037
|
-
if (['cimode', 'dev'].indexOf(l) > -1) return;
|
|
2038
|
-
for (let li = 0; li < this.languages.length; li++) {
|
|
2039
|
-
const lngInLngs = this.languages[li];
|
|
2040
|
-
if (['cimode', 'dev'].indexOf(lngInLngs) > -1) continue;
|
|
2041
|
-
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
2042
|
-
this.resolvedLanguage = lngInLngs;
|
|
2043
|
-
break;
|
|
2044
|
-
}
|
|
2045
|
-
}
|
|
2046
|
-
}
|
|
2047
|
-
changeLanguage(lng, callback) {
|
|
2048
|
-
var _this2 = this;
|
|
2049
|
-
this.isLanguageChangingTo = lng;
|
|
2050
|
-
const deferred = defer();
|
|
2051
|
-
this.emit('languageChanging', lng);
|
|
2052
|
-
const setLngProps = l => {
|
|
2053
|
-
this.language = l;
|
|
2054
|
-
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
2055
|
-
this.resolvedLanguage = undefined;
|
|
2056
|
-
this.setResolvedLanguage(l);
|
|
2057
|
-
};
|
|
2058
|
-
const done = (err, l) => {
|
|
2059
|
-
if (l) {
|
|
2060
|
-
setLngProps(l);
|
|
2061
|
-
this.translator.changeLanguage(l);
|
|
2062
|
-
this.isLanguageChangingTo = undefined;
|
|
2063
|
-
this.emit('languageChanged', l);
|
|
2064
|
-
this.logger.log('languageChanged', l);
|
|
2065
|
-
} else {
|
|
2066
|
-
this.isLanguageChangingTo = undefined;
|
|
2067
|
-
}
|
|
2068
|
-
deferred.resolve(function () {
|
|
2069
|
-
return _this2.t(...arguments);
|
|
2070
|
-
});
|
|
2071
|
-
if (callback) callback(err, function () {
|
|
2072
|
-
return _this2.t(...arguments);
|
|
2073
|
-
});
|
|
2074
|
-
};
|
|
2075
|
-
const setLng = lngs => {
|
|
2076
|
-
if (!lng && !lngs && this.services.languageDetector) lngs = [];
|
|
2077
|
-
const l = typeof lngs === 'string' ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
|
|
2078
|
-
if (l) {
|
|
2079
|
-
if (!this.language) {
|
|
2080
|
-
setLngProps(l);
|
|
2081
|
-
}
|
|
2082
|
-
if (!this.translator.language) this.translator.changeLanguage(l);
|
|
2083
|
-
if (this.services.languageDetector && this.services.languageDetector.cacheUserLanguage) this.services.languageDetector.cacheUserLanguage(l);
|
|
2084
|
-
}
|
|
2085
|
-
this.loadResources(l, err => {
|
|
2086
|
-
done(err, l);
|
|
2087
|
-
});
|
|
2088
|
-
};
|
|
2089
|
-
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
2090
|
-
setLng(this.services.languageDetector.detect());
|
|
2091
|
-
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
2092
|
-
if (this.services.languageDetector.detect.length === 0) {
|
|
2093
|
-
this.services.languageDetector.detect().then(setLng);
|
|
2094
|
-
} else {
|
|
2095
|
-
this.services.languageDetector.detect(setLng);
|
|
2096
|
-
}
|
|
2097
|
-
} else {
|
|
2098
|
-
setLng(lng);
|
|
2099
|
-
}
|
|
2100
|
-
return deferred;
|
|
2101
|
-
}
|
|
2102
|
-
getFixedT(lng, ns, keyPrefix) {
|
|
2103
|
-
var _this3 = this;
|
|
2104
|
-
const fixedT = function (key, opts) {
|
|
2105
|
-
let options;
|
|
2106
|
-
if (typeof opts !== 'object') {
|
|
2107
|
-
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
2108
|
-
rest[_key3 - 2] = arguments[_key3];
|
|
2109
|
-
}
|
|
2110
|
-
options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
2111
|
-
} else {
|
|
2112
|
-
options = {
|
|
2113
|
-
...opts
|
|
2114
|
-
};
|
|
2115
|
-
}
|
|
2116
|
-
options.lng = options.lng || fixedT.lng;
|
|
2117
|
-
options.lngs = options.lngs || fixedT.lngs;
|
|
2118
|
-
options.ns = options.ns || fixedT.ns;
|
|
2119
|
-
options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
2120
|
-
const keySeparator = _this3.options.keySeparator || '.';
|
|
2121
|
-
let resultKey;
|
|
2122
|
-
if (options.keyPrefix && Array.isArray(key)) {
|
|
2123
|
-
resultKey = key.map(k => `${options.keyPrefix}${keySeparator}${k}`);
|
|
2124
|
-
} else {
|
|
2125
|
-
resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
|
|
2126
|
-
}
|
|
2127
|
-
return _this3.t(resultKey, options);
|
|
2128
|
-
};
|
|
2129
|
-
if (typeof lng === 'string') {
|
|
2130
|
-
fixedT.lng = lng;
|
|
2131
|
-
} else {
|
|
2132
|
-
fixedT.lngs = lng;
|
|
2133
|
-
}
|
|
2134
|
-
fixedT.ns = ns;
|
|
2135
|
-
fixedT.keyPrefix = keyPrefix;
|
|
2136
|
-
return fixedT;
|
|
2137
|
-
}
|
|
2138
|
-
t() {
|
|
2139
|
-
return this.translator && this.translator.translate(...arguments);
|
|
2140
|
-
}
|
|
2141
|
-
exists() {
|
|
2142
|
-
return this.translator && this.translator.exists(...arguments);
|
|
2143
|
-
}
|
|
2144
|
-
setDefaultNamespace(ns) {
|
|
2145
|
-
this.options.defaultNS = ns;
|
|
2146
|
-
}
|
|
2147
|
-
hasLoadedNamespace(ns) {
|
|
2148
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2149
|
-
if (!this.isInitialized) {
|
|
2150
|
-
this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
|
|
2151
|
-
return false;
|
|
2152
|
-
}
|
|
2153
|
-
if (!this.languages || !this.languages.length) {
|
|
2154
|
-
this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages);
|
|
2155
|
-
return false;
|
|
2156
|
-
}
|
|
2157
|
-
const lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
2158
|
-
const fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
2159
|
-
const lastLng = this.languages[this.languages.length - 1];
|
|
2160
|
-
if (lng.toLowerCase() === 'cimode') return true;
|
|
2161
|
-
const loadNotPending = (l, n) => {
|
|
2162
|
-
const loadState = this.services.backendConnector.state[`${l}|${n}`];
|
|
2163
|
-
return loadState === -1 || loadState === 2;
|
|
2164
|
-
};
|
|
2165
|
-
if (options.precheck) {
|
|
2166
|
-
const preResult = options.precheck(this, loadNotPending);
|
|
2167
|
-
if (preResult !== undefined) return preResult;
|
|
2168
|
-
}
|
|
2169
|
-
if (this.hasResourceBundle(lng, ns)) return true;
|
|
2170
|
-
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
2171
|
-
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
2172
|
-
return false;
|
|
2173
|
-
}
|
|
2174
|
-
loadNamespaces(ns, callback) {
|
|
2175
|
-
const deferred = defer();
|
|
2176
|
-
if (!this.options.ns) {
|
|
2177
|
-
if (callback) callback();
|
|
2178
|
-
return Promise.resolve();
|
|
2179
|
-
}
|
|
2180
|
-
if (typeof ns === 'string') ns = [ns];
|
|
2181
|
-
ns.forEach(n => {
|
|
2182
|
-
if (this.options.ns.indexOf(n) < 0) this.options.ns.push(n);
|
|
2183
|
-
});
|
|
2184
|
-
this.loadResources(err => {
|
|
2185
|
-
deferred.resolve();
|
|
2186
|
-
if (callback) callback(err);
|
|
2187
|
-
});
|
|
2188
|
-
return deferred;
|
|
2189
|
-
}
|
|
2190
|
-
loadLanguages(lngs, callback) {
|
|
2191
|
-
const deferred = defer();
|
|
2192
|
-
if (typeof lngs === 'string') lngs = [lngs];
|
|
2193
|
-
const preloaded = this.options.preload || [];
|
|
2194
|
-
const newLngs = lngs.filter(lng => preloaded.indexOf(lng) < 0);
|
|
2195
|
-
if (!newLngs.length) {
|
|
2196
|
-
if (callback) callback();
|
|
2197
|
-
return Promise.resolve();
|
|
2198
|
-
}
|
|
2199
|
-
this.options.preload = preloaded.concat(newLngs);
|
|
2200
|
-
this.loadResources(err => {
|
|
2201
|
-
deferred.resolve();
|
|
2202
|
-
if (callback) callback(err);
|
|
2203
|
-
});
|
|
2204
|
-
return deferred;
|
|
2205
|
-
}
|
|
2206
|
-
dir(lng) {
|
|
2207
|
-
if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
|
|
2208
|
-
if (!lng) return 'rtl';
|
|
2209
|
-
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'];
|
|
2210
|
-
const languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
|
|
2211
|
-
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
|
|
2212
|
-
}
|
|
2213
|
-
static createInstance() {
|
|
2214
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2215
|
-
let callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
2216
|
-
return new I18n(options, callback);
|
|
2217
|
-
}
|
|
2218
|
-
cloneInstance() {
|
|
2219
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2220
|
-
let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$2;
|
|
2221
|
-
const forkResourceStore = options.forkResourceStore;
|
|
2222
|
-
if (forkResourceStore) delete options.forkResourceStore;
|
|
2223
|
-
const mergedOptions = {
|
|
2224
|
-
...this.options,
|
|
2225
|
-
...options,
|
|
2226
|
-
...{
|
|
2227
|
-
isClone: true
|
|
2228
|
-
}
|
|
2229
|
-
};
|
|
2230
|
-
const clone = new I18n(mergedOptions);
|
|
2231
|
-
if (options.debug !== undefined || options.prefix !== undefined) {
|
|
2232
|
-
clone.logger = clone.logger.clone(options);
|
|
2233
|
-
}
|
|
2234
|
-
const membersToCopy = ['store', 'services', 'language'];
|
|
2235
|
-
membersToCopy.forEach(m => {
|
|
2236
|
-
clone[m] = this[m];
|
|
2237
|
-
});
|
|
2238
|
-
clone.services = {
|
|
2239
|
-
...this.services
|
|
2240
|
-
};
|
|
2241
|
-
clone.services.utils = {
|
|
2242
|
-
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2243
|
-
};
|
|
2244
|
-
if (forkResourceStore) {
|
|
2245
|
-
clone.store = new ResourceStore(this.store.data, mergedOptions);
|
|
2246
|
-
clone.services.resourceStore = clone.store;
|
|
2247
|
-
}
|
|
2248
|
-
clone.translator = new Translator(clone.services, mergedOptions);
|
|
2249
|
-
clone.translator.on('*', function (event) {
|
|
2250
|
-
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
2251
|
-
args[_key4 - 1] = arguments[_key4];
|
|
2252
|
-
}
|
|
2253
|
-
clone.emit(event, ...args);
|
|
2254
|
-
});
|
|
2255
|
-
clone.init(mergedOptions, callback);
|
|
2256
|
-
clone.translator.options = mergedOptions;
|
|
2257
|
-
clone.translator.backendConnector.services.utils = {
|
|
2258
|
-
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2259
|
-
};
|
|
2260
|
-
return clone;
|
|
2261
|
-
}
|
|
2262
|
-
toJSON() {
|
|
2263
|
-
return {
|
|
2264
|
-
options: this.options,
|
|
2265
|
-
store: this.store,
|
|
2266
|
-
language: this.language,
|
|
2267
|
-
languages: this.languages,
|
|
2268
|
-
resolvedLanguage: this.resolvedLanguage
|
|
2269
|
-
};
|
|
2270
|
-
}
|
|
2271
|
-
}
|
|
2272
|
-
const instance = I18n.createInstance();
|
|
2273
|
-
instance.createInstance = I18n.createInstance;
|
|
2274
|
-
|
|
2275
|
-
instance.createInstance;
|
|
2276
|
-
instance.dir;
|
|
2277
|
-
instance.init;
|
|
2278
|
-
instance.loadResources;
|
|
2279
|
-
instance.reloadResources;
|
|
2280
|
-
instance.use;
|
|
2281
|
-
instance.changeLanguage;
|
|
2282
|
-
instance.getFixedT;
|
|
2283
|
-
const t$2 = instance.t;
|
|
2284
|
-
instance.exists;
|
|
2285
|
-
instance.setDefaultNamespace;
|
|
2286
|
-
instance.hasLoadedNamespace;
|
|
2287
|
-
instance.loadNamespaces;
|
|
2288
|
-
instance.loadLanguages;
|
|
2289
|
-
|
|
2290
|
-
/**
|
|
2291
|
-
* This file automatically generated from `pre-publish.js`.
|
|
2292
|
-
* Do not manually edit.
|
|
2293
|
-
*/
|
|
2294
|
-
|
|
2295
|
-
var voidElements = {
|
|
2296
|
-
"area": true,
|
|
2297
|
-
"base": true,
|
|
2298
|
-
"br": true,
|
|
2299
|
-
"col": true,
|
|
2300
|
-
"embed": true,
|
|
2301
|
-
"hr": true,
|
|
2302
|
-
"img": true,
|
|
2303
|
-
"input": true,
|
|
2304
|
-
"link": true,
|
|
2305
|
-
"meta": true,
|
|
2306
|
-
"param": true,
|
|
2307
|
-
"source": true,
|
|
2308
|
-
"track": true,
|
|
2309
|
-
"wbr": true
|
|
2310
|
-
};
|
|
2311
|
-
|
|
2312
|
-
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)},"")}};
|
|
2313
|
-
|
|
2314
|
-
function warn() {
|
|
2315
|
-
if (console && console.warn) {
|
|
2316
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2317
|
-
args[_key] = arguments[_key];
|
|
2318
|
-
}
|
|
2319
|
-
if (typeof args[0] === 'string') args[0] = `react-i18next:: ${args[0]}`;
|
|
2320
|
-
console.warn(...args);
|
|
2321
|
-
}
|
|
2322
|
-
}
|
|
2323
|
-
const alreadyWarned = {};
|
|
2324
|
-
function warnOnce() {
|
|
2325
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
2326
|
-
args[_key2] = arguments[_key2];
|
|
2327
|
-
}
|
|
2328
|
-
if (typeof args[0] === 'string' && alreadyWarned[args[0]]) return;
|
|
2329
|
-
if (typeof args[0] === 'string') alreadyWarned[args[0]] = new Date();
|
|
2330
|
-
warn(...args);
|
|
2331
|
-
}
|
|
2332
|
-
const loadedClb = (i18n, cb) => () => {
|
|
2333
|
-
if (i18n.isInitialized) {
|
|
2334
|
-
cb();
|
|
2335
|
-
} else {
|
|
2336
|
-
const initialized = () => {
|
|
2337
|
-
setTimeout(() => {
|
|
2338
|
-
i18n.off('initialized', initialized);
|
|
2339
|
-
}, 0);
|
|
2340
|
-
cb();
|
|
2341
|
-
};
|
|
2342
|
-
i18n.on('initialized', initialized);
|
|
2343
|
-
}
|
|
2344
|
-
};
|
|
2345
|
-
function loadNamespaces(i18n, ns, cb) {
|
|
2346
|
-
i18n.loadNamespaces(ns, loadedClb(i18n, cb));
|
|
2347
|
-
}
|
|
2348
|
-
function loadLanguages(i18n, lng, ns, cb) {
|
|
2349
|
-
if (typeof ns === 'string') ns = [ns];
|
|
2350
|
-
ns.forEach(n => {
|
|
2351
|
-
if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
|
|
2352
|
-
});
|
|
2353
|
-
i18n.loadLanguages(lng, loadedClb(i18n, cb));
|
|
2354
|
-
}
|
|
2355
|
-
function oldI18nextHasLoadedNamespace(ns, i18n) {
|
|
2356
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2357
|
-
const lng = i18n.languages[0];
|
|
2358
|
-
const fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
|
|
2359
|
-
const lastLng = i18n.languages[i18n.languages.length - 1];
|
|
2360
|
-
if (lng.toLowerCase() === 'cimode') return true;
|
|
2361
|
-
const loadNotPending = (l, n) => {
|
|
2362
|
-
const loadState = i18n.services.backendConnector.state[`${l}|${n}`];
|
|
2363
|
-
return loadState === -1 || loadState === 2;
|
|
2364
|
-
};
|
|
2365
|
-
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false;
|
|
2366
|
-
if (i18n.hasResourceBundle(lng, ns)) return true;
|
|
2367
|
-
if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true;
|
|
2368
|
-
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
2369
|
-
return false;
|
|
2370
|
-
}
|
|
2371
|
-
function hasLoadedNamespace(ns, i18n) {
|
|
2372
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2373
|
-
if (!i18n.languages || !i18n.languages.length) {
|
|
2374
|
-
warnOnce('i18n.languages were undefined or empty', i18n.languages);
|
|
2375
|
-
return true;
|
|
2376
|
-
}
|
|
2377
|
-
const isNewerI18next = i18n.options.ignoreJSONStructure !== undefined;
|
|
2378
|
-
if (!isNewerI18next) {
|
|
2379
|
-
return oldI18nextHasLoadedNamespace(ns, i18n, options);
|
|
2380
|
-
}
|
|
2381
|
-
return i18n.hasLoadedNamespace(ns, {
|
|
2382
|
-
lng: options.lng,
|
|
2383
|
-
precheck: (i18nInstance, loadNotPending) => {
|
|
2384
|
-
if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
|
|
2385
|
-
}
|
|
2386
|
-
});
|
|
2387
|
-
}
|
|
2388
|
-
|
|
2389
|
-
const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
|
|
2390
|
-
const htmlEntities = {
|
|
2391
|
-
'&': '&',
|
|
2392
|
-
'&': '&',
|
|
2393
|
-
'<': '<',
|
|
2394
|
-
'<': '<',
|
|
2395
|
-
'>': '>',
|
|
2396
|
-
'>': '>',
|
|
2397
|
-
''': "'",
|
|
2398
|
-
''': "'",
|
|
2399
|
-
'"': '"',
|
|
2400
|
-
'"': '"',
|
|
2401
|
-
' ': ' ',
|
|
2402
|
-
' ': ' ',
|
|
2403
|
-
'©': '©',
|
|
2404
|
-
'©': '©',
|
|
2405
|
-
'®': '®',
|
|
2406
|
-
'®': '®',
|
|
2407
|
-
'…': '…',
|
|
2408
|
-
'…': '…',
|
|
2409
|
-
'/': '/',
|
|
2410
|
-
'/': '/'
|
|
2411
|
-
};
|
|
2412
|
-
const unescapeHtmlEntity = m => htmlEntities[m];
|
|
2413
|
-
const unescape = text => text.replace(matchHtmlEntity, unescapeHtmlEntity);
|
|
2414
|
-
|
|
2415
|
-
let defaultOptions = {
|
|
2416
|
-
bindI18n: 'languageChanged',
|
|
2417
|
-
bindI18nStore: '',
|
|
2418
|
-
transEmptyNodeValue: '',
|
|
2419
|
-
transSupportBasicHtmlNodes: true,
|
|
2420
|
-
transWrapTextNodes: '',
|
|
2421
|
-
transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
|
|
2422
|
-
useSuspense: true,
|
|
2423
|
-
unescape
|
|
2424
|
-
};
|
|
2425
|
-
function setDefaults() {
|
|
2426
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2427
|
-
defaultOptions = {
|
|
2428
|
-
...defaultOptions,
|
|
2429
|
-
...options
|
|
2430
|
-
};
|
|
2431
|
-
}
|
|
2432
|
-
function getDefaults() {
|
|
2433
|
-
return defaultOptions;
|
|
2434
|
-
}
|
|
2435
|
-
|
|
2436
|
-
let i18nInstance;
|
|
2437
|
-
function setI18n(instance) {
|
|
2438
|
-
i18nInstance = instance;
|
|
2439
|
-
}
|
|
2440
|
-
function getI18n() {
|
|
2441
|
-
return i18nInstance;
|
|
2442
|
-
}
|
|
2443
|
-
|
|
2444
|
-
function hasChildren(node, checkLength) {
|
|
2445
|
-
if (!node) return false;
|
|
2446
|
-
const base = node.props ? node.props.children : node.children;
|
|
2447
|
-
if (checkLength) return base.length > 0;
|
|
2448
|
-
return !!base;
|
|
2449
|
-
}
|
|
2450
|
-
function getChildren(node) {
|
|
2451
|
-
if (!node) return [];
|
|
2452
|
-
return node.props ? node.props.children : node.children;
|
|
2453
|
-
}
|
|
2454
|
-
function hasValidReactChildren(children) {
|
|
2455
|
-
if (Object.prototype.toString.call(children) !== '[object Array]') return false;
|
|
2456
|
-
return children.every(child => isValidElement(child));
|
|
2457
|
-
}
|
|
2458
|
-
function getAsArray(data) {
|
|
2459
|
-
return Array.isArray(data) ? data : [data];
|
|
2460
|
-
}
|
|
2461
|
-
function mergeProps(source, target) {
|
|
2462
|
-
const newTarget = {
|
|
2463
|
-
...target
|
|
2464
|
-
};
|
|
2465
|
-
newTarget.props = Object.assign(source.props, target.props);
|
|
2466
|
-
return newTarget;
|
|
2467
|
-
}
|
|
2468
|
-
function nodesToString(children, i18nOptions) {
|
|
2469
|
-
if (!children) return '';
|
|
2470
|
-
let stringNode = '';
|
|
2471
|
-
const childrenArray = getAsArray(children);
|
|
2472
|
-
const keepArray = i18nOptions.transSupportBasicHtmlNodes && i18nOptions.transKeepBasicHtmlNodesFor ? i18nOptions.transKeepBasicHtmlNodesFor : [];
|
|
2473
|
-
childrenArray.forEach((child, childIndex) => {
|
|
2474
|
-
if (typeof child === 'string') {
|
|
2475
|
-
stringNode += `${child}`;
|
|
2476
|
-
} else if (isValidElement(child)) {
|
|
2477
|
-
const childPropsCount = Object.keys(child.props).length;
|
|
2478
|
-
const shouldKeepChild = keepArray.indexOf(child.type) > -1;
|
|
2479
|
-
const childChildren = child.props.children;
|
|
2480
|
-
if (!childChildren && shouldKeepChild && childPropsCount === 0) {
|
|
2481
|
-
stringNode += `<${child.type}/>`;
|
|
2482
|
-
} else if (!childChildren && (!shouldKeepChild || childPropsCount !== 0)) {
|
|
2483
|
-
stringNode += `<${childIndex}></${childIndex}>`;
|
|
2484
|
-
} else if (child.props.i18nIsDynamicList) {
|
|
2485
|
-
stringNode += `<${childIndex}></${childIndex}>`;
|
|
2486
|
-
} else if (shouldKeepChild && childPropsCount === 1 && typeof childChildren === 'string') {
|
|
2487
|
-
stringNode += `<${child.type}>${childChildren}</${child.type}>`;
|
|
2488
|
-
} else {
|
|
2489
|
-
const content = nodesToString(childChildren, i18nOptions);
|
|
2490
|
-
stringNode += `<${childIndex}>${content}</${childIndex}>`;
|
|
2491
|
-
}
|
|
2492
|
-
} else if (child === null) {
|
|
2493
|
-
warn(`Trans: the passed in value is invalid - seems you passed in a null child.`);
|
|
2494
|
-
} else if (typeof child === 'object') {
|
|
2495
|
-
const {
|
|
2496
|
-
format,
|
|
2497
|
-
...clone
|
|
2498
|
-
} = child;
|
|
2499
|
-
const keys = Object.keys(clone);
|
|
2500
|
-
if (keys.length === 1) {
|
|
2501
|
-
const value = format ? `${keys[0]}, ${format}` : keys[0];
|
|
2502
|
-
stringNode += `{{${value}}}`;
|
|
2503
|
-
} else {
|
|
2504
|
-
warn(`react-i18next: the passed in object contained more than one variable - the object should look like {{ value, format }} where format is optional.`, child);
|
|
2505
|
-
}
|
|
2506
|
-
} else {
|
|
2507
|
-
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);
|
|
2508
|
-
}
|
|
2509
|
-
});
|
|
2510
|
-
return stringNode;
|
|
2511
|
-
}
|
|
2512
|
-
function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, shouldUnescape) {
|
|
2513
|
-
if (targetString === '') return [];
|
|
2514
|
-
const keepArray = i18nOptions.transKeepBasicHtmlNodesFor || [];
|
|
2515
|
-
const emptyChildrenButNeedsHandling = targetString && new RegExp(keepArray.join('|')).test(targetString);
|
|
2516
|
-
if (!children && !emptyChildrenButNeedsHandling) return [targetString];
|
|
2517
|
-
const data = {};
|
|
2518
|
-
function getData(childs) {
|
|
2519
|
-
const childrenArray = getAsArray(childs);
|
|
2520
|
-
childrenArray.forEach(child => {
|
|
2521
|
-
if (typeof child === 'string') return;
|
|
2522
|
-
if (hasChildren(child)) getData(getChildren(child));else if (typeof child === 'object' && !isValidElement(child)) Object.assign(data, child);
|
|
2523
|
-
});
|
|
2524
|
-
}
|
|
2525
|
-
getData(children);
|
|
2526
|
-
const ast = c.parse(`<0>${targetString}</0>`);
|
|
2527
|
-
const opts = {
|
|
2528
|
-
...data,
|
|
2529
|
-
...combinedTOpts
|
|
2530
|
-
};
|
|
2531
|
-
function renderInner(child, node, rootReactNode) {
|
|
2532
|
-
const childs = getChildren(child);
|
|
2533
|
-
const mappedChildren = mapAST(childs, node.children, rootReactNode);
|
|
2534
|
-
return hasValidReactChildren(childs) && mappedChildren.length === 0 ? childs : mappedChildren;
|
|
2535
|
-
}
|
|
2536
|
-
function pushTranslatedJSX(child, inner, mem, i, isVoid) {
|
|
2537
|
-
if (child.dummy) child.children = inner;
|
|
2538
|
-
mem.push(cloneElement(child, {
|
|
2539
|
-
...child.props,
|
|
2540
|
-
key: i
|
|
2541
|
-
}, isVoid ? undefined : inner));
|
|
2542
|
-
}
|
|
2543
|
-
function mapAST(reactNode, astNode, rootReactNode) {
|
|
2544
|
-
const reactNodes = getAsArray(reactNode);
|
|
2545
|
-
const astNodes = getAsArray(astNode);
|
|
2546
|
-
return astNodes.reduce((mem, node, i) => {
|
|
2547
|
-
const translationContent = node.children && node.children[0] && node.children[0].content && i18n.services.interpolator.interpolate(node.children[0].content, opts, i18n.language);
|
|
2548
|
-
if (node.type === 'tag') {
|
|
2549
|
-
let tmp = reactNodes[parseInt(node.name, 10)];
|
|
2550
|
-
if (!tmp && rootReactNode.length === 1 && rootReactNode[0][node.name]) tmp = rootReactNode[0][node.name];
|
|
2551
|
-
if (!tmp) tmp = {};
|
|
2552
|
-
const child = Object.keys(node.attrs).length !== 0 ? mergeProps({
|
|
2553
|
-
props: node.attrs
|
|
2554
|
-
}, tmp) : tmp;
|
|
2555
|
-
const isElement = isValidElement(child);
|
|
2556
|
-
const isValidTranslationWithChildren = isElement && hasChildren(node, true) && !node.voidElement;
|
|
2557
|
-
const isEmptyTransWithHTML = emptyChildrenButNeedsHandling && typeof child === 'object' && child.dummy && !isElement;
|
|
2558
|
-
const isKnownComponent = typeof children === 'object' && children !== null && Object.hasOwnProperty.call(children, node.name);
|
|
2559
|
-
if (typeof child === 'string') {
|
|
2560
|
-
const value = i18n.services.interpolator.interpolate(child, opts, i18n.language);
|
|
2561
|
-
mem.push(value);
|
|
2562
|
-
} else if (hasChildren(child) || isValidTranslationWithChildren) {
|
|
2563
|
-
const inner = renderInner(child, node, rootReactNode);
|
|
2564
|
-
pushTranslatedJSX(child, inner, mem, i);
|
|
2565
|
-
} else if (isEmptyTransWithHTML) {
|
|
2566
|
-
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
2567
|
-
mem.push(cloneElement(child, {
|
|
2568
|
-
...child.props,
|
|
2569
|
-
key: i
|
|
2570
|
-
}, inner));
|
|
2571
|
-
} else if (Number.isNaN(parseFloat(node.name))) {
|
|
2572
|
-
if (isKnownComponent) {
|
|
2573
|
-
const inner = renderInner(child, node, rootReactNode);
|
|
2574
|
-
pushTranslatedJSX(child, inner, mem, i, node.voidElement);
|
|
2575
|
-
} else if (i18nOptions.transSupportBasicHtmlNodes && keepArray.indexOf(node.name) > -1) {
|
|
2576
|
-
if (node.voidElement) {
|
|
2577
|
-
mem.push(createElement(node.name, {
|
|
2578
|
-
key: `${node.name}-${i}`
|
|
2579
|
-
}));
|
|
2580
|
-
} else {
|
|
2581
|
-
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
2582
|
-
mem.push(createElement(node.name, {
|
|
2583
|
-
key: `${node.name}-${i}`
|
|
2584
|
-
}, inner));
|
|
2585
|
-
}
|
|
2586
|
-
} else if (node.voidElement) {
|
|
2587
|
-
mem.push(`<${node.name} />`);
|
|
2588
|
-
} else {
|
|
2589
|
-
const inner = mapAST(reactNodes, node.children, rootReactNode);
|
|
2590
|
-
mem.push(`<${node.name}>${inner}</${node.name}>`);
|
|
2591
|
-
}
|
|
2592
|
-
} else if (typeof child === 'object' && !isElement) {
|
|
2593
|
-
const content = node.children[0] ? translationContent : null;
|
|
2594
|
-
if (content) mem.push(content);
|
|
2595
|
-
} else if (node.children.length === 1 && translationContent) {
|
|
2596
|
-
mem.push(cloneElement(child, {
|
|
2597
|
-
...child.props,
|
|
2598
|
-
key: i
|
|
2599
|
-
}, translationContent));
|
|
2600
|
-
} else {
|
|
2601
|
-
mem.push(cloneElement(child, {
|
|
2602
|
-
...child.props,
|
|
2603
|
-
key: i
|
|
2604
|
-
}));
|
|
2605
|
-
}
|
|
2606
|
-
} else if (node.type === 'text') {
|
|
2607
|
-
const wrapTextNodes = i18nOptions.transWrapTextNodes;
|
|
2608
|
-
const content = shouldUnescape ? i18nOptions.unescape(i18n.services.interpolator.interpolate(node.content, opts, i18n.language)) : i18n.services.interpolator.interpolate(node.content, opts, i18n.language);
|
|
2609
|
-
if (wrapTextNodes) {
|
|
2610
|
-
mem.push(createElement(wrapTextNodes, {
|
|
2611
|
-
key: `${node.name}-${i}`
|
|
2612
|
-
}, content));
|
|
2613
|
-
} else {
|
|
2614
|
-
mem.push(content);
|
|
2615
|
-
}
|
|
2616
|
-
}
|
|
2617
|
-
return mem;
|
|
2618
|
-
}, []);
|
|
2619
|
-
}
|
|
2620
|
-
const result = mapAST([{
|
|
2621
|
-
dummy: true,
|
|
2622
|
-
children: children || []
|
|
2623
|
-
}], ast, getAsArray(children || []));
|
|
2624
|
-
return getChildren(result[0]);
|
|
2625
|
-
}
|
|
2626
|
-
function Trans$1(_ref) {
|
|
2627
|
-
let {
|
|
2628
|
-
children,
|
|
2629
|
-
count,
|
|
2630
|
-
parent,
|
|
2631
|
-
i18nKey,
|
|
2632
|
-
context,
|
|
2633
|
-
tOptions = {},
|
|
2634
|
-
values,
|
|
2635
|
-
defaults,
|
|
2636
|
-
components,
|
|
2637
|
-
ns,
|
|
2638
|
-
i18n: i18nFromProps,
|
|
2639
|
-
t: tFromProps,
|
|
2640
|
-
shouldUnescape,
|
|
2641
|
-
...additionalProps
|
|
2642
|
-
} = _ref;
|
|
2643
|
-
const i18n = i18nFromProps || getI18n();
|
|
2644
|
-
if (!i18n) {
|
|
2645
|
-
warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
|
|
2646
|
-
return children;
|
|
2647
|
-
}
|
|
2648
|
-
const t = tFromProps || i18n.t.bind(i18n) || (k => k);
|
|
2649
|
-
if (context) tOptions.context = context;
|
|
2650
|
-
const reactI18nextOptions = {
|
|
2651
|
-
...getDefaults(),
|
|
2652
|
-
...(i18n.options && i18n.options.react)
|
|
2653
|
-
};
|
|
2654
|
-
let namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS;
|
|
2655
|
-
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
2656
|
-
const defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
|
|
2657
|
-
const {
|
|
2658
|
-
hashTransKey
|
|
2659
|
-
} = reactI18nextOptions;
|
|
2660
|
-
const key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
|
|
2661
|
-
const interpolationOverride = values ? tOptions.interpolation : {
|
|
2662
|
-
interpolation: {
|
|
2663
|
-
...tOptions.interpolation,
|
|
2664
|
-
prefix: '#$?',
|
|
2665
|
-
suffix: '?$#'
|
|
2666
|
-
}
|
|
2667
|
-
};
|
|
2668
|
-
const combinedTOpts = {
|
|
2669
|
-
...tOptions,
|
|
2670
|
-
count,
|
|
2671
|
-
...values,
|
|
2672
|
-
...interpolationOverride,
|
|
2673
|
-
defaultValue,
|
|
2674
|
-
ns: namespaces
|
|
2675
|
-
};
|
|
2676
|
-
const translation = key ? t(key, combinedTOpts) : defaultValue;
|
|
2677
|
-
const content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
|
|
2678
|
-
const useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
|
|
2679
|
-
return useAsParent ? createElement(useAsParent, additionalProps, content) : content;
|
|
2680
|
-
}
|
|
2681
|
-
|
|
2682
|
-
const initReactI18next = {
|
|
2683
|
-
type: '3rdParty',
|
|
2684
|
-
init(instance) {
|
|
2685
|
-
setDefaults(instance.options.react);
|
|
2686
|
-
setI18n(instance);
|
|
2687
|
-
}
|
|
2688
|
-
};
|
|
2689
|
-
|
|
2690
|
-
const I18nContext = createContext();
|
|
2691
|
-
class ReportNamespaces {
|
|
2692
|
-
constructor() {
|
|
2693
|
-
this.usedNamespaces = {};
|
|
2694
|
-
}
|
|
2695
|
-
addUsedNamespaces(namespaces) {
|
|
2696
|
-
namespaces.forEach(ns => {
|
|
2697
|
-
if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
|
|
2698
|
-
});
|
|
2699
|
-
}
|
|
2700
|
-
getUsedNamespaces() {
|
|
2701
|
-
return Object.keys(this.usedNamespaces);
|
|
2702
|
-
}
|
|
2703
|
-
}
|
|
2704
|
-
|
|
2705
|
-
function Trans(_ref) {
|
|
2706
|
-
let {
|
|
2707
|
-
children,
|
|
2708
|
-
count,
|
|
2709
|
-
parent,
|
|
2710
|
-
i18nKey,
|
|
2711
|
-
context,
|
|
2712
|
-
tOptions = {},
|
|
2713
|
-
values,
|
|
2714
|
-
defaults,
|
|
2715
|
-
components,
|
|
2716
|
-
ns,
|
|
2717
|
-
i18n: i18nFromProps,
|
|
2718
|
-
t: tFromProps,
|
|
2719
|
-
shouldUnescape,
|
|
2720
|
-
...additionalProps
|
|
2721
|
-
} = _ref;
|
|
2722
|
-
const {
|
|
2723
|
-
i18n: i18nFromContext,
|
|
2724
|
-
defaultNS: defaultNSFromContext
|
|
2725
|
-
} = useContext(I18nContext) || {};
|
|
2726
|
-
const i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
2727
|
-
const t = tFromProps || i18n && i18n.t.bind(i18n);
|
|
2728
|
-
return Trans$1({
|
|
2729
|
-
children,
|
|
2730
|
-
count,
|
|
2731
|
-
parent,
|
|
2732
|
-
i18nKey,
|
|
2733
|
-
context,
|
|
2734
|
-
tOptions,
|
|
2735
|
-
values,
|
|
2736
|
-
defaults,
|
|
2737
|
-
components,
|
|
2738
|
-
ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS,
|
|
2739
|
-
i18n,
|
|
2740
|
-
t: tFromProps,
|
|
2741
|
-
shouldUnescape,
|
|
2742
|
-
...additionalProps
|
|
2743
|
-
});
|
|
2744
|
-
}
|
|
2745
|
-
|
|
2746
|
-
const usePrevious = (value, ignore) => {
|
|
2747
|
-
const ref = useRef();
|
|
2748
|
-
useEffect(() => {
|
|
2749
|
-
ref.current = ignore ? ref.current : value;
|
|
2750
|
-
}, [value, ignore]);
|
|
2751
|
-
return ref.current;
|
|
2752
|
-
};
|
|
2753
|
-
function useTranslation(ns) {
|
|
2754
|
-
let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2755
|
-
const {
|
|
2756
|
-
i18n: i18nFromProps
|
|
2757
|
-
} = props;
|
|
2758
|
-
const {
|
|
2759
|
-
i18n: i18nFromContext,
|
|
2760
|
-
defaultNS: defaultNSFromContext
|
|
2761
|
-
} = useContext(I18nContext) || {};
|
|
2762
|
-
const i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
2763
|
-
if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
|
|
2764
|
-
if (!i18n) {
|
|
2765
|
-
warnOnce('You will need to pass in an i18next instance by using initReactI18next');
|
|
2766
|
-
const notReadyT = (k, optsOrDefaultValue) => {
|
|
2767
|
-
if (typeof optsOrDefaultValue === 'string') return optsOrDefaultValue;
|
|
2768
|
-
if (optsOrDefaultValue && typeof optsOrDefaultValue === 'object' && typeof optsOrDefaultValue.defaultValue === 'string') return optsOrDefaultValue.defaultValue;
|
|
2769
|
-
return Array.isArray(k) ? k[k.length - 1] : k;
|
|
2770
|
-
};
|
|
2771
|
-
const retNotReady = [notReadyT, {}, false];
|
|
2772
|
-
retNotReady.t = notReadyT;
|
|
2773
|
-
retNotReady.i18n = {};
|
|
2774
|
-
retNotReady.ready = false;
|
|
2775
|
-
return retNotReady;
|
|
2776
|
-
}
|
|
2777
|
-
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.');
|
|
2778
|
-
const i18nOptions = {
|
|
2779
|
-
...getDefaults(),
|
|
2780
|
-
...i18n.options.react,
|
|
2781
|
-
...props
|
|
2782
|
-
};
|
|
2783
|
-
const {
|
|
2784
|
-
useSuspense,
|
|
2785
|
-
keyPrefix
|
|
2786
|
-
} = i18nOptions;
|
|
2787
|
-
let namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
|
|
2788
|
-
namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
|
|
2789
|
-
if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
|
|
2790
|
-
const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(n => hasLoadedNamespace(n, i18n, i18nOptions));
|
|
2791
|
-
function getT() {
|
|
2792
|
-
return i18n.getFixedT(props.lng || null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
|
|
2793
|
-
}
|
|
2794
|
-
const [t, setT] = useState(getT);
|
|
2795
|
-
let joinedNS = namespaces.join();
|
|
2796
|
-
if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
|
|
2797
|
-
const previousJoinedNS = usePrevious(joinedNS);
|
|
2798
|
-
const isMounted = useRef(true);
|
|
2799
|
-
useEffect(() => {
|
|
2800
|
-
const {
|
|
2801
|
-
bindI18n,
|
|
2802
|
-
bindI18nStore
|
|
2803
|
-
} = i18nOptions;
|
|
2804
|
-
isMounted.current = true;
|
|
2805
|
-
if (!ready && !useSuspense) {
|
|
2806
|
-
if (props.lng) {
|
|
2807
|
-
loadLanguages(i18n, props.lng, namespaces, () => {
|
|
2808
|
-
if (isMounted.current) setT(getT);
|
|
2809
|
-
});
|
|
2810
|
-
} else {
|
|
2811
|
-
loadNamespaces(i18n, namespaces, () => {
|
|
2812
|
-
if (isMounted.current) setT(getT);
|
|
2813
|
-
});
|
|
2814
|
-
}
|
|
2815
|
-
}
|
|
2816
|
-
if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
|
|
2817
|
-
setT(getT);
|
|
2818
|
-
}
|
|
2819
|
-
function boundReset() {
|
|
2820
|
-
if (isMounted.current) setT(getT);
|
|
2821
|
-
}
|
|
2822
|
-
if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
|
|
2823
|
-
if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
|
|
2824
|
-
return () => {
|
|
2825
|
-
isMounted.current = false;
|
|
2826
|
-
if (bindI18n && i18n) bindI18n.split(' ').forEach(e => i18n.off(e, boundReset));
|
|
2827
|
-
if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(e => i18n.store.off(e, boundReset));
|
|
2828
|
-
};
|
|
2829
|
-
}, [i18n, joinedNS]);
|
|
2830
|
-
const isInitial = useRef(true);
|
|
2831
|
-
useEffect(() => {
|
|
2832
|
-
if (isMounted.current && !isInitial.current) {
|
|
2833
|
-
setT(getT);
|
|
2834
|
-
}
|
|
2835
|
-
isInitial.current = false;
|
|
2836
|
-
}, [i18n, keyPrefix]);
|
|
2837
|
-
const ret = [t, i18n, ready];
|
|
2838
|
-
ret.t = t;
|
|
2839
|
-
ret.i18n = i18n;
|
|
2840
|
-
ret.ready = ready;
|
|
2841
|
-
if (ready) return ret;
|
|
2842
|
-
if (!ready && !useSuspense) return ret;
|
|
2843
|
-
throw new Promise(resolve => {
|
|
2844
|
-
if (props.lng) {
|
|
2845
|
-
loadLanguages(i18n, props.lng, namespaces, () => resolve());
|
|
2846
|
-
} else {
|
|
2847
|
-
loadNamespaces(i18n, namespaces, () => resolve());
|
|
2848
|
-
}
|
|
2849
|
-
});
|
|
2850
|
-
}
|
|
2851
|
-
|
|
2852
|
-
var common = {
|
|
2853
|
-
clearFilters: "Clear filters",
|
|
2854
|
-
columns: "Columns",
|
|
2855
|
-
"delete": "Delete",
|
|
2856
|
-
done: "Done",
|
|
2857
|
-
filter: "Filter",
|
|
2858
|
-
filters: "Filters",
|
|
2859
|
-
no: "No",
|
|
2860
|
-
proceed: "Proceed",
|
|
2861
|
-
rename: "Rename",
|
|
2862
|
-
segments: "Segments",
|
|
2863
|
-
userCount: "{{count}} Users",
|
|
2864
|
-
yes: "Yes",
|
|
2865
|
-
update: "Update"
|
|
2866
|
-
};
|
|
2867
|
-
var messages = {
|
|
2868
|
-
enterResource: "Enter {{resource}}",
|
|
2869
|
-
noResourcesFound: "No {{resources}} found",
|
|
2870
|
-
searchResources: "Search {{resources}}",
|
|
2871
|
-
selectResource: "Select {{resource}}",
|
|
2872
|
-
selectOption: "Select an option"
|
|
2873
|
-
};
|
|
2874
|
-
var rules = {
|
|
2875
|
-
contains: "Contains",
|
|
2876
|
-
doesNotContain: "Does not contain",
|
|
2877
|
-
exactly: "Exactly",
|
|
2878
|
-
notExactly: "Not exactly",
|
|
2879
|
-
startsWith: "Starts with",
|
|
2880
|
-
doesNotStartWith: "Does not start with",
|
|
2881
|
-
endsWith: "Ends with",
|
|
2882
|
-
doesNotEndWith: "Does not end with",
|
|
2883
|
-
greaterThan: "Greater than",
|
|
2884
|
-
lessThan: "Less than"
|
|
2885
|
-
};
|
|
2886
|
-
var errors = {
|
|
2887
|
-
cannotPassMultipleModels: "Cannot pass multiple Models except for keyword searching"
|
|
2888
|
-
};
|
|
2889
|
-
var shortcuts = {
|
|
2890
|
-
deleteBlock: "Delete block",
|
|
2891
|
-
openFilterPane: "Open filter pane",
|
|
2892
|
-
closePane: "Close pane"
|
|
2893
|
-
};
|
|
2894
|
-
var segments = {
|
|
2895
|
-
addNewSegment: "Add new segment",
|
|
2896
|
-
deleteAlertMessage: "You are permanently deleting the segment <strong>{{entity}}</strong>. This can't be undone.",
|
|
2897
|
-
deleteAlertTitle: "Delete segment?",
|
|
2898
|
-
manageSegments: "Manage segments",
|
|
2899
|
-
name: "Segment name",
|
|
2900
|
-
noSegmentsFound: "No segments found",
|
|
2901
|
-
saveSegment: "Save segment",
|
|
2902
|
-
saveAsSegment: "Save as segment",
|
|
2903
|
-
saveAsNewSegment: "Save as new segment",
|
|
2904
|
-
searchSegments: "Search segments",
|
|
2905
|
-
segmentName: "Segment name",
|
|
2906
|
-
showLess: "See less",
|
|
2907
|
-
showMoreNumbers: "See {{entity}} more",
|
|
2908
|
-
updateSegment: "Update segment?",
|
|
2909
|
-
updateSegmentMessage: "You are trying to update the current segment."
|
|
2910
|
-
};
|
|
2911
|
-
var labels = {
|
|
2912
|
-
keyword: "Keyword"
|
|
2913
|
-
};
|
|
2914
|
-
var en = {
|
|
2915
|
-
common: common,
|
|
2916
|
-
messages: messages,
|
|
2917
|
-
rules: rules,
|
|
2918
|
-
errors: errors,
|
|
2919
|
-
shortcuts: shortcuts,
|
|
2920
|
-
segments: segments,
|
|
2921
|
-
labels: labels
|
|
2922
|
-
};
|
|
2923
|
-
|
|
2924
|
-
instance.use(initReactI18next).init({
|
|
2925
|
-
resources: {
|
|
2926
|
-
en: {
|
|
2927
|
-
translation: en
|
|
2928
|
-
}
|
|
2929
|
-
},
|
|
2930
|
-
fallbackLng: "en"
|
|
2931
|
-
});
|
|
2932
|
-
|
|
2933
22
|
function _arrayLikeToArray$1(arr, len) {
|
|
2934
23
|
if (len == null || len > arr.length) len = arr.length;
|
|
2935
24
|
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
@@ -3152,15 +241,15 @@ var filterBy = /*#__PURE__*/curry(function (pattern, array) {
|
|
|
3152
241
|
var SHORTCUTS = {
|
|
3153
242
|
closePane: {
|
|
3154
243
|
sequence: "escape",
|
|
3155
|
-
description: t$
|
|
244
|
+
description: t$1("neetoFilters.shortcuts.closePane")
|
|
3156
245
|
},
|
|
3157
246
|
deleteBlock: {
|
|
3158
247
|
sequence: "backspace",
|
|
3159
|
-
description: t$
|
|
248
|
+
description: t$1("neetoFilters.shortcuts.deleteBlock")
|
|
3160
249
|
},
|
|
3161
250
|
openFilterPane: {
|
|
3162
251
|
sequence: "enter",
|
|
3163
|
-
description: t$
|
|
252
|
+
description: t$1("neetoFilters.shortcuts.openFilterPane")
|
|
3164
253
|
}
|
|
3165
254
|
};
|
|
3166
255
|
|
|
@@ -3248,48 +337,48 @@ var DATE_RULES = {
|
|
|
3248
337
|
};
|
|
3249
338
|
|
|
3250
339
|
var NUMBER_RULES = [{
|
|
3251
|
-
label: t$
|
|
340
|
+
label: t$1("neetoFilters.rules.exactly"),
|
|
3252
341
|
value: "is"
|
|
3253
342
|
}, {
|
|
3254
|
-
label: t$
|
|
343
|
+
label: t$1("neetoFilters.rules.notExactly"),
|
|
3255
344
|
value: "is_not"
|
|
3256
345
|
}, {
|
|
3257
|
-
label: t$
|
|
346
|
+
label: t$1("neetoFilters.rules.greaterThan"),
|
|
3258
347
|
value: "greater_than"
|
|
3259
348
|
}, {
|
|
3260
|
-
label: t$
|
|
349
|
+
label: t$1("neetoFilters.rules.lessThan"),
|
|
3261
350
|
value: "less_than"
|
|
3262
351
|
}];
|
|
3263
352
|
var TEXT_RULES = [{
|
|
3264
|
-
label: t$
|
|
353
|
+
label: t$1("neetoFilters.rules.contains"),
|
|
3265
354
|
value: "contains"
|
|
3266
355
|
}, {
|
|
3267
|
-
label: t$
|
|
356
|
+
label: t$1("neetoFilters.rules.doesNotContain"),
|
|
3268
357
|
value: "does_not_contain"
|
|
3269
358
|
}, {
|
|
3270
|
-
label: t$
|
|
359
|
+
label: t$1("neetoFilters.rules.exactly"),
|
|
3271
360
|
value: "is"
|
|
3272
361
|
}, {
|
|
3273
|
-
label: t$
|
|
362
|
+
label: t$1("neetoFilters.rules.notExactly"),
|
|
3274
363
|
value: "is_not"
|
|
3275
364
|
}, {
|
|
3276
|
-
label: t$
|
|
365
|
+
label: t$1("neetoFilters.rules.startsWith"),
|
|
3277
366
|
value: "starts_with"
|
|
3278
367
|
}, {
|
|
3279
|
-
label: t$
|
|
368
|
+
label: t$1("neetoFilters.rules.doesNotStartWith"),
|
|
3280
369
|
value: "does_not_start_with"
|
|
3281
370
|
}, {
|
|
3282
|
-
label: t$
|
|
371
|
+
label: t$1("neetoFilters.rules.endsWith"),
|
|
3283
372
|
value: "ends_with"
|
|
3284
373
|
}, {
|
|
3285
|
-
label: t$
|
|
374
|
+
label: t$1("neetoFilters.rules.doesNotEndWith"),
|
|
3286
375
|
value: "does_not_end_with"
|
|
3287
376
|
}];
|
|
3288
377
|
var DEFAULT_BOOLEAN_OPTIONS = [{
|
|
3289
|
-
label: t$
|
|
378
|
+
label: t$1("neetoFilters.common.yes"),
|
|
3290
379
|
value: "true"
|
|
3291
380
|
}, {
|
|
3292
|
-
label: t$
|
|
381
|
+
label: t$1("neetoFilters.common.no"),
|
|
3293
382
|
value: "false"
|
|
3294
383
|
}];
|
|
3295
384
|
|
|
@@ -3669,7 +758,7 @@ var buildFiltersPayload = function buildFiltersPayload(filters) {
|
|
|
3669
758
|
defaultType = _filterPayload$defaul === void 0 ? filterPayload.type : _filterPayload$defaul,
|
|
3670
759
|
value = filterPayload.value;
|
|
3671
760
|
if (isMultiModelFilter(filterPayload)) {
|
|
3672
|
-
throw
|
|
761
|
+
throw i18next.t("neetoFilters.errors.cannotPassMultipleModels");
|
|
3673
762
|
}
|
|
3674
763
|
if (isDate(defaultType)) {
|
|
3675
764
|
return mergeRight(filterPayload, buildDatePayload(value));
|
|
@@ -3703,7 +792,7 @@ var buildSegmentsPayload = function buildSegmentsPayload(filters) {
|
|
|
3703
792
|
defaultType = _filterPayload$defaul2 === void 0 ? filterPayload.type : _filterPayload$defaul2,
|
|
3704
793
|
value = filterPayload.value;
|
|
3705
794
|
if (filter.key !== "keyword" && isMultiModelFilter(filterPayload)) {
|
|
3706
|
-
throw
|
|
795
|
+
throw i18next.t("neetoFilters.errors.cannotPassMultipleModels");
|
|
3707
796
|
}
|
|
3708
797
|
if (isMulti(defaultType)) {
|
|
3709
798
|
return mergeRight(filterPayload, {
|
|
@@ -3849,6 +938,9 @@ var buildUrlFromFilters = function buildUrlFromFilters(_ref16) {
|
|
|
3849
938
|
columns: columns
|
|
3850
939
|
});
|
|
3851
940
|
});
|
|
941
|
+
if (isEmpty(omit(["segmentId"], searchParams))) {
|
|
942
|
+
delete searchParams["segmentId"];
|
|
943
|
+
}
|
|
3852
944
|
return new URLSearchParams(searchParams).toString();
|
|
3853
945
|
};
|
|
3854
946
|
var createUrlParamStringForSegments = function createUrlParamStringForSegments(_ref18) {
|
|
@@ -4215,10 +1307,12 @@ var Segment = function Segment(_ref) {
|
|
|
4215
1307
|
_useShowSegment$data = _useShowSegment.data,
|
|
4216
1308
|
selectedSegment = _useShowSegment$data === void 0 ? {} : _useShowSegment$data;
|
|
4217
1309
|
var _useCreateSegment = useCreateSegment(),
|
|
4218
|
-
createSegment = _useCreateSegment.mutate
|
|
1310
|
+
createSegment = _useCreateSegment.mutate,
|
|
1311
|
+
isCreating = _useCreateSegment.isLoading;
|
|
4219
1312
|
var _useUpdateSegment = useUpdateSegment(),
|
|
4220
1313
|
updateSegment = _useUpdateSegment.mutate,
|
|
4221
1314
|
isUpdating = _useUpdateSegment.isLoading;
|
|
1315
|
+
var isSubmitting = isCreating || isUpdating;
|
|
4222
1316
|
var handleUpdate = function handleUpdate() {
|
|
4223
1317
|
return updateSegment({
|
|
4224
1318
|
id: segmentId,
|
|
@@ -4257,7 +1351,7 @@ var Segment = function Segment(_ref) {
|
|
|
4257
1351
|
};
|
|
4258
1352
|
return /*#__PURE__*/React.createElement(React.Fragment, null, isNil(segmentId) ? /*#__PURE__*/React.createElement(Button, {
|
|
4259
1353
|
disabled: hasOnlyKeywordFilter(filters),
|
|
4260
|
-
label: t("segments.saveAsSegment"),
|
|
1354
|
+
label: t("neetoFilters.segments.saveAsSegment"),
|
|
4261
1355
|
style: "secondary",
|
|
4262
1356
|
onClick: function onClick() {
|
|
4263
1357
|
setIsFilterPaneOpen(false);
|
|
@@ -4265,16 +1359,16 @@ var Segment = function Segment(_ref) {
|
|
|
4265
1359
|
}
|
|
4266
1360
|
}) : /*#__PURE__*/React.createElement(Dropdown$2, {
|
|
4267
1361
|
buttonStyle: "secondary",
|
|
4268
|
-
label: t("segments.saveSegment")
|
|
1362
|
+
label: t("neetoFilters.segments.saveSegment")
|
|
4269
1363
|
}, /*#__PURE__*/React.createElement(Menu, null, /*#__PURE__*/React.createElement(MenuItem.Button, {
|
|
4270
1364
|
isDisabled: equals(filtersPayload, selectedSegment === null || selectedSegment === void 0 ? void 0 : selectedSegment.filters),
|
|
4271
1365
|
onClick: setIsUpdateAlertOpen
|
|
4272
|
-
}, t("segments.saveSegment")), /*#__PURE__*/React.createElement(MenuItem.Button, {
|
|
1366
|
+
}, t("neetoFilters.segments.saveSegment")), /*#__PURE__*/React.createElement(MenuItem.Button, {
|
|
4273
1367
|
onClick: function onClick() {
|
|
4274
1368
|
setIsFilterPaneOpen(false);
|
|
4275
1369
|
setIsSavePaneOpen(true);
|
|
4276
1370
|
}
|
|
4277
|
-
}, t("segments.saveAsNewSegment")))), /*#__PURE__*/React.createElement(Pane$1, {
|
|
1371
|
+
}, t("neetoFilters.segments.saveAsNewSegment")))), /*#__PURE__*/React.createElement(Pane$1, {
|
|
4278
1372
|
initialFocusRef: inputRef,
|
|
4279
1373
|
isOpen: isSavePaneOpen,
|
|
4280
1374
|
onClose: function onClose() {
|
|
@@ -4283,7 +1377,7 @@ var Segment = function Segment(_ref) {
|
|
|
4283
1377
|
}, /*#__PURE__*/React.createElement(Pane$1.Header, null, /*#__PURE__*/React.createElement(Typography, {
|
|
4284
1378
|
style: "h2",
|
|
4285
1379
|
weight: "semibold"
|
|
4286
|
-
}, t("segments.addNewSegment"))), /*#__PURE__*/React.createElement(Form, {
|
|
1380
|
+
}, t("neetoFilters.segments.addNewSegment"))), /*#__PURE__*/React.createElement(Form, {
|
|
4287
1381
|
className: "w-full",
|
|
4288
1382
|
formProps: {
|
|
4289
1383
|
noValidate: true
|
|
@@ -4299,9 +1393,9 @@ var Segment = function Segment(_ref) {
|
|
|
4299
1393
|
}
|
|
4300
1394
|
}, /*#__PURE__*/React.createElement(Pane$1.Body, null, /*#__PURE__*/React.createElement(Input, {
|
|
4301
1395
|
className: "w-full",
|
|
4302
|
-
label: t("segments.name"),
|
|
1396
|
+
label: t("neetoFilters.segments.name"),
|
|
4303
1397
|
name: "name",
|
|
4304
|
-
placeholder: t("segments.segmentName"),
|
|
1398
|
+
placeholder: t("neetoFilters.segments.segmentName"),
|
|
4305
1399
|
ref: inputRef
|
|
4306
1400
|
})), /*#__PURE__*/React.createElement(Pane$1.Footer, {
|
|
4307
1401
|
className: "flex items-center space-x-2"
|
|
@@ -4311,13 +1405,17 @@ var Segment = function Segment(_ref) {
|
|
|
4311
1405
|
return setIsSavePaneOpen(false);
|
|
4312
1406
|
},
|
|
4313
1407
|
disabled: false
|
|
1408
|
+
},
|
|
1409
|
+
submitButtonProps: {
|
|
1410
|
+
disabled: isSubmitting,
|
|
1411
|
+
loading: isSubmitting
|
|
4314
1412
|
}
|
|
4315
1413
|
})))), /*#__PURE__*/React.createElement(Alert, {
|
|
4316
1414
|
isOpen: isUpdateAlertOpen,
|
|
4317
1415
|
isSubmitting: isUpdating,
|
|
4318
|
-
message: t("segments.updateSegmentMessage"),
|
|
4319
|
-
submitButtonLabel: t("common.update"),
|
|
4320
|
-
title: t("segments.updateSegment"),
|
|
1416
|
+
message: t("neetoFilters.segments.updateSegmentMessage"),
|
|
1417
|
+
submitButtonLabel: t("neetoFilters.common.update"),
|
|
1418
|
+
title: t("neetoFilters.segments.updateSegment"),
|
|
4321
1419
|
onClose: function onClose() {
|
|
4322
1420
|
return setIsUpdateAlertOpen(false);
|
|
4323
1421
|
},
|
|
@@ -4350,7 +1448,7 @@ var Bar = function Bar(_ref) {
|
|
|
4350
1448
|
key: "keyword",
|
|
4351
1449
|
type: "text",
|
|
4352
1450
|
rule: "contains",
|
|
4353
|
-
label: t("labels.keyword")
|
|
1451
|
+
label: t("neetoFilters.labels.keyword")
|
|
4354
1452
|
}, keyword);
|
|
4355
1453
|
var filters = buildFiltersFromSearchParams(keyword.value !== "" ? [keywordFilter].concat(_toConsumableArray(columns)) : columns);
|
|
4356
1454
|
var nonHiddenFilters = removeBy({
|
|
@@ -4444,7 +1542,7 @@ var Bar = function Bar(_ref) {
|
|
|
4444
1542
|
setIsFilterPaneOpen: setIsPaneOpen
|
|
4445
1543
|
}), !hideClearButton && /*#__PURE__*/React.createElement(Button, {
|
|
4446
1544
|
"data-cy": "neeto-filters-bar-clear-btn",
|
|
4447
|
-
label: t("common.clearFilters"),
|
|
1545
|
+
label: t("neetoFilters.common.clearFilters"),
|
|
4448
1546
|
style: "text",
|
|
4449
1547
|
onClick: handleClearAll
|
|
4450
1548
|
}));
|
|
@@ -7126,14 +4224,14 @@ var Boolean = function Boolean(_ref) {
|
|
|
7126
4224
|
handleApplyFilter(updatedFilter);
|
|
7127
4225
|
};
|
|
7128
4226
|
return /*#__PURE__*/React.createElement(Select, _extends$1({
|
|
7129
|
-
isClearable: true,
|
|
7130
4227
|
autoFocus: autoFocus,
|
|
7131
|
-
"data-cy": "neeto-filters-".concat(key, "-filter"),
|
|
7132
4228
|
label: label,
|
|
7133
4229
|
options: options,
|
|
7134
|
-
strategy: "fixed",
|
|
7135
4230
|
value: value,
|
|
7136
|
-
|
|
4231
|
+
isClearable: true,
|
|
4232
|
+
"data-cy": "neeto-filters-".concat(key, "-filter"),
|
|
4233
|
+
strategy: "fixed",
|
|
4234
|
+
placeholder: t("neetoFilters.messages.selectOption", {
|
|
7137
4235
|
resource: label.toLocaleLowerCase()
|
|
7138
4236
|
}),
|
|
7139
4237
|
onChange: handleChange
|
|
@@ -7199,14 +4297,14 @@ var Datetime = function Datetime(_ref) {
|
|
|
7199
4297
|
return /*#__PURE__*/React.createElement("div", {
|
|
7200
4298
|
className: "neeto-filters-pane-filter__item-wrapper"
|
|
7201
4299
|
}, /*#__PURE__*/React.createElement(Select, {
|
|
7202
|
-
isClearable: true,
|
|
7203
4300
|
autoFocus: autoFocus,
|
|
7204
4301
|
label: label,
|
|
4302
|
+
isClearable: true,
|
|
7205
4303
|
"data-cy": "neeto-filters-".concat(key, "-filter"),
|
|
7206
4304
|
options: DATE_OPTIONS,
|
|
7207
4305
|
strategy: "fixed",
|
|
7208
4306
|
value: selectedRule,
|
|
7209
|
-
placeholder: t("messages.selectResource", {
|
|
4307
|
+
placeholder: t("neetoFilters.messages.selectResource", {
|
|
7210
4308
|
resource: label.toLocaleLowerCase()
|
|
7211
4309
|
}),
|
|
7212
4310
|
onChange: handleChange
|
|
@@ -7262,14 +4360,14 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
7262
4360
|
};
|
|
7263
4361
|
return /*#__PURE__*/React.createElement(Select, _extends$1({
|
|
7264
4362
|
autoFocus: autoFocus,
|
|
4363
|
+
label: label,
|
|
4364
|
+
options: options,
|
|
4365
|
+
value: value,
|
|
7265
4366
|
"data-cy": "neeto-filters-".concat(key, "-filter"),
|
|
7266
4367
|
isClearable: !defaultValue && isClearable,
|
|
7267
4368
|
isMulti: isMulti(defaultType),
|
|
7268
|
-
label: label,
|
|
7269
|
-
options: options,
|
|
7270
4369
|
strategy: "fixed",
|
|
7271
|
-
|
|
7272
|
-
placeholder: t("messages.selectResource", {
|
|
4370
|
+
placeholder: t("neetoFilters.messages.selectResource", {
|
|
7273
4371
|
resource: label.toLocaleLowerCase()
|
|
7274
4372
|
}),
|
|
7275
4373
|
onChange: handleChange
|
|
@@ -7513,9 +4611,9 @@ var Text = function Text(_ref) {
|
|
|
7513
4611
|
return /*#__PURE__*/React.createElement("div", {
|
|
7514
4612
|
className: "neeto-filters-pane-filter__item-wrapper"
|
|
7515
4613
|
}, showRuleSelector && /*#__PURE__*/React.createElement(Select, {
|
|
4614
|
+
label: label,
|
|
7516
4615
|
"data-cy": "neeto-filters-".concat(key, "-filter-rule"),
|
|
7517
4616
|
defaultValue: ruleOptions[0],
|
|
7518
|
-
label: label,
|
|
7519
4617
|
options: ruleOptions,
|
|
7520
4618
|
strategy: "fixed",
|
|
7521
4619
|
value: selectedRule,
|
|
@@ -7526,7 +4624,7 @@ var Text = function Text(_ref) {
|
|
|
7526
4624
|
label: !showRuleSelector && label,
|
|
7527
4625
|
type: inputType,
|
|
7528
4626
|
value: inputValue,
|
|
7529
|
-
placeholder: t("messages.enterResource", {
|
|
4627
|
+
placeholder: t("neetoFilters.messages.enterResource", {
|
|
7530
4628
|
resource: label.toLocaleLowerCase()
|
|
7531
4629
|
}),
|
|
7532
4630
|
onChange: function onChange(event) {
|
|
@@ -7579,14 +4677,14 @@ var Time = function Time(_ref) {
|
|
|
7579
4677
|
return /*#__PURE__*/React.createElement("div", {
|
|
7580
4678
|
className: "neeto-filters-pane-filter__item-wrapper"
|
|
7581
4679
|
}, /*#__PURE__*/React.createElement(Select, {
|
|
7582
|
-
isClearable: true,
|
|
7583
4680
|
autoFocus: autoFocus,
|
|
7584
4681
|
label: label,
|
|
7585
4682
|
value: value,
|
|
4683
|
+
isClearable: true,
|
|
7586
4684
|
"data-cy": "neeto-filters-".concat(key, "-filter"),
|
|
7587
4685
|
options: TIME_OPTIONS,
|
|
7588
4686
|
strategy: "fixed",
|
|
7589
|
-
placeholder: t("messages.selectResource", {
|
|
4687
|
+
placeholder: t("neetoFilters.messages.selectResource", {
|
|
7590
4688
|
resource: label.toLocaleLowerCase()
|
|
7591
4689
|
}),
|
|
7592
4690
|
onChange: handleChange
|
|
@@ -7741,7 +4839,7 @@ var Pane = function Pane(_ref) {
|
|
|
7741
4839
|
key: "keyword",
|
|
7742
4840
|
type: "text",
|
|
7743
4841
|
rule: "contains",
|
|
7744
|
-
label: t("labels.keyword")
|
|
4842
|
+
label: t("neetoFilters.labels.keyword")
|
|
7745
4843
|
}, keyword);
|
|
7746
4844
|
var handleClearAll = function handleClearAll() {
|
|
7747
4845
|
keyword.setValue("");
|
|
@@ -7776,25 +4874,25 @@ var Pane = function Pane(_ref) {
|
|
|
7776
4874
|
}, /*#__PURE__*/React.createElement(Typography, {
|
|
7777
4875
|
style: "h2",
|
|
7778
4876
|
weight: "semibold"
|
|
7779
|
-
}, t("common.filters"))), /*#__PURE__*/React.createElement(Slider.Body, {
|
|
4877
|
+
}, t("neetoFilters.common.filters"))), /*#__PURE__*/React.createElement(Slider.Body, {
|
|
7780
4878
|
className: "neeto-filters-pane-filter__body neeto-ui-pt-2"
|
|
7781
4879
|
}, isSearchable && /*#__PURE__*/React.createElement(Input$1, {
|
|
7782
4880
|
autoFocus: true,
|
|
7783
4881
|
"data-cy": "neeto-filters-column-search",
|
|
7784
4882
|
prefix: /*#__PURE__*/React.createElement(Search, null),
|
|
7785
4883
|
value: searchTerm,
|
|
7786
|
-
placeholder: t("messages.searchResources", {
|
|
7787
|
-
resources: t("common.filters").toLocaleLowerCase()
|
|
4884
|
+
placeholder: t("neetoFilters.messages.searchResources", {
|
|
4885
|
+
resources: t("neetoFilters.common.filters").toLocaleLowerCase()
|
|
7788
4886
|
}),
|
|
7789
4887
|
onChange: function onChange(event) {
|
|
7790
4888
|
return setSearchTerm(event.target.value);
|
|
7791
4889
|
}
|
|
7792
4890
|
}), ungroupedColumns.map(function (column) {
|
|
7793
4891
|
return /*#__PURE__*/React.createElement(Item, {
|
|
7794
|
-
autoFocus: column.key === isOpen,
|
|
7795
4892
|
column: column,
|
|
7796
4893
|
filters: filters,
|
|
7797
4894
|
onClose: onClose,
|
|
4895
|
+
autoFocus: column.key === isOpen,
|
|
7798
4896
|
key: column.key,
|
|
7799
4897
|
onChange: handleChange
|
|
7800
4898
|
});
|
|
@@ -7814,27 +4912,27 @@ var Pane = function Pane(_ref) {
|
|
|
7814
4912
|
title: group
|
|
7815
4913
|
}, columns.map(function (column) {
|
|
7816
4914
|
return /*#__PURE__*/React.createElement(Item, {
|
|
7817
|
-
autoFocus: column.key === isOpen,
|
|
7818
4915
|
column: column,
|
|
7819
4916
|
filters: filters,
|
|
4917
|
+
autoFocus: column.key === isOpen,
|
|
7820
4918
|
key: column.key,
|
|
7821
4919
|
onChange: handleChange
|
|
7822
4920
|
});
|
|
7823
4921
|
}));
|
|
7824
4922
|
})), isEmpty(ungroupedColumns) && isEmpty(groupedColumns) && /*#__PURE__*/React.createElement(Typography, {
|
|
7825
4923
|
style: "body2"
|
|
7826
|
-
}, t("messages.noResourcesFound", {
|
|
7827
|
-
resources: t("common.columns").toLocaleLowerCase()
|
|
4924
|
+
}, t("neetoFilters.messages.noResourcesFound", {
|
|
4925
|
+
resources: t("neetoFilters.common.columns").toLocaleLowerCase()
|
|
7828
4926
|
})), children), /*#__PURE__*/React.createElement(Slider.Footer, {
|
|
7829
4927
|
className: "neeto-filters-pane-filter__footer"
|
|
7830
4928
|
}, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Button, {
|
|
7831
4929
|
"data-cy": "neeto-filters-done-btn",
|
|
7832
|
-
label: t("common.done"),
|
|
4930
|
+
label: t("neetoFilters.common.done"),
|
|
7833
4931
|
onClick: onClose
|
|
7834
4932
|
}), /*#__PURE__*/React.createElement(Button, {
|
|
7835
4933
|
"data-cy": "neeto-filters-clear-btn",
|
|
7836
4934
|
disabled: isClearFiltersDisabled,
|
|
7837
|
-
label: t("common.clearFilters"),
|
|
4935
|
+
label: t("neetoFilters.common.clearFilters"),
|
|
7838
4936
|
style: "text",
|
|
7839
4937
|
onClick: handleClearAll
|
|
7840
4938
|
})))));
|
|
@@ -7879,7 +4977,7 @@ var Filters = withT(function (_ref) {
|
|
|
7879
4977
|
className: classnames(_defineProperty({}, className, className))
|
|
7880
4978
|
}, /*#__PURE__*/React.createElement(Button, _extends$1({
|
|
7881
4979
|
"data-cy": "neeto-filters-toggle-btn",
|
|
7882
|
-
label: t("common.filter"),
|
|
4980
|
+
label: t("neetoFilters.common.filter"),
|
|
7883
4981
|
style: "secondary",
|
|
7884
4982
|
onClick: function onClick() {
|
|
7885
4983
|
return setIsOpen(true);
|
|
@@ -7931,16 +5029,16 @@ var DeleteAlert = function DeleteAlert(_ref) {
|
|
|
7931
5029
|
};
|
|
7932
5030
|
return /*#__PURE__*/React.createElement(Alert, {
|
|
7933
5031
|
isOpen: isOpen,
|
|
5032
|
+
onClose: onClose,
|
|
7934
5033
|
isSubmitting: isDeleting,
|
|
7935
|
-
submitButtonLabel: t("common.delete"),
|
|
7936
|
-
title: t("segments.deleteAlertTitle"),
|
|
5034
|
+
submitButtonLabel: t("neetoFilters.common.delete"),
|
|
5035
|
+
title: t("neetoFilters.segments.deleteAlertTitle"),
|
|
7937
5036
|
message: /*#__PURE__*/React.createElement(Trans, {
|
|
7938
|
-
i18nKey: "segments.deleteAlertMessage",
|
|
5037
|
+
i18nKey: "neetoFilters.segments.deleteAlertMessage",
|
|
7939
5038
|
values: {
|
|
7940
5039
|
entity: segment.name
|
|
7941
5040
|
}
|
|
7942
5041
|
}),
|
|
7943
|
-
onClose: onClose,
|
|
7944
5042
|
onSubmit: handleDelete
|
|
7945
5043
|
});
|
|
7946
5044
|
};
|
|
@@ -7973,7 +5071,7 @@ var Card = function Card(_ref) {
|
|
|
7973
5071
|
});
|
|
7974
5072
|
};
|
|
7975
5073
|
return /*#__PURE__*/React.createElement(Form, {
|
|
7976
|
-
className: "flex w-full items-center justify-between
|
|
5074
|
+
className: "neeto-ui-rounded-md flex w-full items-center justify-between border p-2",
|
|
7977
5075
|
formProps: {
|
|
7978
5076
|
noValidate: true
|
|
7979
5077
|
},
|
|
@@ -7990,7 +5088,7 @@ var Card = function Card(_ref) {
|
|
|
7990
5088
|
autoFocus: true,
|
|
7991
5089
|
nakedInput: true,
|
|
7992
5090
|
name: "name",
|
|
7993
|
-
placeholder: t("segments.name")
|
|
5091
|
+
placeholder: t("neetoFilters.segments.name")
|
|
7994
5092
|
}), /*#__PURE__*/React.createElement(ActionBlock, {
|
|
7995
5093
|
cancelButtonProps: {
|
|
7996
5094
|
icon: Close,
|
|
@@ -8017,14 +5115,14 @@ var Card = function Card(_ref) {
|
|
|
8017
5115
|
setIsEditing(true);
|
|
8018
5116
|
resetForm();
|
|
8019
5117
|
}
|
|
8020
|
-
}, t("common.rename")), /*#__PURE__*/React.createElement(MenuItem.Button, {
|
|
5118
|
+
}, t("neetoFilters.common.rename")), /*#__PURE__*/React.createElement(MenuItem.Button, {
|
|
8021
5119
|
onClick: function onClick() {
|
|
8022
5120
|
return setIsDeleteAlertOpen(true);
|
|
8023
5121
|
}
|
|
8024
|
-
}, t("common.delete"))))), /*#__PURE__*/React.createElement(DeleteAlert, {
|
|
5122
|
+
}, t("neetoFilters.common.delete"))))), /*#__PURE__*/React.createElement(DeleteAlert, {
|
|
8025
5123
|
columns: columns,
|
|
8026
|
-
isOpen: isDeleteAlertOpen,
|
|
8027
5124
|
segment: segment,
|
|
5125
|
+
isOpen: isDeleteAlertOpen,
|
|
8028
5126
|
onClose: function onClose() {
|
|
8029
5127
|
return setIsDeleteAlertOpen(false);
|
|
8030
5128
|
}
|
|
@@ -8054,16 +5152,16 @@ var ManagePane = function ManagePane(_ref) {
|
|
|
8054
5152
|
segments = _useFetchSegments$dat === void 0 ? [] : _useFetchSegments$dat,
|
|
8055
5153
|
isLoading = _useFetchSegments.isLoading;
|
|
8056
5154
|
return /*#__PURE__*/React.createElement(Pane$1, {
|
|
8057
|
-
initialFocusRef: inputRef,
|
|
8058
5155
|
isOpen: isOpen,
|
|
8059
|
-
onClose: onClose
|
|
5156
|
+
onClose: onClose,
|
|
5157
|
+
initialFocusRef: inputRef
|
|
8060
5158
|
}, /*#__PURE__*/React.createElement(Pane$1.Header, null, /*#__PURE__*/React.createElement(Typography, {
|
|
8061
5159
|
style: "h2"
|
|
8062
|
-
}, t("segments.manageSegments"))), /*#__PURE__*/React.createElement(Pane$1.Body, {
|
|
5160
|
+
}, t("neetoFilters.segments.manageSegments"))), /*#__PURE__*/React.createElement(Pane$1.Body, {
|
|
8063
5161
|
className: "max-h-full gap-4 overflow-scroll"
|
|
8064
5162
|
}, /*#__PURE__*/React.createElement(Input$1, {
|
|
8065
5163
|
className: "w-full flex-grow-0",
|
|
8066
|
-
placeholder: t("segments.searchSegments"),
|
|
5164
|
+
placeholder: t("neetoFilters.segments.searchSegments"),
|
|
8067
5165
|
prefix: /*#__PURE__*/React.createElement(Search, null),
|
|
8068
5166
|
ref: inputRef,
|
|
8069
5167
|
type: "search",
|
|
@@ -8077,16 +5175,16 @@ var ManagePane = function ManagePane(_ref) {
|
|
|
8077
5175
|
}) : /*#__PURE__*/React.createElement(React.Fragment, null, isEmpty(segments) ? /*#__PURE__*/React.createElement(Typography, {
|
|
8078
5176
|
className: "mx-auto",
|
|
8079
5177
|
style: "body2"
|
|
8080
|
-
}, t("segments.noSegmentsFound")) : segments.map(function (segment) {
|
|
5178
|
+
}, t("neetoFilters.segments.noSegmentsFound")) : segments.map(function (segment) {
|
|
8081
5179
|
return /*#__PURE__*/React.createElement(Card$1, {
|
|
8082
5180
|
columns: columns,
|
|
8083
|
-
|
|
8084
|
-
|
|
5181
|
+
segment: segment,
|
|
5182
|
+
key: segment.id
|
|
8085
5183
|
});
|
|
8086
5184
|
}))));
|
|
8087
5185
|
};
|
|
8088
5186
|
|
|
8089
|
-
var ITEMS_MAX_COUNT =
|
|
5187
|
+
var ITEMS_MAX_COUNT = 20;
|
|
8090
5188
|
|
|
8091
5189
|
var MenuBlocks = function MenuBlocks(_ref) {
|
|
8092
5190
|
var entity = _ref.entity,
|
|
@@ -8136,12 +5234,12 @@ var MenuBlocks = function MenuBlocks(_ref) {
|
|
|
8136
5234
|
if (isEmpty(segments)) {
|
|
8137
5235
|
return /*#__PURE__*/React.createElement(Typography, {
|
|
8138
5236
|
style: "body2"
|
|
8139
|
-
}, t("segments.noSegmentsFound"));
|
|
5237
|
+
}, t("neetoFilters.segments.noSegmentsFound"));
|
|
8140
5238
|
}
|
|
8141
5239
|
return /*#__PURE__*/React.createElement(React.Fragment, null, segments.length > ITEMS_MAX_COUNT && /*#__PURE__*/React.createElement(Button, {
|
|
8142
5240
|
icon: Down,
|
|
8143
5241
|
style: "link",
|
|
8144
|
-
label: showAll ? t("segments.showLess") : t("segments.showMoreNumbers", {
|
|
5242
|
+
label: showAll ? t("neetoFilters.segments.showLess") : t("neetoFilters.segments.showMoreNumbers", {
|
|
8145
5243
|
entity: segments.length - ITEMS_MAX_COUNT
|
|
8146
5244
|
}),
|
|
8147
5245
|
onClick: function onClick() {
|
|
@@ -8192,7 +5290,7 @@ var Segments = function Segments(_ref) {
|
|
|
8192
5290
|
});
|
|
8193
5291
|
},
|
|
8194
5292
|
tooltipProps: {
|
|
8195
|
-
content: t("segments.searchSegments"),
|
|
5293
|
+
content: t("neetoFilters.segments.searchSegments"),
|
|
8196
5294
|
position: "top"
|
|
8197
5295
|
}
|
|
8198
5296
|
}, {
|
|
@@ -8202,7 +5300,7 @@ var Segments = function Segments(_ref) {
|
|
|
8202
5300
|
setIsSegmentsPaneOpen(true);
|
|
8203
5301
|
},
|
|
8204
5302
|
tooltipProps: {
|
|
8205
|
-
content: t("segments.manageSegments"),
|
|
5303
|
+
content: t("neetoFilters.segments.manageSegments"),
|
|
8206
5304
|
position: "top"
|
|
8207
5305
|
}
|
|
8208
5306
|
}];
|
|
@@ -8213,10 +5311,10 @@ var Segments = function Segments(_ref) {
|
|
|
8213
5311
|
style: "h5",
|
|
8214
5312
|
textTransform: "uppercase",
|
|
8215
5313
|
weight: "bold"
|
|
8216
|
-
}, t("common.segments"))), /*#__PURE__*/React.createElement(MenuBar.Search, {
|
|
5314
|
+
}, t("neetoFilters.common.segments"))), /*#__PURE__*/React.createElement(MenuBar.Search, {
|
|
8217
5315
|
autoFocus: true,
|
|
8218
5316
|
isCollapsed: isSearchCollapsed,
|
|
8219
|
-
placeholder: t("segments.searchSegments"),
|
|
5317
|
+
placeholder: t("neetoFilters.segments.searchSegments"),
|
|
8220
5318
|
value: searchTerm,
|
|
8221
5319
|
onChange: function onChange(_ref2) {
|
|
8222
5320
|
var value = _ref2.target.value;
|
|
@@ -8241,7 +5339,75 @@ var Segments = function Segments(_ref) {
|
|
|
8241
5339
|
};
|
|
8242
5340
|
var index = /*#__PURE__*/React.memo(Segments);
|
|
8243
5341
|
|
|
8244
|
-
|
|
5342
|
+
var neetoFilters = {
|
|
5343
|
+
common: {
|
|
5344
|
+
clearFilters: "Clear filters",
|
|
5345
|
+
columns: "Columns",
|
|
5346
|
+
"delete": "Delete",
|
|
5347
|
+
done: "Done",
|
|
5348
|
+
filter: "Filter",
|
|
5349
|
+
filters: "Filters",
|
|
5350
|
+
no: "No",
|
|
5351
|
+
proceed: "Proceed",
|
|
5352
|
+
rename: "Rename",
|
|
5353
|
+
segments: "Segments",
|
|
5354
|
+
userCount: "{{count}} Users",
|
|
5355
|
+
yes: "Yes",
|
|
5356
|
+
update: "Update"
|
|
5357
|
+
},
|
|
5358
|
+
messages: {
|
|
5359
|
+
enterResource: "Enter {{resource}}",
|
|
5360
|
+
noResourcesFound: "No {{resources}} found",
|
|
5361
|
+
searchResources: "Search {{resources}}",
|
|
5362
|
+
selectResource: "Select {{resource}}",
|
|
5363
|
+
selectOption: "Select an option"
|
|
5364
|
+
},
|
|
5365
|
+
rules: {
|
|
5366
|
+
contains: "Contains",
|
|
5367
|
+
doesNotContain: "Does not contain",
|
|
5368
|
+
exactly: "Exactly",
|
|
5369
|
+
notExactly: "Not exactly",
|
|
5370
|
+
startsWith: "Starts with",
|
|
5371
|
+
doesNotStartWith: "Does not start with",
|
|
5372
|
+
endsWith: "Ends with",
|
|
5373
|
+
doesNotEndWith: "Does not end with",
|
|
5374
|
+
greaterThan: "Greater than",
|
|
5375
|
+
lessThan: "Less than"
|
|
5376
|
+
},
|
|
5377
|
+
errors: {
|
|
5378
|
+
cannotPassMultipleModels: "Cannot pass multiple Models except for keyword searching"
|
|
5379
|
+
},
|
|
5380
|
+
shortcuts: {
|
|
5381
|
+
deleteBlock: "Delete block",
|
|
5382
|
+
openFilterPane: "Open filter pane",
|
|
5383
|
+
closePane: "Close pane"
|
|
5384
|
+
},
|
|
5385
|
+
segments: {
|
|
5386
|
+
addNewSegment: "Add new segment",
|
|
5387
|
+
deleteAlertMessage: "You are permanently deleting the segment <strong>{{entity}}</strong>. This can't be undone.",
|
|
5388
|
+
deleteAlertTitle: "Delete segment?",
|
|
5389
|
+
manageSegments: "Manage segments",
|
|
5390
|
+
name: "Segment name",
|
|
5391
|
+
noSegmentsFound: "No segments found",
|
|
5392
|
+
saveSegment: "Save segment",
|
|
5393
|
+
saveAsSegment: "Save as segment",
|
|
5394
|
+
saveAsNewSegment: "Save as new segment",
|
|
5395
|
+
searchSegments: "Search segments",
|
|
5396
|
+
segmentName: "Segment name",
|
|
5397
|
+
showLess: "See less",
|
|
5398
|
+
showMoreNumbers: "See {{entity}} more",
|
|
5399
|
+
updateSegment: "Update segment?",
|
|
5400
|
+
updateSegmentMessage: "You are trying to update the current segment."
|
|
5401
|
+
},
|
|
5402
|
+
labels: {
|
|
5403
|
+
keyword: "Keyword"
|
|
5404
|
+
}
|
|
5405
|
+
};
|
|
5406
|
+
var en = {
|
|
5407
|
+
neetoFilters: neetoFilters
|
|
5408
|
+
};
|
|
5409
|
+
|
|
5410
|
+
i18next.use(initReactI18next).init({
|
|
8245
5411
|
resources: {
|
|
8246
5412
|
en: {
|
|
8247
5413
|
translation: en
|