andoncloud-widget-preview 1.1.6 → 1.1.8

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.js CHANGED
@@ -20,7 +20,24 @@ function _typeof(obj) {
20
20
  }, _typeof(obj);
21
21
  }
22
22
 
23
+ function _toPrimitive(input, hint) {
24
+ if (_typeof(input) !== "object" || input === null) return input;
25
+ var prim = input[Symbol.toPrimitive];
26
+ if (prim !== undefined) {
27
+ var res = prim.call(input, hint || "default");
28
+ if (_typeof(res) !== "object") return res;
29
+ throw new TypeError("@@toPrimitive must return a primitive value.");
30
+ }
31
+ return (hint === "string" ? String : Number)(input);
32
+ }
33
+
34
+ function _toPropertyKey(arg) {
35
+ var key = _toPrimitive(arg, "string");
36
+ return _typeof(key) === "symbol" ? key : String(key);
37
+ }
38
+
23
39
  function _defineProperty(obj, key, value) {
40
+ key = _toPropertyKey(key);
24
41
  if (key in obj) {
25
42
  Object.defineProperty(obj, key, {
26
43
  value: value,
@@ -31,36 +48,10 @@ function _defineProperty(obj, key, value) {
31
48
  } else {
32
49
  obj[key] = value;
33
50
  }
34
-
35
51
  return obj;
36
52
  }
37
53
 
38
- function _classCallCheck(instance, Constructor) {
39
- if (!(instance instanceof Constructor)) {
40
- throw new TypeError("Cannot call a class as a function");
41
- }
42
- }
43
-
44
- function _defineProperties(target, props) {
45
- for (var i = 0; i < props.length; i++) {
46
- var descriptor = props[i];
47
- descriptor.enumerable = descriptor.enumerable || false;
48
- descriptor.configurable = true;
49
- if ("value" in descriptor) descriptor.writable = true;
50
- Object.defineProperty(target, descriptor.key, descriptor);
51
- }
52
- }
53
-
54
- function _createClass(Constructor, protoProps, staticProps) {
55
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
56
- if (staticProps) _defineProperties(Constructor, staticProps);
57
- Object.defineProperty(Constructor, "prototype", {
58
- writable: false
59
- });
60
- return Constructor;
61
- }
62
-
63
- var matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230);/g;
54
+ var matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
64
55
  var htmlEntities = {
65
56
  '&amp;': '&',
66
57
  '&#38;': '&',
@@ -79,14 +70,16 @@ var htmlEntities = {
79
70
  '&reg;': '®',
80
71
  '&#174;': '®',
81
72
  '&hellip;': '…',
82
- '&#8230;': '…'
73
+ '&#8230;': '…',
74
+ '&#x2F;': '/',
75
+ '&#47;': '/'
83
76
  };
84
77
 
85
78
  var unescapeHtmlEntity = function unescapeHtmlEntity(m) {
86
79
  return htmlEntities[m];
87
80
  };
88
81
 
89
- var unescape = function unescape(text) {
82
+ var unescape$1 = function unescape(text) {
90
83
  return text.replace(matchHtmlEntity, unescapeHtmlEntity);
91
84
  };
92
85
 
@@ -101,13 +94,45 @@ var defaultOptions = {
101
94
  transWrapTextNodes: '',
102
95
  transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
103
96
  useSuspense: true,
104
- unescape: unescape
97
+ unescape: unescape$1
105
98
  };
106
- React.createContext();
107
99
  function setDefaults() {
108
100
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
109
101
  defaultOptions = _objectSpread$7(_objectSpread$7({}, defaultOptions), options);
110
102
  }
103
+
104
+ function _classCallCheck(instance, Constructor) {
105
+ if (!(instance instanceof Constructor)) {
106
+ throw new TypeError("Cannot call a class as a function");
107
+ }
108
+ }
109
+
110
+ function _defineProperties(target, props) {
111
+ for (var i = 0; i < props.length; i++) {
112
+ var descriptor = props[i];
113
+ descriptor.enumerable = descriptor.enumerable || false;
114
+ descriptor.configurable = true;
115
+ if ("value" in descriptor) descriptor.writable = true;
116
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
117
+ }
118
+ }
119
+ function _createClass(Constructor, protoProps, staticProps) {
120
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
121
+ if (staticProps) _defineProperties(Constructor, staticProps);
122
+ Object.defineProperty(Constructor, "prototype", {
123
+ writable: false
124
+ });
125
+ return Constructor;
126
+ }
127
+
128
+ var initReactI18next = {
129
+ type: '3rdParty',
130
+ init: function init(instance) {
131
+ setDefaults(instance.options.react);
132
+ }
133
+ };
134
+
135
+ React.createContext();
111
136
  (function () {
112
137
  function ReportNamespaces() {
113
138
  _classCallCheck(this, ReportNamespaces);
@@ -133,12 +158,6 @@ function setDefaults() {
133
158
 
134
159
  return ReportNamespaces;
135
160
  })();
136
- var initReactI18next = {
137
- type: '3rdParty',
138
- init: function init(instance) {
139
- setDefaults(instance.options.react);
140
- }
141
- };
142
161
 
143
162
  function _arrayWithHoles(arr) {
144
163
  if (Array.isArray(arr)) return arr;
@@ -146,11 +165,7 @@ function _arrayWithHoles(arr) {
146
165
 
147
166
  function _arrayLikeToArray(arr, len) {
148
167
  if (len == null || len > arr.length) len = arr.length;
149
-
150
- for (var i = 0, arr2 = new Array(len); i < len; i++) {
151
- arr2[i] = arr[i];
152
- }
153
-
168
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
154
169
  return arr2;
155
170
  }
156
171
 
@@ -171,7 +186,6 @@ function _assertThisInitialized(self) {
171
186
  if (self === void 0) {
172
187
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
173
188
  }
174
-
175
189
  return self;
176
190
  }
177
191
 
@@ -187,7 +201,6 @@ function _inherits(subClass, superClass) {
187
201
  if (typeof superClass !== "function" && superClass !== null) {
188
202
  throw new TypeError("Super expression must either be null or a function");
189
203
  }
190
-
191
204
  subClass.prototype = Object.create(superClass && superClass.prototype, {
192
205
  constructor: {
193
206
  value: subClass,
@@ -207,7 +220,6 @@ function _possibleConstructorReturn(self, call) {
207
220
  } else if (call !== void 0) {
208
221
  throw new TypeError("Derived constructors may only return object or undefined");
209
222
  }
210
-
211
223
  return _assertThisInitialized(self);
212
224
  }
213
225
 
@@ -226,10 +238,8 @@ function _toArray(arr) {
226
238
  return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
227
239
  }
228
240
 
229
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
230
-
231
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
232
-
241
+ function ownKeys$6(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
242
+ function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$6(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$6(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
233
243
  var consoleLogger = {
234
244
  type: 'logger',
235
245
  log: function log(args) {
@@ -245,16 +255,12 @@ var consoleLogger = {
245
255
  if (console && console[type]) console[type].apply(console, args);
246
256
  }
247
257
  };
248
-
249
258
  var Logger = function () {
250
259
  function Logger(concreteLogger) {
251
260
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
252
-
253
261
  _classCallCheck(this, Logger);
254
-
255
262
  this.init(concreteLogger, options);
256
263
  }
257
-
258
264
  _createClass(Logger, [{
259
265
  key: "init",
260
266
  value: function init(concreteLogger) {
@@ -275,7 +281,6 @@ var Logger = function () {
275
281
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
276
282
  args[_key] = arguments[_key];
277
283
  }
278
-
279
284
  return this.forward(args, 'log', '', true);
280
285
  }
281
286
  }, {
@@ -284,7 +289,6 @@ var Logger = function () {
284
289
  for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
285
290
  args[_key2] = arguments[_key2];
286
291
  }
287
-
288
292
  return this.forward(args, 'warn', '', true);
289
293
  }
290
294
  }, {
@@ -293,7 +297,6 @@ var Logger = function () {
293
297
  for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
294
298
  args[_key3] = arguments[_key3];
295
299
  }
296
-
297
300
  return this.forward(args, 'error', '');
298
301
  }
299
302
  }, {
@@ -302,7 +305,6 @@ var Logger = function () {
302
305
  for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
303
306
  args[_key4] = arguments[_key4];
304
307
  }
305
-
306
308
  return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
307
309
  }
308
310
  }, {
@@ -315,32 +317,33 @@ var Logger = function () {
315
317
  }, {
316
318
  key: "create",
317
319
  value: function create(moduleName) {
318
- return new Logger(this.logger, _objectSpread(_objectSpread({}, {
320
+ return new Logger(this.logger, _objectSpread$6(_objectSpread$6({}, {
319
321
  prefix: "".concat(this.prefix, ":").concat(moduleName, ":")
320
322
  }), this.options));
321
323
  }
324
+ }, {
325
+ key: "clone",
326
+ value: function clone(options) {
327
+ options = options || this.options;
328
+ options.prefix = options.prefix || this.prefix;
329
+ return new Logger(this.logger, options);
330
+ }
322
331
  }]);
323
-
324
332
  return Logger;
325
333
  }();
326
-
327
334
  var baseLogger = new Logger();
328
335
 
329
336
  var EventEmitter = function () {
330
337
  function EventEmitter() {
331
338
  _classCallCheck(this, EventEmitter);
332
-
333
339
  this.observers = {};
334
340
  }
335
-
336
341
  _createClass(EventEmitter, [{
337
342
  key: "on",
338
343
  value: function on(events, listener) {
339
344
  var _this = this;
340
-
341
345
  events.split(' ').forEach(function (event) {
342
346
  _this.observers[event] = _this.observers[event] || [];
343
-
344
347
  _this.observers[event].push(listener);
345
348
  });
346
349
  return this;
@@ -349,12 +352,10 @@ var EventEmitter = function () {
349
352
  key: "off",
350
353
  value: function off(event, listener) {
351
354
  if (!this.observers[event]) return;
352
-
353
355
  if (!listener) {
354
356
  delete this.observers[event];
355
357
  return;
356
358
  }
357
-
358
359
  this.observers[event] = this.observers[event].filter(function (l) {
359
360
  return l !== listener;
360
361
  });
@@ -365,24 +366,20 @@ var EventEmitter = function () {
365
366
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
366
367
  args[_key - 1] = arguments[_key];
367
368
  }
368
-
369
369
  if (this.observers[event]) {
370
370
  var cloned = [].concat(this.observers[event]);
371
371
  cloned.forEach(function (observer) {
372
372
  observer.apply(void 0, args);
373
373
  });
374
374
  }
375
-
376
375
  if (this.observers['*']) {
377
376
  var _cloned = [].concat(this.observers['*']);
378
-
379
377
  _cloned.forEach(function (observer) {
380
378
  observer.apply(observer, [event].concat(args));
381
379
  });
382
380
  }
383
381
  }
384
382
  }]);
385
-
386
383
  return EventEmitter;
387
384
  }();
388
385
 
@@ -406,68 +403,56 @@ function copy(a, s, t) {
406
403
  if (s[m]) t[m] = s[m];
407
404
  });
408
405
  }
409
-
410
406
  function getLastOfPath(object, path, Empty) {
411
407
  function cleanKey(key) {
412
408
  return key && key.indexOf('###') > -1 ? key.replace(/###/g, '.') : key;
413
409
  }
414
-
415
410
  function canNotTraverseDeeper() {
416
411
  return !object || typeof object === 'string';
417
412
  }
418
-
419
413
  var stack = typeof path !== 'string' ? [].concat(path) : path.split('.');
420
-
421
414
  while (stack.length > 1) {
422
415
  if (canNotTraverseDeeper()) return {};
423
416
  var key = cleanKey(stack.shift());
424
417
  if (!object[key] && Empty) object[key] = new Empty();
425
-
426
418
  if (Object.prototype.hasOwnProperty.call(object, key)) {
427
419
  object = object[key];
428
420
  } else {
429
421
  object = {};
430
422
  }
431
423
  }
432
-
433
424
  if (canNotTraverseDeeper()) return {};
434
425
  return {
435
426
  obj: object,
436
427
  k: cleanKey(stack.shift())
437
428
  };
438
429
  }
439
-
440
430
  function setPath(object, path, newValue) {
441
431
  var _getLastOfPath = getLastOfPath(object, path, Object),
442
- obj = _getLastOfPath.obj,
443
- k = _getLastOfPath.k;
444
-
432
+ obj = _getLastOfPath.obj,
433
+ k = _getLastOfPath.k;
445
434
  obj[k] = newValue;
446
435
  }
447
436
  function pushPath(object, path, newValue, concat) {
448
437
  var _getLastOfPath2 = getLastOfPath(object, path, Object),
449
- obj = _getLastOfPath2.obj,
450
- k = _getLastOfPath2.k;
451
-
438
+ obj = _getLastOfPath2.obj,
439
+ k = _getLastOfPath2.k;
452
440
  obj[k] = obj[k] || [];
453
441
  if (concat) obj[k] = obj[k].concat(newValue);
454
442
  if (!concat) obj[k].push(newValue);
455
443
  }
456
444
  function getPath(object, path) {
457
445
  var _getLastOfPath3 = getLastOfPath(object, path),
458
- obj = _getLastOfPath3.obj,
459
- k = _getLastOfPath3.k;
460
-
446
+ obj = _getLastOfPath3.obj,
447
+ k = _getLastOfPath3.k;
461
448
  if (!obj) return undefined;
462
449
  return obj[k];
463
450
  }
464
451
  function getPathWithDefaults(data, defaultData, key) {
465
452
  var value = getPath(data, key);
466
-
467
453
  if (value !== undefined) {
468
454
  return value;
469
455
  }
470
-
471
456
  return getPath(defaultData, key);
472
457
  }
473
458
  function deepExtend(target, source, overwrite) {
@@ -484,7 +469,6 @@ function deepExtend(target, source, overwrite) {
484
469
  }
485
470
  }
486
471
  }
487
-
488
472
  return target;
489
473
  }
490
474
  function regexEscape(str) {
@@ -504,7 +488,6 @@ function escape(data) {
504
488
  return _entityMap[s];
505
489
  });
506
490
  }
507
-
508
491
  return data;
509
492
  }
510
493
  var isIE10 = typeof window !== 'undefined' && window.navigator && typeof window.navigator.userAgentData === 'undefined' && window.navigator.userAgent && window.navigator.userAgent.indexOf('MSIE') > -1;
@@ -520,105 +503,77 @@ function looksLikeObjectPath(key, nsSeparator, keySeparator) {
520
503
  return c === '?' ? '\\?' : c;
521
504
  }).join('|'), ")"));
522
505
  var matched = !r.test(key);
523
-
524
506
  if (!matched) {
525
507
  var ki = key.indexOf(keySeparator);
526
-
527
508
  if (ki > 0 && !r.test(key.substring(0, ki))) {
528
509
  matched = true;
529
510
  }
530
511
  }
531
-
532
512
  return matched;
533
513
  }
534
514
 
535
- function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
536
-
537
- function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
538
-
539
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
540
-
541
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
542
-
515
+ function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
516
+ function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$5(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
517
+ function _createSuper$3(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$3(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
518
+ function _isNativeReflectConstruct$3() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
543
519
  function deepFind(obj, path) {
544
520
  var keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
545
521
  if (!obj) return undefined;
546
522
  if (obj[path]) return obj[path];
547
523
  var paths = path.split(keySeparator);
548
524
  var current = obj;
549
-
550
525
  for (var i = 0; i < paths.length; ++i) {
551
526
  if (!current) return undefined;
552
-
553
527
  if (typeof current[paths[i]] === 'string' && i + 1 < paths.length) {
554
528
  return undefined;
555
529
  }
556
-
557
530
  if (current[paths[i]] === undefined) {
558
531
  var j = 2;
559
532
  var p = paths.slice(i, i + j).join(keySeparator);
560
533
  var mix = current[p];
561
-
562
534
  while (mix === undefined && paths.length > i + j) {
563
535
  j++;
564
536
  p = paths.slice(i, i + j).join(keySeparator);
565
537
  mix = current[p];
566
538
  }
567
-
568
539
  if (mix === undefined) return undefined;
569
540
  if (mix === null) return null;
570
-
571
541
  if (path.endsWith(p)) {
572
542
  if (typeof mix === 'string') return mix;
573
543
  if (p && typeof mix[p] === 'string') return mix[p];
574
544
  }
575
-
576
545
  var joinedPath = paths.slice(i + j).join(keySeparator);
577
546
  if (joinedPath) return deepFind(mix, joinedPath, keySeparator);
578
547
  return undefined;
579
548
  }
580
-
581
549
  current = current[paths[i]];
582
550
  }
583
-
584
551
  return current;
585
552
  }
586
-
587
553
  var ResourceStore = function (_EventEmitter) {
588
554
  _inherits(ResourceStore, _EventEmitter);
589
-
590
- var _super = _createSuper(ResourceStore);
591
-
555
+ var _super = _createSuper$3(ResourceStore);
592
556
  function ResourceStore(data) {
593
557
  var _this;
594
-
595
558
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
596
559
  ns: ['translation'],
597
560
  defaultNS: 'translation'
598
561
  };
599
-
600
562
  _classCallCheck(this, ResourceStore);
601
-
602
563
  _this = _super.call(this);
603
-
604
564
  if (isIE10) {
605
565
  EventEmitter.call(_assertThisInitialized(_this));
606
566
  }
607
-
608
567
  _this.data = data || {};
609
568
  _this.options = options;
610
-
611
569
  if (_this.options.keySeparator === undefined) {
612
570
  _this.options.keySeparator = '.';
613
571
  }
614
-
615
572
  if (_this.options.ignoreJSONStructure === undefined) {
616
573
  _this.options.ignoreJSONStructure = true;
617
574
  }
618
-
619
575
  return _this;
620
576
  }
621
-
622
577
  _createClass(ResourceStore, [{
623
578
  key: "addNamespaces",
624
579
  value: function addNamespaces(ns) {
@@ -630,7 +585,6 @@ var ResourceStore = function (_EventEmitter) {
630
585
  key: "removeNamespaces",
631
586
  value: function removeNamespaces(ns) {
632
587
  var index = this.options.ns.indexOf(ns);
633
-
634
588
  if (index > -1) {
635
589
  this.options.ns.splice(index, 1);
636
590
  }
@@ -644,11 +598,9 @@ var ResourceStore = function (_EventEmitter) {
644
598
  var path = [lng, ns];
645
599
  if (key && typeof key !== 'string') path = path.concat(key);
646
600
  if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key);
647
-
648
601
  if (lng.indexOf('.') > -1) {
649
602
  path = lng.split('.');
650
603
  }
651
-
652
604
  var result = getPath(this.data, path);
653
605
  if (result || !ignoreJSONStructure || typeof key !== 'string') return result;
654
606
  return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
@@ -663,13 +615,11 @@ var ResourceStore = function (_EventEmitter) {
663
615
  if (keySeparator === undefined) keySeparator = '.';
664
616
  var path = [lng, ns];
665
617
  if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
666
-
667
618
  if (lng.indexOf('.') > -1) {
668
619
  path = lng.split('.');
669
620
  value = ns;
670
621
  ns = path[1];
671
622
  }
672
-
673
623
  this.addNamespaces(ns);
674
624
  setPath(this.data, path, value);
675
625
  if (!options.silent) this.emit('added', lng, ns, key, value);
@@ -680,13 +630,11 @@ var ResourceStore = function (_EventEmitter) {
680
630
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
681
631
  silent: false
682
632
  };
683
-
684
633
  for (var m in resources) {
685
634
  if (typeof resources[m] === 'string' || Object.prototype.toString.apply(resources[m]) === '[object Array]') this.addResource(lng, ns, m, resources[m], {
686
635
  silent: true
687
636
  });
688
637
  }
689
-
690
638
  if (!options.silent) this.emit('added', lng, ns, resources);
691
639
  }
692
640
  }, {
@@ -696,23 +644,19 @@ var ResourceStore = function (_EventEmitter) {
696
644
  silent: false
697
645
  };
698
646
  var path = [lng, ns];
699
-
700
647
  if (lng.indexOf('.') > -1) {
701
648
  path = lng.split('.');
702
649
  deep = resources;
703
650
  resources = ns;
704
651
  ns = path[1];
705
652
  }
706
-
707
653
  this.addNamespaces(ns);
708
654
  var pack = getPath(this.data, path) || {};
709
-
710
655
  if (deep) {
711
656
  deepExtend(pack, resources, overwrite);
712
657
  } else {
713
- pack = _objectSpread$1(_objectSpread$1({}, pack), resources);
658
+ pack = _objectSpread$5(_objectSpread$5({}, pack), resources);
714
659
  }
715
-
716
660
  setPath(this.data, path, pack);
717
661
  if (!options.silent) this.emit('added', lng, ns, resources);
718
662
  }
@@ -722,7 +666,6 @@ var ResourceStore = function (_EventEmitter) {
722
666
  if (this.hasResourceBundle(lng, ns)) {
723
667
  delete this.data[lng][ns];
724
668
  }
725
-
726
669
  this.removeNamespaces(ns);
727
670
  this.emit('removed', lng, ns);
728
671
  }
@@ -735,7 +678,7 @@ var ResourceStore = function (_EventEmitter) {
735
678
  key: "getResourceBundle",
736
679
  value: function getResourceBundle(lng, ns) {
737
680
  if (!ns) ns = this.options.defaultNS;
738
- if (this.options.compatibilityAPI === 'v1') return _objectSpread$1(_objectSpread$1({}, {}), this.getResource(lng, ns));
681
+ if (this.options.compatibilityAPI === 'v1') return _objectSpread$5(_objectSpread$5({}, {}), this.getResource(lng, ns));
739
682
  return this.getResource(lng, ns);
740
683
  }
741
684
  }, {
@@ -758,7 +701,6 @@ var ResourceStore = function (_EventEmitter) {
758
701
  return this.data;
759
702
  }
760
703
  }]);
761
-
762
704
  return ResourceStore;
763
705
  }(EventEmitter);
764
706
 
@@ -769,7 +711,6 @@ var postProcessor = {
769
711
  },
770
712
  handle: function handle(processors, value, key, options, translator) {
771
713
  var _this = this;
772
-
773
714
  processors.forEach(function (processor) {
774
715
  if (_this.processors[processor]) value = _this.processors[processor].process(value, key, options, translator);
775
716
  });
@@ -777,44 +718,30 @@ var postProcessor = {
777
718
  }
778
719
  };
779
720
 
780
- function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
781
-
782
- function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$2(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
783
-
784
- function _createSuper$1(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$1(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
785
-
786
- function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
721
+ function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
722
+ function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$4(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
723
+ function _createSuper$2(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$2(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
724
+ function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
787
725
  var checkedLoadedFor = {};
788
-
789
726
  var Translator = function (_EventEmitter) {
790
727
  _inherits(Translator, _EventEmitter);
791
-
792
- var _super = _createSuper$1(Translator);
793
-
728
+ var _super = _createSuper$2(Translator);
794
729
  function Translator(services) {
795
730
  var _this;
796
-
797
731
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
798
-
799
732
  _classCallCheck(this, Translator);
800
-
801
733
  _this = _super.call(this);
802
-
803
734
  if (isIE10) {
804
735
  EventEmitter.call(_assertThisInitialized(_this));
805
736
  }
806
-
807
737
  copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, _assertThisInitialized(_this));
808
738
  _this.options = options;
809
-
810
739
  if (_this.options.keySeparator === undefined) {
811
740
  _this.options.keySeparator = '.';
812
741
  }
813
-
814
742
  _this.logger = baseLogger.create('translator');
815
743
  return _this;
816
744
  }
817
-
818
745
  _createClass(Translator, [{
819
746
  key: "changeLanguage",
820
747
  value: function changeLanguage(lng) {
@@ -826,11 +753,9 @@ var Translator = function (_EventEmitter) {
826
753
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
827
754
  interpolation: {}
828
755
  };
829
-
830
756
  if (key === undefined || key === null) {
831
757
  return false;
832
758
  }
833
-
834
759
  var resolved = this.resolve(key, options);
835
760
  return resolved && resolved.res !== undefined;
836
761
  }
@@ -843,22 +768,18 @@ var Translator = function (_EventEmitter) {
843
768
  var namespaces = options.ns || this.options.defaultNS || [];
844
769
  var wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
845
770
  var seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
846
-
847
771
  if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
848
772
  var m = key.match(this.interpolator.nestingRegexp);
849
-
850
773
  if (m && m.length > 0) {
851
774
  return {
852
775
  key: key,
853
776
  namespaces: namespaces
854
777
  };
855
778
  }
856
-
857
779
  var parts = key.split(nsSeparator);
858
780
  if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
859
781
  key = parts.join(keySeparator);
860
782
  }
861
-
862
783
  if (typeof namespaces === 'string') namespaces = [namespaces];
863
784
  return {
864
785
  key: key,
@@ -869,45 +790,35 @@ var Translator = function (_EventEmitter) {
869
790
  key: "translate",
870
791
  value: function translate(keys, options, lastKey) {
871
792
  var _this2 = this;
872
-
873
793
  if (_typeof(options) !== 'object' && this.options.overloadTranslationOptionHandler) {
874
794
  options = this.options.overloadTranslationOptionHandler(arguments);
875
795
  }
876
-
877
796
  if (!options) options = {};
878
797
  if (keys === undefined || keys === null) return '';
879
798
  if (!Array.isArray(keys)) keys = [String(keys)];
880
799
  var returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
881
800
  var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
882
-
883
801
  var _this$extractFromKey = this.extractFromKey(keys[keys.length - 1], options),
884
- key = _this$extractFromKey.key,
885
- namespaces = _this$extractFromKey.namespaces;
886
-
802
+ key = _this$extractFromKey.key,
803
+ namespaces = _this$extractFromKey.namespaces;
887
804
  var namespace = namespaces[namespaces.length - 1];
888
805
  var lng = options.lng || this.language;
889
806
  var appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
890
-
891
807
  if (lng && lng.toLowerCase() === 'cimode') {
892
808
  if (appendNamespaceToCIMode) {
893
809
  var nsSeparator = options.nsSeparator || this.options.nsSeparator;
894
-
895
810
  if (returnDetails) {
896
811
  resolved.res = "".concat(namespace).concat(nsSeparator).concat(key);
897
812
  return resolved;
898
813
  }
899
-
900
814
  return "".concat(namespace).concat(nsSeparator).concat(key);
901
815
  }
902
-
903
816
  if (returnDetails) {
904
817
  resolved.res = key;
905
818
  return resolved;
906
819
  }
907
-
908
820
  return key;
909
821
  }
910
-
911
822
  var resolved = this.resolve(keys, options);
912
823
  var res = resolved && resolved.res;
913
824
  var resUsedKey = resolved && resolved.usedKey || key;
@@ -917,41 +828,34 @@ var Translator = function (_EventEmitter) {
917
828
  var joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
918
829
  var handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
919
830
  var handleAsObject = typeof res !== 'string' && typeof res !== 'boolean' && typeof res !== 'number';
920
-
921
831
  if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === 'string' && resType === '[object Array]')) {
922
832
  if (!options.returnObjects && !this.options.returnObjects) {
923
833
  if (!this.options.returnedObjectHandler) {
924
834
  this.logger.warn('accessing an object - but returnObjects options is not enabled!');
925
835
  }
926
-
927
- var r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, _objectSpread$2(_objectSpread$2({}, options), {}, {
836
+ var r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, _objectSpread$4(_objectSpread$4({}, options), {}, {
928
837
  ns: namespaces
929
838
  })) : "key '".concat(key, " (").concat(this.language, ")' returned an object instead of string.");
930
-
931
839
  if (returnDetails) {
932
840
  resolved.res = r;
933
841
  return resolved;
934
842
  }
935
-
936
843
  return r;
937
844
  }
938
-
939
845
  if (keySeparator) {
940
846
  var resTypeIsArray = resType === '[object Array]';
941
847
  var copy = resTypeIsArray ? [] : {};
942
848
  var newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
943
-
944
849
  for (var m in res) {
945
850
  if (Object.prototype.hasOwnProperty.call(res, m)) {
946
851
  var deepKey = "".concat(newKeyToUse).concat(keySeparator).concat(m);
947
- copy[m] = this.translate(deepKey, _objectSpread$2(_objectSpread$2({}, options), {
852
+ copy[m] = this.translate(deepKey, _objectSpread$4(_objectSpread$4({}, options), {
948
853
  joinArrays: false,
949
854
  ns: namespaces
950
855
  }));
951
856
  if (copy[m] === deepKey) copy[m] = res[m];
952
857
  }
953
858
  }
954
-
955
859
  res = copy;
956
860
  }
957
861
  } else if (handleAsObjectInI18nFormat && typeof joinArrays === 'string' && resType === '[object Array]') {
@@ -964,34 +868,27 @@ var Translator = function (_EventEmitter) {
964
868
  var hasDefaultValue = Translator.hasDefaultValue(options);
965
869
  var defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : '';
966
870
  var defaultValue = options["defaultValue".concat(defaultValueSuffix)] || options.defaultValue;
967
-
968
871
  if (!this.isValidLookup(res) && hasDefaultValue) {
969
872
  usedDefault = true;
970
873
  res = defaultValue;
971
874
  }
972
-
973
875
  if (!this.isValidLookup(res)) {
974
876
  usedKey = true;
975
877
  res = key;
976
878
  }
977
-
978
879
  var missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
979
880
  var resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
980
881
  var updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
981
-
982
882
  if (usedKey || usedDefault || updateMissing) {
983
883
  this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
984
-
985
884
  if (keySeparator) {
986
- var fk = this.resolve(key, _objectSpread$2(_objectSpread$2({}, options), {}, {
885
+ var fk = this.resolve(key, _objectSpread$4(_objectSpread$4({}, options), {}, {
987
886
  keySeparator: false
988
887
  }));
989
888
  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.');
990
889
  }
991
-
992
890
  var lngs = [];
993
891
  var fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
994
-
995
892
  if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
996
893
  for (var i = 0; i < fallbackLngs.length; i++) {
997
894
  lngs.push(fallbackLngs[i]);
@@ -1001,19 +898,15 @@ var Translator = function (_EventEmitter) {
1001
898
  } else {
1002
899
  lngs.push(options.lng || this.language);
1003
900
  }
1004
-
1005
901
  var send = function send(l, k, specificDefaultValue) {
1006
902
  var defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
1007
-
1008
903
  if (_this2.options.missingKeyHandler) {
1009
904
  _this2.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
1010
905
  } else if (_this2.backendConnector && _this2.backendConnector.saveMissing) {
1011
906
  _this2.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
1012
907
  }
1013
-
1014
908
  _this2.emit('missingKey', l, namespace, k, res);
1015
909
  };
1016
-
1017
910
  if (this.options.saveMissing) {
1018
911
  if (this.options.saveMissingPlurals && needsPluralHandling) {
1019
912
  lngs.forEach(function (language) {
@@ -1026,10 +919,8 @@ var Translator = function (_EventEmitter) {
1026
919
  }
1027
920
  }
1028
921
  }
1029
-
1030
922
  res = this.extendTranslation(res, keys, options, resolved, lastKey);
1031
923
  if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = "".concat(namespace, ":").concat(key);
1032
-
1033
924
  if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
1034
925
  if (this.options.compatibilityAPI !== 'v1') {
1035
926
  res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? "".concat(namespace, ":").concat(key) : key, usedDefault ? res : undefined);
@@ -1038,77 +929,63 @@ var Translator = function (_EventEmitter) {
1038
929
  }
1039
930
  }
1040
931
  }
1041
-
1042
932
  if (returnDetails) {
1043
933
  resolved.res = res;
1044
934
  return resolved;
1045
935
  }
1046
-
1047
936
  return res;
1048
937
  }
1049
938
  }, {
1050
939
  key: "extendTranslation",
1051
940
  value: function extendTranslation(res, key, options, resolved, lastKey) {
1052
941
  var _this3 = this;
1053
-
1054
942
  if (this.i18nFormat && this.i18nFormat.parse) {
1055
- res = this.i18nFormat.parse(res, _objectSpread$2(_objectSpread$2({}, this.options.interpolation.defaultVariables), options), resolved.usedLng, resolved.usedNS, resolved.usedKey, {
943
+ res = this.i18nFormat.parse(res, _objectSpread$4(_objectSpread$4({}, this.options.interpolation.defaultVariables), options), resolved.usedLng, resolved.usedNS, resolved.usedKey, {
1056
944
  resolved: resolved
1057
945
  });
1058
946
  } else if (!options.skipInterpolation) {
1059
- if (options.interpolation) this.interpolator.init(_objectSpread$2(_objectSpread$2({}, options), {
1060
- interpolation: _objectSpread$2(_objectSpread$2({}, this.options.interpolation), options.interpolation)
947
+ if (options.interpolation) this.interpolator.init(_objectSpread$4(_objectSpread$4({}, options), {
948
+ interpolation: _objectSpread$4(_objectSpread$4({}, this.options.interpolation), options.interpolation)
1061
949
  }));
1062
950
  var skipOnVariables = typeof res === 'string' && (options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
1063
951
  var nestBef;
1064
-
1065
952
  if (skipOnVariables) {
1066
953
  var nb = res.match(this.interpolator.nestingRegexp);
1067
954
  nestBef = nb && nb.length;
1068
955
  }
1069
-
1070
956
  var data = options.replace && typeof options.replace !== 'string' ? options.replace : options;
1071
- if (this.options.interpolation.defaultVariables) data = _objectSpread$2(_objectSpread$2({}, this.options.interpolation.defaultVariables), data);
957
+ if (this.options.interpolation.defaultVariables) data = _objectSpread$4(_objectSpread$4({}, this.options.interpolation.defaultVariables), data);
1072
958
  res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
1073
-
1074
959
  if (skipOnVariables) {
1075
960
  var na = res.match(this.interpolator.nestingRegexp);
1076
961
  var nestAft = na && na.length;
1077
962
  if (nestBef < nestAft) options.nest = false;
1078
963
  }
1079
-
1080
964
  if (options.nest !== false) res = this.interpolator.nest(res, function () {
1081
965
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1082
966
  args[_key] = arguments[_key];
1083
967
  }
1084
-
1085
968
  if (lastKey && lastKey[0] === args[0] && !options.context) {
1086
969
  _this3.logger.warn("It seems you are nesting recursively key: ".concat(args[0], " in key: ").concat(key[0]));
1087
-
1088
970
  return null;
1089
971
  }
1090
-
1091
972
  return _this3.translate.apply(_this3, args.concat([key]));
1092
973
  }, options);
1093
974
  if (options.interpolation) this.interpolator.reset();
1094
975
  }
1095
-
1096
976
  var postProcess = options.postProcess || this.options.postProcess;
1097
977
  var postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess;
1098
-
1099
978
  if (res !== undefined && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
1100
- res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? _objectSpread$2({
979
+ res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? _objectSpread$4({
1101
980
  i18nResolved: resolved
1102
981
  }, options) : options, this);
1103
982
  }
1104
-
1105
983
  return res;
1106
984
  }
1107
985
  }, {
1108
986
  key: "resolve",
1109
987
  value: function resolve(keys) {
1110
988
  var _this4 = this;
1111
-
1112
989
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1113
990
  var found;
1114
991
  var usedKey;
@@ -1118,65 +995,50 @@ var Translator = function (_EventEmitter) {
1118
995
  if (typeof keys === 'string') keys = [keys];
1119
996
  keys.forEach(function (k) {
1120
997
  if (_this4.isValidLookup(found)) return;
1121
-
1122
998
  var extracted = _this4.extractFromKey(k, options);
1123
-
1124
999
  var key = extracted.key;
1125
1000
  usedKey = key;
1126
1001
  var namespaces = extracted.namespaces;
1127
1002
  if (_this4.options.fallbackNS) namespaces = namespaces.concat(_this4.options.fallbackNS);
1128
1003
  var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
1129
-
1130
1004
  var needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && _this4.pluralResolver.shouldUseIntlApi();
1131
-
1132
1005
  var needsContextHandling = options.context !== undefined && (typeof options.context === 'string' || typeof options.context === 'number') && options.context !== '';
1133
1006
  var codes = options.lngs ? options.lngs : _this4.languageUtils.toResolveHierarchy(options.lng || _this4.language, options.fallbackLng);
1134
1007
  namespaces.forEach(function (ns) {
1135
1008
  if (_this4.isValidLookup(found)) return;
1136
1009
  usedNS = ns;
1137
-
1138
1010
  if (!checkedLoadedFor["".concat(codes[0], "-").concat(ns)] && _this4.utils && _this4.utils.hasLoadedNamespace && !_this4.utils.hasLoadedNamespace(usedNS)) {
1139
1011
  checkedLoadedFor["".concat(codes[0], "-").concat(ns)] = true;
1140
-
1141
1012
  _this4.logger.warn("key \"".concat(usedKey, "\" for languages \"").concat(codes.join(', '), "\" won't get resolved as namespace \"").concat(usedNS, "\" was not yet loaded"), 'This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!');
1142
1013
  }
1143
-
1144
1014
  codes.forEach(function (code) {
1145
1015
  if (_this4.isValidLookup(found)) return;
1146
1016
  usedLng = code;
1147
1017
  var finalKeys = [key];
1148
-
1149
1018
  if (_this4.i18nFormat && _this4.i18nFormat.addLookupKeys) {
1150
1019
  _this4.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
1151
1020
  } else {
1152
1021
  var pluralSuffix;
1153
1022
  if (needsPluralHandling) pluralSuffix = _this4.pluralResolver.getSuffix(code, options.count, options);
1154
1023
  var zeroSuffix = "".concat(_this4.options.pluralSeparator, "zero");
1155
-
1156
1024
  if (needsPluralHandling) {
1157
1025
  finalKeys.push(key + pluralSuffix);
1158
-
1159
1026
  if (needsZeroSuffixLookup) {
1160
1027
  finalKeys.push(key + zeroSuffix);
1161
1028
  }
1162
1029
  }
1163
-
1164
1030
  if (needsContextHandling) {
1165
1031
  var contextKey = "".concat(key).concat(_this4.options.contextSeparator).concat(options.context);
1166
1032
  finalKeys.push(contextKey);
1167
-
1168
1033
  if (needsPluralHandling) {
1169
1034
  finalKeys.push(contextKey + pluralSuffix);
1170
-
1171
1035
  if (needsZeroSuffixLookup) {
1172
1036
  finalKeys.push(contextKey + zeroSuffix);
1173
1037
  }
1174
1038
  }
1175
1039
  }
1176
1040
  }
1177
-
1178
1041
  var possibleKey;
1179
-
1180
1042
  while (possibleKey = finalKeys.pop()) {
1181
1043
  if (!_this4.isValidLookup(found)) {
1182
1044
  exactUsedKey = possibleKey;
@@ -1210,33 +1072,27 @@ var Translator = function (_EventEmitter) {
1210
1072
  key: "hasDefaultValue",
1211
1073
  value: function hasDefaultValue(options) {
1212
1074
  var prefix = 'defaultValue';
1213
-
1214
1075
  for (var option in options) {
1215
1076
  if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
1216
1077
  return true;
1217
1078
  }
1218
1079
  }
1219
-
1220
1080
  return false;
1221
1081
  }
1222
1082
  }]);
1223
-
1224
1083
  return Translator;
1225
1084
  }(EventEmitter);
1226
1085
 
1227
1086
  function capitalize(string) {
1228
1087
  return string.charAt(0).toUpperCase() + string.slice(1);
1229
1088
  }
1230
-
1231
1089
  var LanguageUtil = function () {
1232
1090
  function LanguageUtil(options) {
1233
1091
  _classCallCheck(this, LanguageUtil);
1234
-
1235
1092
  this.options = options;
1236
1093
  this.supportedLngs = this.options.supportedLngs || false;
1237
1094
  this.logger = baseLogger.create('languageUtils');
1238
1095
  }
1239
-
1240
1096
  _createClass(LanguageUtil, [{
1241
1097
  key: "getScriptPartFromCode",
1242
1098
  value: function getScriptPartFromCode(code) {
@@ -1260,7 +1116,6 @@ var LanguageUtil = function () {
1260
1116
  if (typeof code === 'string' && code.indexOf('-') > -1) {
1261
1117
  var specialCases = ['hans', 'hant', 'latn', 'cyrl', 'cans', 'mong', 'arab'];
1262
1118
  var p = code.split('-');
1263
-
1264
1119
  if (this.options.lowerCaseLng) {
1265
1120
  p = p.map(function (part) {
1266
1121
  return part.toLowerCase();
@@ -1276,10 +1131,8 @@ var LanguageUtil = function () {
1276
1131
  if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
1277
1132
  if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
1278
1133
  }
1279
-
1280
1134
  return p.join('-');
1281
1135
  }
1282
-
1283
1136
  return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
1284
1137
  }
1285
1138
  }, {
@@ -1288,37 +1141,29 @@ var LanguageUtil = function () {
1288
1141
  if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
1289
1142
  code = this.getLanguagePartFromCode(code);
1290
1143
  }
1291
-
1292
1144
  return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
1293
1145
  }
1294
1146
  }, {
1295
1147
  key: "getBestMatchFromCodes",
1296
1148
  value: function getBestMatchFromCodes(codes) {
1297
1149
  var _this = this;
1298
-
1299
1150
  if (!codes) return null;
1300
1151
  var found;
1301
1152
  codes.forEach(function (code) {
1302
1153
  if (found) return;
1303
-
1304
1154
  var cleanedLng = _this.formatLanguageCode(code);
1305
-
1306
1155
  if (!_this.options.supportedLngs || _this.isSupportedCode(cleanedLng)) found = cleanedLng;
1307
1156
  });
1308
-
1309
1157
  if (!found && this.options.supportedLngs) {
1310
1158
  codes.forEach(function (code) {
1311
1159
  if (found) return;
1312
-
1313
1160
  var lngOnly = _this.getLanguagePartFromCode(code);
1314
-
1315
1161
  if (_this.isSupportedCode(lngOnly)) return found = lngOnly;
1316
1162
  found = _this.options.supportedLngs.find(function (supportedLng) {
1317
1163
  if (supportedLng.indexOf(lngOnly) === 0) return supportedLng;
1318
1164
  });
1319
1165
  });
1320
1166
  }
1321
-
1322
1167
  if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
1323
1168
  return found;
1324
1169
  }
@@ -1341,20 +1186,16 @@ var LanguageUtil = function () {
1341
1186
  key: "toResolveHierarchy",
1342
1187
  value: function toResolveHierarchy(code, fallbackCode) {
1343
1188
  var _this2 = this;
1344
-
1345
1189
  var fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
1346
1190
  var codes = [];
1347
-
1348
1191
  var addCode = function addCode(c) {
1349
1192
  if (!c) return;
1350
-
1351
1193
  if (_this2.isSupportedCode(c)) {
1352
1194
  codes.push(c);
1353
1195
  } else {
1354
1196
  _this2.logger.warn("rejecting language code not found in supportedLngs: ".concat(c));
1355
1197
  }
1356
1198
  };
1357
-
1358
1199
  if (typeof code === 'string' && code.indexOf('-') > -1) {
1359
1200
  if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
1360
1201
  if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
@@ -1362,14 +1203,12 @@ var LanguageUtil = function () {
1362
1203
  } else if (typeof code === 'string') {
1363
1204
  addCode(this.formatLanguageCode(code));
1364
1205
  }
1365
-
1366
1206
  fallbackCodes.forEach(function (fc) {
1367
1207
  if (codes.indexOf(fc) < 0) addCode(_this2.formatLanguageCode(fc));
1368
1208
  });
1369
1209
  return codes;
1370
1210
  }
1371
1211
  }]);
1372
-
1373
1212
  return LanguageUtil;
1374
1213
  }();
1375
1214
 
@@ -1543,7 +1382,6 @@ var suffixesOrder = {
1543
1382
  many: 4,
1544
1383
  other: 5
1545
1384
  };
1546
-
1547
1385
  function createRules() {
1548
1386
  var rules = {};
1549
1387
  sets.forEach(function (set) {
@@ -1556,25 +1394,19 @@ function createRules() {
1556
1394
  });
1557
1395
  return rules;
1558
1396
  }
1559
-
1560
1397
  var PluralResolver = function () {
1561
1398
  function PluralResolver(languageUtils) {
1562
1399
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1563
-
1564
1400
  _classCallCheck(this, PluralResolver);
1565
-
1566
1401
  this.languageUtils = languageUtils;
1567
1402
  this.options = options;
1568
1403
  this.logger = baseLogger.create('pluralResolver');
1569
-
1570
1404
  if ((!this.options.compatibilityJSON || this.options.compatibilityJSON === 'v4') && (typeof Intl === 'undefined' || !Intl.PluralRules)) {
1571
1405
  this.options.compatibilityJSON = 'v3';
1572
1406
  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.');
1573
1407
  }
1574
-
1575
1408
  this.rules = createRules();
1576
1409
  }
1577
-
1578
1410
  _createClass(PluralResolver, [{
1579
1411
  key: "addRule",
1580
1412
  value: function addRule(lng, obj) {
@@ -1584,7 +1416,6 @@ var PluralResolver = function () {
1584
1416
  key: "getRule",
1585
1417
  value: function getRule(code) {
1586
1418
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1587
-
1588
1419
  if (this.shouldUseIntlApi()) {
1589
1420
  try {
1590
1421
  return new Intl.PluralRules(code, {
@@ -1594,7 +1425,6 @@ var PluralResolver = function () {
1594
1425
  return;
1595
1426
  }
1596
1427
  }
1597
-
1598
1428
  return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
1599
1429
  }
1600
1430
  }, {
@@ -1602,11 +1432,9 @@ var PluralResolver = function () {
1602
1432
  value: function needsPlural(code) {
1603
1433
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1604
1434
  var rule = this.getRule(code, options);
1605
-
1606
1435
  if (this.shouldUseIntlApi()) {
1607
1436
  return rule && rule.resolvedOptions().pluralCategories.length > 1;
1608
1437
  }
1609
-
1610
1438
  return rule && rule.numbers.length > 1;
1611
1439
  }
1612
1440
  }, {
@@ -1621,14 +1449,11 @@ var PluralResolver = function () {
1621
1449
  key: "getSuffixes",
1622
1450
  value: function getSuffixes(code) {
1623
1451
  var _this = this;
1624
-
1625
1452
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1626
1453
  var rule = this.getRule(code, options);
1627
-
1628
1454
  if (!rule) {
1629
1455
  return [];
1630
1456
  }
1631
-
1632
1457
  if (this.shouldUseIntlApi()) {
1633
1458
  return rule.resolvedOptions().pluralCategories.sort(function (pluralCategory1, pluralCategory2) {
1634
1459
  return suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2];
@@ -1636,7 +1461,6 @@ var PluralResolver = function () {
1636
1461
  return "".concat(_this.options.prepend).concat(pluralCategory);
1637
1462
  });
1638
1463
  }
1639
-
1640
1464
  return rule.numbers.map(function (number) {
1641
1465
  return _this.getSuffix(code, number, options);
1642
1466
  });
@@ -1646,15 +1470,12 @@ var PluralResolver = function () {
1646
1470
  value: function getSuffix(code, count) {
1647
1471
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1648
1472
  var rule = this.getRule(code, options);
1649
-
1650
1473
  if (rule) {
1651
1474
  if (this.shouldUseIntlApi()) {
1652
1475
  return "".concat(this.options.prepend).concat(rule.select(count));
1653
1476
  }
1654
-
1655
1477
  return this.getSuffixRetroCompatible(rule, count);
1656
1478
  }
1657
-
1658
1479
  this.logger.warn("no plural rule found for: ".concat(code));
1659
1480
  return '';
1660
1481
  }
@@ -1662,10 +1483,8 @@ var PluralResolver = function () {
1662
1483
  key: "getSuffixRetroCompatible",
1663
1484
  value: function getSuffixRetroCompatible(rule, count) {
1664
1485
  var _this2 = this;
1665
-
1666
1486
  var idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
1667
1487
  var suffix = rule.numbers[idx];
1668
-
1669
1488
  if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
1670
1489
  if (suffix === 2) {
1671
1490
  suffix = 'plural';
@@ -1673,11 +1492,9 @@ var PluralResolver = function () {
1673
1492
  suffix = '';
1674
1493
  }
1675
1494
  }
1676
-
1677
1495
  var returnSuffix = function returnSuffix() {
1678
1496
  return _this2.options.prepend && suffix.toString() ? _this2.options.prepend + suffix.toString() : suffix.toString();
1679
1497
  };
1680
-
1681
1498
  if (this.options.compatibilityJSON === 'v1') {
1682
1499
  if (suffix === 1) return '';
1683
1500
  if (typeof suffix === 'number') return "_plural_".concat(suffix.toString());
@@ -1687,7 +1504,6 @@ var PluralResolver = function () {
1687
1504
  } else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
1688
1505
  return returnSuffix();
1689
1506
  }
1690
-
1691
1507
  return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
1692
1508
  }
1693
1509
  }, {
@@ -1696,30 +1512,22 @@ var PluralResolver = function () {
1696
1512
  return !deprecatedJsonVersions.includes(this.options.compatibilityJSON);
1697
1513
  }
1698
1514
  }]);
1699
-
1700
1515
  return PluralResolver;
1701
1516
  }();
1702
1517
 
1703
- function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
1704
-
1705
- function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$3(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
1706
-
1518
+ function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
1519
+ function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$3(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
1707
1520
  var Interpolator = function () {
1708
1521
  function Interpolator() {
1709
1522
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1710
-
1711
1523
  _classCallCheck(this, Interpolator);
1712
-
1713
1524
  this.logger = baseLogger.create('interpolator');
1714
1525
  this.options = options;
1715
-
1716
1526
  this.format = options.interpolation && options.interpolation.format || function (value) {
1717
1527
  return value;
1718
1528
  };
1719
-
1720
1529
  this.init(options);
1721
1530
  }
1722
-
1723
1531
  _createClass(Interpolator, [{
1724
1532
  key: "init",
1725
1533
  value: function init() {
@@ -1762,16 +1570,13 @@ var Interpolator = function () {
1762
1570
  key: "interpolate",
1763
1571
  value: function interpolate(str, data, lng, options) {
1764
1572
  var _this = this;
1765
-
1766
1573
  var match;
1767
1574
  var value;
1768
1575
  var replaces;
1769
1576
  var defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
1770
-
1771
1577
  function regexSafe(val) {
1772
1578
  return val.replace(/\$/g, '$$$$');
1773
1579
  }
1774
-
1775
1580
  var handleFormat = function handleFormat(key) {
1776
1581
  if (key.indexOf(_this.formatSeparator) < 0) {
1777
1582
  var path = getPathWithDefaults(data, defaultData, key);
@@ -1779,7 +1584,6 @@ var Interpolator = function () {
1779
1584
  interpolationkey: key
1780
1585
  })) : path;
1781
1586
  }
1782
-
1783
1587
  var p = key.split(_this.formatSeparator);
1784
1588
  var k = p.shift().trim();
1785
1589
  var f = p.join(_this.formatSeparator).trim();
@@ -1787,7 +1591,6 @@ var Interpolator = function () {
1787
1591
  interpolationkey: k
1788
1592
  }));
1789
1593
  };
1790
-
1791
1594
  this.resetRegExp();
1792
1595
  var missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
1793
1596
  var skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
@@ -1804,11 +1607,9 @@ var Interpolator = function () {
1804
1607
  }];
1805
1608
  todos.forEach(function (todo) {
1806
1609
  replaces = 0;
1807
-
1808
1610
  while (match = todo.regex.exec(str)) {
1809
1611
  var matchedVar = match[1].trim();
1810
1612
  value = handleFormat(matchedVar);
1811
-
1812
1613
  if (value === undefined) {
1813
1614
  if (typeof missingInterpolationHandler === 'function') {
1814
1615
  var temp = missingInterpolationHandler(str, match, options);
@@ -1820,25 +1621,20 @@ var Interpolator = function () {
1820
1621
  continue;
1821
1622
  } else {
1822
1623
  _this.logger.warn("missed to pass in variable ".concat(matchedVar, " for interpolating ").concat(str));
1823
-
1824
1624
  value = '';
1825
1625
  }
1826
1626
  } else if (typeof value !== 'string' && !_this.useRawValueToEscape) {
1827
1627
  value = makeString(value);
1828
1628
  }
1829
-
1830
1629
  var safeValue = todo.safeValue(value);
1831
1630
  str = str.replace(match[0], safeValue);
1832
-
1833
1631
  if (skipOnVariables) {
1834
1632
  todo.regex.lastIndex += value.length;
1835
1633
  todo.regex.lastIndex -= match[0].length;
1836
1634
  } else {
1837
1635
  todo.regex.lastIndex = 0;
1838
1636
  }
1839
-
1840
1637
  replaces++;
1841
-
1842
1638
  if (replaces >= _this.maxReplaces) {
1843
1639
  break;
1844
1640
  }
@@ -1850,16 +1646,10 @@ var Interpolator = function () {
1850
1646
  key: "nest",
1851
1647
  value: function nest(str, fc) {
1852
1648
  var _this2 = this;
1853
-
1854
1649
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1855
1650
  var match;
1856
1651
  var value;
1857
-
1858
- var clonedOptions = _objectSpread$3({}, options);
1859
-
1860
- clonedOptions.applyPostProcessor = false;
1861
- delete clonedOptions.defaultValue;
1862
-
1652
+ var clonedOptions;
1863
1653
  function handleHasOptions(key, inheritedOptions) {
1864
1654
  var sep = this.nestingOptionsSeparator;
1865
1655
  if (key.indexOf(sep) < 0) return key;
@@ -1867,8 +1657,11 @@ var Interpolator = function () {
1867
1657
  var optionsString = "{".concat(c[1]);
1868
1658
  key = c[0];
1869
1659
  optionsString = this.interpolate(optionsString, clonedOptions);
1870
- optionsString = optionsString.replace(/'/g, '"');
1871
-
1660
+ var matchedSingleQuotes = optionsString.match(/'/g);
1661
+ var matchedDoubleQuotes = optionsString.match(/"/g);
1662
+ if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
1663
+ optionsString = optionsString.replace(/'/g, '"');
1664
+ }
1872
1665
  try {
1873
1666
  clonedOptions = JSON.parse(optionsString);
1874
1667
  if (inheritedOptions) clonedOptions = _objectSpread$3(_objectSpread$3({}, inheritedOptions), clonedOptions);
@@ -1876,15 +1669,15 @@ var Interpolator = function () {
1876
1669
  this.logger.warn("failed parsing options string in nesting for key ".concat(key), e);
1877
1670
  return "".concat(key).concat(sep).concat(optionsString);
1878
1671
  }
1879
-
1880
1672
  delete clonedOptions.defaultValue;
1881
1673
  return key;
1882
1674
  }
1883
-
1884
1675
  while (match = this.nestingRegexp.exec(str)) {
1885
1676
  var formatters = [];
1677
+ clonedOptions = _objectSpread$3({}, options);
1678
+ clonedOptions.applyPostProcessor = false;
1679
+ delete clonedOptions.defaultValue;
1886
1680
  var doReduce = false;
1887
-
1888
1681
  if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
1889
1682
  var r = match[1].split(this.formatSeparator).map(function (elem) {
1890
1683
  return elem.trim();
@@ -1893,16 +1686,13 @@ var Interpolator = function () {
1893
1686
  formatters = r;
1894
1687
  doReduce = true;
1895
1688
  }
1896
-
1897
1689
  value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
1898
1690
  if (value && match[0] === str && typeof value !== 'string') return value;
1899
1691
  if (typeof value !== 'string') value = makeString(value);
1900
-
1901
1692
  if (!value) {
1902
1693
  this.logger.warn("missed to resolve ".concat(match[1], " for nesting ").concat(str));
1903
1694
  value = '';
1904
1695
  }
1905
-
1906
1696
  if (doReduce) {
1907
1697
  value = formatters.reduce(function (v, f) {
1908
1698
  return _this2.format(v, f, options.lng, _objectSpread$3(_objectSpread$3({}, options), {}, {
@@ -1910,31 +1700,24 @@ var Interpolator = function () {
1910
1700
  }));
1911
1701
  }, value.trim());
1912
1702
  }
1913
-
1914
1703
  str = str.replace(match[0], value);
1915
1704
  this.regexp.lastIndex = 0;
1916
1705
  }
1917
-
1918
1706
  return str;
1919
1707
  }
1920
1708
  }]);
1921
-
1922
1709
  return Interpolator;
1923
1710
  }();
1924
1711
 
1925
- function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
1926
-
1927
- function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$4(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
1928
-
1712
+ function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
1713
+ function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$2(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
1929
1714
  function parseFormatStr(formatStr) {
1930
1715
  var formatName = formatStr.toLowerCase().trim();
1931
1716
  var formatOptions = {};
1932
-
1933
1717
  if (formatStr.indexOf('(') > -1) {
1934
1718
  var p = formatStr.split('(');
1935
1719
  formatName = p[0].toLowerCase().trim();
1936
1720
  var optStr = p[1].substring(0, p[1].length - 1);
1937
-
1938
1721
  if (formatName === 'currency' && optStr.indexOf(':') < 0) {
1939
1722
  if (!formatOptions.currency) formatOptions.currency = optStr.trim();
1940
1723
  } else if (formatName === 'relativetime' && optStr.indexOf(':') < 0) {
@@ -1943,12 +1726,10 @@ function parseFormatStr(formatStr) {
1943
1726
  var opts = optStr.split(';');
1944
1727
  opts.forEach(function (opt) {
1945
1728
  if (!opt) return;
1946
-
1947
1729
  var _opt$split = opt.split(':'),
1948
- _opt$split2 = _toArray(_opt$split),
1949
- key = _opt$split2[0],
1950
- rest = _opt$split2.slice(1);
1951
-
1730
+ _opt$split2 = _toArray(_opt$split),
1731
+ key = _opt$split2[0],
1732
+ rest = _opt$split2.slice(1);
1952
1733
  var val = rest.join(':').trim().replace(/^'+|'+$/g, '');
1953
1734
  if (!formatOptions[key.trim()]) formatOptions[key.trim()] = val;
1954
1735
  if (val === 'false') formatOptions[key.trim()] = false;
@@ -1957,43 +1738,65 @@ function parseFormatStr(formatStr) {
1957
1738
  });
1958
1739
  }
1959
1740
  }
1960
-
1961
1741
  return {
1962
1742
  formatName: formatName,
1963
1743
  formatOptions: formatOptions
1964
1744
  };
1965
1745
  }
1966
-
1746
+ function createCachedFormatter(fn) {
1747
+ var cache = {};
1748
+ return function invokeFormatter(val, lng, options) {
1749
+ var key = lng + JSON.stringify(options);
1750
+ var formatter = cache[key];
1751
+ if (!formatter) {
1752
+ formatter = fn(lng, options);
1753
+ cache[key] = formatter;
1754
+ }
1755
+ return formatter(val);
1756
+ };
1757
+ }
1967
1758
  var Formatter = function () {
1968
1759
  function Formatter() {
1969
1760
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1970
-
1971
1761
  _classCallCheck(this, Formatter);
1972
-
1973
1762
  this.logger = baseLogger.create('formatter');
1974
1763
  this.options = options;
1975
1764
  this.formats = {
1976
- number: function number(val, lng, options) {
1977
- return new Intl.NumberFormat(lng, options).format(val);
1978
- },
1979
- currency: function currency(val, lng, options) {
1980
- return new Intl.NumberFormat(lng, _objectSpread$4(_objectSpread$4({}, options), {}, {
1765
+ number: createCachedFormatter(function (lng, options) {
1766
+ var formatter = new Intl.NumberFormat(lng, options);
1767
+ return function (val) {
1768
+ return formatter.format(val);
1769
+ };
1770
+ }),
1771
+ currency: createCachedFormatter(function (lng, options) {
1772
+ var formatter = new Intl.NumberFormat(lng, _objectSpread$2(_objectSpread$2({}, options), {}, {
1981
1773
  style: 'currency'
1982
- })).format(val);
1983
- },
1984
- datetime: function datetime(val, lng, options) {
1985
- return new Intl.DateTimeFormat(lng, _objectSpread$4({}, options)).format(val);
1986
- },
1987
- relativetime: function relativetime(val, lng, options) {
1988
- return new Intl.RelativeTimeFormat(lng, _objectSpread$4({}, options)).format(val, options.range || 'day');
1989
- },
1990
- list: function list(val, lng, options) {
1991
- return new Intl.ListFormat(lng, _objectSpread$4({}, options)).format(val);
1992
- }
1774
+ }));
1775
+ return function (val) {
1776
+ return formatter.format(val);
1777
+ };
1778
+ }),
1779
+ datetime: createCachedFormatter(function (lng, options) {
1780
+ var formatter = new Intl.DateTimeFormat(lng, _objectSpread$2({}, options));
1781
+ return function (val) {
1782
+ return formatter.format(val);
1783
+ };
1784
+ }),
1785
+ relativetime: createCachedFormatter(function (lng, options) {
1786
+ var formatter = new Intl.RelativeTimeFormat(lng, _objectSpread$2({}, options));
1787
+ return function (val) {
1788
+ return formatter.format(val, options.range || 'day');
1789
+ };
1790
+ }),
1791
+ list: createCachedFormatter(function (lng, options) {
1792
+ var formatter = new Intl.ListFormat(lng, _objectSpread$2({}, options));
1793
+ return function (val) {
1794
+ return formatter.format(val);
1795
+ };
1796
+ })
1993
1797
  };
1994
1798
  this.init(options);
1995
1799
  }
1996
-
1997
1800
  _createClass(Formatter, [{
1998
1801
  key: "init",
1999
1802
  value: function init(services) {
@@ -2008,76 +1811,62 @@ var Formatter = function () {
2008
1811
  value: function add(name, fc) {
2009
1812
  this.formats[name.toLowerCase().trim()] = fc;
2010
1813
  }
1814
+ }, {
1815
+ key: "addCached",
1816
+ value: function addCached(name, fc) {
1817
+ this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
1818
+ }
2011
1819
  }, {
2012
1820
  key: "format",
2013
1821
  value: function format(value, _format, lng, options) {
2014
1822
  var _this = this;
2015
-
2016
1823
  var formats = _format.split(this.formatSeparator);
2017
-
2018
1824
  var result = formats.reduce(function (mem, f) {
2019
1825
  var _parseFormatStr = parseFormatStr(f),
2020
- formatName = _parseFormatStr.formatName,
2021
- formatOptions = _parseFormatStr.formatOptions;
2022
-
1826
+ formatName = _parseFormatStr.formatName,
1827
+ formatOptions = _parseFormatStr.formatOptions;
2023
1828
  if (_this.formats[formatName]) {
2024
1829
  var formatted = mem;
2025
-
2026
1830
  try {
2027
1831
  var valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
2028
1832
  var l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
2029
- formatted = _this.formats[formatName](mem, l, _objectSpread$4(_objectSpread$4(_objectSpread$4({}, formatOptions), options), valOptions));
1833
+ formatted = _this.formats[formatName](mem, l, _objectSpread$2(_objectSpread$2(_objectSpread$2({}, formatOptions), options), valOptions));
2030
1834
  } catch (error) {
2031
1835
  _this.logger.warn(error);
2032
1836
  }
2033
-
2034
1837
  return formatted;
2035
1838
  } else {
2036
1839
  _this.logger.warn("there was no format function for ".concat(formatName));
2037
1840
  }
2038
-
2039
1841
  return mem;
2040
1842
  }, value);
2041
1843
  return result;
2042
1844
  }
2043
1845
  }]);
2044
-
2045
1846
  return Formatter;
2046
1847
  }();
2047
1848
 
2048
- function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
2049
-
2050
- function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$5(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
2051
-
2052
- function _createSuper$2(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$2(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
2053
-
2054
- function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
2055
-
1849
+ function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
1850
+ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
1851
+ function _createSuper$1(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$1(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1852
+ function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
2056
1853
  function removePending(q, name) {
2057
1854
  if (q.pending[name] !== undefined) {
2058
1855
  delete q.pending[name];
2059
1856
  q.pendingCount--;
2060
1857
  }
2061
1858
  }
2062
-
2063
1859
  var Connector = function (_EventEmitter) {
2064
1860
  _inherits(Connector, _EventEmitter);
2065
-
2066
- var _super = _createSuper$2(Connector);
2067
-
1861
+ var _super = _createSuper$1(Connector);
2068
1862
  function Connector(backend, store, services) {
2069
1863
  var _this;
2070
-
2071
1864
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2072
-
2073
1865
  _classCallCheck(this, Connector);
2074
-
2075
1866
  _this = _super.call(this);
2076
-
2077
1867
  if (isIE10) {
2078
1868
  EventEmitter.call(_assertThisInitialized(_this));
2079
1869
  }
2080
-
2081
1870
  _this.backend = backend;
2082
1871
  _this.store = store;
2083
1872
  _this.services = services;
@@ -2091,19 +1880,15 @@ var Connector = function (_EventEmitter) {
2091
1880
  _this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
2092
1881
  _this.state = {};
2093
1882
  _this.queue = [];
2094
-
2095
1883
  if (_this.backend && _this.backend.init) {
2096
1884
  _this.backend.init(services, options.backend, options);
2097
1885
  }
2098
-
2099
1886
  return _this;
2100
1887
  }
2101
-
2102
1888
  _createClass(Connector, [{
2103
1889
  key: "queueLoad",
2104
1890
  value: function queueLoad(languages, namespaces, options, callback) {
2105
1891
  var _this2 = this;
2106
-
2107
1892
  var toLoad = {};
2108
1893
  var pending = {};
2109
1894
  var toLoadLanguages = {};
@@ -2112,7 +1897,6 @@ var Connector = function (_EventEmitter) {
2112
1897
  var hasAllNamespaces = true;
2113
1898
  namespaces.forEach(function (ns) {
2114
1899
  var name = "".concat(lng, "|").concat(ns);
2115
-
2116
1900
  if (!options.reload && _this2.store.hasResourceBundle(lng, ns)) {
2117
1901
  _this2.state[name] = 2;
2118
1902
  } else if (_this2.state[name] < 0) ; else if (_this2.state[name] === 1) {
@@ -2127,7 +1911,6 @@ var Connector = function (_EventEmitter) {
2127
1911
  });
2128
1912
  if (!hasAllNamespaces) toLoadLanguages[lng] = true;
2129
1913
  });
2130
-
2131
1914
  if (Object.keys(toLoad).length || Object.keys(pending).length) {
2132
1915
  this.queue.push({
2133
1916
  pending: pending,
@@ -2137,7 +1920,6 @@ var Connector = function (_EventEmitter) {
2137
1920
  callback: callback
2138
1921
  });
2139
1922
  }
2140
-
2141
1923
  return {
2142
1924
  toLoad: Object.keys(toLoad),
2143
1925
  pending: Object.keys(pending),
@@ -2152,23 +1934,19 @@ var Connector = function (_EventEmitter) {
2152
1934
  var lng = s[0];
2153
1935
  var ns = s[1];
2154
1936
  if (err) this.emit('failedLoading', lng, ns, err);
2155
-
2156
1937
  if (data) {
2157
1938
  this.store.addResourceBundle(lng, ns, data);
2158
1939
  }
2159
-
2160
1940
  this.state[name] = err ? -1 : 2;
2161
1941
  var loaded = {};
2162
1942
  this.queue.forEach(function (q) {
2163
1943
  pushPath(q.loaded, [lng], ns);
2164
1944
  removePending(q, name);
2165
1945
  if (err) q.errors.push(err);
2166
-
2167
1946
  if (q.pendingCount === 0 && !q.done) {
2168
1947
  Object.keys(q.loaded).forEach(function (l) {
2169
1948
  if (!loaded[l]) loaded[l] = {};
2170
1949
  var loadedKeys = q.loaded[l];
2171
-
2172
1950
  if (loadedKeys.length) {
2173
1951
  loadedKeys.forEach(function (ns) {
2174
1952
  if (loaded[l][ns] === undefined) loaded[l][ns] = true;
@@ -2176,7 +1954,6 @@ var Connector = function (_EventEmitter) {
2176
1954
  }
2177
1955
  });
2178
1956
  q.done = true;
2179
-
2180
1957
  if (q.errors.length) {
2181
1958
  q.callback(q.errors);
2182
1959
  } else {
@@ -2193,12 +1970,10 @@ var Connector = function (_EventEmitter) {
2193
1970
  key: "read",
2194
1971
  value: function read(lng, ns, fcName) {
2195
1972
  var _this3 = this;
2196
-
2197
1973
  var tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
2198
1974
  var wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
2199
1975
  var callback = arguments.length > 5 ? arguments[5] : undefined;
2200
1976
  if (!lng.length) return callback(null, {});
2201
-
2202
1977
  if (this.readingCalls >= this.maxParallelReads) {
2203
1978
  this.waitingReads.push({
2204
1979
  lng: lng,
@@ -2210,49 +1985,56 @@ var Connector = function (_EventEmitter) {
2210
1985
  });
2211
1986
  return;
2212
1987
  }
2213
-
2214
1988
  this.readingCalls++;
2215
- return this.backend[fcName](lng, ns, function (err, data) {
1989
+ var resolver = function resolver(err, data) {
2216
1990
  _this3.readingCalls--;
2217
-
2218
1991
  if (_this3.waitingReads.length > 0) {
2219
1992
  var next = _this3.waitingReads.shift();
2220
-
2221
1993
  _this3.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
2222
1994
  }
2223
-
2224
1995
  if (err && data && tried < _this3.maxRetries) {
2225
1996
  setTimeout(function () {
2226
1997
  _this3.read.call(_this3, lng, ns, fcName, tried + 1, wait * 2, callback);
2227
1998
  }, wait);
2228
1999
  return;
2229
2000
  }
2230
-
2231
2001
  callback(err, data);
2232
- });
2002
+ };
2003
+ var fc = this.backend[fcName].bind(this.backend);
2004
+ if (fc.length === 2) {
2005
+ try {
2006
+ var r = fc(lng, ns);
2007
+ if (r && typeof r.then === 'function') {
2008
+ r.then(function (data) {
2009
+ return resolver(null, data);
2010
+ })["catch"](resolver);
2011
+ } else {
2012
+ resolver(null, r);
2013
+ }
2014
+ } catch (err) {
2015
+ resolver(err);
2016
+ }
2017
+ return;
2018
+ }
2019
+ return fc(lng, ns, resolver);
2233
2020
  }
2234
2021
  }, {
2235
2022
  key: "prepareLoading",
2236
2023
  value: function prepareLoading(languages, namespaces) {
2237
2024
  var _this4 = this;
2238
-
2239
2025
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2240
2026
  var callback = arguments.length > 3 ? arguments[3] : undefined;
2241
-
2242
2027
  if (!this.backend) {
2243
2028
  this.logger.warn('No backend was added via i18next.use. Will not load resources.');
2244
2029
  return callback && callback();
2245
2030
  }
2246
-
2247
2031
  if (typeof languages === 'string') languages = this.languageUtils.toResolveHierarchy(languages);
2248
2032
  if (typeof namespaces === 'string') namespaces = [namespaces];
2249
2033
  var toLoad = this.queueLoad(languages, namespaces, options, callback);
2250
-
2251
2034
  if (!toLoad.toLoad.length) {
2252
2035
  if (!toLoad.pending.length) callback();
2253
2036
  return null;
2254
2037
  }
2255
-
2256
2038
  toLoad.toLoad.forEach(function (name) {
2257
2039
  _this4.loadOne(name);
2258
2040
  });
@@ -2273,7 +2055,6 @@ var Connector = function (_EventEmitter) {
2273
2055
  key: "loadOne",
2274
2056
  value: function loadOne(name) {
2275
2057
  var _this5 = this;
2276
-
2277
2058
  var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
2278
2059
  var s = name.split('|');
2279
2060
  var lng = s[0];
@@ -2281,7 +2062,6 @@ var Connector = function (_EventEmitter) {
2281
2062
  this.read(lng, ns, 'read', undefined, undefined, function (err, data) {
2282
2063
  if (err) _this5.logger.warn("".concat(prefix, "loading namespace ").concat(ns, " for language ").concat(lng, " failed"), err);
2283
2064
  if (!err && data) _this5.logger.log("".concat(prefix, "loaded namespace ").concat(ns, " for language ").concat(lng), data);
2284
-
2285
2065
  _this5.loaded(name, err, data);
2286
2066
  });
2287
2067
  }
@@ -2289,25 +2069,43 @@ var Connector = function (_EventEmitter) {
2289
2069
  key: "saveMissing",
2290
2070
  value: function saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
2291
2071
  var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
2292
-
2072
+ var clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : function () {};
2293
2073
  if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
2294
2074
  this.logger.warn("did not save key \"".concat(key, "\" as the namespace \"").concat(namespace, "\" was not yet loaded"), 'This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!');
2295
2075
  return;
2296
2076
  }
2297
-
2298
2077
  if (key === undefined || key === null || key === '') return;
2299
-
2300
2078
  if (this.backend && this.backend.create) {
2301
- this.backend.create(languages, namespace, key, fallbackValue, null, _objectSpread$5(_objectSpread$5({}, options), {}, {
2079
+ var opts = _objectSpread$1(_objectSpread$1({}, options), {}, {
2302
2080
  isUpdate: isUpdate
2303
- }));
2081
+ });
2082
+ var fc = this.backend.create.bind(this.backend);
2083
+ if (fc.length < 6) {
2084
+ try {
2085
+ var r;
2086
+ if (fc.length === 5) {
2087
+ r = fc(languages, namespace, key, fallbackValue, opts);
2088
+ } else {
2089
+ r = fc(languages, namespace, key, fallbackValue);
2090
+ }
2091
+ if (r && typeof r.then === 'function') {
2092
+ r.then(function (data) {
2093
+ return clb(null, data);
2094
+ })["catch"](clb);
2095
+ } else {
2096
+ clb(null, r);
2097
+ }
2098
+ } catch (err) {
2099
+ clb(err);
2100
+ }
2101
+ } else {
2102
+ fc(languages, namespace, key, fallbackValue, clb, opts);
2103
+ }
2304
2104
  }
2305
-
2306
2105
  if (!languages || !languages[0]) return;
2307
2106
  this.store.addResource(languages[0], namespace, key, fallbackValue);
2308
2107
  }
2309
2108
  }]);
2310
-
2311
2109
  return Connector;
2312
2110
  }(EventEmitter);
2313
2111
 
@@ -2350,14 +2148,12 @@ function get() {
2350
2148
  if (_typeof(args[1]) === 'object') ret = args[1];
2351
2149
  if (typeof args[1] === 'string') ret.defaultValue = args[1];
2352
2150
  if (typeof args[2] === 'string') ret.tDescription = args[2];
2353
-
2354
2151
  if (_typeof(args[2]) === 'object' || _typeof(args[3]) === 'object') {
2355
2152
  var options = args[3] || args[2];
2356
2153
  Object.keys(options).forEach(function (key) {
2357
2154
  ret[key] = options[key];
2358
2155
  });
2359
2156
  }
2360
-
2361
2157
  return ret;
2362
2158
  },
2363
2159
  interpolation: {
@@ -2381,24 +2177,17 @@ function transformOptions(options) {
2381
2177
  if (typeof options.ns === 'string') options.ns = [options.ns];
2382
2178
  if (typeof options.fallbackLng === 'string') options.fallbackLng = [options.fallbackLng];
2383
2179
  if (typeof options.fallbackNS === 'string') options.fallbackNS = [options.fallbackNS];
2384
-
2385
2180
  if (options.supportedLngs && options.supportedLngs.indexOf('cimode') < 0) {
2386
2181
  options.supportedLngs = options.supportedLngs.concat(['cimode']);
2387
2182
  }
2388
-
2389
2183
  return options;
2390
2184
  }
2391
2185
 
2392
- function ownKeys$6(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
2393
-
2394
- function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$6(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$6(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
2395
-
2396
- function _createSuper$3(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$3(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
2397
-
2398
- function _isNativeReflectConstruct$3() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
2399
-
2186
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2187
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2188
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
2189
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
2400
2190
  function noop() {}
2401
-
2402
2191
  function bindMemberFunctions(inst) {
2403
2192
  var mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
2404
2193
  mems.forEach(function (mem) {
@@ -2407,26 +2196,18 @@ function bindMemberFunctions(inst) {
2407
2196
  }
2408
2197
  });
2409
2198
  }
2410
-
2411
2199
  var I18n = function (_EventEmitter) {
2412
2200
  _inherits(I18n, _EventEmitter);
2413
-
2414
- var _super = _createSuper$3(I18n);
2415
-
2201
+ var _super = _createSuper(I18n);
2416
2202
  function I18n() {
2417
2203
  var _this;
2418
-
2419
2204
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2420
2205
  var callback = arguments.length > 1 ? arguments[1] : undefined;
2421
-
2422
2206
  _classCallCheck(this, I18n);
2423
-
2424
2207
  _this = _super.call(this);
2425
-
2426
2208
  if (isIE10) {
2427
2209
  EventEmitter.call(_assertThisInitialized(_this));
2428
2210
  }
2429
-
2430
2211
  _this.options = transformOptions(options);
2431
2212
  _this.services = {};
2432
2213
  _this.logger = baseLogger;
@@ -2434,35 +2215,27 @@ var I18n = function (_EventEmitter) {
2434
2215
  external: []
2435
2216
  };
2436
2217
  bindMemberFunctions(_assertThisInitialized(_this));
2437
-
2438
2218
  if (callback && !_this.isInitialized && !options.isClone) {
2439
2219
  if (!_this.options.initImmediate) {
2440
2220
  _this.init(options, callback);
2441
-
2442
2221
  return _possibleConstructorReturn(_this, _assertThisInitialized(_this));
2443
2222
  }
2444
-
2445
2223
  setTimeout(function () {
2446
2224
  _this.init(options, callback);
2447
2225
  }, 0);
2448
2226
  }
2449
-
2450
2227
  return _this;
2451
2228
  }
2452
-
2453
2229
  _createClass(I18n, [{
2454
2230
  key: "init",
2455
2231
  value: function init() {
2456
2232
  var _this2 = this;
2457
-
2458
2233
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2459
2234
  var callback = arguments.length > 1 ? arguments[1] : undefined;
2460
-
2461
2235
  if (typeof options === 'function') {
2462
2236
  callback = options;
2463
2237
  options = {};
2464
2238
  }
2465
-
2466
2239
  if (!options.defaultNS && options.defaultNS !== false && options.ns) {
2467
2240
  if (typeof options.ns === 'string') {
2468
2241
  options.defaultNS = options.ns;
@@ -2470,43 +2243,34 @@ var I18n = function (_EventEmitter) {
2470
2243
  options.defaultNS = options.ns[0];
2471
2244
  }
2472
2245
  }
2473
-
2474
2246
  var defOpts = get();
2475
- this.options = _objectSpread$6(_objectSpread$6(_objectSpread$6({}, defOpts), this.options), transformOptions(options));
2476
-
2247
+ this.options = _objectSpread(_objectSpread(_objectSpread({}, defOpts), this.options), transformOptions(options));
2477
2248
  if (this.options.compatibilityAPI !== 'v1') {
2478
- this.options.interpolation = _objectSpread$6(_objectSpread$6({}, defOpts.interpolation), this.options.interpolation);
2249
+ this.options.interpolation = _objectSpread(_objectSpread({}, defOpts.interpolation), this.options.interpolation);
2479
2250
  }
2480
-
2481
2251
  if (options.keySeparator !== undefined) {
2482
2252
  this.options.userDefinedKeySeparator = options.keySeparator;
2483
2253
  }
2484
-
2485
2254
  if (options.nsSeparator !== undefined) {
2486
2255
  this.options.userDefinedNsSeparator = options.nsSeparator;
2487
2256
  }
2488
-
2489
2257
  function createClassOnDemand(ClassOrObject) {
2490
2258
  if (!ClassOrObject) return null;
2491
2259
  if (typeof ClassOrObject === 'function') return new ClassOrObject();
2492
2260
  return ClassOrObject;
2493
2261
  }
2494
-
2495
2262
  if (!this.options.isClone) {
2496
2263
  if (this.modules.logger) {
2497
2264
  baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
2498
2265
  } else {
2499
2266
  baseLogger.init(null, this.options);
2500
2267
  }
2501
-
2502
2268
  var formatter;
2503
-
2504
2269
  if (this.modules.formatter) {
2505
2270
  formatter = this.modules.formatter;
2506
2271
  } else if (typeof Intl !== 'undefined') {
2507
2272
  formatter = Formatter;
2508
2273
  }
2509
-
2510
2274
  var lu = new LanguageUtil(this.options);
2511
2275
  this.store = new ResourceStore(this.options.resources, this.options);
2512
2276
  var s = this.services;
@@ -2518,13 +2282,11 @@ var I18n = function (_EventEmitter) {
2518
2282
  compatibilityJSON: this.options.compatibilityJSON,
2519
2283
  simplifyPluralSuffix: this.options.simplifyPluralSuffix
2520
2284
  });
2521
-
2522
2285
  if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
2523
2286
  s.formatter = createClassOnDemand(formatter);
2524
2287
  s.formatter.init(s, this.options);
2525
2288
  this.options.interpolation.format = s.formatter.format.bind(s.formatter);
2526
2289
  }
2527
-
2528
2290
  s.interpolator = new Interpolator(this.options);
2529
2291
  s.utils = {
2530
2292
  hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
@@ -2534,50 +2296,40 @@ var I18n = function (_EventEmitter) {
2534
2296
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2535
2297
  args[_key - 1] = arguments[_key];
2536
2298
  }
2537
-
2538
2299
  _this2.emit.apply(_this2, [event].concat(args));
2539
2300
  });
2540
-
2541
2301
  if (this.modules.languageDetector) {
2542
2302
  s.languageDetector = createClassOnDemand(this.modules.languageDetector);
2543
- s.languageDetector.init(s, this.options.detection, this.options);
2303
+ if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
2544
2304
  }
2545
-
2546
2305
  if (this.modules.i18nFormat) {
2547
2306
  s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
2548
2307
  if (s.i18nFormat.init) s.i18nFormat.init(this);
2549
2308
  }
2550
-
2551
2309
  this.translator = new Translator(this.services, this.options);
2552
2310
  this.translator.on('*', function (event) {
2553
2311
  for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
2554
2312
  args[_key2 - 1] = arguments[_key2];
2555
2313
  }
2556
-
2557
2314
  _this2.emit.apply(_this2, [event].concat(args));
2558
2315
  });
2559
2316
  this.modules.external.forEach(function (m) {
2560
2317
  if (m.init) m.init(_this2);
2561
2318
  });
2562
2319
  }
2563
-
2564
2320
  this.format = this.options.interpolation.format;
2565
2321
  if (!callback) callback = noop;
2566
-
2567
2322
  if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
2568
2323
  var codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
2569
2324
  if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
2570
2325
  }
2571
-
2572
2326
  if (!this.services.languageDetector && !this.options.lng) {
2573
2327
  this.logger.warn('init: no languageDetector is used and no lng is defined');
2574
2328
  }
2575
-
2576
2329
  var storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
2577
2330
  storeApi.forEach(function (fcName) {
2578
2331
  _this2[fcName] = function () {
2579
2332
  var _this2$store;
2580
-
2581
2333
  return (_this2$store = _this2.store)[fcName].apply(_this2$store, arguments);
2582
2334
  };
2583
2335
  });
@@ -2585,63 +2337,48 @@ var I18n = function (_EventEmitter) {
2585
2337
  storeApiChained.forEach(function (fcName) {
2586
2338
  _this2[fcName] = function () {
2587
2339
  var _this2$store2;
2588
-
2589
2340
  (_this2$store2 = _this2.store)[fcName].apply(_this2$store2, arguments);
2590
-
2591
2341
  return _this2;
2592
2342
  };
2593
2343
  });
2594
2344
  var deferred = defer();
2595
-
2596
2345
  var load = function load() {
2597
2346
  var finish = function finish(err, t) {
2598
2347
  if (_this2.isInitialized && !_this2.initializedStoreOnce) _this2.logger.warn('init: i18next is already initialized. You should call init just once!');
2599
2348
  _this2.isInitialized = true;
2600
2349
  if (!_this2.options.isClone) _this2.logger.log('initialized', _this2.options);
2601
-
2602
2350
  _this2.emit('initialized', _this2.options);
2603
-
2604
2351
  deferred.resolve(t);
2605
2352
  callback(err, t);
2606
2353
  };
2607
-
2608
2354
  if (_this2.languages && _this2.options.compatibilityAPI !== 'v1' && !_this2.isInitialized) return finish(null, _this2.t.bind(_this2));
2609
-
2610
2355
  _this2.changeLanguage(_this2.options.lng, finish);
2611
2356
  };
2612
-
2613
2357
  if (this.options.resources || !this.options.initImmediate) {
2614
2358
  load();
2615
2359
  } else {
2616
2360
  setTimeout(load, 0);
2617
2361
  }
2618
-
2619
2362
  return deferred;
2620
2363
  }
2621
2364
  }, {
2622
2365
  key: "loadResources",
2623
2366
  value: function loadResources(language) {
2624
2367
  var _this3 = this;
2625
-
2626
2368
  var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
2627
2369
  var usedCallback = callback;
2628
2370
  var usedLng = typeof language === 'string' ? language : this.language;
2629
2371
  if (typeof language === 'function') usedCallback = language;
2630
-
2631
2372
  if (!this.options.resources || this.options.partialBundledLanguages) {
2632
2373
  if (usedLng && usedLng.toLowerCase() === 'cimode') return usedCallback();
2633
2374
  var toLoad = [];
2634
-
2635
2375
  var append = function append(lng) {
2636
2376
  if (!lng) return;
2637
-
2638
2377
  var lngs = _this3.services.languageUtils.toResolveHierarchy(lng);
2639
-
2640
2378
  lngs.forEach(function (l) {
2641
2379
  if (toLoad.indexOf(l) < 0) toLoad.push(l);
2642
2380
  });
2643
2381
  };
2644
-
2645
2382
  if (!usedLng) {
2646
2383
  var fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
2647
2384
  fallbacks.forEach(function (l) {
@@ -2650,13 +2387,11 @@ var I18n = function (_EventEmitter) {
2650
2387
  } else {
2651
2388
  append(usedLng);
2652
2389
  }
2653
-
2654
2390
  if (this.options.preload) {
2655
2391
  this.options.preload.forEach(function (l) {
2656
2392
  return append(l);
2657
2393
  });
2658
2394
  }
2659
-
2660
2395
  this.services.backendConnector.load(toLoad, this.options.ns, function (e) {
2661
2396
  if (!e && !_this3.resolvedLanguage && _this3.language) _this3.setResolvedLanguage(_this3.language);
2662
2397
  usedCallback(e);
@@ -2683,35 +2418,27 @@ var I18n = function (_EventEmitter) {
2683
2418
  value: function use(module) {
2684
2419
  if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
2685
2420
  if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
2686
-
2687
2421
  if (module.type === 'backend') {
2688
2422
  this.modules.backend = module;
2689
2423
  }
2690
-
2691
2424
  if (module.type === 'logger' || module.log && module.warn && module.error) {
2692
2425
  this.modules.logger = module;
2693
2426
  }
2694
-
2695
2427
  if (module.type === 'languageDetector') {
2696
2428
  this.modules.languageDetector = module;
2697
2429
  }
2698
-
2699
2430
  if (module.type === 'i18nFormat') {
2700
2431
  this.modules.i18nFormat = module;
2701
2432
  }
2702
-
2703
2433
  if (module.type === 'postProcessor') {
2704
2434
  postProcessor.addPostProcessor(module);
2705
2435
  }
2706
-
2707
2436
  if (module.type === 'formatter') {
2708
2437
  this.modules.formatter = module;
2709
2438
  }
2710
-
2711
2439
  if (module.type === '3rdParty') {
2712
2440
  this.modules.external.push(module);
2713
2441
  }
2714
-
2715
2442
  return this;
2716
2443
  }
2717
2444
  }, {
@@ -2719,11 +2446,9 @@ var I18n = function (_EventEmitter) {
2719
2446
  value: function setResolvedLanguage(l) {
2720
2447
  if (!l || !this.languages) return;
2721
2448
  if (['cimode', 'dev'].indexOf(l) > -1) return;
2722
-
2723
2449
  for (var li = 0; li < this.languages.length; li++) {
2724
2450
  var lngInLngs = this.languages[li];
2725
2451
  if (['cimode', 'dev'].indexOf(lngInLngs) > -1) continue;
2726
-
2727
2452
  if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
2728
2453
  this.resolvedLanguage = lngInLngs;
2729
2454
  break;
@@ -2734,34 +2459,25 @@ var I18n = function (_EventEmitter) {
2734
2459
  key: "changeLanguage",
2735
2460
  value: function changeLanguage(lng, callback) {
2736
2461
  var _this4 = this;
2737
-
2738
2462
  this.isLanguageChangingTo = lng;
2739
2463
  var deferred = defer();
2740
2464
  this.emit('languageChanging', lng);
2741
-
2742
2465
  var setLngProps = function setLngProps(l) {
2743
2466
  _this4.language = l;
2744
2467
  _this4.languages = _this4.services.languageUtils.toResolveHierarchy(l);
2745
2468
  _this4.resolvedLanguage = undefined;
2746
-
2747
2469
  _this4.setResolvedLanguage(l);
2748
2470
  };
2749
-
2750
2471
  var done = function done(err, l) {
2751
2472
  if (l) {
2752
2473
  setLngProps(l);
2753
-
2754
2474
  _this4.translator.changeLanguage(l);
2755
-
2756
2475
  _this4.isLanguageChangingTo = undefined;
2757
-
2758
2476
  _this4.emit('languageChanged', l);
2759
-
2760
2477
  _this4.logger.log('languageChanged', l);
2761
2478
  } else {
2762
2479
  _this4.isLanguageChangingTo = undefined;
2763
2480
  }
2764
-
2765
2481
  deferred.resolve(function () {
2766
2482
  return _this4.t.apply(_this4, arguments);
2767
2483
  });
@@ -2769,53 +2485,47 @@ var I18n = function (_EventEmitter) {
2769
2485
  return _this4.t.apply(_this4, arguments);
2770
2486
  });
2771
2487
  };
2772
-
2773
2488
  var setLng = function setLng(lngs) {
2774
2489
  if (!lng && !lngs && _this4.services.languageDetector) lngs = [];
2775
2490
  var l = typeof lngs === 'string' ? lngs : _this4.services.languageUtils.getBestMatchFromCodes(lngs);
2776
-
2777
2491
  if (l) {
2778
2492
  if (!_this4.language) {
2779
2493
  setLngProps(l);
2780
2494
  }
2781
-
2782
2495
  if (!_this4.translator.language) _this4.translator.changeLanguage(l);
2783
- if (_this4.services.languageDetector) _this4.services.languageDetector.cacheUserLanguage(l);
2496
+ if (_this4.services.languageDetector && _this4.services.languageDetector.cacheUserLanguage) _this4.services.languageDetector.cacheUserLanguage(l);
2784
2497
  }
2785
-
2786
2498
  _this4.loadResources(l, function (err) {
2787
2499
  done(err, l);
2788
2500
  });
2789
2501
  };
2790
-
2791
2502
  if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
2792
2503
  setLng(this.services.languageDetector.detect());
2793
2504
  } else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
2794
- this.services.languageDetector.detect(setLng);
2505
+ if (this.services.languageDetector.detect.length === 0) {
2506
+ this.services.languageDetector.detect().then(setLng);
2507
+ } else {
2508
+ this.services.languageDetector.detect(setLng);
2509
+ }
2795
2510
  } else {
2796
2511
  setLng(lng);
2797
2512
  }
2798
-
2799
2513
  return deferred;
2800
2514
  }
2801
2515
  }, {
2802
2516
  key: "getFixedT",
2803
2517
  value: function getFixedT(lng, ns, keyPrefix) {
2804
2518
  var _this5 = this;
2805
-
2806
2519
  var fixedT = function fixedT(key, opts) {
2807
2520
  var options;
2808
-
2809
2521
  if (_typeof(opts) !== 'object') {
2810
2522
  for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
2811
2523
  rest[_key3 - 2] = arguments[_key3];
2812
2524
  }
2813
-
2814
2525
  options = _this5.options.overloadTranslationOptionHandler([key, opts].concat(rest));
2815
2526
  } else {
2816
- options = _objectSpread$6({}, opts);
2527
+ options = _objectSpread({}, opts);
2817
2528
  }
2818
-
2819
2529
  options.lng = options.lng || fixedT.lng;
2820
2530
  options.lngs = options.lngs || fixedT.lngs;
2821
2531
  options.ns = options.ns || fixedT.ns;
@@ -2824,13 +2534,11 @@ var I18n = function (_EventEmitter) {
2824
2534
  var resultKey = options.keyPrefix ? "".concat(options.keyPrefix).concat(keySeparator).concat(key) : key;
2825
2535
  return _this5.t(resultKey, options);
2826
2536
  };
2827
-
2828
2537
  if (typeof lng === 'string') {
2829
2538
  fixedT.lng = lng;
2830
2539
  } else {
2831
2540
  fixedT.lngs = lng;
2832
2541
  }
2833
-
2834
2542
  fixedT.ns = ns;
2835
2543
  fixedT.keyPrefix = keyPrefix;
2836
2544
  return fixedT;
@@ -2839,14 +2547,12 @@ var I18n = function (_EventEmitter) {
2839
2547
  key: "t",
2840
2548
  value: function t() {
2841
2549
  var _this$translator;
2842
-
2843
2550
  return this.translator && (_this$translator = this.translator).translate.apply(_this$translator, arguments);
2844
2551
  }
2845
2552
  }, {
2846
2553
  key: "exists",
2847
2554
  value: function exists() {
2848
2555
  var _this$translator2;
2849
-
2850
2556
  return this.translator && (_this$translator2 = this.translator).exists.apply(_this$translator2, arguments);
2851
2557
  }
2852
2558
  }, {
@@ -2858,35 +2564,27 @@ var I18n = function (_EventEmitter) {
2858
2564
  key: "hasLoadedNamespace",
2859
2565
  value: function hasLoadedNamespace(ns) {
2860
2566
  var _this6 = this;
2861
-
2862
2567
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2863
-
2864
2568
  if (!this.isInitialized) {
2865
2569
  this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
2866
2570
  return false;
2867
2571
  }
2868
-
2869
2572
  if (!this.languages || !this.languages.length) {
2870
2573
  this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages);
2871
2574
  return false;
2872
2575
  }
2873
-
2874
2576
  var lng = this.resolvedLanguage || this.languages[0];
2875
2577
  var fallbackLng = this.options ? this.options.fallbackLng : false;
2876
2578
  var lastLng = this.languages[this.languages.length - 1];
2877
2579
  if (lng.toLowerCase() === 'cimode') return true;
2878
-
2879
2580
  var loadNotPending = function loadNotPending(l, n) {
2880
2581
  var loadState = _this6.services.backendConnector.state["".concat(l, "|").concat(n)];
2881
-
2882
2582
  return loadState === -1 || loadState === 2;
2883
2583
  };
2884
-
2885
2584
  if (options.precheck) {
2886
2585
  var preResult = options.precheck(this, loadNotPending);
2887
2586
  if (preResult !== undefined) return preResult;
2888
2587
  }
2889
-
2890
2588
  if (this.hasResourceBundle(lng, ns)) return true;
2891
2589
  if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
2892
2590
  if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
@@ -2896,14 +2594,11 @@ var I18n = function (_EventEmitter) {
2896
2594
  key: "loadNamespaces",
2897
2595
  value: function loadNamespaces(ns, callback) {
2898
2596
  var _this7 = this;
2899
-
2900
2597
  var deferred = defer();
2901
-
2902
2598
  if (!this.options.ns) {
2903
2599
  callback && callback();
2904
2600
  return Promise.resolve();
2905
2601
  }
2906
-
2907
2602
  if (typeof ns === 'string') ns = [ns];
2908
2603
  ns.forEach(function (n) {
2909
2604
  if (_this7.options.ns.indexOf(n) < 0) _this7.options.ns.push(n);
@@ -2923,12 +2618,10 @@ var I18n = function (_EventEmitter) {
2923
2618
  var newLngs = lngs.filter(function (lng) {
2924
2619
  return preloaded.indexOf(lng) < 0;
2925
2620
  });
2926
-
2927
2621
  if (!newLngs.length) {
2928
2622
  if (callback) callback();
2929
2623
  return Promise.resolve();
2930
2624
  }
2931
-
2932
2625
  this.options.preload = preloaded.concat(newLngs);
2933
2626
  this.loadResources(function (err) {
2934
2627
  deferred.resolve();
@@ -2942,26 +2635,27 @@ var I18n = function (_EventEmitter) {
2942
2635
  if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
2943
2636
  if (!lng) return 'rtl';
2944
2637
  var rtlLngs = ['ar', 'shu', 'sqr', 'ssh', 'xaa', 'yhd', 'yud', 'aao', 'abh', 'abv', 'acm', 'acq', 'acw', 'acx', 'acy', 'adf', 'ads', 'aeb', 'aec', 'afb', 'ajp', 'apc', 'apd', 'arb', 'arq', 'ars', 'ary', 'arz', 'auz', 'avl', 'ayh', 'ayl', 'ayn', 'ayp', 'bbz', 'pga', 'he', 'iw', 'ps', 'pbt', 'pbu', 'pst', 'prp', 'prd', 'ug', 'ur', 'ydd', 'yds', 'yih', 'ji', 'yi', 'hbo', 'men', 'xmn', 'fa', 'jpr', 'peo', 'pes', 'prs', 'dv', 'sam', 'ckb'];
2945
- return rtlLngs.indexOf(this.services.languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
2638
+ var languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
2639
+ return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
2946
2640
  }
2947
2641
  }, {
2948
2642
  key: "cloneInstance",
2949
2643
  value: function cloneInstance() {
2950
2644
  var _this8 = this;
2951
-
2952
2645
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2953
2646
  var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
2954
-
2955
- var mergedOptions = _objectSpread$6(_objectSpread$6(_objectSpread$6({}, this.options), options), {
2647
+ var mergedOptions = _objectSpread(_objectSpread(_objectSpread({}, this.options), options), {
2956
2648
  isClone: true
2957
2649
  });
2958
-
2959
2650
  var clone = new I18n(mergedOptions);
2651
+ if (options.debug !== undefined || options.prefix !== undefined) {
2652
+ clone.logger = clone.logger.clone(options);
2653
+ }
2960
2654
  var membersToCopy = ['store', 'services', 'language'];
2961
2655
  membersToCopy.forEach(function (m) {
2962
2656
  clone[m] = _this8[m];
2963
2657
  });
2964
- clone.services = _objectSpread$6({}, this.services);
2658
+ clone.services = _objectSpread({}, this.services);
2965
2659
  clone.services.utils = {
2966
2660
  hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
2967
2661
  };
@@ -2970,7 +2664,6 @@ var I18n = function (_EventEmitter) {
2970
2664
  for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
2971
2665
  args[_key4 - 1] = arguments[_key4];
2972
2666
  }
2973
-
2974
2667
  clone.emit.apply(clone, [event].concat(args));
2975
2668
  });
2976
2669
  clone.init(mergedOptions, callback);
@@ -2992,16 +2685,13 @@ var I18n = function (_EventEmitter) {
2992
2685
  };
2993
2686
  }
2994
2687
  }]);
2995
-
2996
2688
  return I18n;
2997
2689
  }(EventEmitter);
2998
-
2999
2690
  _defineProperty(I18n, "createInstance", function () {
3000
2691
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
3001
2692
  var callback = arguments.length > 1 ? arguments[1] : undefined;
3002
2693
  return new I18n(options, callback);
3003
2694
  });
3004
-
3005
2695
  var instance = I18n.createInstance();
3006
2696
  instance.createInstance = I18n.createInstance;
3007
2697
 
@@ -4088,12 +3778,31 @@ var sha1 = createCommonjsModule(function (module) {
4088
3778
  /** List of hex digit for fast accessing by index */
4089
3779
  var HEX_DIGITS = '0123456789abcdef'.split('');
4090
3780
 
3781
+ /** Length of string containing uuid */
3782
+ var UUID_LENGTH = 36;
3783
+
3784
+ /** Regular expression for uuid testing */
3785
+ var UUID_REGEXP = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
3786
+
3787
+ /** Map matching of hex number and corresponding byte */
3788
+ var HEX_TO_BYTE_MAP = (function () {
3789
+ var map = {};
3790
+
3791
+ for (var i = 0; i < 256; i++) {
3792
+ var hex = i.toString(16);
3793
+
3794
+ map[hex.length === 1 ? '0' + hex : hex] = i;
3795
+ }
3796
+
3797
+ return map;
3798
+ })();
3799
+
4091
3800
  /**
4092
3801
  * Converts unsigned byte to hex representation
4093
3802
  * @param {number} ubyte The unsigned byte to convert
4094
3803
  * @returns {string} The hex representation
4095
3804
  */
4096
- var uint8ToHex = function(ubyte) {
3805
+ var uint8ToHex = function (ubyte) {
4097
3806
  var first = ubyte >> 4;
4098
3807
  var second = ubyte - (first << 4);
4099
3808
 
@@ -4105,14 +3814,14 @@ var uint8ToHex = function(ubyte) {
4105
3814
  * @param {Uint8Array} buf The unsigned bytes buffer
4106
3815
  * @returns {string} The hex string representation
4107
3816
  */
4108
- var uint8ArrayToHex = function(buf) {
4109
- var out = [];
3817
+ var uint8ArrayToHex = function (buf) {
3818
+ var out = '';
4110
3819
 
4111
3820
  for (var i = 0; i < buf.length; i++) {
4112
- out.push(uint8ToHex(buf[i]));
3821
+ out += uint8ToHex(buf[i]);
4113
3822
  }
4114
3823
 
4115
- return out.join('');
3824
+ return out;
4116
3825
  };
4117
3826
 
4118
3827
  /**
@@ -4120,11 +3829,12 @@ var uint8ArrayToHex = function(buf) {
4120
3829
  * @param {string} str The string to parse
4121
3830
  * @returns {Uint8Array} Buffer of char codes
4122
3831
  */
4123
- var stringToCharBuffer = function(str) {
4124
- var buffer = new Uint8Array(str.length);
3832
+ var stringToCharBuffer = function (str) {
3833
+ var escapedStr = unescape(encodeURIComponent(str));
3834
+ var buffer = new Uint8Array(escapedStr.length);
4125
3835
 
4126
- for (var i = 0; i < str.length; i++) {
4127
- buffer[i] = str[i].charCodeAt(0);
3836
+ for (var i = 0; i < escapedStr.length; i++) {
3837
+ buffer[i] = escapedStr[i].charCodeAt(0);
4128
3838
  }
4129
3839
 
4130
3840
  return buffer;
@@ -4135,7 +3845,7 @@ var stringToCharBuffer = function(str) {
4135
3845
  * @param {Uint8Array} buf Buffer of char codes
4136
3846
  * @returns {Uint8Array} MD5 hash buffer
4137
3847
  */
4138
- var md5Hash = function(buf) {
3848
+ var md5Hash = function (buf) {
4139
3849
  return new Uint8Array(md5.arrayBuffer(buf));
4140
3850
  };
4141
3851
 
@@ -4144,7 +3854,7 @@ var md5Hash = function(buf) {
4144
3854
  * @param {Uint8Array} buf Buffer of char codes
4145
3855
  * @returns {Uint8Array} SHA-1 hash buffer
4146
3856
  */
4147
- var sha1Hash = function(buf) {
3857
+ var sha1Hash = function (buf) {
4148
3858
  return new Uint8Array(sha1.arrayBuffer(buf));
4149
3859
  };
4150
3860
 
@@ -4154,7 +3864,7 @@ var sha1Hash = function(buf) {
4154
3864
  * @param {Uint8Array} buf2 The second buffer to concatenate
4155
3865
  * @returns {Uint8Array} Concatenation result
4156
3866
  */
4157
- var concatBuffers = function(buf1, buf2) {
3867
+ var concatBuffers = function (buf1, buf2) {
4158
3868
  var out = new Uint8Array(buf1.length + buf2.length);
4159
3869
 
4160
3870
  out.set(new Uint8Array(buf1), 0);
@@ -4163,46 +3873,83 @@ var concatBuffers = function(buf1, buf2) {
4163
3873
  return out;
4164
3874
  };
4165
3875
 
3876
+ /**
3877
+ * Validates UUID
3878
+ * @param {string} uuid UUID to validate
3879
+ * @return {boolean} Validation result
3880
+ */
3881
+ var validateUuid = function (uuid) {
3882
+ return typeof uuid === 'string' && uuid.length === UUID_LENGTH && UUID_REGEXP.test(uuid);
3883
+ };
3884
+
3885
+ /**
3886
+ * Parses UUID into a buffer
3887
+ * @param {string} uuid UUID to parse
3888
+ * @returns {Uint8Array} Ready buffer
3889
+ */
3890
+ var parseUuid = function (uuid) {
3891
+ if (!validateUuid(uuid)) {
3892
+ throw TypeError('Invalid UUID');
3893
+ }
3894
+
3895
+ var buf = new Uint8Array(16);
3896
+ var strIndex = 0;
3897
+ var bufIndex = 0;
3898
+
3899
+ while (strIndex < uuid.length) {
3900
+ if (uuid[strIndex] === '-') {
3901
+ strIndex++;
3902
+ continue;
3903
+ }
3904
+
3905
+ var oct = (uuid[strIndex] + uuid[strIndex + 1]).toLowerCase();
3906
+ buf[bufIndex] = HEX_TO_BYTE_MAP[oct];
3907
+
3908
+ bufIndex++;
3909
+ strIndex += 2;
3910
+ }
3911
+
3912
+ return buf;
3913
+ };
3914
+
4166
3915
  /**
4167
3916
  * Creates uuid from hash buffer
4168
3917
  * @param {Uint8Array} hashBuffer Hash buffer
4169
3918
  * @param {3|5} version Version of uuid
4170
3919
  * @returns {string} The uuid
4171
3920
  */
4172
- var hashToUuid = function(hashBuffer, version) {
4173
- return [
3921
+ var hashToUuid = function (hashBuffer, version) {
3922
+ return (
4174
3923
  // The low field of the timestamp
4175
- uint8ArrayToHex(hashBuffer.slice(0, 4)),
4176
- '-',
4177
-
3924
+ uint8ArrayToHex(hashBuffer.slice(0, 4)) +
3925
+ '-' +
4178
3926
  // The middle field of the timestamp
4179
- uint8ArrayToHex(hashBuffer.slice(4, 6)),
4180
- '-',
4181
-
3927
+ uint8ArrayToHex(hashBuffer.slice(4, 6)) +
3928
+ '-' +
4182
3929
  // The high field of the timestamp multiplexed with the version number
4183
- uint8ToHex((hashBuffer[6] & 0x0f) | parseInt(version * 10, 16)),
4184
- uint8ToHex(hashBuffer[7]),
4185
- '-',
4186
-
3930
+ uint8ToHex((hashBuffer[6] & 0x0f) | parseInt(version * 10, 16)) +
3931
+ uint8ToHex(hashBuffer[7]) +
3932
+ '-' +
4187
3933
  // The high field of the clock sequence multiplexed with the variant
4188
- uint8ToHex((hashBuffer[8] & 0x3f) | 0x80),
3934
+ uint8ToHex((hashBuffer[8] & 0x3f) | 0x80) +
4189
3935
  // The low field of the clock sequence
4190
- uint8ToHex(hashBuffer[9]),
4191
- '-',
3936
+ uint8ToHex(hashBuffer[9]) +
3937
+ '-' +
4192
3938
  // The spatially unique node identifier
4193
-
4194
3939
  uint8ArrayToHex(hashBuffer.slice(10, 16))
4195
- ].join('');
3940
+ );
4196
3941
  };
4197
3942
 
4198
3943
  var lib = {
4199
- uint8ToHex,
4200
- uint8ArrayToHex,
4201
- stringToCharBuffer,
4202
- md5Hash,
4203
- sha1Hash,
4204
- concatBuffers,
4205
- hashToUuid
3944
+ uint8ToHex: uint8ToHex,
3945
+ uint8ArrayToHex: uint8ArrayToHex,
3946
+ stringToCharBuffer: stringToCharBuffer,
3947
+ md5Hash: md5Hash,
3948
+ sha1Hash: sha1Hash,
3949
+ concatBuffers: concatBuffers,
3950
+ validateUuid: validateUuid,
3951
+ parseUuid: parseUuid,
3952
+ hashToUuid: hashToUuid,
4206
3953
  };
4207
3954
 
4208
3955
  /** Uin8Array with zero items */
@@ -4236,13 +3983,11 @@ function generateUuid(target, namespace, version) {
4236
3983
  }
4237
3984
 
4238
3985
  // Parsing target chars
4239
- var charBuffer = lib.stringToCharBuffer(target);
4240
-
4241
- // TODO: Test namespace for uuid and parse to buffer
4242
- var namespaceCharBuffer = typeof namespace === 'string' ? lib.stringToCharBuffer(namespace) : EMPTY_UINT8_ARRAY;
3986
+ var targetCharBuffer = lib.stringToCharBuffer(target);
3987
+ var namespaceCharBuffer = typeof namespace === 'string' ? lib.parseUuid(namespace) : EMPTY_UINT8_ARRAY;
4243
3988
 
4244
3989
  // Concatenation two buffers of strings to one
4245
- var buffer = lib.concatBuffers(namespaceCharBuffer, charBuffer);
3990
+ var buffer = lib.concatBuffers(namespaceCharBuffer, targetCharBuffer);
4246
3991
 
4247
3992
  // Getting hash
4248
3993
  var hash = version === 3 ? lib.md5Hash(buffer) : lib.sha1Hash(buffer);