andoncloud-prometheus-widget 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -8,29 +8,66 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
8
8
 
9
9
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
10
10
 
11
- function _objectWithoutPropertiesLoose(source, excluded) {
11
+ function _typeof(obj) {
12
+ "@babel/helpers - typeof";
13
+
14
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
15
+ return typeof obj;
16
+ } : function (obj) {
17
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
18
+ }, _typeof(obj);
19
+ }
20
+
21
+ function _toPrimitive(input, hint) {
22
+ if (_typeof(input) !== "object" || input === null) return input;
23
+ var prim = input[Symbol.toPrimitive];
24
+ if (prim !== undefined) {
25
+ var res = prim.call(input, hint || "default");
26
+ if (_typeof(res) !== "object") return res;
27
+ throw new TypeError("@@toPrimitive must return a primitive value.");
28
+ }
29
+ return (hint === "string" ? String : Number)(input);
30
+ }
31
+
32
+ function _toPropertyKey(arg) {
33
+ var key = _toPrimitive(arg, "string");
34
+ return _typeof(key) === "symbol" ? key : String(key);
35
+ }
36
+
37
+ function _defineProperty(obj, key, value) {
38
+ key = _toPropertyKey(key);
39
+ if (key in obj) {
40
+ Object.defineProperty(obj, key, {
41
+ value: value,
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true
45
+ });
46
+ } else {
47
+ obj[key] = value;
48
+ }
49
+ return obj;
50
+ }
51
+
52
+ function _objectWithoutPropertiesLoose$1(source, excluded) {
12
53
  if (source == null) return {};
13
54
  var target = {};
14
55
  var sourceKeys = Object.keys(source);
15
56
  var key, i;
16
-
17
57
  for (i = 0; i < sourceKeys.length; i++) {
18
58
  key = sourceKeys[i];
19
59
  if (excluded.indexOf(key) >= 0) continue;
20
60
  target[key] = source[key];
21
61
  }
22
-
23
62
  return target;
24
63
  }
25
64
 
26
65
  function _objectWithoutProperties(source, excluded) {
27
66
  if (source == null) return {};
28
- var target = _objectWithoutPropertiesLoose(source, excluded);
67
+ var target = _objectWithoutPropertiesLoose$1(source, excluded);
29
68
  var key, i;
30
-
31
69
  if (Object.getOwnPropertySymbols) {
32
70
  var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
33
-
34
71
  for (i = 0; i < sourceSymbolKeys.length; i++) {
35
72
  key = sourceSymbolKeys[i];
36
73
  if (excluded.indexOf(key) >= 0) continue;
@@ -38,35 +75,9 @@ function _objectWithoutProperties(source, excluded) {
38
75
  target[key] = source[key];
39
76
  }
40
77
  }
41
-
42
78
  return target;
43
79
  }
44
80
 
45
- function _typeof(obj) {
46
- "@babel/helpers - typeof";
47
-
48
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
49
- return typeof obj;
50
- } : function (obj) {
51
- return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
52
- }, _typeof(obj);
53
- }
54
-
55
- function _defineProperty(obj, key, value) {
56
- if (key in obj) {
57
- Object.defineProperty(obj, key, {
58
- value: value,
59
- enumerable: true,
60
- configurable: true,
61
- writable: true
62
- });
63
- } else {
64
- obj[key] = value;
65
- }
66
-
67
- return obj;
68
- }
69
-
70
81
  /**
71
82
  * This file automatically generated from `pre-publish.js`.
72
83
  * Do not manually edit.
@@ -90,122 +101,6 @@ var voidElements = {
90
101
 
91
102
  var t=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function n(n){var r={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},i=n.match(/<\/?([^\s]+?)[/\s>]/);if(i&&(r.name=i[1],(voidElements[i[1]]||"/"===n.charAt(n.length-2))&&(r.voidElement=!0),r.name.startsWith("!--"))){var s=n.indexOf("--\x3e");return {type:"comment",comment:-1!==s?n.slice(4,s):""}}for(var a=new RegExp(t),c=null;null!==(c=a.exec(n));)if(c[0].trim())if(c[1]){var o=c[1].trim(),l=[o,""];o.indexOf("=")>-1&&(l=o.split("=")),r.attrs[l[0]]=l[1],a.lastIndex--;}else c[2]&&(r.attrs[c[2]]=c[3].trim().substring(1,c[3].length-1));return r}var r=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,i=/^\s*$/,s=Object.create(null);function a(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(a,"")+"</"+t.name+">";case"comment":return e+"\x3c!--"+t.comment+"--\x3e"}}var c={parse:function(e,t){t||(t={}),t.components||(t.components=s);var a,c=[],o=[],l=-1,m=!1;if(0!==e.indexOf("<")){var u=e.indexOf("<");c.push({type:"text",content:-1===u?e:e.substring(0,u)});}return e.replace(r,function(r,s){if(m){if(r!=="</"+a.name+">")return;m=!1;}var u,f="/"!==r.charAt(1),h=r.startsWith("\x3c!--"),p=s+r.length,d=e.charAt(p);if(h){var v=n(r);return l<0?(c.push(v),c):((u=o[l]).children.push(v),c)}if(f&&(l++,"tag"===(a=n(r)).type&&t.components[a.name]&&(a.type="component",m=!0),a.voidElement||m||!d||"<"===d||a.children.push({type:"text",content:e.slice(p,e.indexOf("<",p))}),0===l&&c.push(a),(u=o[l-1])&&u.children.push(a),o[l]=a),(!f||a.voidElement)&&(l>-1&&(a.voidElement||a.name===r.slice(2,-1))&&(l--,a=-1===l?c:o[l]),!m&&"<"!==d&&d)){u=-1===l?c:o[l].children;var x=e.indexOf("<",p),g=e.slice(p,-1===x?void 0:x);i.test(g)&&(g=" "),(x>-1&&l+u.length>=0||" "!==g)&&u.push({type:"text",content:g});}}),c},stringify:function(e){return e.reduce(function(e,t){return e+a("",t)},"")}};
92
103
 
93
- function _classCallCheck(instance, Constructor) {
94
- if (!(instance instanceof Constructor)) {
95
- throw new TypeError("Cannot call a class as a function");
96
- }
97
- }
98
-
99
- function _defineProperties(target, props) {
100
- for (var i = 0; i < props.length; i++) {
101
- var descriptor = props[i];
102
- descriptor.enumerable = descriptor.enumerable || false;
103
- descriptor.configurable = true;
104
- if ("value" in descriptor) descriptor.writable = true;
105
- Object.defineProperty(target, descriptor.key, descriptor);
106
- }
107
- }
108
-
109
- function _createClass(Constructor, protoProps, staticProps) {
110
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
111
- if (staticProps) _defineProperties(Constructor, staticProps);
112
- Object.defineProperty(Constructor, "prototype", {
113
- writable: false
114
- });
115
- return Constructor;
116
- }
117
-
118
- var matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230);/g;
119
- var htmlEntities = {
120
- '&amp;': '&',
121
- '&#38;': '&',
122
- '&lt;': '<',
123
- '&#60;': '<',
124
- '&gt;': '>',
125
- '&#62;': '>',
126
- '&apos;': "'",
127
- '&#39;': "'",
128
- '&quot;': '"',
129
- '&#34;': '"',
130
- '&nbsp;': ' ',
131
- '&#160;': ' ',
132
- '&copy;': '©',
133
- '&#169;': '©',
134
- '&reg;': '®',
135
- '&#174;': '®',
136
- '&hellip;': '…',
137
- '&#8230;': '…'
138
- };
139
-
140
- var unescapeHtmlEntity = function unescapeHtmlEntity(m) {
141
- return htmlEntities[m];
142
- };
143
-
144
- var unescape$1 = function unescape(text) {
145
- return text.replace(matchHtmlEntity, unescapeHtmlEntity);
146
- };
147
-
148
- function ownKeys$9(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; }
149
-
150
- function _objectSpread$9(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$9(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$9(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
151
- var defaultOptions = {
152
- bindI18n: 'languageChanged',
153
- bindI18nStore: '',
154
- transEmptyNodeValue: '',
155
- transSupportBasicHtmlNodes: true,
156
- transWrapTextNodes: '',
157
- transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
158
- useSuspense: true,
159
- unescape: unescape$1
160
- };
161
- var i18nInstance;
162
- var I18nContext = React.createContext();
163
- function setDefaults() {
164
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
165
- defaultOptions = _objectSpread$9(_objectSpread$9({}, defaultOptions), options);
166
- }
167
- function getDefaults() {
168
- return defaultOptions;
169
- }
170
- var ReportNamespaces = function () {
171
- function ReportNamespaces() {
172
- _classCallCheck(this, ReportNamespaces);
173
-
174
- this.usedNamespaces = {};
175
- }
176
-
177
- _createClass(ReportNamespaces, [{
178
- key: "addUsedNamespaces",
179
- value: function addUsedNamespaces(namespaces) {
180
- var _this = this;
181
-
182
- namespaces.forEach(function (ns) {
183
- if (!_this.usedNamespaces[ns]) _this.usedNamespaces[ns] = true;
184
- });
185
- }
186
- }, {
187
- key: "getUsedNamespaces",
188
- value: function getUsedNamespaces() {
189
- return Object.keys(this.usedNamespaces);
190
- }
191
- }]);
192
-
193
- return ReportNamespaces;
194
- }();
195
- function setI18n(instance) {
196
- i18nInstance = instance;
197
- }
198
- function getI18n() {
199
- return i18nInstance;
200
- }
201
- var initReactI18next = {
202
- type: '3rdParty',
203
- init: function init(instance) {
204
- setDefaults(instance.options.react);
205
- setI18n(instance);
206
- }
207
- };
208
-
209
104
  function warn() {
210
105
  if (console && console.warn) {
211
106
  var _console;
@@ -286,12 +181,73 @@ function hasLoadedNamespace(ns, i18n) {
286
181
  });
287
182
  }
288
183
 
289
- var _excluded = ["format"],
184
+ var matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
185
+ var htmlEntities = {
186
+ '&amp;': '&',
187
+ '&#38;': '&',
188
+ '&lt;': '<',
189
+ '&#60;': '<',
190
+ '&gt;': '>',
191
+ '&#62;': '>',
192
+ '&apos;': "'",
193
+ '&#39;': "'",
194
+ '&quot;': '"',
195
+ '&#34;': '"',
196
+ '&nbsp;': ' ',
197
+ '&#160;': ' ',
198
+ '&copy;': '©',
199
+ '&#169;': '©',
200
+ '&reg;': '®',
201
+ '&#174;': '®',
202
+ '&hellip;': '…',
203
+ '&#8230;': '…',
204
+ '&#x2F;': '/',
205
+ '&#47;': '/'
206
+ };
207
+
208
+ var unescapeHtmlEntity = function unescapeHtmlEntity(m) {
209
+ return htmlEntities[m];
210
+ };
211
+
212
+ var unescape$1 = function unescape(text) {
213
+ return text.replace(matchHtmlEntity, unescapeHtmlEntity);
214
+ };
215
+
216
+ function ownKeys$a(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; }
217
+
218
+ function _objectSpread$a(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$a(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$a(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
219
+ var defaultOptions = {
220
+ bindI18n: 'languageChanged',
221
+ bindI18nStore: '',
222
+ transEmptyNodeValue: '',
223
+ transSupportBasicHtmlNodes: true,
224
+ transWrapTextNodes: '',
225
+ transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
226
+ useSuspense: true,
227
+ unescape: unescape$1
228
+ };
229
+ function setDefaults() {
230
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
231
+ defaultOptions = _objectSpread$a(_objectSpread$a({}, defaultOptions), options);
232
+ }
233
+ function getDefaults() {
234
+ return defaultOptions;
235
+ }
236
+
237
+ var i18nInstance;
238
+ function setI18n(instance) {
239
+ i18nInstance = instance;
240
+ }
241
+ function getI18n() {
242
+ return i18nInstance;
243
+ }
244
+
245
+ var _excluded$2 = ["format"],
290
246
  _excluded2 = ["children", "count", "parent", "i18nKey", "context", "tOptions", "values", "defaults", "components", "ns", "i18n", "t", "shouldUnescape"];
291
247
 
292
- function ownKeys$8(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; }
248
+ function ownKeys$9(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; }
293
249
 
294
- function _objectSpread$8(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$8(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$8(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
250
+ function _objectSpread$9(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$9(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$9(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
295
251
 
296
252
  function hasChildren(node, checkLength) {
297
253
  if (!node) return false;
@@ -317,7 +273,7 @@ function getAsArray(data) {
317
273
  }
318
274
 
319
275
  function mergeProps(source, target) {
320
- var newTarget = _objectSpread$8({}, target);
276
+ var newTarget = _objectSpread$9({}, target);
321
277
 
322
278
  newTarget.props = Object.assign(source.props, target.props);
323
279
  return newTarget;
@@ -352,7 +308,7 @@ function nodesToString(children, i18nOptions) {
352
308
  warn("Trans: the passed in value is invalid - seems you passed in a null child.");
353
309
  } else if (_typeof(child) === 'object') {
354
310
  var format = child.format,
355
- clone = _objectWithoutProperties(child, _excluded);
311
+ clone = _objectWithoutProperties(child, _excluded$2);
356
312
 
357
313
  var keys = Object.keys(clone);
358
314
 
@@ -387,7 +343,7 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
387
343
  getData(children);
388
344
  var ast = c.parse("<0>".concat(targetString, "</0>"));
389
345
 
390
- var opts = _objectSpread$8(_objectSpread$8({}, data), combinedTOpts);
346
+ var opts = _objectSpread$9(_objectSpread$9({}, data), combinedTOpts);
391
347
 
392
348
  function renderInner(child, node, rootReactNode) {
393
349
  var childs = getChildren(child);
@@ -397,7 +353,7 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
397
353
 
398
354
  function pushTranslatedJSX(child, inner, mem, i, isVoid) {
399
355
  if (child.dummy) child.children = inner;
400
- mem.push(React.cloneElement(child, _objectSpread$8(_objectSpread$8({}, child.props), {}, {
356
+ mem.push(React.cloneElement(child, _objectSpread$9(_objectSpread$9({}, child.props), {}, {
401
357
  key: i
402
358
  }), isVoid ? undefined : inner));
403
359
  }
@@ -429,7 +385,7 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
429
385
  } else if (isEmptyTransWithHTML) {
430
386
  var _inner = mapAST(reactNodes, node.children, rootReactNode);
431
387
 
432
- mem.push(React.cloneElement(child, _objectSpread$8(_objectSpread$8({}, child.props), {}, {
388
+ mem.push(React.cloneElement(child, _objectSpread$9(_objectSpread$9({}, child.props), {}, {
433
389
  key: i
434
390
  }), _inner));
435
391
  } else if (Number.isNaN(parseFloat(node.name))) {
@@ -460,11 +416,11 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
460
416
  var content = node.children[0] ? translationContent : null;
461
417
  if (content) mem.push(content);
462
418
  } else if (node.children.length === 1 && translationContent) {
463
- mem.push(React.cloneElement(child, _objectSpread$8(_objectSpread$8({}, child.props), {}, {
419
+ mem.push(React.cloneElement(child, _objectSpread$9(_objectSpread$9({}, child.props), {}, {
464
420
  key: i
465
421
  }), translationContent));
466
422
  } else {
467
- mem.push(React.cloneElement(child, _objectSpread$8(_objectSpread$8({}, child.props), {}, {
423
+ mem.push(React.cloneElement(child, _objectSpread$9(_objectSpread$9({}, child.props), {}, {
468
424
  key: i
469
425
  })));
470
426
  }
@@ -493,7 +449,7 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts, s
493
449
  return getChildren(result[0]);
494
450
  }
495
451
 
496
- function Trans(_ref) {
452
+ function Trans$1(_ref) {
497
453
  var children = _ref.children,
498
454
  count = _ref.count,
499
455
  parent = _ref.parent,
@@ -510,11 +466,7 @@ function Trans(_ref) {
510
466
  shouldUnescape = _ref.shouldUnescape,
511
467
  additionalProps = _objectWithoutProperties(_ref, _excluded2);
512
468
 
513
- var _ref2 = React.useContext(I18nContext) || {},
514
- i18nFromContext = _ref2.i18n,
515
- defaultNSFromContext = _ref2.defaultNS;
516
-
517
- var i18n = i18nFromProps || i18nFromContext || getI18n();
469
+ var i18n = i18nFromProps || getI18n();
518
470
 
519
471
  if (!i18n) {
520
472
  warnOnce('You will need to pass in an i18next instance by using i18nextReactModule');
@@ -527,31 +479,135 @@ function Trans(_ref) {
527
479
 
528
480
  if (context) tOptions.context = context;
529
481
 
530
- var reactI18nextOptions = _objectSpread$8(_objectSpread$8({}, getDefaults()), i18n.options && i18n.options.react);
482
+ var reactI18nextOptions = _objectSpread$9(_objectSpread$9({}, getDefaults()), i18n.options && i18n.options.react);
531
483
 
532
- var namespaces = ns || t.ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
484
+ var namespaces = ns || t.ns || i18n.options && i18n.options.defaultNS;
533
485
  namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
534
486
  var defaultValue = defaults || nodesToString(children, reactI18nextOptions) || reactI18nextOptions.transEmptyNodeValue || i18nKey;
535
487
  var hashTransKey = reactI18nextOptions.hashTransKey;
536
488
  var key = i18nKey || (hashTransKey ? hashTransKey(defaultValue) : defaultValue);
537
489
  var interpolationOverride = values ? tOptions.interpolation : {
538
- interpolation: _objectSpread$8(_objectSpread$8({}, tOptions.interpolation), {}, {
490
+ interpolation: _objectSpread$9(_objectSpread$9({}, tOptions.interpolation), {}, {
539
491
  prefix: '#$?',
540
492
  suffix: '?$#'
541
493
  })
542
494
  };
543
495
 
544
- var combinedTOpts = _objectSpread$8(_objectSpread$8(_objectSpread$8(_objectSpread$8({}, tOptions), {}, {
496
+ var combinedTOpts = _objectSpread$9(_objectSpread$9(_objectSpread$9(_objectSpread$9({}, tOptions), {}, {
545
497
  count: count
546
498
  }, values), interpolationOverride), {}, {
547
499
  defaultValue: defaultValue,
548
500
  ns: namespaces
549
501
  });
550
502
 
551
- var translation = key ? t(key, combinedTOpts) : defaultValue;
552
- var content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
553
- var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
554
- return useAsParent ? React.createElement(useAsParent, additionalProps, content) : content;
503
+ var translation = key ? t(key, combinedTOpts) : defaultValue;
504
+ var content = renderNodes(components || children, translation, i18n, reactI18nextOptions, combinedTOpts, shouldUnescape);
505
+ var useAsParent = parent !== undefined ? parent : reactI18nextOptions.defaultTransParent;
506
+ return useAsParent ? React.createElement(useAsParent, additionalProps, content) : content;
507
+ }
508
+
509
+ function _classCallCheck(instance, Constructor) {
510
+ if (!(instance instanceof Constructor)) {
511
+ throw new TypeError("Cannot call a class as a function");
512
+ }
513
+ }
514
+
515
+ function _defineProperties(target, props) {
516
+ for (var i = 0; i < props.length; i++) {
517
+ var descriptor = props[i];
518
+ descriptor.enumerable = descriptor.enumerable || false;
519
+ descriptor.configurable = true;
520
+ if ("value" in descriptor) descriptor.writable = true;
521
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
522
+ }
523
+ }
524
+ function _createClass(Constructor, protoProps, staticProps) {
525
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
526
+ if (staticProps) _defineProperties(Constructor, staticProps);
527
+ Object.defineProperty(Constructor, "prototype", {
528
+ writable: false
529
+ });
530
+ return Constructor;
531
+ }
532
+
533
+ var initReactI18next = {
534
+ type: '3rdParty',
535
+ init: function init(instance) {
536
+ setDefaults(instance.options.react);
537
+ setI18n(instance);
538
+ }
539
+ };
540
+
541
+ var I18nContext = React.createContext();
542
+ var ReportNamespaces = function () {
543
+ function ReportNamespaces() {
544
+ _classCallCheck(this, ReportNamespaces);
545
+
546
+ this.usedNamespaces = {};
547
+ }
548
+
549
+ _createClass(ReportNamespaces, [{
550
+ key: "addUsedNamespaces",
551
+ value: function addUsedNamespaces(namespaces) {
552
+ var _this = this;
553
+
554
+ namespaces.forEach(function (ns) {
555
+ if (!_this.usedNamespaces[ns]) _this.usedNamespaces[ns] = true;
556
+ });
557
+ }
558
+ }, {
559
+ key: "getUsedNamespaces",
560
+ value: function getUsedNamespaces() {
561
+ return Object.keys(this.usedNamespaces);
562
+ }
563
+ }]);
564
+
565
+ return ReportNamespaces;
566
+ }();
567
+
568
+ var _excluded$1 = ["children", "count", "parent", "i18nKey", "context", "tOptions", "values", "defaults", "components", "ns", "i18n", "t", "shouldUnescape"];
569
+
570
+ function ownKeys$8(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; }
571
+
572
+ function _objectSpread$8(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$8(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$8(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
573
+ function Trans(_ref) {
574
+ var children = _ref.children,
575
+ count = _ref.count,
576
+ parent = _ref.parent,
577
+ i18nKey = _ref.i18nKey,
578
+ context = _ref.context,
579
+ _ref$tOptions = _ref.tOptions,
580
+ tOptions = _ref$tOptions === void 0 ? {} : _ref$tOptions,
581
+ values = _ref.values,
582
+ defaults = _ref.defaults,
583
+ components = _ref.components,
584
+ ns = _ref.ns,
585
+ i18nFromProps = _ref.i18n,
586
+ tFromProps = _ref.t,
587
+ shouldUnescape = _ref.shouldUnescape,
588
+ additionalProps = _objectWithoutProperties(_ref, _excluded$1);
589
+
590
+ var _ref2 = React.useContext(I18nContext) || {},
591
+ i18nFromContext = _ref2.i18n,
592
+ defaultNSFromContext = _ref2.defaultNS;
593
+
594
+ var i18n = i18nFromProps || i18nFromContext || getI18n();
595
+ var t = tFromProps || i18n && i18n.t.bind(i18n);
596
+ return Trans$1(_objectSpread$8({
597
+ children: children,
598
+ count: count,
599
+ parent: parent,
600
+ i18nKey: i18nKey,
601
+ context: context,
602
+ tOptions: tOptions,
603
+ values: values,
604
+ defaults: defaults,
605
+ components: components,
606
+ ns: ns || t && t.ns || defaultNSFromContext || i18n && i18n.options && i18n.options.defaultNS,
607
+ i18n: i18n,
608
+ t: tFromProps,
609
+ shouldUnescape: shouldUnescape
610
+ }, additionalProps));
555
611
  }
556
612
 
557
613
  function _arrayWithHoles(arr) {
@@ -559,42 +615,36 @@ function _arrayWithHoles(arr) {
559
615
  }
560
616
 
561
617
  function _iterableToArrayLimit(arr, i) {
562
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
563
-
564
- if (_i == null) return;
565
- var _arr = [];
566
- var _n = true;
567
- var _d = false;
568
-
569
- var _s, _e;
570
-
571
- try {
572
- for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
573
- _arr.push(_s.value);
574
-
575
- if (i && _arr.length === i) break;
576
- }
577
- } catch (err) {
578
- _d = true;
579
- _e = err;
580
- } finally {
618
+ var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
619
+ if (null != _i) {
620
+ var _s,
621
+ _e,
622
+ _x,
623
+ _r,
624
+ _arr = [],
625
+ _n = !0,
626
+ _d = !1;
581
627
  try {
582
- if (!_n && _i["return"] != null) _i["return"]();
628
+ if (_x = (_i = _i.call(arr)).next, 0 === i) {
629
+ if (Object(_i) !== _i) return;
630
+ _n = !1;
631
+ } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
632
+ } catch (err) {
633
+ _d = !0, _e = err;
583
634
  } finally {
584
- if (_d) throw _e;
635
+ try {
636
+ if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return;
637
+ } finally {
638
+ if (_d) throw _e;
639
+ }
585
640
  }
641
+ return _arr;
586
642
  }
587
-
588
- return _arr;
589
643
  }
590
644
 
591
645
  function _arrayLikeToArray(arr, len) {
592
646
  if (len == null || len > arr.length) len = arr.length;
593
-
594
- for (var i = 0, arr2 = new Array(len); i < len; i++) {
595
- arr2[i] = arr[i];
596
- }
597
-
647
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
598
648
  return arr2;
599
649
  }
600
650
 
@@ -733,7 +783,6 @@ function _assertThisInitialized(self) {
733
783
  if (self === void 0) {
734
784
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
735
785
  }
736
-
737
786
  return self;
738
787
  }
739
788
 
@@ -749,7 +798,6 @@ function _inherits(subClass, superClass) {
749
798
  if (typeof superClass !== "function" && superClass !== null) {
750
799
  throw new TypeError("Super expression must either be null or a function");
751
800
  }
752
-
753
801
  subClass.prototype = Object.create(superClass && superClass.prototype, {
754
802
  constructor: {
755
803
  value: subClass,
@@ -769,7 +817,6 @@ function _possibleConstructorReturn(self, call) {
769
817
  } else if (call !== void 0) {
770
818
  throw new TypeError("Derived constructors may only return object or undefined");
771
819
  }
772
-
773
820
  return _assertThisInitialized(self);
774
821
  }
775
822
 
@@ -788,10 +835,8 @@ function _toArray(arr) {
788
835
  return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
789
836
  }
790
837
 
791
- 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; }
792
-
793
- 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; }
794
-
838
+ 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; }
839
+ 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; }
795
840
  var consoleLogger = {
796
841
  type: 'logger',
797
842
  log: function log(args) {
@@ -807,16 +852,12 @@ var consoleLogger = {
807
852
  if (console && console[type]) console[type].apply(console, args);
808
853
  }
809
854
  };
810
-
811
855
  var Logger = function () {
812
856
  function Logger(concreteLogger) {
813
857
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
814
-
815
858
  _classCallCheck(this, Logger);
816
-
817
859
  this.init(concreteLogger, options);
818
860
  }
819
-
820
861
  _createClass(Logger, [{
821
862
  key: "init",
822
863
  value: function init(concreteLogger) {
@@ -837,7 +878,6 @@ var Logger = function () {
837
878
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
838
879
  args[_key] = arguments[_key];
839
880
  }
840
-
841
881
  return this.forward(args, 'log', '', true);
842
882
  }
843
883
  }, {
@@ -846,7 +886,6 @@ var Logger = function () {
846
886
  for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
847
887
  args[_key2] = arguments[_key2];
848
888
  }
849
-
850
889
  return this.forward(args, 'warn', '', true);
851
890
  }
852
891
  }, {
@@ -855,7 +894,6 @@ var Logger = function () {
855
894
  for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
856
895
  args[_key3] = arguments[_key3];
857
896
  }
858
-
859
897
  return this.forward(args, 'error', '');
860
898
  }
861
899
  }, {
@@ -864,7 +902,6 @@ var Logger = function () {
864
902
  for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
865
903
  args[_key4] = arguments[_key4];
866
904
  }
867
-
868
905
  return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
869
906
  }
870
907
  }, {
@@ -877,32 +914,33 @@ var Logger = function () {
877
914
  }, {
878
915
  key: "create",
879
916
  value: function create(moduleName) {
880
- return new Logger(this.logger, _objectSpread(_objectSpread({}, {
917
+ return new Logger(this.logger, _objectSpread$6(_objectSpread$6({}, {
881
918
  prefix: "".concat(this.prefix, ":").concat(moduleName, ":")
882
919
  }), this.options));
883
920
  }
921
+ }, {
922
+ key: "clone",
923
+ value: function clone(options) {
924
+ options = options || this.options;
925
+ options.prefix = options.prefix || this.prefix;
926
+ return new Logger(this.logger, options);
927
+ }
884
928
  }]);
885
-
886
929
  return Logger;
887
930
  }();
888
-
889
931
  var baseLogger = new Logger();
890
932
 
891
933
  var EventEmitter = function () {
892
934
  function EventEmitter() {
893
935
  _classCallCheck(this, EventEmitter);
894
-
895
936
  this.observers = {};
896
937
  }
897
-
898
938
  _createClass(EventEmitter, [{
899
939
  key: "on",
900
940
  value: function on(events, listener) {
901
941
  var _this = this;
902
-
903
942
  events.split(' ').forEach(function (event) {
904
943
  _this.observers[event] = _this.observers[event] || [];
905
-
906
944
  _this.observers[event].push(listener);
907
945
  });
908
946
  return this;
@@ -911,12 +949,10 @@ var EventEmitter = function () {
911
949
  key: "off",
912
950
  value: function off(event, listener) {
913
951
  if (!this.observers[event]) return;
914
-
915
952
  if (!listener) {
916
953
  delete this.observers[event];
917
954
  return;
918
955
  }
919
-
920
956
  this.observers[event] = this.observers[event].filter(function (l) {
921
957
  return l !== listener;
922
958
  });
@@ -927,24 +963,20 @@ var EventEmitter = function () {
927
963
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
928
964
  args[_key - 1] = arguments[_key];
929
965
  }
930
-
931
966
  if (this.observers[event]) {
932
967
  var cloned = [].concat(this.observers[event]);
933
968
  cloned.forEach(function (observer) {
934
969
  observer.apply(void 0, args);
935
970
  });
936
971
  }
937
-
938
972
  if (this.observers['*']) {
939
973
  var _cloned = [].concat(this.observers['*']);
940
-
941
974
  _cloned.forEach(function (observer) {
942
975
  observer.apply(observer, [event].concat(args));
943
976
  });
944
977
  }
945
978
  }
946
979
  }]);
947
-
948
980
  return EventEmitter;
949
981
  }();
950
982
 
@@ -968,68 +1000,56 @@ function copy(a, s, t) {
968
1000
  if (s[m]) t[m] = s[m];
969
1001
  });
970
1002
  }
971
-
972
1003
  function getLastOfPath(object, path, Empty) {
973
1004
  function cleanKey(key) {
974
1005
  return key && key.indexOf('###') > -1 ? key.replace(/###/g, '.') : key;
975
1006
  }
976
-
977
1007
  function canNotTraverseDeeper() {
978
1008
  return !object || typeof object === 'string';
979
1009
  }
980
-
981
1010
  var stack = typeof path !== 'string' ? [].concat(path) : path.split('.');
982
-
983
1011
  while (stack.length > 1) {
984
1012
  if (canNotTraverseDeeper()) return {};
985
1013
  var key = cleanKey(stack.shift());
986
1014
  if (!object[key] && Empty) object[key] = new Empty();
987
-
988
1015
  if (Object.prototype.hasOwnProperty.call(object, key)) {
989
1016
  object = object[key];
990
1017
  } else {
991
1018
  object = {};
992
1019
  }
993
1020
  }
994
-
995
1021
  if (canNotTraverseDeeper()) return {};
996
1022
  return {
997
1023
  obj: object,
998
1024
  k: cleanKey(stack.shift())
999
1025
  };
1000
1026
  }
1001
-
1002
1027
  function setPath(object, path, newValue) {
1003
1028
  var _getLastOfPath = getLastOfPath(object, path, Object),
1004
- obj = _getLastOfPath.obj,
1005
- k = _getLastOfPath.k;
1006
-
1029
+ obj = _getLastOfPath.obj,
1030
+ k = _getLastOfPath.k;
1007
1031
  obj[k] = newValue;
1008
1032
  }
1009
1033
  function pushPath(object, path, newValue, concat) {
1010
1034
  var _getLastOfPath2 = getLastOfPath(object, path, Object),
1011
- obj = _getLastOfPath2.obj,
1012
- k = _getLastOfPath2.k;
1013
-
1035
+ obj = _getLastOfPath2.obj,
1036
+ k = _getLastOfPath2.k;
1014
1037
  obj[k] = obj[k] || [];
1015
1038
  if (concat) obj[k] = obj[k].concat(newValue);
1016
1039
  if (!concat) obj[k].push(newValue);
1017
1040
  }
1018
1041
  function getPath(object, path) {
1019
1042
  var _getLastOfPath3 = getLastOfPath(object, path),
1020
- obj = _getLastOfPath3.obj,
1021
- k = _getLastOfPath3.k;
1022
-
1043
+ obj = _getLastOfPath3.obj,
1044
+ k = _getLastOfPath3.k;
1023
1045
  if (!obj) return undefined;
1024
1046
  return obj[k];
1025
1047
  }
1026
1048
  function getPathWithDefaults(data, defaultData, key) {
1027
1049
  var value = getPath(data, key);
1028
-
1029
1050
  if (value !== undefined) {
1030
1051
  return value;
1031
1052
  }
1032
-
1033
1053
  return getPath(defaultData, key);
1034
1054
  }
1035
1055
  function deepExtend(target, source, overwrite) {
@@ -1046,7 +1066,6 @@ function deepExtend(target, source, overwrite) {
1046
1066
  }
1047
1067
  }
1048
1068
  }
1049
-
1050
1069
  return target;
1051
1070
  }
1052
1071
  function regexEscape(str) {
@@ -1066,7 +1085,6 @@ function escape(data) {
1066
1085
  return _entityMap[s];
1067
1086
  });
1068
1087
  }
1069
-
1070
1088
  return data;
1071
1089
  }
1072
1090
  var isIE10 = typeof window !== 'undefined' && window.navigator && typeof window.navigator.userAgentData === 'undefined' && window.navigator.userAgent && window.navigator.userAgent.indexOf('MSIE') > -1;
@@ -1082,105 +1100,77 @@ function looksLikeObjectPath(key, nsSeparator, keySeparator) {
1082
1100
  return c === '?' ? '\\?' : c;
1083
1101
  }).join('|'), ")"));
1084
1102
  var matched = !r.test(key);
1085
-
1086
1103
  if (!matched) {
1087
1104
  var ki = key.indexOf(keySeparator);
1088
-
1089
1105
  if (ki > 0 && !r.test(key.substring(0, ki))) {
1090
1106
  matched = true;
1091
1107
  }
1092
1108
  }
1093
-
1094
1109
  return matched;
1095
1110
  }
1096
1111
 
1097
- 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; }
1098
-
1099
- 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; }
1100
-
1101
- 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); }; }
1102
-
1103
- 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; } }
1104
-
1112
+ 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; }
1113
+ 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; }
1114
+ 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); }; }
1115
+ 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; } }
1105
1116
  function deepFind(obj, path) {
1106
1117
  var keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
1107
1118
  if (!obj) return undefined;
1108
1119
  if (obj[path]) return obj[path];
1109
1120
  var paths = path.split(keySeparator);
1110
1121
  var current = obj;
1111
-
1112
1122
  for (var i = 0; i < paths.length; ++i) {
1113
1123
  if (!current) return undefined;
1114
-
1115
1124
  if (typeof current[paths[i]] === 'string' && i + 1 < paths.length) {
1116
1125
  return undefined;
1117
1126
  }
1118
-
1119
1127
  if (current[paths[i]] === undefined) {
1120
1128
  var j = 2;
1121
1129
  var p = paths.slice(i, i + j).join(keySeparator);
1122
1130
  var mix = current[p];
1123
-
1124
1131
  while (mix === undefined && paths.length > i + j) {
1125
1132
  j++;
1126
1133
  p = paths.slice(i, i + j).join(keySeparator);
1127
1134
  mix = current[p];
1128
1135
  }
1129
-
1130
1136
  if (mix === undefined) return undefined;
1131
1137
  if (mix === null) return null;
1132
-
1133
1138
  if (path.endsWith(p)) {
1134
1139
  if (typeof mix === 'string') return mix;
1135
1140
  if (p && typeof mix[p] === 'string') return mix[p];
1136
1141
  }
1137
-
1138
1142
  var joinedPath = paths.slice(i + j).join(keySeparator);
1139
1143
  if (joinedPath) return deepFind(mix, joinedPath, keySeparator);
1140
1144
  return undefined;
1141
1145
  }
1142
-
1143
1146
  current = current[paths[i]];
1144
1147
  }
1145
-
1146
1148
  return current;
1147
1149
  }
1148
-
1149
1150
  var ResourceStore = function (_EventEmitter) {
1150
1151
  _inherits(ResourceStore, _EventEmitter);
1151
-
1152
- var _super = _createSuper(ResourceStore);
1153
-
1152
+ var _super = _createSuper$3(ResourceStore);
1154
1153
  function ResourceStore(data) {
1155
1154
  var _this;
1156
-
1157
1155
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
1158
1156
  ns: ['translation'],
1159
1157
  defaultNS: 'translation'
1160
1158
  };
1161
-
1162
1159
  _classCallCheck(this, ResourceStore);
1163
-
1164
1160
  _this = _super.call(this);
1165
-
1166
1161
  if (isIE10) {
1167
1162
  EventEmitter.call(_assertThisInitialized(_this));
1168
1163
  }
1169
-
1170
1164
  _this.data = data || {};
1171
1165
  _this.options = options;
1172
-
1173
1166
  if (_this.options.keySeparator === undefined) {
1174
1167
  _this.options.keySeparator = '.';
1175
1168
  }
1176
-
1177
1169
  if (_this.options.ignoreJSONStructure === undefined) {
1178
1170
  _this.options.ignoreJSONStructure = true;
1179
1171
  }
1180
-
1181
1172
  return _this;
1182
1173
  }
1183
-
1184
1174
  _createClass(ResourceStore, [{
1185
1175
  key: "addNamespaces",
1186
1176
  value: function addNamespaces(ns) {
@@ -1192,7 +1182,6 @@ var ResourceStore = function (_EventEmitter) {
1192
1182
  key: "removeNamespaces",
1193
1183
  value: function removeNamespaces(ns) {
1194
1184
  var index = this.options.ns.indexOf(ns);
1195
-
1196
1185
  if (index > -1) {
1197
1186
  this.options.ns.splice(index, 1);
1198
1187
  }
@@ -1206,11 +1195,9 @@ var ResourceStore = function (_EventEmitter) {
1206
1195
  var path = [lng, ns];
1207
1196
  if (key && typeof key !== 'string') path = path.concat(key);
1208
1197
  if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key);
1209
-
1210
1198
  if (lng.indexOf('.') > -1) {
1211
1199
  path = lng.split('.');
1212
1200
  }
1213
-
1214
1201
  var result = getPath(this.data, path);
1215
1202
  if (result || !ignoreJSONStructure || typeof key !== 'string') return result;
1216
1203
  return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
@@ -1225,13 +1212,11 @@ var ResourceStore = function (_EventEmitter) {
1225
1212
  if (keySeparator === undefined) keySeparator = '.';
1226
1213
  var path = [lng, ns];
1227
1214
  if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
1228
-
1229
1215
  if (lng.indexOf('.') > -1) {
1230
1216
  path = lng.split('.');
1231
1217
  value = ns;
1232
1218
  ns = path[1];
1233
1219
  }
1234
-
1235
1220
  this.addNamespaces(ns);
1236
1221
  setPath(this.data, path, value);
1237
1222
  if (!options.silent) this.emit('added', lng, ns, key, value);
@@ -1242,13 +1227,11 @@ var ResourceStore = function (_EventEmitter) {
1242
1227
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
1243
1228
  silent: false
1244
1229
  };
1245
-
1246
1230
  for (var m in resources) {
1247
1231
  if (typeof resources[m] === 'string' || Object.prototype.toString.apply(resources[m]) === '[object Array]') this.addResource(lng, ns, m, resources[m], {
1248
1232
  silent: true
1249
1233
  });
1250
1234
  }
1251
-
1252
1235
  if (!options.silent) this.emit('added', lng, ns, resources);
1253
1236
  }
1254
1237
  }, {
@@ -1258,23 +1241,19 @@ var ResourceStore = function (_EventEmitter) {
1258
1241
  silent: false
1259
1242
  };
1260
1243
  var path = [lng, ns];
1261
-
1262
1244
  if (lng.indexOf('.') > -1) {
1263
1245
  path = lng.split('.');
1264
1246
  deep = resources;
1265
1247
  resources = ns;
1266
1248
  ns = path[1];
1267
1249
  }
1268
-
1269
1250
  this.addNamespaces(ns);
1270
1251
  var pack = getPath(this.data, path) || {};
1271
-
1272
1252
  if (deep) {
1273
1253
  deepExtend(pack, resources, overwrite);
1274
1254
  } else {
1275
- pack = _objectSpread$1(_objectSpread$1({}, pack), resources);
1255
+ pack = _objectSpread$5(_objectSpread$5({}, pack), resources);
1276
1256
  }
1277
-
1278
1257
  setPath(this.data, path, pack);
1279
1258
  if (!options.silent) this.emit('added', lng, ns, resources);
1280
1259
  }
@@ -1284,7 +1263,6 @@ var ResourceStore = function (_EventEmitter) {
1284
1263
  if (this.hasResourceBundle(lng, ns)) {
1285
1264
  delete this.data[lng][ns];
1286
1265
  }
1287
-
1288
1266
  this.removeNamespaces(ns);
1289
1267
  this.emit('removed', lng, ns);
1290
1268
  }
@@ -1297,7 +1275,7 @@ var ResourceStore = function (_EventEmitter) {
1297
1275
  key: "getResourceBundle",
1298
1276
  value: function getResourceBundle(lng, ns) {
1299
1277
  if (!ns) ns = this.options.defaultNS;
1300
- if (this.options.compatibilityAPI === 'v1') return _objectSpread$1(_objectSpread$1({}, {}), this.getResource(lng, ns));
1278
+ if (this.options.compatibilityAPI === 'v1') return _objectSpread$5(_objectSpread$5({}, {}), this.getResource(lng, ns));
1301
1279
  return this.getResource(lng, ns);
1302
1280
  }
1303
1281
  }, {
@@ -1320,7 +1298,6 @@ var ResourceStore = function (_EventEmitter) {
1320
1298
  return this.data;
1321
1299
  }
1322
1300
  }]);
1323
-
1324
1301
  return ResourceStore;
1325
1302
  }(EventEmitter);
1326
1303
 
@@ -1331,7 +1308,6 @@ var postProcessor = {
1331
1308
  },
1332
1309
  handle: function handle(processors, value, key, options, translator) {
1333
1310
  var _this = this;
1334
-
1335
1311
  processors.forEach(function (processor) {
1336
1312
  if (_this.processors[processor]) value = _this.processors[processor].process(value, key, options, translator);
1337
1313
  });
@@ -1339,44 +1315,30 @@ var postProcessor = {
1339
1315
  }
1340
1316
  };
1341
1317
 
1342
- 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; }
1343
-
1344
- 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; }
1345
-
1346
- 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); }; }
1347
-
1348
- 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; } }
1318
+ 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; }
1319
+ 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; }
1320
+ 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); }; }
1321
+ 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; } }
1349
1322
  var checkedLoadedFor = {};
1350
-
1351
1323
  var Translator = function (_EventEmitter) {
1352
1324
  _inherits(Translator, _EventEmitter);
1353
-
1354
- var _super = _createSuper$1(Translator);
1355
-
1325
+ var _super = _createSuper$2(Translator);
1356
1326
  function Translator(services) {
1357
1327
  var _this;
1358
-
1359
1328
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1360
-
1361
1329
  _classCallCheck(this, Translator);
1362
-
1363
1330
  _this = _super.call(this);
1364
-
1365
1331
  if (isIE10) {
1366
1332
  EventEmitter.call(_assertThisInitialized(_this));
1367
1333
  }
1368
-
1369
1334
  copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, _assertThisInitialized(_this));
1370
1335
  _this.options = options;
1371
-
1372
1336
  if (_this.options.keySeparator === undefined) {
1373
1337
  _this.options.keySeparator = '.';
1374
1338
  }
1375
-
1376
1339
  _this.logger = baseLogger.create('translator');
1377
1340
  return _this;
1378
1341
  }
1379
-
1380
1342
  _createClass(Translator, [{
1381
1343
  key: "changeLanguage",
1382
1344
  value: function changeLanguage(lng) {
@@ -1388,11 +1350,9 @@ var Translator = function (_EventEmitter) {
1388
1350
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
1389
1351
  interpolation: {}
1390
1352
  };
1391
-
1392
1353
  if (key === undefined || key === null) {
1393
1354
  return false;
1394
1355
  }
1395
-
1396
1356
  var resolved = this.resolve(key, options);
1397
1357
  return resolved && resolved.res !== undefined;
1398
1358
  }
@@ -1405,22 +1365,18 @@ var Translator = function (_EventEmitter) {
1405
1365
  var namespaces = options.ns || this.options.defaultNS || [];
1406
1366
  var wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
1407
1367
  var seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
1408
-
1409
1368
  if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
1410
1369
  var m = key.match(this.interpolator.nestingRegexp);
1411
-
1412
1370
  if (m && m.length > 0) {
1413
1371
  return {
1414
1372
  key: key,
1415
1373
  namespaces: namespaces
1416
1374
  };
1417
1375
  }
1418
-
1419
1376
  var parts = key.split(nsSeparator);
1420
1377
  if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
1421
1378
  key = parts.join(keySeparator);
1422
1379
  }
1423
-
1424
1380
  if (typeof namespaces === 'string') namespaces = [namespaces];
1425
1381
  return {
1426
1382
  key: key,
@@ -1431,45 +1387,35 @@ var Translator = function (_EventEmitter) {
1431
1387
  key: "translate",
1432
1388
  value: function translate(keys, options, lastKey) {
1433
1389
  var _this2 = this;
1434
-
1435
1390
  if (_typeof(options) !== 'object' && this.options.overloadTranslationOptionHandler) {
1436
1391
  options = this.options.overloadTranslationOptionHandler(arguments);
1437
1392
  }
1438
-
1439
1393
  if (!options) options = {};
1440
1394
  if (keys === undefined || keys === null) return '';
1441
1395
  if (!Array.isArray(keys)) keys = [String(keys)];
1442
1396
  var returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
1443
1397
  var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
1444
-
1445
1398
  var _this$extractFromKey = this.extractFromKey(keys[keys.length - 1], options),
1446
- key = _this$extractFromKey.key,
1447
- namespaces = _this$extractFromKey.namespaces;
1448
-
1399
+ key = _this$extractFromKey.key,
1400
+ namespaces = _this$extractFromKey.namespaces;
1449
1401
  var namespace = namespaces[namespaces.length - 1];
1450
1402
  var lng = options.lng || this.language;
1451
1403
  var appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
1452
-
1453
1404
  if (lng && lng.toLowerCase() === 'cimode') {
1454
1405
  if (appendNamespaceToCIMode) {
1455
1406
  var nsSeparator = options.nsSeparator || this.options.nsSeparator;
1456
-
1457
1407
  if (returnDetails) {
1458
1408
  resolved.res = "".concat(namespace).concat(nsSeparator).concat(key);
1459
1409
  return resolved;
1460
1410
  }
1461
-
1462
1411
  return "".concat(namespace).concat(nsSeparator).concat(key);
1463
1412
  }
1464
-
1465
1413
  if (returnDetails) {
1466
1414
  resolved.res = key;
1467
1415
  return resolved;
1468
1416
  }
1469
-
1470
1417
  return key;
1471
1418
  }
1472
-
1473
1419
  var resolved = this.resolve(keys, options);
1474
1420
  var res = resolved && resolved.res;
1475
1421
  var resUsedKey = resolved && resolved.usedKey || key;
@@ -1479,41 +1425,34 @@ var Translator = function (_EventEmitter) {
1479
1425
  var joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
1480
1426
  var handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
1481
1427
  var handleAsObject = typeof res !== 'string' && typeof res !== 'boolean' && typeof res !== 'number';
1482
-
1483
1428
  if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === 'string' && resType === '[object Array]')) {
1484
1429
  if (!options.returnObjects && !this.options.returnObjects) {
1485
1430
  if (!this.options.returnedObjectHandler) {
1486
1431
  this.logger.warn('accessing an object - but returnObjects options is not enabled!');
1487
1432
  }
1488
-
1489
- var r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, _objectSpread$2(_objectSpread$2({}, options), {}, {
1433
+ var r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, _objectSpread$4(_objectSpread$4({}, options), {}, {
1490
1434
  ns: namespaces
1491
1435
  })) : "key '".concat(key, " (").concat(this.language, ")' returned an object instead of string.");
1492
-
1493
1436
  if (returnDetails) {
1494
1437
  resolved.res = r;
1495
1438
  return resolved;
1496
1439
  }
1497
-
1498
1440
  return r;
1499
1441
  }
1500
-
1501
1442
  if (keySeparator) {
1502
1443
  var resTypeIsArray = resType === '[object Array]';
1503
1444
  var copy = resTypeIsArray ? [] : {};
1504
1445
  var newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
1505
-
1506
1446
  for (var m in res) {
1507
1447
  if (Object.prototype.hasOwnProperty.call(res, m)) {
1508
1448
  var deepKey = "".concat(newKeyToUse).concat(keySeparator).concat(m);
1509
- copy[m] = this.translate(deepKey, _objectSpread$2(_objectSpread$2({}, options), {
1449
+ copy[m] = this.translate(deepKey, _objectSpread$4(_objectSpread$4({}, options), {
1510
1450
  joinArrays: false,
1511
1451
  ns: namespaces
1512
1452
  }));
1513
1453
  if (copy[m] === deepKey) copy[m] = res[m];
1514
1454
  }
1515
1455
  }
1516
-
1517
1456
  res = copy;
1518
1457
  }
1519
1458
  } else if (handleAsObjectInI18nFormat && typeof joinArrays === 'string' && resType === '[object Array]') {
@@ -1526,34 +1465,27 @@ var Translator = function (_EventEmitter) {
1526
1465
  var hasDefaultValue = Translator.hasDefaultValue(options);
1527
1466
  var defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : '';
1528
1467
  var defaultValue = options["defaultValue".concat(defaultValueSuffix)] || options.defaultValue;
1529
-
1530
1468
  if (!this.isValidLookup(res) && hasDefaultValue) {
1531
1469
  usedDefault = true;
1532
1470
  res = defaultValue;
1533
1471
  }
1534
-
1535
1472
  if (!this.isValidLookup(res)) {
1536
1473
  usedKey = true;
1537
1474
  res = key;
1538
1475
  }
1539
-
1540
1476
  var missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
1541
1477
  var resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
1542
1478
  var updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
1543
-
1544
1479
  if (usedKey || usedDefault || updateMissing) {
1545
1480
  this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
1546
-
1547
1481
  if (keySeparator) {
1548
- var fk = this.resolve(key, _objectSpread$2(_objectSpread$2({}, options), {}, {
1482
+ var fk = this.resolve(key, _objectSpread$4(_objectSpread$4({}, options), {}, {
1549
1483
  keySeparator: false
1550
1484
  }));
1551
1485
  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.');
1552
1486
  }
1553
-
1554
1487
  var lngs = [];
1555
1488
  var fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
1556
-
1557
1489
  if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
1558
1490
  for (var i = 0; i < fallbackLngs.length; i++) {
1559
1491
  lngs.push(fallbackLngs[i]);
@@ -1563,19 +1495,15 @@ var Translator = function (_EventEmitter) {
1563
1495
  } else {
1564
1496
  lngs.push(options.lng || this.language);
1565
1497
  }
1566
-
1567
1498
  var send = function send(l, k, specificDefaultValue) {
1568
1499
  var defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
1569
-
1570
1500
  if (_this2.options.missingKeyHandler) {
1571
1501
  _this2.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
1572
1502
  } else if (_this2.backendConnector && _this2.backendConnector.saveMissing) {
1573
1503
  _this2.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
1574
1504
  }
1575
-
1576
1505
  _this2.emit('missingKey', l, namespace, k, res);
1577
1506
  };
1578
-
1579
1507
  if (this.options.saveMissing) {
1580
1508
  if (this.options.saveMissingPlurals && needsPluralHandling) {
1581
1509
  lngs.forEach(function (language) {
@@ -1588,10 +1516,8 @@ var Translator = function (_EventEmitter) {
1588
1516
  }
1589
1517
  }
1590
1518
  }
1591
-
1592
1519
  res = this.extendTranslation(res, keys, options, resolved, lastKey);
1593
1520
  if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = "".concat(namespace, ":").concat(key);
1594
-
1595
1521
  if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
1596
1522
  if (this.options.compatibilityAPI !== 'v1') {
1597
1523
  res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? "".concat(namespace, ":").concat(key) : key, usedDefault ? res : undefined);
@@ -1600,77 +1526,63 @@ var Translator = function (_EventEmitter) {
1600
1526
  }
1601
1527
  }
1602
1528
  }
1603
-
1604
1529
  if (returnDetails) {
1605
1530
  resolved.res = res;
1606
1531
  return resolved;
1607
1532
  }
1608
-
1609
1533
  return res;
1610
1534
  }
1611
1535
  }, {
1612
1536
  key: "extendTranslation",
1613
1537
  value: function extendTranslation(res, key, options, resolved, lastKey) {
1614
1538
  var _this3 = this;
1615
-
1616
1539
  if (this.i18nFormat && this.i18nFormat.parse) {
1617
- res = this.i18nFormat.parse(res, _objectSpread$2(_objectSpread$2({}, this.options.interpolation.defaultVariables), options), resolved.usedLng, resolved.usedNS, resolved.usedKey, {
1540
+ res = this.i18nFormat.parse(res, _objectSpread$4(_objectSpread$4({}, this.options.interpolation.defaultVariables), options), resolved.usedLng, resolved.usedNS, resolved.usedKey, {
1618
1541
  resolved: resolved
1619
1542
  });
1620
1543
  } else if (!options.skipInterpolation) {
1621
- if (options.interpolation) this.interpolator.init(_objectSpread$2(_objectSpread$2({}, options), {
1622
- interpolation: _objectSpread$2(_objectSpread$2({}, this.options.interpolation), options.interpolation)
1544
+ if (options.interpolation) this.interpolator.init(_objectSpread$4(_objectSpread$4({}, options), {
1545
+ interpolation: _objectSpread$4(_objectSpread$4({}, this.options.interpolation), options.interpolation)
1623
1546
  }));
1624
1547
  var skipOnVariables = typeof res === 'string' && (options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
1625
1548
  var nestBef;
1626
-
1627
1549
  if (skipOnVariables) {
1628
1550
  var nb = res.match(this.interpolator.nestingRegexp);
1629
1551
  nestBef = nb && nb.length;
1630
1552
  }
1631
-
1632
1553
  var data = options.replace && typeof options.replace !== 'string' ? options.replace : options;
1633
- if (this.options.interpolation.defaultVariables) data = _objectSpread$2(_objectSpread$2({}, this.options.interpolation.defaultVariables), data);
1554
+ if (this.options.interpolation.defaultVariables) data = _objectSpread$4(_objectSpread$4({}, this.options.interpolation.defaultVariables), data);
1634
1555
  res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
1635
-
1636
1556
  if (skipOnVariables) {
1637
1557
  var na = res.match(this.interpolator.nestingRegexp);
1638
1558
  var nestAft = na && na.length;
1639
1559
  if (nestBef < nestAft) options.nest = false;
1640
1560
  }
1641
-
1642
1561
  if (options.nest !== false) res = this.interpolator.nest(res, function () {
1643
1562
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1644
1563
  args[_key] = arguments[_key];
1645
1564
  }
1646
-
1647
1565
  if (lastKey && lastKey[0] === args[0] && !options.context) {
1648
1566
  _this3.logger.warn("It seems you are nesting recursively key: ".concat(args[0], " in key: ").concat(key[0]));
1649
-
1650
1567
  return null;
1651
1568
  }
1652
-
1653
1569
  return _this3.translate.apply(_this3, args.concat([key]));
1654
1570
  }, options);
1655
1571
  if (options.interpolation) this.interpolator.reset();
1656
1572
  }
1657
-
1658
1573
  var postProcess = options.postProcess || this.options.postProcess;
1659
1574
  var postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess;
1660
-
1661
1575
  if (res !== undefined && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
1662
- res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? _objectSpread$2({
1576
+ res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? _objectSpread$4({
1663
1577
  i18nResolved: resolved
1664
1578
  }, options) : options, this);
1665
1579
  }
1666
-
1667
1580
  return res;
1668
1581
  }
1669
1582
  }, {
1670
1583
  key: "resolve",
1671
1584
  value: function resolve(keys) {
1672
1585
  var _this4 = this;
1673
-
1674
1586
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1675
1587
  var found;
1676
1588
  var usedKey;
@@ -1680,65 +1592,50 @@ var Translator = function (_EventEmitter) {
1680
1592
  if (typeof keys === 'string') keys = [keys];
1681
1593
  keys.forEach(function (k) {
1682
1594
  if (_this4.isValidLookup(found)) return;
1683
-
1684
1595
  var extracted = _this4.extractFromKey(k, options);
1685
-
1686
1596
  var key = extracted.key;
1687
1597
  usedKey = key;
1688
1598
  var namespaces = extracted.namespaces;
1689
1599
  if (_this4.options.fallbackNS) namespaces = namespaces.concat(_this4.options.fallbackNS);
1690
1600
  var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
1691
-
1692
1601
  var needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && _this4.pluralResolver.shouldUseIntlApi();
1693
-
1694
1602
  var needsContextHandling = options.context !== undefined && (typeof options.context === 'string' || typeof options.context === 'number') && options.context !== '';
1695
1603
  var codes = options.lngs ? options.lngs : _this4.languageUtils.toResolveHierarchy(options.lng || _this4.language, options.fallbackLng);
1696
1604
  namespaces.forEach(function (ns) {
1697
1605
  if (_this4.isValidLookup(found)) return;
1698
1606
  usedNS = ns;
1699
-
1700
1607
  if (!checkedLoadedFor["".concat(codes[0], "-").concat(ns)] && _this4.utils && _this4.utils.hasLoadedNamespace && !_this4.utils.hasLoadedNamespace(usedNS)) {
1701
1608
  checkedLoadedFor["".concat(codes[0], "-").concat(ns)] = true;
1702
-
1703
1609
  _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!!!');
1704
1610
  }
1705
-
1706
1611
  codes.forEach(function (code) {
1707
1612
  if (_this4.isValidLookup(found)) return;
1708
1613
  usedLng = code;
1709
1614
  var finalKeys = [key];
1710
-
1711
1615
  if (_this4.i18nFormat && _this4.i18nFormat.addLookupKeys) {
1712
1616
  _this4.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
1713
1617
  } else {
1714
1618
  var pluralSuffix;
1715
1619
  if (needsPluralHandling) pluralSuffix = _this4.pluralResolver.getSuffix(code, options.count, options);
1716
1620
  var zeroSuffix = "".concat(_this4.options.pluralSeparator, "zero");
1717
-
1718
1621
  if (needsPluralHandling) {
1719
1622
  finalKeys.push(key + pluralSuffix);
1720
-
1721
1623
  if (needsZeroSuffixLookup) {
1722
1624
  finalKeys.push(key + zeroSuffix);
1723
1625
  }
1724
1626
  }
1725
-
1726
1627
  if (needsContextHandling) {
1727
1628
  var contextKey = "".concat(key).concat(_this4.options.contextSeparator).concat(options.context);
1728
1629
  finalKeys.push(contextKey);
1729
-
1730
1630
  if (needsPluralHandling) {
1731
1631
  finalKeys.push(contextKey + pluralSuffix);
1732
-
1733
1632
  if (needsZeroSuffixLookup) {
1734
1633
  finalKeys.push(contextKey + zeroSuffix);
1735
1634
  }
1736
1635
  }
1737
1636
  }
1738
1637
  }
1739
-
1740
1638
  var possibleKey;
1741
-
1742
1639
  while (possibleKey = finalKeys.pop()) {
1743
1640
  if (!_this4.isValidLookup(found)) {
1744
1641
  exactUsedKey = possibleKey;
@@ -1772,33 +1669,27 @@ var Translator = function (_EventEmitter) {
1772
1669
  key: "hasDefaultValue",
1773
1670
  value: function hasDefaultValue(options) {
1774
1671
  var prefix = 'defaultValue';
1775
-
1776
1672
  for (var option in options) {
1777
1673
  if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
1778
1674
  return true;
1779
1675
  }
1780
1676
  }
1781
-
1782
1677
  return false;
1783
1678
  }
1784
1679
  }]);
1785
-
1786
1680
  return Translator;
1787
1681
  }(EventEmitter);
1788
1682
 
1789
1683
  function capitalize(string) {
1790
1684
  return string.charAt(0).toUpperCase() + string.slice(1);
1791
1685
  }
1792
-
1793
1686
  var LanguageUtil = function () {
1794
1687
  function LanguageUtil(options) {
1795
1688
  _classCallCheck(this, LanguageUtil);
1796
-
1797
1689
  this.options = options;
1798
1690
  this.supportedLngs = this.options.supportedLngs || false;
1799
1691
  this.logger = baseLogger.create('languageUtils');
1800
1692
  }
1801
-
1802
1693
  _createClass(LanguageUtil, [{
1803
1694
  key: "getScriptPartFromCode",
1804
1695
  value: function getScriptPartFromCode(code) {
@@ -1822,7 +1713,6 @@ var LanguageUtil = function () {
1822
1713
  if (typeof code === 'string' && code.indexOf('-') > -1) {
1823
1714
  var specialCases = ['hans', 'hant', 'latn', 'cyrl', 'cans', 'mong', 'arab'];
1824
1715
  var p = code.split('-');
1825
-
1826
1716
  if (this.options.lowerCaseLng) {
1827
1717
  p = p.map(function (part) {
1828
1718
  return part.toLowerCase();
@@ -1838,10 +1728,8 @@ var LanguageUtil = function () {
1838
1728
  if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
1839
1729
  if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
1840
1730
  }
1841
-
1842
1731
  return p.join('-');
1843
1732
  }
1844
-
1845
1733
  return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
1846
1734
  }
1847
1735
  }, {
@@ -1850,37 +1738,29 @@ var LanguageUtil = function () {
1850
1738
  if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
1851
1739
  code = this.getLanguagePartFromCode(code);
1852
1740
  }
1853
-
1854
1741
  return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
1855
1742
  }
1856
1743
  }, {
1857
1744
  key: "getBestMatchFromCodes",
1858
1745
  value: function getBestMatchFromCodes(codes) {
1859
1746
  var _this = this;
1860
-
1861
1747
  if (!codes) return null;
1862
1748
  var found;
1863
1749
  codes.forEach(function (code) {
1864
1750
  if (found) return;
1865
-
1866
1751
  var cleanedLng = _this.formatLanguageCode(code);
1867
-
1868
1752
  if (!_this.options.supportedLngs || _this.isSupportedCode(cleanedLng)) found = cleanedLng;
1869
1753
  });
1870
-
1871
1754
  if (!found && this.options.supportedLngs) {
1872
1755
  codes.forEach(function (code) {
1873
1756
  if (found) return;
1874
-
1875
1757
  var lngOnly = _this.getLanguagePartFromCode(code);
1876
-
1877
1758
  if (_this.isSupportedCode(lngOnly)) return found = lngOnly;
1878
1759
  found = _this.options.supportedLngs.find(function (supportedLng) {
1879
1760
  if (supportedLng.indexOf(lngOnly) === 0) return supportedLng;
1880
1761
  });
1881
1762
  });
1882
1763
  }
1883
-
1884
1764
  if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
1885
1765
  return found;
1886
1766
  }
@@ -1903,20 +1783,16 @@ var LanguageUtil = function () {
1903
1783
  key: "toResolveHierarchy",
1904
1784
  value: function toResolveHierarchy(code, fallbackCode) {
1905
1785
  var _this2 = this;
1906
-
1907
1786
  var fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
1908
1787
  var codes = [];
1909
-
1910
1788
  var addCode = function addCode(c) {
1911
1789
  if (!c) return;
1912
-
1913
1790
  if (_this2.isSupportedCode(c)) {
1914
1791
  codes.push(c);
1915
1792
  } else {
1916
1793
  _this2.logger.warn("rejecting language code not found in supportedLngs: ".concat(c));
1917
1794
  }
1918
1795
  };
1919
-
1920
1796
  if (typeof code === 'string' && code.indexOf('-') > -1) {
1921
1797
  if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
1922
1798
  if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
@@ -1924,14 +1800,12 @@ var LanguageUtil = function () {
1924
1800
  } else if (typeof code === 'string') {
1925
1801
  addCode(this.formatLanguageCode(code));
1926
1802
  }
1927
-
1928
1803
  fallbackCodes.forEach(function (fc) {
1929
1804
  if (codes.indexOf(fc) < 0) addCode(_this2.formatLanguageCode(fc));
1930
1805
  });
1931
1806
  return codes;
1932
1807
  }
1933
1808
  }]);
1934
-
1935
1809
  return LanguageUtil;
1936
1810
  }();
1937
1811
 
@@ -2105,7 +1979,6 @@ var suffixesOrder = {
2105
1979
  many: 4,
2106
1980
  other: 5
2107
1981
  };
2108
-
2109
1982
  function createRules() {
2110
1983
  var rules = {};
2111
1984
  sets.forEach(function (set) {
@@ -2118,25 +1991,19 @@ function createRules() {
2118
1991
  });
2119
1992
  return rules;
2120
1993
  }
2121
-
2122
1994
  var PluralResolver = function () {
2123
1995
  function PluralResolver(languageUtils) {
2124
1996
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2125
-
2126
1997
  _classCallCheck(this, PluralResolver);
2127
-
2128
1998
  this.languageUtils = languageUtils;
2129
1999
  this.options = options;
2130
2000
  this.logger = baseLogger.create('pluralResolver');
2131
-
2132
2001
  if ((!this.options.compatibilityJSON || this.options.compatibilityJSON === 'v4') && (typeof Intl === 'undefined' || !Intl.PluralRules)) {
2133
2002
  this.options.compatibilityJSON = 'v3';
2134
2003
  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.');
2135
2004
  }
2136
-
2137
2005
  this.rules = createRules();
2138
2006
  }
2139
-
2140
2007
  _createClass(PluralResolver, [{
2141
2008
  key: "addRule",
2142
2009
  value: function addRule(lng, obj) {
@@ -2146,7 +2013,6 @@ var PluralResolver = function () {
2146
2013
  key: "getRule",
2147
2014
  value: function getRule(code) {
2148
2015
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2149
-
2150
2016
  if (this.shouldUseIntlApi()) {
2151
2017
  try {
2152
2018
  return new Intl.PluralRules(code, {
@@ -2156,7 +2022,6 @@ var PluralResolver = function () {
2156
2022
  return;
2157
2023
  }
2158
2024
  }
2159
-
2160
2025
  return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
2161
2026
  }
2162
2027
  }, {
@@ -2164,11 +2029,9 @@ var PluralResolver = function () {
2164
2029
  value: function needsPlural(code) {
2165
2030
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2166
2031
  var rule = this.getRule(code, options);
2167
-
2168
2032
  if (this.shouldUseIntlApi()) {
2169
2033
  return rule && rule.resolvedOptions().pluralCategories.length > 1;
2170
2034
  }
2171
-
2172
2035
  return rule && rule.numbers.length > 1;
2173
2036
  }
2174
2037
  }, {
@@ -2183,14 +2046,11 @@ var PluralResolver = function () {
2183
2046
  key: "getSuffixes",
2184
2047
  value: function getSuffixes(code) {
2185
2048
  var _this = this;
2186
-
2187
2049
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2188
2050
  var rule = this.getRule(code, options);
2189
-
2190
2051
  if (!rule) {
2191
2052
  return [];
2192
2053
  }
2193
-
2194
2054
  if (this.shouldUseIntlApi()) {
2195
2055
  return rule.resolvedOptions().pluralCategories.sort(function (pluralCategory1, pluralCategory2) {
2196
2056
  return suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2];
@@ -2198,7 +2058,6 @@ var PluralResolver = function () {
2198
2058
  return "".concat(_this.options.prepend).concat(pluralCategory);
2199
2059
  });
2200
2060
  }
2201
-
2202
2061
  return rule.numbers.map(function (number) {
2203
2062
  return _this.getSuffix(code, number, options);
2204
2063
  });
@@ -2208,15 +2067,12 @@ var PluralResolver = function () {
2208
2067
  value: function getSuffix(code, count) {
2209
2068
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2210
2069
  var rule = this.getRule(code, options);
2211
-
2212
2070
  if (rule) {
2213
2071
  if (this.shouldUseIntlApi()) {
2214
2072
  return "".concat(this.options.prepend).concat(rule.select(count));
2215
2073
  }
2216
-
2217
2074
  return this.getSuffixRetroCompatible(rule, count);
2218
2075
  }
2219
-
2220
2076
  this.logger.warn("no plural rule found for: ".concat(code));
2221
2077
  return '';
2222
2078
  }
@@ -2224,10 +2080,8 @@ var PluralResolver = function () {
2224
2080
  key: "getSuffixRetroCompatible",
2225
2081
  value: function getSuffixRetroCompatible(rule, count) {
2226
2082
  var _this2 = this;
2227
-
2228
2083
  var idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
2229
2084
  var suffix = rule.numbers[idx];
2230
-
2231
2085
  if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
2232
2086
  if (suffix === 2) {
2233
2087
  suffix = 'plural';
@@ -2235,11 +2089,9 @@ var PluralResolver = function () {
2235
2089
  suffix = '';
2236
2090
  }
2237
2091
  }
2238
-
2239
2092
  var returnSuffix = function returnSuffix() {
2240
2093
  return _this2.options.prepend && suffix.toString() ? _this2.options.prepend + suffix.toString() : suffix.toString();
2241
2094
  };
2242
-
2243
2095
  if (this.options.compatibilityJSON === 'v1') {
2244
2096
  if (suffix === 1) return '';
2245
2097
  if (typeof suffix === 'number') return "_plural_".concat(suffix.toString());
@@ -2249,7 +2101,6 @@ var PluralResolver = function () {
2249
2101
  } else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
2250
2102
  return returnSuffix();
2251
2103
  }
2252
-
2253
2104
  return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
2254
2105
  }
2255
2106
  }, {
@@ -2258,30 +2109,22 @@ var PluralResolver = function () {
2258
2109
  return !deprecatedJsonVersions.includes(this.options.compatibilityJSON);
2259
2110
  }
2260
2111
  }]);
2261
-
2262
2112
  return PluralResolver;
2263
2113
  }();
2264
2114
 
2265
- 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; }
2266
-
2267
- 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; }
2268
-
2115
+ 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; }
2116
+ 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; }
2269
2117
  var Interpolator = function () {
2270
2118
  function Interpolator() {
2271
2119
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2272
-
2273
2120
  _classCallCheck(this, Interpolator);
2274
-
2275
2121
  this.logger = baseLogger.create('interpolator');
2276
2122
  this.options = options;
2277
-
2278
2123
  this.format = options.interpolation && options.interpolation.format || function (value) {
2279
2124
  return value;
2280
2125
  };
2281
-
2282
2126
  this.init(options);
2283
2127
  }
2284
-
2285
2128
  _createClass(Interpolator, [{
2286
2129
  key: "init",
2287
2130
  value: function init() {
@@ -2324,16 +2167,13 @@ var Interpolator = function () {
2324
2167
  key: "interpolate",
2325
2168
  value: function interpolate(str, data, lng, options) {
2326
2169
  var _this = this;
2327
-
2328
2170
  var match;
2329
2171
  var value;
2330
2172
  var replaces;
2331
2173
  var defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
2332
-
2333
2174
  function regexSafe(val) {
2334
2175
  return val.replace(/\$/g, '$$$$');
2335
2176
  }
2336
-
2337
2177
  var handleFormat = function handleFormat(key) {
2338
2178
  if (key.indexOf(_this.formatSeparator) < 0) {
2339
2179
  var path = getPathWithDefaults(data, defaultData, key);
@@ -2341,7 +2181,6 @@ var Interpolator = function () {
2341
2181
  interpolationkey: key
2342
2182
  })) : path;
2343
2183
  }
2344
-
2345
2184
  var p = key.split(_this.formatSeparator);
2346
2185
  var k = p.shift().trim();
2347
2186
  var f = p.join(_this.formatSeparator).trim();
@@ -2349,7 +2188,6 @@ var Interpolator = function () {
2349
2188
  interpolationkey: k
2350
2189
  }));
2351
2190
  };
2352
-
2353
2191
  this.resetRegExp();
2354
2192
  var missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
2355
2193
  var skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
@@ -2366,11 +2204,9 @@ var Interpolator = function () {
2366
2204
  }];
2367
2205
  todos.forEach(function (todo) {
2368
2206
  replaces = 0;
2369
-
2370
2207
  while (match = todo.regex.exec(str)) {
2371
2208
  var matchedVar = match[1].trim();
2372
2209
  value = handleFormat(matchedVar);
2373
-
2374
2210
  if (value === undefined) {
2375
2211
  if (typeof missingInterpolationHandler === 'function') {
2376
2212
  var temp = missingInterpolationHandler(str, match, options);
@@ -2382,25 +2218,20 @@ var Interpolator = function () {
2382
2218
  continue;
2383
2219
  } else {
2384
2220
  _this.logger.warn("missed to pass in variable ".concat(matchedVar, " for interpolating ").concat(str));
2385
-
2386
2221
  value = '';
2387
2222
  }
2388
2223
  } else if (typeof value !== 'string' && !_this.useRawValueToEscape) {
2389
2224
  value = makeString(value);
2390
2225
  }
2391
-
2392
2226
  var safeValue = todo.safeValue(value);
2393
2227
  str = str.replace(match[0], safeValue);
2394
-
2395
2228
  if (skipOnVariables) {
2396
2229
  todo.regex.lastIndex += value.length;
2397
2230
  todo.regex.lastIndex -= match[0].length;
2398
2231
  } else {
2399
2232
  todo.regex.lastIndex = 0;
2400
2233
  }
2401
-
2402
2234
  replaces++;
2403
-
2404
2235
  if (replaces >= _this.maxReplaces) {
2405
2236
  break;
2406
2237
  }
@@ -2412,16 +2243,10 @@ var Interpolator = function () {
2412
2243
  key: "nest",
2413
2244
  value: function nest(str, fc) {
2414
2245
  var _this2 = this;
2415
-
2416
2246
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2417
2247
  var match;
2418
- var value;
2419
-
2420
- var clonedOptions = _objectSpread$3({}, options);
2421
-
2422
- clonedOptions.applyPostProcessor = false;
2423
- delete clonedOptions.defaultValue;
2424
-
2248
+ var value;
2249
+ var clonedOptions;
2425
2250
  function handleHasOptions(key, inheritedOptions) {
2426
2251
  var sep = this.nestingOptionsSeparator;
2427
2252
  if (key.indexOf(sep) < 0) return key;
@@ -2429,8 +2254,11 @@ var Interpolator = function () {
2429
2254
  var optionsString = "{".concat(c[1]);
2430
2255
  key = c[0];
2431
2256
  optionsString = this.interpolate(optionsString, clonedOptions);
2432
- optionsString = optionsString.replace(/'/g, '"');
2433
-
2257
+ var matchedSingleQuotes = optionsString.match(/'/g);
2258
+ var matchedDoubleQuotes = optionsString.match(/"/g);
2259
+ if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
2260
+ optionsString = optionsString.replace(/'/g, '"');
2261
+ }
2434
2262
  try {
2435
2263
  clonedOptions = JSON.parse(optionsString);
2436
2264
  if (inheritedOptions) clonedOptions = _objectSpread$3(_objectSpread$3({}, inheritedOptions), clonedOptions);
@@ -2438,15 +2266,16 @@ var Interpolator = function () {
2438
2266
  this.logger.warn("failed parsing options string in nesting for key ".concat(key), e);
2439
2267
  return "".concat(key).concat(sep).concat(optionsString);
2440
2268
  }
2441
-
2442
2269
  delete clonedOptions.defaultValue;
2443
2270
  return key;
2444
2271
  }
2445
-
2446
2272
  while (match = this.nestingRegexp.exec(str)) {
2447
2273
  var formatters = [];
2274
+ clonedOptions = _objectSpread$3({}, options);
2275
+ clonedOptions = clonedOptions.replace && typeof clonedOptions.replace !== 'string' ? clonedOptions.replace : clonedOptions;
2276
+ clonedOptions.applyPostProcessor = false;
2277
+ delete clonedOptions.defaultValue;
2448
2278
  var doReduce = false;
2449
-
2450
2279
  if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
2451
2280
  var r = match[1].split(this.formatSeparator).map(function (elem) {
2452
2281
  return elem.trim();
@@ -2455,16 +2284,13 @@ var Interpolator = function () {
2455
2284
  formatters = r;
2456
2285
  doReduce = true;
2457
2286
  }
2458
-
2459
2287
  value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
2460
2288
  if (value && match[0] === str && typeof value !== 'string') return value;
2461
2289
  if (typeof value !== 'string') value = makeString(value);
2462
-
2463
2290
  if (!value) {
2464
2291
  this.logger.warn("missed to resolve ".concat(match[1], " for nesting ").concat(str));
2465
2292
  value = '';
2466
2293
  }
2467
-
2468
2294
  if (doReduce) {
2469
2295
  value = formatters.reduce(function (v, f) {
2470
2296
  return _this2.format(v, f, options.lng, _objectSpread$3(_objectSpread$3({}, options), {}, {
@@ -2472,31 +2298,24 @@ var Interpolator = function () {
2472
2298
  }));
2473
2299
  }, value.trim());
2474
2300
  }
2475
-
2476
2301
  str = str.replace(match[0], value);
2477
2302
  this.regexp.lastIndex = 0;
2478
2303
  }
2479
-
2480
2304
  return str;
2481
2305
  }
2482
2306
  }]);
2483
-
2484
2307
  return Interpolator;
2485
2308
  }();
2486
2309
 
2487
- 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; }
2488
-
2489
- 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; }
2490
-
2310
+ 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; }
2311
+ 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; }
2491
2312
  function parseFormatStr(formatStr) {
2492
2313
  var formatName = formatStr.toLowerCase().trim();
2493
2314
  var formatOptions = {};
2494
-
2495
2315
  if (formatStr.indexOf('(') > -1) {
2496
2316
  var p = formatStr.split('(');
2497
2317
  formatName = p[0].toLowerCase().trim();
2498
2318
  var optStr = p[1].substring(0, p[1].length - 1);
2499
-
2500
2319
  if (formatName === 'currency' && optStr.indexOf(':') < 0) {
2501
2320
  if (!formatOptions.currency) formatOptions.currency = optStr.trim();
2502
2321
  } else if (formatName === 'relativetime' && optStr.indexOf(':') < 0) {
@@ -2505,12 +2324,10 @@ function parseFormatStr(formatStr) {
2505
2324
  var opts = optStr.split(';');
2506
2325
  opts.forEach(function (opt) {
2507
2326
  if (!opt) return;
2508
-
2509
2327
  var _opt$split = opt.split(':'),
2510
- _opt$split2 = _toArray(_opt$split),
2511
- key = _opt$split2[0],
2512
- rest = _opt$split2.slice(1);
2513
-
2328
+ _opt$split2 = _toArray(_opt$split),
2329
+ key = _opt$split2[0],
2330
+ rest = _opt$split2.slice(1);
2514
2331
  var val = rest.join(':').trim().replace(/^'+|'+$/g, '');
2515
2332
  if (!formatOptions[key.trim()]) formatOptions[key.trim()] = val;
2516
2333
  if (val === 'false') formatOptions[key.trim()] = false;
@@ -2519,43 +2336,65 @@ function parseFormatStr(formatStr) {
2519
2336
  });
2520
2337
  }
2521
2338
  }
2522
-
2523
2339
  return {
2524
2340
  formatName: formatName,
2525
2341
  formatOptions: formatOptions
2526
2342
  };
2527
2343
  }
2528
-
2344
+ function createCachedFormatter(fn) {
2345
+ var cache = {};
2346
+ return function invokeFormatter(val, lng, options) {
2347
+ var key = lng + JSON.stringify(options);
2348
+ var formatter = cache[key];
2349
+ if (!formatter) {
2350
+ formatter = fn(lng, options);
2351
+ cache[key] = formatter;
2352
+ }
2353
+ return formatter(val);
2354
+ };
2355
+ }
2529
2356
  var Formatter = function () {
2530
2357
  function Formatter() {
2531
2358
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2532
-
2533
2359
  _classCallCheck(this, Formatter);
2534
-
2535
2360
  this.logger = baseLogger.create('formatter');
2536
2361
  this.options = options;
2537
2362
  this.formats = {
2538
- number: function number(val, lng, options) {
2539
- return new Intl.NumberFormat(lng, options).format(val);
2540
- },
2541
- currency: function currency(val, lng, options) {
2542
- return new Intl.NumberFormat(lng, _objectSpread$4(_objectSpread$4({}, options), {}, {
2363
+ number: createCachedFormatter(function (lng, options) {
2364
+ var formatter = new Intl.NumberFormat(lng, options);
2365
+ return function (val) {
2366
+ return formatter.format(val);
2367
+ };
2368
+ }),
2369
+ currency: createCachedFormatter(function (lng, options) {
2370
+ var formatter = new Intl.NumberFormat(lng, _objectSpread$2(_objectSpread$2({}, options), {}, {
2543
2371
  style: 'currency'
2544
- })).format(val);
2545
- },
2546
- datetime: function datetime(val, lng, options) {
2547
- return new Intl.DateTimeFormat(lng, _objectSpread$4({}, options)).format(val);
2548
- },
2549
- relativetime: function relativetime(val, lng, options) {
2550
- return new Intl.RelativeTimeFormat(lng, _objectSpread$4({}, options)).format(val, options.range || 'day');
2551
- },
2552
- list: function list(val, lng, options) {
2553
- return new Intl.ListFormat(lng, _objectSpread$4({}, options)).format(val);
2554
- }
2372
+ }));
2373
+ return function (val) {
2374
+ return formatter.format(val);
2375
+ };
2376
+ }),
2377
+ datetime: createCachedFormatter(function (lng, options) {
2378
+ var formatter = new Intl.DateTimeFormat(lng, _objectSpread$2({}, options));
2379
+ return function (val) {
2380
+ return formatter.format(val);
2381
+ };
2382
+ }),
2383
+ relativetime: createCachedFormatter(function (lng, options) {
2384
+ var formatter = new Intl.RelativeTimeFormat(lng, _objectSpread$2({}, options));
2385
+ return function (val) {
2386
+ return formatter.format(val, options.range || 'day');
2387
+ };
2388
+ }),
2389
+ list: createCachedFormatter(function (lng, options) {
2390
+ var formatter = new Intl.ListFormat(lng, _objectSpread$2({}, options));
2391
+ return function (val) {
2392
+ return formatter.format(val);
2393
+ };
2394
+ })
2555
2395
  };
2556
2396
  this.init(options);
2557
2397
  }
2558
-
2559
2398
  _createClass(Formatter, [{
2560
2399
  key: "init",
2561
2400
  value: function init(services) {
@@ -2570,76 +2409,62 @@ var Formatter = function () {
2570
2409
  value: function add(name, fc) {
2571
2410
  this.formats[name.toLowerCase().trim()] = fc;
2572
2411
  }
2412
+ }, {
2413
+ key: "addCached",
2414
+ value: function addCached(name, fc) {
2415
+ this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
2416
+ }
2573
2417
  }, {
2574
2418
  key: "format",
2575
2419
  value: function format(value, _format, lng, options) {
2576
2420
  var _this = this;
2577
-
2578
2421
  var formats = _format.split(this.formatSeparator);
2579
-
2580
2422
  var result = formats.reduce(function (mem, f) {
2581
2423
  var _parseFormatStr = parseFormatStr(f),
2582
- formatName = _parseFormatStr.formatName,
2583
- formatOptions = _parseFormatStr.formatOptions;
2584
-
2424
+ formatName = _parseFormatStr.formatName,
2425
+ formatOptions = _parseFormatStr.formatOptions;
2585
2426
  if (_this.formats[formatName]) {
2586
2427
  var formatted = mem;
2587
-
2588
2428
  try {
2589
2429
  var valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
2590
2430
  var l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
2591
- formatted = _this.formats[formatName](mem, l, _objectSpread$4(_objectSpread$4(_objectSpread$4({}, formatOptions), options), valOptions));
2431
+ formatted = _this.formats[formatName](mem, l, _objectSpread$2(_objectSpread$2(_objectSpread$2({}, formatOptions), options), valOptions));
2592
2432
  } catch (error) {
2593
2433
  _this.logger.warn(error);
2594
2434
  }
2595
-
2596
2435
  return formatted;
2597
2436
  } else {
2598
2437
  _this.logger.warn("there was no format function for ".concat(formatName));
2599
2438
  }
2600
-
2601
2439
  return mem;
2602
2440
  }, value);
2603
2441
  return result;
2604
2442
  }
2605
2443
  }]);
2606
-
2607
2444
  return Formatter;
2608
2445
  }();
2609
2446
 
2610
- 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; }
2611
-
2612
- 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; }
2613
-
2614
- 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); }; }
2615
-
2616
- 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; } }
2617
-
2447
+ 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; }
2448
+ 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; }
2449
+ 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); }; }
2450
+ 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; } }
2618
2451
  function removePending(q, name) {
2619
2452
  if (q.pending[name] !== undefined) {
2620
2453
  delete q.pending[name];
2621
2454
  q.pendingCount--;
2622
2455
  }
2623
2456
  }
2624
-
2625
2457
  var Connector = function (_EventEmitter) {
2626
2458
  _inherits(Connector, _EventEmitter);
2627
-
2628
- var _super = _createSuper$2(Connector);
2629
-
2459
+ var _super = _createSuper$1(Connector);
2630
2460
  function Connector(backend, store, services) {
2631
2461
  var _this;
2632
-
2633
2462
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
2634
-
2635
2463
  _classCallCheck(this, Connector);
2636
-
2637
2464
  _this = _super.call(this);
2638
-
2639
2465
  if (isIE10) {
2640
2466
  EventEmitter.call(_assertThisInitialized(_this));
2641
2467
  }
2642
-
2643
2468
  _this.backend = backend;
2644
2469
  _this.store = store;
2645
2470
  _this.services = services;
@@ -2653,19 +2478,15 @@ var Connector = function (_EventEmitter) {
2653
2478
  _this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
2654
2479
  _this.state = {};
2655
2480
  _this.queue = [];
2656
-
2657
2481
  if (_this.backend && _this.backend.init) {
2658
2482
  _this.backend.init(services, options.backend, options);
2659
2483
  }
2660
-
2661
2484
  return _this;
2662
2485
  }
2663
-
2664
2486
  _createClass(Connector, [{
2665
2487
  key: "queueLoad",
2666
2488
  value: function queueLoad(languages, namespaces, options, callback) {
2667
2489
  var _this2 = this;
2668
-
2669
2490
  var toLoad = {};
2670
2491
  var pending = {};
2671
2492
  var toLoadLanguages = {};
@@ -2674,7 +2495,6 @@ var Connector = function (_EventEmitter) {
2674
2495
  var hasAllNamespaces = true;
2675
2496
  namespaces.forEach(function (ns) {
2676
2497
  var name = "".concat(lng, "|").concat(ns);
2677
-
2678
2498
  if (!options.reload && _this2.store.hasResourceBundle(lng, ns)) {
2679
2499
  _this2.state[name] = 2;
2680
2500
  } else if (_this2.state[name] < 0) ; else if (_this2.state[name] === 1) {
@@ -2689,7 +2509,6 @@ var Connector = function (_EventEmitter) {
2689
2509
  });
2690
2510
  if (!hasAllNamespaces) toLoadLanguages[lng] = true;
2691
2511
  });
2692
-
2693
2512
  if (Object.keys(toLoad).length || Object.keys(pending).length) {
2694
2513
  this.queue.push({
2695
2514
  pending: pending,
@@ -2699,7 +2518,6 @@ var Connector = function (_EventEmitter) {
2699
2518
  callback: callback
2700
2519
  });
2701
2520
  }
2702
-
2703
2521
  return {
2704
2522
  toLoad: Object.keys(toLoad),
2705
2523
  pending: Object.keys(pending),
@@ -2714,23 +2532,19 @@ var Connector = function (_EventEmitter) {
2714
2532
  var lng = s[0];
2715
2533
  var ns = s[1];
2716
2534
  if (err) this.emit('failedLoading', lng, ns, err);
2717
-
2718
2535
  if (data) {
2719
2536
  this.store.addResourceBundle(lng, ns, data);
2720
2537
  }
2721
-
2722
2538
  this.state[name] = err ? -1 : 2;
2723
2539
  var loaded = {};
2724
2540
  this.queue.forEach(function (q) {
2725
2541
  pushPath(q.loaded, [lng], ns);
2726
2542
  removePending(q, name);
2727
2543
  if (err) q.errors.push(err);
2728
-
2729
2544
  if (q.pendingCount === 0 && !q.done) {
2730
2545
  Object.keys(q.loaded).forEach(function (l) {
2731
2546
  if (!loaded[l]) loaded[l] = {};
2732
2547
  var loadedKeys = q.loaded[l];
2733
-
2734
2548
  if (loadedKeys.length) {
2735
2549
  loadedKeys.forEach(function (ns) {
2736
2550
  if (loaded[l][ns] === undefined) loaded[l][ns] = true;
@@ -2738,7 +2552,6 @@ var Connector = function (_EventEmitter) {
2738
2552
  }
2739
2553
  });
2740
2554
  q.done = true;
2741
-
2742
2555
  if (q.errors.length) {
2743
2556
  q.callback(q.errors);
2744
2557
  } else {
@@ -2755,12 +2568,10 @@ var Connector = function (_EventEmitter) {
2755
2568
  key: "read",
2756
2569
  value: function read(lng, ns, fcName) {
2757
2570
  var _this3 = this;
2758
-
2759
2571
  var tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
2760
2572
  var wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
2761
2573
  var callback = arguments.length > 5 ? arguments[5] : undefined;
2762
2574
  if (!lng.length) return callback(null, {});
2763
-
2764
2575
  if (this.readingCalls >= this.maxParallelReads) {
2765
2576
  this.waitingReads.push({
2766
2577
  lng: lng,
@@ -2772,49 +2583,56 @@ var Connector = function (_EventEmitter) {
2772
2583
  });
2773
2584
  return;
2774
2585
  }
2775
-
2776
2586
  this.readingCalls++;
2777
- return this.backend[fcName](lng, ns, function (err, data) {
2587
+ var resolver = function resolver(err, data) {
2778
2588
  _this3.readingCalls--;
2779
-
2780
2589
  if (_this3.waitingReads.length > 0) {
2781
2590
  var next = _this3.waitingReads.shift();
2782
-
2783
2591
  _this3.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
2784
2592
  }
2785
-
2786
2593
  if (err && data && tried < _this3.maxRetries) {
2787
2594
  setTimeout(function () {
2788
2595
  _this3.read.call(_this3, lng, ns, fcName, tried + 1, wait * 2, callback);
2789
2596
  }, wait);
2790
2597
  return;
2791
2598
  }
2792
-
2793
2599
  callback(err, data);
2794
- });
2600
+ };
2601
+ var fc = this.backend[fcName].bind(this.backend);
2602
+ if (fc.length === 2) {
2603
+ try {
2604
+ var r = fc(lng, ns);
2605
+ if (r && typeof r.then === 'function') {
2606
+ r.then(function (data) {
2607
+ return resolver(null, data);
2608
+ })["catch"](resolver);
2609
+ } else {
2610
+ resolver(null, r);
2611
+ }
2612
+ } catch (err) {
2613
+ resolver(err);
2614
+ }
2615
+ return;
2616
+ }
2617
+ return fc(lng, ns, resolver);
2795
2618
  }
2796
2619
  }, {
2797
2620
  key: "prepareLoading",
2798
2621
  value: function prepareLoading(languages, namespaces) {
2799
2622
  var _this4 = this;
2800
-
2801
2623
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2802
2624
  var callback = arguments.length > 3 ? arguments[3] : undefined;
2803
-
2804
2625
  if (!this.backend) {
2805
2626
  this.logger.warn('No backend was added via i18next.use. Will not load resources.');
2806
2627
  return callback && callback();
2807
2628
  }
2808
-
2809
2629
  if (typeof languages === 'string') languages = this.languageUtils.toResolveHierarchy(languages);
2810
2630
  if (typeof namespaces === 'string') namespaces = [namespaces];
2811
2631
  var toLoad = this.queueLoad(languages, namespaces, options, callback);
2812
-
2813
2632
  if (!toLoad.toLoad.length) {
2814
2633
  if (!toLoad.pending.length) callback();
2815
2634
  return null;
2816
2635
  }
2817
-
2818
2636
  toLoad.toLoad.forEach(function (name) {
2819
2637
  _this4.loadOne(name);
2820
2638
  });
@@ -2835,7 +2653,6 @@ var Connector = function (_EventEmitter) {
2835
2653
  key: "loadOne",
2836
2654
  value: function loadOne(name) {
2837
2655
  var _this5 = this;
2838
-
2839
2656
  var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
2840
2657
  var s = name.split('|');
2841
2658
  var lng = s[0];
@@ -2843,7 +2660,6 @@ var Connector = function (_EventEmitter) {
2843
2660
  this.read(lng, ns, 'read', undefined, undefined, function (err, data) {
2844
2661
  if (err) _this5.logger.warn("".concat(prefix, "loading namespace ").concat(ns, " for language ").concat(lng, " failed"), err);
2845
2662
  if (!err && data) _this5.logger.log("".concat(prefix, "loaded namespace ").concat(ns, " for language ").concat(lng), data);
2846
-
2847
2663
  _this5.loaded(name, err, data);
2848
2664
  });
2849
2665
  }
@@ -2851,25 +2667,43 @@ var Connector = function (_EventEmitter) {
2851
2667
  key: "saveMissing",
2852
2668
  value: function saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
2853
2669
  var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
2854
-
2670
+ var clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : function () {};
2855
2671
  if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
2856
2672
  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!!!');
2857
2673
  return;
2858
2674
  }
2859
-
2860
2675
  if (key === undefined || key === null || key === '') return;
2861
-
2862
2676
  if (this.backend && this.backend.create) {
2863
- this.backend.create(languages, namespace, key, fallbackValue, null, _objectSpread$5(_objectSpread$5({}, options), {}, {
2677
+ var opts = _objectSpread$1(_objectSpread$1({}, options), {}, {
2864
2678
  isUpdate: isUpdate
2865
- }));
2679
+ });
2680
+ var fc = this.backend.create.bind(this.backend);
2681
+ if (fc.length < 6) {
2682
+ try {
2683
+ var r;
2684
+ if (fc.length === 5) {
2685
+ r = fc(languages, namespace, key, fallbackValue, opts);
2686
+ } else {
2687
+ r = fc(languages, namespace, key, fallbackValue);
2688
+ }
2689
+ if (r && typeof r.then === 'function') {
2690
+ r.then(function (data) {
2691
+ return clb(null, data);
2692
+ })["catch"](clb);
2693
+ } else {
2694
+ clb(null, r);
2695
+ }
2696
+ } catch (err) {
2697
+ clb(err);
2698
+ }
2699
+ } else {
2700
+ fc(languages, namespace, key, fallbackValue, clb, opts);
2701
+ }
2866
2702
  }
2867
-
2868
2703
  if (!languages || !languages[0]) return;
2869
2704
  this.store.addResource(languages[0], namespace, key, fallbackValue);
2870
2705
  }
2871
2706
  }]);
2872
-
2873
2707
  return Connector;
2874
2708
  }(EventEmitter);
2875
2709
 
@@ -2912,14 +2746,12 @@ function get() {
2912
2746
  if (_typeof(args[1]) === 'object') ret = args[1];
2913
2747
  if (typeof args[1] === 'string') ret.defaultValue = args[1];
2914
2748
  if (typeof args[2] === 'string') ret.tDescription = args[2];
2915
-
2916
2749
  if (_typeof(args[2]) === 'object' || _typeof(args[3]) === 'object') {
2917
2750
  var options = args[3] || args[2];
2918
2751
  Object.keys(options).forEach(function (key) {
2919
2752
  ret[key] = options[key];
2920
2753
  });
2921
2754
  }
2922
-
2923
2755
  return ret;
2924
2756
  },
2925
2757
  interpolation: {
@@ -2943,24 +2775,17 @@ function transformOptions(options) {
2943
2775
  if (typeof options.ns === 'string') options.ns = [options.ns];
2944
2776
  if (typeof options.fallbackLng === 'string') options.fallbackLng = [options.fallbackLng];
2945
2777
  if (typeof options.fallbackNS === 'string') options.fallbackNS = [options.fallbackNS];
2946
-
2947
2778
  if (options.supportedLngs && options.supportedLngs.indexOf('cimode') < 0) {
2948
2779
  options.supportedLngs = options.supportedLngs.concat(['cimode']);
2949
2780
  }
2950
-
2951
2781
  return options;
2952
2782
  }
2953
2783
 
2954
- 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; }
2955
-
2956
- 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; }
2957
-
2958
- 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); }; }
2959
-
2960
- 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; } }
2961
-
2784
+ 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; }
2785
+ 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; }
2786
+ 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); }; }
2787
+ 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; } }
2962
2788
  function noop() {}
2963
-
2964
2789
  function bindMemberFunctions(inst) {
2965
2790
  var mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
2966
2791
  mems.forEach(function (mem) {
@@ -2969,26 +2794,18 @@ function bindMemberFunctions(inst) {
2969
2794
  }
2970
2795
  });
2971
2796
  }
2972
-
2973
2797
  var I18n = function (_EventEmitter) {
2974
2798
  _inherits(I18n, _EventEmitter);
2975
-
2976
- var _super = _createSuper$3(I18n);
2977
-
2799
+ var _super = _createSuper(I18n);
2978
2800
  function I18n() {
2979
2801
  var _this;
2980
-
2981
2802
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2982
2803
  var callback = arguments.length > 1 ? arguments[1] : undefined;
2983
-
2984
2804
  _classCallCheck(this, I18n);
2985
-
2986
2805
  _this = _super.call(this);
2987
-
2988
2806
  if (isIE10) {
2989
2807
  EventEmitter.call(_assertThisInitialized(_this));
2990
2808
  }
2991
-
2992
2809
  _this.options = transformOptions(options);
2993
2810
  _this.services = {};
2994
2811
  _this.logger = baseLogger;
@@ -2996,35 +2813,27 @@ var I18n = function (_EventEmitter) {
2996
2813
  external: []
2997
2814
  };
2998
2815
  bindMemberFunctions(_assertThisInitialized(_this));
2999
-
3000
2816
  if (callback && !_this.isInitialized && !options.isClone) {
3001
2817
  if (!_this.options.initImmediate) {
3002
2818
  _this.init(options, callback);
3003
-
3004
2819
  return _possibleConstructorReturn(_this, _assertThisInitialized(_this));
3005
2820
  }
3006
-
3007
2821
  setTimeout(function () {
3008
2822
  _this.init(options, callback);
3009
2823
  }, 0);
3010
2824
  }
3011
-
3012
2825
  return _this;
3013
2826
  }
3014
-
3015
2827
  _createClass(I18n, [{
3016
2828
  key: "init",
3017
2829
  value: function init() {
3018
2830
  var _this2 = this;
3019
-
3020
2831
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
3021
2832
  var callback = arguments.length > 1 ? arguments[1] : undefined;
3022
-
3023
2833
  if (typeof options === 'function') {
3024
2834
  callback = options;
3025
2835
  options = {};
3026
2836
  }
3027
-
3028
2837
  if (!options.defaultNS && options.defaultNS !== false && options.ns) {
3029
2838
  if (typeof options.ns === 'string') {
3030
2839
  options.defaultNS = options.ns;
@@ -3032,43 +2841,34 @@ var I18n = function (_EventEmitter) {
3032
2841
  options.defaultNS = options.ns[0];
3033
2842
  }
3034
2843
  }
3035
-
3036
2844
  var defOpts = get();
3037
- this.options = _objectSpread$6(_objectSpread$6(_objectSpread$6({}, defOpts), this.options), transformOptions(options));
3038
-
2845
+ this.options = _objectSpread(_objectSpread(_objectSpread({}, defOpts), this.options), transformOptions(options));
3039
2846
  if (this.options.compatibilityAPI !== 'v1') {
3040
- this.options.interpolation = _objectSpread$6(_objectSpread$6({}, defOpts.interpolation), this.options.interpolation);
2847
+ this.options.interpolation = _objectSpread(_objectSpread({}, defOpts.interpolation), this.options.interpolation);
3041
2848
  }
3042
-
3043
2849
  if (options.keySeparator !== undefined) {
3044
2850
  this.options.userDefinedKeySeparator = options.keySeparator;
3045
2851
  }
3046
-
3047
2852
  if (options.nsSeparator !== undefined) {
3048
2853
  this.options.userDefinedNsSeparator = options.nsSeparator;
3049
2854
  }
3050
-
3051
2855
  function createClassOnDemand(ClassOrObject) {
3052
2856
  if (!ClassOrObject) return null;
3053
2857
  if (typeof ClassOrObject === 'function') return new ClassOrObject();
3054
2858
  return ClassOrObject;
3055
2859
  }
3056
-
3057
2860
  if (!this.options.isClone) {
3058
2861
  if (this.modules.logger) {
3059
2862
  baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
3060
2863
  } else {
3061
2864
  baseLogger.init(null, this.options);
3062
2865
  }
3063
-
3064
2866
  var formatter;
3065
-
3066
2867
  if (this.modules.formatter) {
3067
2868
  formatter = this.modules.formatter;
3068
2869
  } else if (typeof Intl !== 'undefined') {
3069
2870
  formatter = Formatter;
3070
2871
  }
3071
-
3072
2872
  var lu = new LanguageUtil(this.options);
3073
2873
  this.store = new ResourceStore(this.options.resources, this.options);
3074
2874
  var s = this.services;
@@ -3080,13 +2880,11 @@ var I18n = function (_EventEmitter) {
3080
2880
  compatibilityJSON: this.options.compatibilityJSON,
3081
2881
  simplifyPluralSuffix: this.options.simplifyPluralSuffix
3082
2882
  });
3083
-
3084
2883
  if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
3085
2884
  s.formatter = createClassOnDemand(formatter);
3086
2885
  s.formatter.init(s, this.options);
3087
2886
  this.options.interpolation.format = s.formatter.format.bind(s.formatter);
3088
2887
  }
3089
-
3090
2888
  s.interpolator = new Interpolator(this.options);
3091
2889
  s.utils = {
3092
2890
  hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
@@ -3096,50 +2894,40 @@ var I18n = function (_EventEmitter) {
3096
2894
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
3097
2895
  args[_key - 1] = arguments[_key];
3098
2896
  }
3099
-
3100
2897
  _this2.emit.apply(_this2, [event].concat(args));
3101
2898
  });
3102
-
3103
2899
  if (this.modules.languageDetector) {
3104
2900
  s.languageDetector = createClassOnDemand(this.modules.languageDetector);
3105
- s.languageDetector.init(s, this.options.detection, this.options);
2901
+ if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
3106
2902
  }
3107
-
3108
2903
  if (this.modules.i18nFormat) {
3109
2904
  s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
3110
2905
  if (s.i18nFormat.init) s.i18nFormat.init(this);
3111
2906
  }
3112
-
3113
2907
  this.translator = new Translator(this.services, this.options);
3114
2908
  this.translator.on('*', function (event) {
3115
2909
  for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
3116
2910
  args[_key2 - 1] = arguments[_key2];
3117
2911
  }
3118
-
3119
2912
  _this2.emit.apply(_this2, [event].concat(args));
3120
2913
  });
3121
2914
  this.modules.external.forEach(function (m) {
3122
2915
  if (m.init) m.init(_this2);
3123
2916
  });
3124
2917
  }
3125
-
3126
2918
  this.format = this.options.interpolation.format;
3127
2919
  if (!callback) callback = noop;
3128
-
3129
2920
  if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
3130
2921
  var codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
3131
2922
  if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
3132
2923
  }
3133
-
3134
2924
  if (!this.services.languageDetector && !this.options.lng) {
3135
2925
  this.logger.warn('init: no languageDetector is used and no lng is defined');
3136
2926
  }
3137
-
3138
2927
  var storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
3139
2928
  storeApi.forEach(function (fcName) {
3140
2929
  _this2[fcName] = function () {
3141
2930
  var _this2$store;
3142
-
3143
2931
  return (_this2$store = _this2.store)[fcName].apply(_this2$store, arguments);
3144
2932
  };
3145
2933
  });
@@ -3147,63 +2935,48 @@ var I18n = function (_EventEmitter) {
3147
2935
  storeApiChained.forEach(function (fcName) {
3148
2936
  _this2[fcName] = function () {
3149
2937
  var _this2$store2;
3150
-
3151
2938
  (_this2$store2 = _this2.store)[fcName].apply(_this2$store2, arguments);
3152
-
3153
2939
  return _this2;
3154
2940
  };
3155
2941
  });
3156
2942
  var deferred = defer();
3157
-
3158
2943
  var load = function load() {
3159
2944
  var finish = function finish(err, t) {
3160
2945
  if (_this2.isInitialized && !_this2.initializedStoreOnce) _this2.logger.warn('init: i18next is already initialized. You should call init just once!');
3161
2946
  _this2.isInitialized = true;
3162
2947
  if (!_this2.options.isClone) _this2.logger.log('initialized', _this2.options);
3163
-
3164
2948
  _this2.emit('initialized', _this2.options);
3165
-
3166
2949
  deferred.resolve(t);
3167
2950
  callback(err, t);
3168
2951
  };
3169
-
3170
2952
  if (_this2.languages && _this2.options.compatibilityAPI !== 'v1' && !_this2.isInitialized) return finish(null, _this2.t.bind(_this2));
3171
-
3172
2953
  _this2.changeLanguage(_this2.options.lng, finish);
3173
2954
  };
3174
-
3175
2955
  if (this.options.resources || !this.options.initImmediate) {
3176
2956
  load();
3177
2957
  } else {
3178
2958
  setTimeout(load, 0);
3179
2959
  }
3180
-
3181
2960
  return deferred;
3182
2961
  }
3183
2962
  }, {
3184
2963
  key: "loadResources",
3185
2964
  value: function loadResources(language) {
3186
2965
  var _this3 = this;
3187
-
3188
2966
  var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
3189
2967
  var usedCallback = callback;
3190
2968
  var usedLng = typeof language === 'string' ? language : this.language;
3191
2969
  if (typeof language === 'function') usedCallback = language;
3192
-
3193
2970
  if (!this.options.resources || this.options.partialBundledLanguages) {
3194
2971
  if (usedLng && usedLng.toLowerCase() === 'cimode') return usedCallback();
3195
2972
  var toLoad = [];
3196
-
3197
2973
  var append = function append(lng) {
3198
2974
  if (!lng) return;
3199
-
3200
2975
  var lngs = _this3.services.languageUtils.toResolveHierarchy(lng);
3201
-
3202
2976
  lngs.forEach(function (l) {
3203
2977
  if (toLoad.indexOf(l) < 0) toLoad.push(l);
3204
2978
  });
3205
2979
  };
3206
-
3207
2980
  if (!usedLng) {
3208
2981
  var fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
3209
2982
  fallbacks.forEach(function (l) {
@@ -3212,13 +2985,11 @@ var I18n = function (_EventEmitter) {
3212
2985
  } else {
3213
2986
  append(usedLng);
3214
2987
  }
3215
-
3216
2988
  if (this.options.preload) {
3217
2989
  this.options.preload.forEach(function (l) {
3218
2990
  return append(l);
3219
2991
  });
3220
2992
  }
3221
-
3222
2993
  this.services.backendConnector.load(toLoad, this.options.ns, function (e) {
3223
2994
  if (!e && !_this3.resolvedLanguage && _this3.language) _this3.setResolvedLanguage(_this3.language);
3224
2995
  usedCallback(e);
@@ -3245,35 +3016,27 @@ var I18n = function (_EventEmitter) {
3245
3016
  value: function use(module) {
3246
3017
  if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
3247
3018
  if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
3248
-
3249
3019
  if (module.type === 'backend') {
3250
3020
  this.modules.backend = module;
3251
3021
  }
3252
-
3253
3022
  if (module.type === 'logger' || module.log && module.warn && module.error) {
3254
3023
  this.modules.logger = module;
3255
3024
  }
3256
-
3257
3025
  if (module.type === 'languageDetector') {
3258
3026
  this.modules.languageDetector = module;
3259
3027
  }
3260
-
3261
3028
  if (module.type === 'i18nFormat') {
3262
3029
  this.modules.i18nFormat = module;
3263
3030
  }
3264
-
3265
3031
  if (module.type === 'postProcessor') {
3266
3032
  postProcessor.addPostProcessor(module);
3267
3033
  }
3268
-
3269
3034
  if (module.type === 'formatter') {
3270
3035
  this.modules.formatter = module;
3271
3036
  }
3272
-
3273
3037
  if (module.type === '3rdParty') {
3274
3038
  this.modules.external.push(module);
3275
3039
  }
3276
-
3277
3040
  return this;
3278
3041
  }
3279
3042
  }, {
@@ -3281,11 +3044,9 @@ var I18n = function (_EventEmitter) {
3281
3044
  value: function setResolvedLanguage(l) {
3282
3045
  if (!l || !this.languages) return;
3283
3046
  if (['cimode', 'dev'].indexOf(l) > -1) return;
3284
-
3285
3047
  for (var li = 0; li < this.languages.length; li++) {
3286
3048
  var lngInLngs = this.languages[li];
3287
3049
  if (['cimode', 'dev'].indexOf(lngInLngs) > -1) continue;
3288
-
3289
3050
  if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
3290
3051
  this.resolvedLanguage = lngInLngs;
3291
3052
  break;
@@ -3296,34 +3057,25 @@ var I18n = function (_EventEmitter) {
3296
3057
  key: "changeLanguage",
3297
3058
  value: function changeLanguage(lng, callback) {
3298
3059
  var _this4 = this;
3299
-
3300
3060
  this.isLanguageChangingTo = lng;
3301
3061
  var deferred = defer();
3302
3062
  this.emit('languageChanging', lng);
3303
-
3304
3063
  var setLngProps = function setLngProps(l) {
3305
3064
  _this4.language = l;
3306
3065
  _this4.languages = _this4.services.languageUtils.toResolveHierarchy(l);
3307
3066
  _this4.resolvedLanguage = undefined;
3308
-
3309
3067
  _this4.setResolvedLanguage(l);
3310
3068
  };
3311
-
3312
3069
  var done = function done(err, l) {
3313
3070
  if (l) {
3314
3071
  setLngProps(l);
3315
-
3316
3072
  _this4.translator.changeLanguage(l);
3317
-
3318
3073
  _this4.isLanguageChangingTo = undefined;
3319
-
3320
3074
  _this4.emit('languageChanged', l);
3321
-
3322
3075
  _this4.logger.log('languageChanged', l);
3323
3076
  } else {
3324
3077
  _this4.isLanguageChangingTo = undefined;
3325
3078
  }
3326
-
3327
3079
  deferred.resolve(function () {
3328
3080
  return _this4.t.apply(_this4, arguments);
3329
3081
  });
@@ -3331,68 +3083,67 @@ var I18n = function (_EventEmitter) {
3331
3083
  return _this4.t.apply(_this4, arguments);
3332
3084
  });
3333
3085
  };
3334
-
3335
3086
  var setLng = function setLng(lngs) {
3336
3087
  if (!lng && !lngs && _this4.services.languageDetector) lngs = [];
3337
3088
  var l = typeof lngs === 'string' ? lngs : _this4.services.languageUtils.getBestMatchFromCodes(lngs);
3338
-
3339
3089
  if (l) {
3340
3090
  if (!_this4.language) {
3341
3091
  setLngProps(l);
3342
3092
  }
3343
-
3344
3093
  if (!_this4.translator.language) _this4.translator.changeLanguage(l);
3345
- if (_this4.services.languageDetector) _this4.services.languageDetector.cacheUserLanguage(l);
3094
+ if (_this4.services.languageDetector && _this4.services.languageDetector.cacheUserLanguage) _this4.services.languageDetector.cacheUserLanguage(l);
3346
3095
  }
3347
-
3348
3096
  _this4.loadResources(l, function (err) {
3349
3097
  done(err, l);
3350
3098
  });
3351
3099
  };
3352
-
3353
3100
  if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
3354
3101
  setLng(this.services.languageDetector.detect());
3355
3102
  } else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
3356
- this.services.languageDetector.detect(setLng);
3103
+ if (this.services.languageDetector.detect.length === 0) {
3104
+ this.services.languageDetector.detect().then(setLng);
3105
+ } else {
3106
+ this.services.languageDetector.detect(setLng);
3107
+ }
3357
3108
  } else {
3358
3109
  setLng(lng);
3359
3110
  }
3360
-
3361
3111
  return deferred;
3362
3112
  }
3363
3113
  }, {
3364
3114
  key: "getFixedT",
3365
3115
  value: function getFixedT(lng, ns, keyPrefix) {
3366
3116
  var _this5 = this;
3367
-
3368
3117
  var fixedT = function fixedT(key, opts) {
3369
3118
  var options;
3370
-
3371
3119
  if (_typeof(opts) !== 'object') {
3372
3120
  for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
3373
3121
  rest[_key3 - 2] = arguments[_key3];
3374
3122
  }
3375
-
3376
3123
  options = _this5.options.overloadTranslationOptionHandler([key, opts].concat(rest));
3377
3124
  } else {
3378
- options = _objectSpread$6({}, opts);
3125
+ options = _objectSpread({}, opts);
3379
3126
  }
3380
-
3381
3127
  options.lng = options.lng || fixedT.lng;
3382
3128
  options.lngs = options.lngs || fixedT.lngs;
3383
3129
  options.ns = options.ns || fixedT.ns;
3384
3130
  options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
3385
3131
  var keySeparator = _this5.options.keySeparator || '.';
3386
- var resultKey = options.keyPrefix ? "".concat(options.keyPrefix).concat(keySeparator).concat(key) : key;
3132
+ var resultKey;
3133
+ if (options.keyPrefix && Array.isArray(key)) {
3134
+ resultKey = key.map(function (k) {
3135
+ return "".concat(options.keyPrefix).concat(keySeparator).concat(k);
3136
+ });
3137
+ } else {
3138
+ resultKey = options.keyPrefix ? "".concat(options.keyPrefix).concat(keySeparator).concat(key) : key;
3139
+ }
3387
3140
  return _this5.t(resultKey, options);
3388
3141
  };
3389
-
3390
3142
  if (typeof lng === 'string') {
3391
3143
  fixedT.lng = lng;
3392
3144
  } else {
3393
3145
  fixedT.lngs = lng;
3394
3146
  }
3395
-
3396
3147
  fixedT.ns = ns;
3397
3148
  fixedT.keyPrefix = keyPrefix;
3398
3149
  return fixedT;
@@ -3401,14 +3152,12 @@ var I18n = function (_EventEmitter) {
3401
3152
  key: "t",
3402
3153
  value: function t() {
3403
3154
  var _this$translator;
3404
-
3405
3155
  return this.translator && (_this$translator = this.translator).translate.apply(_this$translator, arguments);
3406
3156
  }
3407
3157
  }, {
3408
3158
  key: "exists",
3409
3159
  value: function exists() {
3410
3160
  var _this$translator2;
3411
-
3412
3161
  return this.translator && (_this$translator2 = this.translator).exists.apply(_this$translator2, arguments);
3413
3162
  }
3414
3163
  }, {
@@ -3420,35 +3169,27 @@ var I18n = function (_EventEmitter) {
3420
3169
  key: "hasLoadedNamespace",
3421
3170
  value: function hasLoadedNamespace(ns) {
3422
3171
  var _this6 = this;
3423
-
3424
3172
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3425
-
3426
3173
  if (!this.isInitialized) {
3427
3174
  this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
3428
3175
  return false;
3429
3176
  }
3430
-
3431
3177
  if (!this.languages || !this.languages.length) {
3432
3178
  this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages);
3433
3179
  return false;
3434
3180
  }
3435
-
3436
3181
  var lng = this.resolvedLanguage || this.languages[0];
3437
3182
  var fallbackLng = this.options ? this.options.fallbackLng : false;
3438
3183
  var lastLng = this.languages[this.languages.length - 1];
3439
3184
  if (lng.toLowerCase() === 'cimode') return true;
3440
-
3441
3185
  var loadNotPending = function loadNotPending(l, n) {
3442
3186
  var loadState = _this6.services.backendConnector.state["".concat(l, "|").concat(n)];
3443
-
3444
3187
  return loadState === -1 || loadState === 2;
3445
3188
  };
3446
-
3447
3189
  if (options.precheck) {
3448
3190
  var preResult = options.precheck(this, loadNotPending);
3449
3191
  if (preResult !== undefined) return preResult;
3450
3192
  }
3451
-
3452
3193
  if (this.hasResourceBundle(lng, ns)) return true;
3453
3194
  if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
3454
3195
  if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
@@ -3458,14 +3199,11 @@ var I18n = function (_EventEmitter) {
3458
3199
  key: "loadNamespaces",
3459
3200
  value: function loadNamespaces(ns, callback) {
3460
3201
  var _this7 = this;
3461
-
3462
3202
  var deferred = defer();
3463
-
3464
3203
  if (!this.options.ns) {
3465
3204
  callback && callback();
3466
3205
  return Promise.resolve();
3467
3206
  }
3468
-
3469
3207
  if (typeof ns === 'string') ns = [ns];
3470
3208
  ns.forEach(function (n) {
3471
3209
  if (_this7.options.ns.indexOf(n) < 0) _this7.options.ns.push(n);
@@ -3485,12 +3223,10 @@ var I18n = function (_EventEmitter) {
3485
3223
  var newLngs = lngs.filter(function (lng) {
3486
3224
  return preloaded.indexOf(lng) < 0;
3487
3225
  });
3488
-
3489
3226
  if (!newLngs.length) {
3490
3227
  if (callback) callback();
3491
3228
  return Promise.resolve();
3492
3229
  }
3493
-
3494
3230
  this.options.preload = preloaded.concat(newLngs);
3495
3231
  this.loadResources(function (err) {
3496
3232
  deferred.resolve();
@@ -3504,26 +3240,27 @@ var I18n = function (_EventEmitter) {
3504
3240
  if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
3505
3241
  if (!lng) return 'rtl';
3506
3242
  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'];
3507
- return rtlLngs.indexOf(this.services.languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
3243
+ var languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
3244
+ return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
3508
3245
  }
3509
3246
  }, {
3510
3247
  key: "cloneInstance",
3511
3248
  value: function cloneInstance() {
3512
3249
  var _this8 = this;
3513
-
3514
3250
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
3515
3251
  var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
3516
-
3517
- var mergedOptions = _objectSpread$6(_objectSpread$6(_objectSpread$6({}, this.options), options), {
3252
+ var mergedOptions = _objectSpread(_objectSpread(_objectSpread({}, this.options), options), {
3518
3253
  isClone: true
3519
3254
  });
3520
-
3521
3255
  var clone = new I18n(mergedOptions);
3256
+ if (options.debug !== undefined || options.prefix !== undefined) {
3257
+ clone.logger = clone.logger.clone(options);
3258
+ }
3522
3259
  var membersToCopy = ['store', 'services', 'language'];
3523
3260
  membersToCopy.forEach(function (m) {
3524
3261
  clone[m] = _this8[m];
3525
3262
  });
3526
- clone.services = _objectSpread$6({}, this.services);
3263
+ clone.services = _objectSpread({}, this.services);
3527
3264
  clone.services.utils = {
3528
3265
  hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
3529
3266
  };
@@ -3532,7 +3269,6 @@ var I18n = function (_EventEmitter) {
3532
3269
  for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
3533
3270
  args[_key4 - 1] = arguments[_key4];
3534
3271
  }
3535
-
3536
3272
  clone.emit.apply(clone, [event].concat(args));
3537
3273
  });
3538
3274
  clone.init(mergedOptions, callback);
@@ -3554,16 +3290,13 @@ var I18n = function (_EventEmitter) {
3554
3290
  };
3555
3291
  }
3556
3292
  }]);
3557
-
3558
3293
  return I18n;
3559
3294
  }(EventEmitter);
3560
-
3561
3295
  _defineProperty(I18n, "createInstance", function () {
3562
3296
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
3563
3297
  var callback = arguments.length > 1 ? arguments[1] : undefined;
3564
3298
  return new I18n(options, callback);
3565
3299
  });
3566
-
3567
3300
  var instance = I18n.createInstance();
3568
3301
  instance.createInstance = I18n.createInstance;
3569
3302
 
@@ -3647,7 +3380,22 @@ function _extends() {
3647
3380
  return _extends.apply(this, arguments);
3648
3381
  }
3649
3382
 
3650
- var LIBRARY_VERSION = '1.2.1';
3383
+ function _objectWithoutPropertiesLoose(source, excluded) {
3384
+ if (source == null) return {};
3385
+ var target = {};
3386
+ var sourceKeys = Object.keys(source);
3387
+ var key, i;
3388
+
3389
+ for (i = 0; i < sourceKeys.length; i++) {
3390
+ key = sourceKeys[i];
3391
+ if (excluded.indexOf(key) >= 0) continue;
3392
+ target[key] = source[key];
3393
+ }
3394
+
3395
+ return target;
3396
+ }
3397
+
3398
+ var LIBRARY_VERSION = '1.2.2';
3651
3399
 
3652
3400
  var QueriesPeriod;
3653
3401
 
@@ -25686,16 +25434,19 @@ return src;
25686
25434
  })));
25687
25435
  });
25688
25436
 
25689
- const defaultDatasetIdKey = 'label';
25437
+ const defaultDatasetIdKey = "label";
25690
25438
  function reforwardRef(ref, value) {
25691
- if (typeof ref === 'function') {
25439
+ if (typeof ref === "function") {
25692
25440
  ref(value);
25693
25441
  } else if (ref) {
25694
25442
  ref.current = value;
25695
25443
  }
25696
25444
  }
25697
25445
  function setOptions(chart, nextOptions) {
25698
- Object.assign(chart.options, nextOptions);
25446
+ const options = chart.options;
25447
+ if (options && nextOptions) {
25448
+ Object.assign(options, nextOptions);
25449
+ }
25699
25450
  }
25700
25451
  function setLabels(currentData, nextLabels) {
25701
25452
  currentData.labels = nextLabels;
@@ -25705,8 +25456,7 @@ function setDatasets(currentData, nextDatasets) {
25705
25456
  const addedDatasets = [];
25706
25457
  currentData.datasets = nextDatasets.map((nextDataset)=>{
25707
25458
  // given the new set, find it's current match
25708
- const currentDataset = currentData.datasets.find((dataset)=>dataset[datasetIdKey] === nextDataset[datasetIdKey]
25709
- );
25459
+ const currentDataset = currentData.datasets.find((dataset)=>dataset[datasetIdKey] === nextDataset[datasetIdKey]);
25710
25460
  // There is no original to update, so simply add new one
25711
25461
  if (!currentDataset || !nextDataset.data || addedDatasets.includes(currentDataset)) {
25712
25462
  return {
@@ -25729,8 +25479,8 @@ function cloneData(data) {
25729
25479
  return nextData;
25730
25480
  }
25731
25481
 
25732
- function ChartComponent(param, ref) {
25733
- let { height =150 , width =300 , redraw =false , datasetIdKey , type , data , options , plugins =[] , fallbackContent , updateMode , ...props } = param;
25482
+ function ChartComponent(props, ref) {
25483
+ const { height =150 , width =300 , redraw =false , datasetIdKey , type , data , options , plugins =[] , fallbackContent , updateMode , ...canvasProps } = props;
25734
25484
  const canvasRef = React.useRef(null);
25735
25485
  const chartRef = React.useRef();
25736
25486
  const renderChart = ()=>{
@@ -25800,15 +25550,14 @@ function ChartComponent(param, ref) {
25800
25550
  ]);
25801
25551
  React.useEffect(()=>{
25802
25552
  renderChart();
25803
- return ()=>destroyChart()
25804
- ;
25553
+ return ()=>destroyChart();
25805
25554
  }, []);
25806
- return(/*#__PURE__*/ React__default["default"].createElement("canvas", Object.assign({
25555
+ return /*#__PURE__*/ React__default["default"].createElement("canvas", Object.assign({
25807
25556
  ref: canvasRef,
25808
25557
  role: "img",
25809
25558
  height: height,
25810
25559
  width: width
25811
- }, props), fallbackContent));
25560
+ }, canvasProps), fallbackContent);
25812
25561
  }
25813
25562
  const Chart = /*#__PURE__*/ React.forwardRef(ChartComponent);
25814
25563
 
@@ -28538,17 +28287,14 @@ var WidgetView = function WidgetView(_ref) {
28538
28287
  }));
28539
28288
  };
28540
28289
 
28290
+ var _excluded = ["url", "token", "lang", "data"];
28291
+
28541
28292
  var Widget = function Widget(_ref) {
28542
- var id = _ref.id,
28543
- url = _ref.url,
28293
+ var url = _ref.url,
28544
28294
  token = _ref.token,
28545
28295
  lang = _ref.lang,
28546
28296
  data = _ref.data,
28547
- settings = _ref.settings,
28548
- editMode = _ref.editMode,
28549
- openSettingsModal = _ref.openSettingsModal,
28550
- onSettingsModalOpened = _ref.onSettingsModalOpened,
28551
- onSettingsModalClosed = _ref.onSettingsModalClosed;
28297
+ widgetProps = _objectWithoutPropertiesLoose(_ref, _excluded);
28552
28298
 
28553
28299
  var _useState = React.useState(),
28554
28300
  graphqlSdk = _useState[0],
@@ -28575,21 +28321,16 @@ var Widget = function Widget(_ref) {
28575
28321
  })["catch"](function () {});
28576
28322
  }
28577
28323
  }, [data, graphqlSdk]);
28578
- return React__default["default"].createElement(andoncloudWidgetBase.BaseWidget, {
28579
- id: id,
28324
+ return React__default["default"].createElement(andoncloudWidgetBase.BaseWidget, _extends({
28580
28325
  url: url,
28581
28326
  token: token,
28582
28327
  lang: lang,
28583
28328
  data: widgetData,
28584
- settings: settings,
28585
- openSettingsModal: openSettingsModal,
28586
- onSettingsModalOpened: onSettingsModalOpened,
28587
- onSettingsModalClosed: onSettingsModalClosed,
28588
- editMode: editMode,
28589
28329
  WidgetView: WidgetView,
28590
28330
  SettingsFormContent: SettingsFormContent,
28591
- version: LIBRARY_VERSION
28592
- });
28331
+ version: LIBRARY_VERSION,
28332
+ "data-testid": "prometheus-widget"
28333
+ }, widgetProps));
28593
28334
  };
28594
28335
 
28595
28336
  var getDisplayName = function getDisplayName(lang) {