@shipengine/alchemy 0.4.14 → 0.4.16

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.
Files changed (3) hide show
  1. package/index.js +85 -2630
  2. package/index.mjs +85 -2630
  3. package/package.json +2 -1
package/index.mjs CHANGED
@@ -6,6 +6,7 @@ import { BrandName, Theme } from '@packlink/brands';
6
6
  import { getEmotionResetStyles, GigerConfigProvider } from '@packlink/giger';
7
7
  import { QueryClient, QueryClientProvider, useMutation, useQuery, useQueryClient } from 'react-query';
8
8
  import { I18nextProvider } from 'react-i18next';
9
+ import i18n from 'i18next';
9
10
 
10
11
  /*
11
12
 
@@ -311,7 +312,7 @@ function node (value, root, parent, type, props, children, length) {
311
312
  * @param {object} props
312
313
  * @return {object}
313
314
  */
314
- function copy$1 (root, props) {
315
+ function copy (root, props) {
315
316
  return assign$1(node('', null, null, '', null, null, 0), root, {length: -root.length}, props)
316
317
  }
317
318
 
@@ -912,20 +913,20 @@ function prefixer$1 (element, index, children, callback) {
912
913
  case DECLARATION: element.return = prefix$1(element.value, element.length, children);
913
914
  return
914
915
  case KEYFRAMES:
915
- return serialize([copy$1(element, {value: replace$1(element.value, '@', '@' + WEBKIT)})], callback)
916
+ return serialize([copy(element, {value: replace$1(element.value, '@', '@' + WEBKIT)})], callback)
916
917
  case RULESET:
917
918
  if (element.length)
918
919
  return combine$1(element.props, function (value) {
919
920
  switch (match(value, /(::plac\w+|:read-\w+)/)) {
920
921
  // :read-(only|write)
921
922
  case ':read-only': case ':read-write':
922
- return serialize([copy$1(element, {props: [replace$1(value, /:(read-\w+)/, ':' + MOZ + '$1')]})], callback)
923
+ return serialize([copy(element, {props: [replace$1(value, /:(read-\w+)/, ':' + MOZ + '$1')]})], callback)
923
924
  // :placeholder
924
925
  case '::placeholder':
925
926
  return serialize([
926
- copy$1(element, {props: [replace$1(value, /:(plac\w+)/, ':' + WEBKIT + 'input-$1')]}),
927
- copy$1(element, {props: [replace$1(value, /:(plac\w+)/, ':' + MOZ + '$1')]}),
928
- copy$1(element, {props: [replace$1(value, /:(plac\w+)/, MS + 'input-$1')]})
927
+ copy(element, {props: [replace$1(value, /:(plac\w+)/, ':' + WEBKIT + 'input-$1')]}),
928
+ copy(element, {props: [replace$1(value, /:(plac\w+)/, ':' + MOZ + '$1')]}),
929
+ copy(element, {props: [replace$1(value, /:(plac\w+)/, MS + 'input-$1')]})
929
930
  ], callback)
930
931
  }
931
932
 
@@ -1357,7 +1358,7 @@ var prefixer = function prefixer(element, index, children, callback) {
1357
1358
  break;
1358
1359
 
1359
1360
  case KEYFRAMES:
1360
- return serialize([copy$1(element, {
1361
+ return serialize([copy(element, {
1361
1362
  value: replace$1(element.value, '@', '@' + WEBKIT)
1362
1363
  })], callback);
1363
1364
 
@@ -1367,17 +1368,17 @@ var prefixer = function prefixer(element, index, children, callback) {
1367
1368
  // :read-(only|write)
1368
1369
  case ':read-only':
1369
1370
  case ':read-write':
1370
- return serialize([copy$1(element, {
1371
+ return serialize([copy(element, {
1371
1372
  props: [replace$1(value, /:(read-\w+)/, ':' + MOZ + '$1')]
1372
1373
  })], callback);
1373
1374
  // :placeholder
1374
1375
 
1375
1376
  case '::placeholder':
1376
- return serialize([copy$1(element, {
1377
+ return serialize([copy(element, {
1377
1378
  props: [replace$1(value, /:(plac\w+)/, ':' + WEBKIT + 'input-$1')]
1378
- }), copy$1(element, {
1379
+ }), copy(element, {
1379
1380
  props: [replace$1(value, /:(plac\w+)/, ':' + MOZ + '$1')]
1380
- }), copy$1(element, {
1381
+ }), copy(element, {
1381
1382
  props: [replace$1(value, /:(plac\w+)/, MS + 'input-$1')]
1382
1383
  })], callback);
1383
1384
  }
@@ -2453,17 +2454,17 @@ Object.defineProperty(dist, "__esModule", { value: true });
2453
2454
  var _default = dist.default = (function () {
2454
2455
  });
2455
2456
 
2456
- var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
2457
- var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
2458
- var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
2457
+ var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
2458
+ var __hasOwnProp$a = Object.prototype.hasOwnProperty;
2459
+ var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
2459
2460
  var __objRest$7 = (source, exclude) => {
2460
2461
  var target = {};
2461
2462
  for (var prop in source)
2462
- if (__hasOwnProp$9.call(source, prop) && exclude.indexOf(prop) < 0)
2463
+ if (__hasOwnProp$a.call(source, prop) && exclude.indexOf(prop) < 0)
2463
2464
  target[prop] = source[prop];
2464
- if (source != null && __getOwnPropSymbols$9)
2465
- for (var prop of __getOwnPropSymbols$9(source)) {
2466
- if (exclude.indexOf(prop) < 0 && __propIsEnum$9.call(source, prop))
2465
+ if (source != null && __getOwnPropSymbols$a)
2466
+ for (var prop of __getOwnPropSymbols$a(source)) {
2467
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$a.call(source, prop))
2467
2468
  target[prop] = source[prop];
2468
2469
  }
2469
2470
  return target;
@@ -5207,21 +5208,21 @@ var ipaddr = {
5207
5208
  const isCodedErrors = (errs) => Array.isArray(errs) && errs.every((err) => isCodedError(err));
5208
5209
  const isCodedError = (err) => !!err.errorCode;
5209
5210
 
5210
- var __defProp$3 = Object.defineProperty;
5211
+ var __defProp$4 = Object.defineProperty;
5211
5212
  var __defProps$2 = Object.defineProperties;
5212
5213
  var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
5213
- var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
5214
- var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
5215
- var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
5216
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5217
- var __spreadValues$3 = (a, b) => {
5214
+ var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
5215
+ var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
5216
+ var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
5217
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5218
+ var __spreadValues$4 = (a, b) => {
5218
5219
  for (var prop in b || (b = {}))
5219
- if (__hasOwnProp$8.call(b, prop))
5220
- __defNormalProp$3(a, prop, b[prop]);
5221
- if (__getOwnPropSymbols$8)
5222
- for (var prop of __getOwnPropSymbols$8(b)) {
5223
- if (__propIsEnum$8.call(b, prop))
5224
- __defNormalProp$3(a, prop, b[prop]);
5220
+ if (__hasOwnProp$9.call(b, prop))
5221
+ __defNormalProp$4(a, prop, b[prop]);
5222
+ if (__getOwnPropSymbols$9)
5223
+ for (var prop of __getOwnPropSymbols$9(b)) {
5224
+ if (__propIsEnum$9.call(b, prop))
5225
+ __defNormalProp$4(a, prop, b[prop]);
5225
5226
  }
5226
5227
  return a;
5227
5228
  };
@@ -5229,16 +5230,16 @@ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
5229
5230
  var __objRest$6 = (source, exclude) => {
5230
5231
  var target = {};
5231
5232
  for (var prop in source)
5232
- if (__hasOwnProp$8.call(source, prop) && exclude.indexOf(prop) < 0)
5233
+ if (__hasOwnProp$9.call(source, prop) && exclude.indexOf(prop) < 0)
5233
5234
  target[prop] = source[prop];
5234
- if (source != null && __getOwnPropSymbols$8)
5235
- for (var prop of __getOwnPropSymbols$8(source)) {
5236
- if (exclude.indexOf(prop) < 0 && __propIsEnum$8.call(source, prop))
5235
+ if (source != null && __getOwnPropSymbols$9)
5236
+ for (var prop of __getOwnPropSymbols$9(source)) {
5237
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$9.call(source, prop))
5237
5238
  target[prop] = source[prop];
5238
5239
  }
5239
5240
  return target;
5240
5241
  };
5241
- var __async$l = (__this, __arguments, generator) => {
5242
+ var __async$m = (__this, __arguments, generator) => {
5242
5243
  return new Promise((resolve, reject) => {
5243
5244
  var fulfilled = (value) => {
5244
5245
  try {
@@ -5258,7 +5259,7 @@ var __async$l = (__this, __arguments, generator) => {
5258
5259
  step((generator = generator.apply(__this, __arguments)).next());
5259
5260
  });
5260
5261
  };
5261
- const getEndUserIpAddress = () => __async$l(void 0, null, function* () {
5262
+ const getEndUserIpAddress = () => __async$m(void 0, null, function* () {
5262
5263
  try {
5263
5264
  const response = yield axios.get("https://api.ipify.org/?format=json");
5264
5265
  if (response.data.ip && ipaddrExports.isValid(response.data.ip)) {
@@ -5278,12 +5279,12 @@ class CarriersAPI {
5278
5279
  this.get = (carrierId) => {
5279
5280
  return this.client.get(`/v1/carriers/${carrierId}`);
5280
5281
  };
5281
- this.connect = (_a) => __async$l(this, null, function* () {
5282
+ this.connect = (_a) => __async$m(this, null, function* () {
5282
5283
  var _b = _a, { carrierCode } = _b, connection = __objRest$6(_b, ["carrierCode"]);
5283
5284
  const endUserIpAddress = yield getEndUserIpAddress();
5284
5285
  if (!endUserIpAddress)
5285
5286
  return Promise.reject([new CodedError("Unable to get IP address")]);
5286
- return yield this.client.post(`/v1/registration/${carrierCode}`, __spreadProps$2(__spreadValues$3({}, connection), {
5287
+ return yield this.client.post(`/v1/registration/${carrierCode}`, __spreadProps$2(__spreadValues$4({}, connection), {
5287
5288
  endUserIpAddress
5288
5289
  }));
5289
5290
  });
@@ -7597,6 +7598,42 @@ class SalesOrdersAPI {
7597
7598
  }
7598
7599
  }
7599
7600
 
7601
+ var __defProp$3 = Object.defineProperty;
7602
+ var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
7603
+ var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
7604
+ var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
7605
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7606
+ var __spreadValues$3 = (a, b) => {
7607
+ for (var prop in b || (b = {}))
7608
+ if (__hasOwnProp$8.call(b, prop))
7609
+ __defNormalProp$3(a, prop, b[prop]);
7610
+ if (__getOwnPropSymbols$8)
7611
+ for (var prop of __getOwnPropSymbols$8(b)) {
7612
+ if (__propIsEnum$8.call(b, prop))
7613
+ __defNormalProp$3(a, prop, b[prop]);
7614
+ }
7615
+ return a;
7616
+ };
7617
+ var __async$l = (__this, __arguments, generator) => {
7618
+ return new Promise((resolve, reject) => {
7619
+ var fulfilled = (value) => {
7620
+ try {
7621
+ step(generator.next(value));
7622
+ } catch (e) {
7623
+ reject(e);
7624
+ }
7625
+ };
7626
+ var rejected = (value) => {
7627
+ try {
7628
+ step(generator.throw(value));
7629
+ } catch (e) {
7630
+ reject(e);
7631
+ }
7632
+ };
7633
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
7634
+ step((generator = generator.apply(__this, __arguments)).next());
7635
+ });
7636
+ };
7600
7637
  class ShipmentsAPI {
7601
7638
  constructor(client) {
7602
7639
  this.client = client;
@@ -7606,6 +7643,9 @@ class ShipmentsAPI {
7606
7643
  createdAtStart !== void 0 ? { params: { createdAtStart } } : void 0
7607
7644
  );
7608
7645
  };
7646
+ this.create = (shipment) => __async$l(this, null, function* () {
7647
+ return this.client.post("/v1/shipments", __spreadValues$3({}, shipment));
7648
+ });
7609
7649
  this.client = client;
7610
7650
  }
7611
7651
  }
@@ -9039,6 +9079,12 @@ class ErrorBoundary extends React.Component {
9039
9079
  }
9040
9080
  }
9041
9081
 
9082
+ function _classCallCheck(instance, Constructor) {
9083
+ if (!(instance instanceof Constructor)) {
9084
+ throw new TypeError("Cannot call a class as a function");
9085
+ }
9086
+ }
9087
+
9042
9088
  function _typeof(obj) {
9043
9089
  "@babel/helpers - typeof";
9044
9090
 
@@ -9049,12 +9095,6 @@ function _typeof(obj) {
9049
9095
  }, _typeof(obj);
9050
9096
  }
9051
9097
 
9052
- function _classCallCheck(instance, Constructor) {
9053
- if (!(instance instanceof Constructor)) {
9054
- throw new TypeError("Cannot call a class as a function");
9055
- }
9056
- }
9057
-
9058
9098
  function _toPrimitive(input, hint) {
9059
9099
  if (_typeof(input) !== "object" || input === null) return input;
9060
9100
  var prim = input[Symbol.toPrimitive];
@@ -9089,2591 +9129,6 @@ function _createClass(Constructor, protoProps, staticProps) {
9089
9129
  return Constructor;
9090
9130
  }
9091
9131
 
9092
- function _assertThisInitialized(self) {
9093
- if (self === void 0) {
9094
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
9095
- }
9096
- return self;
9097
- }
9098
-
9099
- function _setPrototypeOf(o, p) {
9100
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
9101
- o.__proto__ = p;
9102
- return o;
9103
- };
9104
- return _setPrototypeOf(o, p);
9105
- }
9106
-
9107
- function _inherits(subClass, superClass) {
9108
- if (typeof superClass !== "function" && superClass !== null) {
9109
- throw new TypeError("Super expression must either be null or a function");
9110
- }
9111
- subClass.prototype = Object.create(superClass && superClass.prototype, {
9112
- constructor: {
9113
- value: subClass,
9114
- writable: true,
9115
- configurable: true
9116
- }
9117
- });
9118
- Object.defineProperty(subClass, "prototype", {
9119
- writable: false
9120
- });
9121
- if (superClass) _setPrototypeOf(subClass, superClass);
9122
- }
9123
-
9124
- function _possibleConstructorReturn(self, call) {
9125
- if (call && (_typeof(call) === "object" || typeof call === "function")) {
9126
- return call;
9127
- } else if (call !== void 0) {
9128
- throw new TypeError("Derived constructors may only return object or undefined");
9129
- }
9130
- return _assertThisInitialized(self);
9131
- }
9132
-
9133
- function _getPrototypeOf(o) {
9134
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
9135
- return o.__proto__ || Object.getPrototypeOf(o);
9136
- };
9137
- return _getPrototypeOf(o);
9138
- }
9139
-
9140
- function _defineProperty(obj, key, value) {
9141
- key = _toPropertyKey(key);
9142
- if (key in obj) {
9143
- Object.defineProperty(obj, key, {
9144
- value: value,
9145
- enumerable: true,
9146
- configurable: true,
9147
- writable: true
9148
- });
9149
- } else {
9150
- obj[key] = value;
9151
- }
9152
- return obj;
9153
- }
9154
-
9155
- function _arrayWithHoles(arr) {
9156
- if (Array.isArray(arr)) return arr;
9157
- }
9158
-
9159
- function _iterableToArray(iter) {
9160
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
9161
- }
9162
-
9163
- function _arrayLikeToArray(arr, len) {
9164
- if (len == null || len > arr.length) len = arr.length;
9165
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
9166
- return arr2;
9167
- }
9168
-
9169
- function _unsupportedIterableToArray(o, minLen) {
9170
- if (!o) return;
9171
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
9172
- var n = Object.prototype.toString.call(o).slice(8, -1);
9173
- if (n === "Object" && o.constructor) n = o.constructor.name;
9174
- if (n === "Map" || n === "Set") return Array.from(o);
9175
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
9176
- }
9177
-
9178
- function _nonIterableRest() {
9179
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
9180
- }
9181
-
9182
- function _toArray(arr) {
9183
- return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
9184
- }
9185
-
9186
- 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; }
9187
- 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; }
9188
- var consoleLogger = {
9189
- type: 'logger',
9190
- log: function log(args) {
9191
- this.output('log', args);
9192
- },
9193
- warn: function warn(args) {
9194
- this.output('warn', args);
9195
- },
9196
- error: function error(args) {
9197
- this.output('error', args);
9198
- },
9199
- output: function output(type, args) {
9200
- if (console && console[type]) console[type].apply(console, args);
9201
- }
9202
- };
9203
- var Logger = function () {
9204
- function Logger(concreteLogger) {
9205
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
9206
- _classCallCheck(this, Logger);
9207
- this.init(concreteLogger, options);
9208
- }
9209
- _createClass(Logger, [{
9210
- key: "init",
9211
- value: function init(concreteLogger) {
9212
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
9213
- this.prefix = options.prefix || 'i18next:';
9214
- this.logger = concreteLogger || consoleLogger;
9215
- this.options = options;
9216
- this.debug = options.debug;
9217
- }
9218
- }, {
9219
- key: "setDebug",
9220
- value: function setDebug(bool) {
9221
- this.debug = bool;
9222
- }
9223
- }, {
9224
- key: "log",
9225
- value: function log() {
9226
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
9227
- args[_key] = arguments[_key];
9228
- }
9229
- return this.forward(args, 'log', '', true);
9230
- }
9231
- }, {
9232
- key: "warn",
9233
- value: function warn() {
9234
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
9235
- args[_key2] = arguments[_key2];
9236
- }
9237
- return this.forward(args, 'warn', '', true);
9238
- }
9239
- }, {
9240
- key: "error",
9241
- value: function error() {
9242
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
9243
- args[_key3] = arguments[_key3];
9244
- }
9245
- return this.forward(args, 'error', '');
9246
- }
9247
- }, {
9248
- key: "deprecate",
9249
- value: function deprecate() {
9250
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
9251
- args[_key4] = arguments[_key4];
9252
- }
9253
- return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
9254
- }
9255
- }, {
9256
- key: "forward",
9257
- value: function forward(args, lvl, prefix, debugOnly) {
9258
- if (debugOnly && !this.debug) return null;
9259
- if (typeof args[0] === 'string') args[0] = "".concat(prefix).concat(this.prefix, " ").concat(args[0]);
9260
- return this.logger[lvl](args);
9261
- }
9262
- }, {
9263
- key: "create",
9264
- value: function create(moduleName) {
9265
- return new Logger(this.logger, _objectSpread$6(_objectSpread$6({}, {
9266
- prefix: "".concat(this.prefix, ":").concat(moduleName, ":")
9267
- }), this.options));
9268
- }
9269
- }, {
9270
- key: "clone",
9271
- value: function clone(options) {
9272
- options = options || this.options;
9273
- options.prefix = options.prefix || this.prefix;
9274
- return new Logger(this.logger, options);
9275
- }
9276
- }]);
9277
- return Logger;
9278
- }();
9279
- var baseLogger = new Logger();
9280
-
9281
- var EventEmitter = function () {
9282
- function EventEmitter() {
9283
- _classCallCheck(this, EventEmitter);
9284
- this.observers = {};
9285
- }
9286
- _createClass(EventEmitter, [{
9287
- key: "on",
9288
- value: function on(events, listener) {
9289
- var _this = this;
9290
- events.split(' ').forEach(function (event) {
9291
- _this.observers[event] = _this.observers[event] || [];
9292
- _this.observers[event].push(listener);
9293
- });
9294
- return this;
9295
- }
9296
- }, {
9297
- key: "off",
9298
- value: function off(event, listener) {
9299
- if (!this.observers[event]) return;
9300
- if (!listener) {
9301
- delete this.observers[event];
9302
- return;
9303
- }
9304
- this.observers[event] = this.observers[event].filter(function (l) {
9305
- return l !== listener;
9306
- });
9307
- }
9308
- }, {
9309
- key: "emit",
9310
- value: function emit(event) {
9311
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
9312
- args[_key - 1] = arguments[_key];
9313
- }
9314
- if (this.observers[event]) {
9315
- var cloned = [].concat(this.observers[event]);
9316
- cloned.forEach(function (observer) {
9317
- observer.apply(void 0, args);
9318
- });
9319
- }
9320
- if (this.observers['*']) {
9321
- var _cloned = [].concat(this.observers['*']);
9322
- _cloned.forEach(function (observer) {
9323
- observer.apply(observer, [event].concat(args));
9324
- });
9325
- }
9326
- }
9327
- }]);
9328
- return EventEmitter;
9329
- }();
9330
-
9331
- function defer() {
9332
- var res;
9333
- var rej;
9334
- var promise = new Promise(function (resolve, reject) {
9335
- res = resolve;
9336
- rej = reject;
9337
- });
9338
- promise.resolve = res;
9339
- promise.reject = rej;
9340
- return promise;
9341
- }
9342
- function makeString(object) {
9343
- if (object == null) return '';
9344
- return '' + object;
9345
- }
9346
- function copy(a, s, t) {
9347
- a.forEach(function (m) {
9348
- if (s[m]) t[m] = s[m];
9349
- });
9350
- }
9351
- function getLastOfPath(object, path, Empty) {
9352
- function cleanKey(key) {
9353
- return key && key.indexOf('###') > -1 ? key.replace(/###/g, '.') : key;
9354
- }
9355
- function canNotTraverseDeeper() {
9356
- return !object || typeof object === 'string';
9357
- }
9358
- var stack = typeof path !== 'string' ? [].concat(path) : path.split('.');
9359
- while (stack.length > 1) {
9360
- if (canNotTraverseDeeper()) return {};
9361
- var key = cleanKey(stack.shift());
9362
- if (!object[key] && Empty) object[key] = new Empty();
9363
- if (Object.prototype.hasOwnProperty.call(object, key)) {
9364
- object = object[key];
9365
- } else {
9366
- object = {};
9367
- }
9368
- }
9369
- if (canNotTraverseDeeper()) return {};
9370
- return {
9371
- obj: object,
9372
- k: cleanKey(stack.shift())
9373
- };
9374
- }
9375
- function setPath(object, path, newValue) {
9376
- var _getLastOfPath = getLastOfPath(object, path, Object),
9377
- obj = _getLastOfPath.obj,
9378
- k = _getLastOfPath.k;
9379
- obj[k] = newValue;
9380
- }
9381
- function pushPath(object, path, newValue, concat) {
9382
- var _getLastOfPath2 = getLastOfPath(object, path, Object),
9383
- obj = _getLastOfPath2.obj,
9384
- k = _getLastOfPath2.k;
9385
- obj[k] = obj[k] || [];
9386
- if (concat) obj[k] = obj[k].concat(newValue);
9387
- if (!concat) obj[k].push(newValue);
9388
- }
9389
- function getPath(object, path) {
9390
- var _getLastOfPath3 = getLastOfPath(object, path),
9391
- obj = _getLastOfPath3.obj,
9392
- k = _getLastOfPath3.k;
9393
- if (!obj) return undefined;
9394
- return obj[k];
9395
- }
9396
- function getPathWithDefaults(data, defaultData, key) {
9397
- var value = getPath(data, key);
9398
- if (value !== undefined) {
9399
- return value;
9400
- }
9401
- return getPath(defaultData, key);
9402
- }
9403
- function deepExtend(target, source, overwrite) {
9404
- for (var prop in source) {
9405
- if (prop !== '__proto__' && prop !== 'constructor') {
9406
- if (prop in target) {
9407
- if (typeof target[prop] === 'string' || target[prop] instanceof String || typeof source[prop] === 'string' || source[prop] instanceof String) {
9408
- if (overwrite) target[prop] = source[prop];
9409
- } else {
9410
- deepExtend(target[prop], source[prop], overwrite);
9411
- }
9412
- } else {
9413
- target[prop] = source[prop];
9414
- }
9415
- }
9416
- }
9417
- return target;
9418
- }
9419
- function regexEscape(str) {
9420
- return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
9421
- }
9422
- var _entityMap = {
9423
- '&': '&amp;',
9424
- '<': '&lt;',
9425
- '>': '&gt;',
9426
- '"': '&quot;',
9427
- "'": '&#39;',
9428
- '/': '&#x2F;'
9429
- };
9430
- function escape$1(data) {
9431
- if (typeof data === 'string') {
9432
- return data.replace(/[&<>"'\/]/g, function (s) {
9433
- return _entityMap[s];
9434
- });
9435
- }
9436
- return data;
9437
- }
9438
- var isIE10 = typeof window !== 'undefined' && window.navigator && typeof window.navigator.userAgentData === 'undefined' && window.navigator.userAgent && window.navigator.userAgent.indexOf('MSIE') > -1;
9439
- var chars = [' ', ',', '?', '!', ';'];
9440
- function looksLikeObjectPath(key, nsSeparator, keySeparator) {
9441
- nsSeparator = nsSeparator || '';
9442
- keySeparator = keySeparator || '';
9443
- var possibleChars = chars.filter(function (c) {
9444
- return nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0;
9445
- });
9446
- if (possibleChars.length === 0) return true;
9447
- var r = new RegExp("(".concat(possibleChars.map(function (c) {
9448
- return c === '?' ? '\\?' : c;
9449
- }).join('|'), ")"));
9450
- var matched = !r.test(key);
9451
- if (!matched) {
9452
- var ki = key.indexOf(keySeparator);
9453
- if (ki > 0 && !r.test(key.substring(0, ki))) {
9454
- matched = true;
9455
- }
9456
- }
9457
- return matched;
9458
- }
9459
-
9460
- 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; }
9461
- 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; }
9462
- 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); }; }
9463
- 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; } }
9464
- function deepFind(obj, path) {
9465
- var keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
9466
- if (!obj) return undefined;
9467
- if (obj[path]) return obj[path];
9468
- var paths = path.split(keySeparator);
9469
- var current = obj;
9470
- for (var i = 0; i < paths.length; ++i) {
9471
- if (!current) return undefined;
9472
- if (typeof current[paths[i]] === 'string' && i + 1 < paths.length) {
9473
- return undefined;
9474
- }
9475
- if (current[paths[i]] === undefined) {
9476
- var j = 2;
9477
- var p = paths.slice(i, i + j).join(keySeparator);
9478
- var mix = current[p];
9479
- while (mix === undefined && paths.length > i + j) {
9480
- j++;
9481
- p = paths.slice(i, i + j).join(keySeparator);
9482
- mix = current[p];
9483
- }
9484
- if (mix === undefined) return undefined;
9485
- if (mix === null) return null;
9486
- if (path.endsWith(p)) {
9487
- if (typeof mix === 'string') return mix;
9488
- if (p && typeof mix[p] === 'string') return mix[p];
9489
- }
9490
- var joinedPath = paths.slice(i + j).join(keySeparator);
9491
- if (joinedPath) return deepFind(mix, joinedPath, keySeparator);
9492
- return undefined;
9493
- }
9494
- current = current[paths[i]];
9495
- }
9496
- return current;
9497
- }
9498
- var ResourceStore = function (_EventEmitter) {
9499
- _inherits(ResourceStore, _EventEmitter);
9500
- var _super = _createSuper$3(ResourceStore);
9501
- function ResourceStore(data) {
9502
- var _this;
9503
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
9504
- ns: ['translation'],
9505
- defaultNS: 'translation'
9506
- };
9507
- _classCallCheck(this, ResourceStore);
9508
- _this = _super.call(this);
9509
- if (isIE10) {
9510
- EventEmitter.call(_assertThisInitialized(_this));
9511
- }
9512
- _this.data = data || {};
9513
- _this.options = options;
9514
- if (_this.options.keySeparator === undefined) {
9515
- _this.options.keySeparator = '.';
9516
- }
9517
- if (_this.options.ignoreJSONStructure === undefined) {
9518
- _this.options.ignoreJSONStructure = true;
9519
- }
9520
- return _this;
9521
- }
9522
- _createClass(ResourceStore, [{
9523
- key: "addNamespaces",
9524
- value: function addNamespaces(ns) {
9525
- if (this.options.ns.indexOf(ns) < 0) {
9526
- this.options.ns.push(ns);
9527
- }
9528
- }
9529
- }, {
9530
- key: "removeNamespaces",
9531
- value: function removeNamespaces(ns) {
9532
- var index = this.options.ns.indexOf(ns);
9533
- if (index > -1) {
9534
- this.options.ns.splice(index, 1);
9535
- }
9536
- }
9537
- }, {
9538
- key: "getResource",
9539
- value: function getResource(lng, ns, key) {
9540
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
9541
- var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
9542
- var ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
9543
- var path = [lng, ns];
9544
- if (key && typeof key !== 'string') path = path.concat(key);
9545
- if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key);
9546
- if (lng.indexOf('.') > -1) {
9547
- path = lng.split('.');
9548
- }
9549
- var result = getPath(this.data, path);
9550
- if (result || !ignoreJSONStructure || typeof key !== 'string') return result;
9551
- return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
9552
- }
9553
- }, {
9554
- key: "addResource",
9555
- value: function addResource(lng, ns, key, value) {
9556
- var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
9557
- silent: false
9558
- };
9559
- var keySeparator = this.options.keySeparator;
9560
- if (keySeparator === undefined) keySeparator = '.';
9561
- var path = [lng, ns];
9562
- if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
9563
- if (lng.indexOf('.') > -1) {
9564
- path = lng.split('.');
9565
- value = ns;
9566
- ns = path[1];
9567
- }
9568
- this.addNamespaces(ns);
9569
- setPath(this.data, path, value);
9570
- if (!options.silent) this.emit('added', lng, ns, key, value);
9571
- }
9572
- }, {
9573
- key: "addResources",
9574
- value: function addResources(lng, ns, resources) {
9575
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
9576
- silent: false
9577
- };
9578
- for (var m in resources) {
9579
- if (typeof resources[m] === 'string' || Object.prototype.toString.apply(resources[m]) === '[object Array]') this.addResource(lng, ns, m, resources[m], {
9580
- silent: true
9581
- });
9582
- }
9583
- if (!options.silent) this.emit('added', lng, ns, resources);
9584
- }
9585
- }, {
9586
- key: "addResourceBundle",
9587
- value: function addResourceBundle(lng, ns, resources, deep, overwrite) {
9588
- var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
9589
- silent: false
9590
- };
9591
- var path = [lng, ns];
9592
- if (lng.indexOf('.') > -1) {
9593
- path = lng.split('.');
9594
- deep = resources;
9595
- resources = ns;
9596
- ns = path[1];
9597
- }
9598
- this.addNamespaces(ns);
9599
- var pack = getPath(this.data, path) || {};
9600
- if (deep) {
9601
- deepExtend(pack, resources, overwrite);
9602
- } else {
9603
- pack = _objectSpread$5(_objectSpread$5({}, pack), resources);
9604
- }
9605
- setPath(this.data, path, pack);
9606
- if (!options.silent) this.emit('added', lng, ns, resources);
9607
- }
9608
- }, {
9609
- key: "removeResourceBundle",
9610
- value: function removeResourceBundle(lng, ns) {
9611
- if (this.hasResourceBundle(lng, ns)) {
9612
- delete this.data[lng][ns];
9613
- }
9614
- this.removeNamespaces(ns);
9615
- this.emit('removed', lng, ns);
9616
- }
9617
- }, {
9618
- key: "hasResourceBundle",
9619
- value: function hasResourceBundle(lng, ns) {
9620
- return this.getResource(lng, ns) !== undefined;
9621
- }
9622
- }, {
9623
- key: "getResourceBundle",
9624
- value: function getResourceBundle(lng, ns) {
9625
- if (!ns) ns = this.options.defaultNS;
9626
- if (this.options.compatibilityAPI === 'v1') return _objectSpread$5(_objectSpread$5({}, {}), this.getResource(lng, ns));
9627
- return this.getResource(lng, ns);
9628
- }
9629
- }, {
9630
- key: "getDataByLanguage",
9631
- value: function getDataByLanguage(lng) {
9632
- return this.data[lng];
9633
- }
9634
- }, {
9635
- key: "hasLanguageSomeTranslations",
9636
- value: function hasLanguageSomeTranslations(lng) {
9637
- var data = this.getDataByLanguage(lng);
9638
- var n = data && Object.keys(data) || [];
9639
- return !!n.find(function (v) {
9640
- return data[v] && Object.keys(data[v]).length > 0;
9641
- });
9642
- }
9643
- }, {
9644
- key: "toJSON",
9645
- value: function toJSON() {
9646
- return this.data;
9647
- }
9648
- }]);
9649
- return ResourceStore;
9650
- }(EventEmitter);
9651
-
9652
- var postProcessor = {
9653
- processors: {},
9654
- addPostProcessor: function addPostProcessor(module) {
9655
- this.processors[module.name] = module;
9656
- },
9657
- handle: function handle(processors, value, key, options, translator) {
9658
- var _this = this;
9659
- processors.forEach(function (processor) {
9660
- if (_this.processors[processor]) value = _this.processors[processor].process(value, key, options, translator);
9661
- });
9662
- return value;
9663
- }
9664
- };
9665
-
9666
- 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; }
9667
- 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; }
9668
- 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); }; }
9669
- 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; } }
9670
- var checkedLoadedFor = {};
9671
- var Translator = function (_EventEmitter) {
9672
- _inherits(Translator, _EventEmitter);
9673
- var _super = _createSuper$2(Translator);
9674
- function Translator(services) {
9675
- var _this;
9676
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
9677
- _classCallCheck(this, Translator);
9678
- _this = _super.call(this);
9679
- if (isIE10) {
9680
- EventEmitter.call(_assertThisInitialized(_this));
9681
- }
9682
- copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, _assertThisInitialized(_this));
9683
- _this.options = options;
9684
- if (_this.options.keySeparator === undefined) {
9685
- _this.options.keySeparator = '.';
9686
- }
9687
- _this.logger = baseLogger.create('translator');
9688
- return _this;
9689
- }
9690
- _createClass(Translator, [{
9691
- key: "changeLanguage",
9692
- value: function changeLanguage(lng) {
9693
- if (lng) this.language = lng;
9694
- }
9695
- }, {
9696
- key: "exists",
9697
- value: function exists(key) {
9698
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
9699
- interpolation: {}
9700
- };
9701
- if (key === undefined || key === null) {
9702
- return false;
9703
- }
9704
- var resolved = this.resolve(key, options);
9705
- return resolved && resolved.res !== undefined;
9706
- }
9707
- }, {
9708
- key: "extractFromKey",
9709
- value: function extractFromKey(key, options) {
9710
- var nsSeparator = options.nsSeparator !== undefined ? options.nsSeparator : this.options.nsSeparator;
9711
- if (nsSeparator === undefined) nsSeparator = ':';
9712
- var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
9713
- var namespaces = options.ns || this.options.defaultNS || [];
9714
- var wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
9715
- var seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
9716
- if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
9717
- var m = key.match(this.interpolator.nestingRegexp);
9718
- if (m && m.length > 0) {
9719
- return {
9720
- key: key,
9721
- namespaces: namespaces
9722
- };
9723
- }
9724
- var parts = key.split(nsSeparator);
9725
- if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
9726
- key = parts.join(keySeparator);
9727
- }
9728
- if (typeof namespaces === 'string') namespaces = [namespaces];
9729
- return {
9730
- key: key,
9731
- namespaces: namespaces
9732
- };
9733
- }
9734
- }, {
9735
- key: "translate",
9736
- value: function translate(keys, options, lastKey) {
9737
- var _this2 = this;
9738
- if (_typeof(options) !== 'object' && this.options.overloadTranslationOptionHandler) {
9739
- options = this.options.overloadTranslationOptionHandler(arguments);
9740
- }
9741
- if (!options) options = {};
9742
- if (keys === undefined || keys === null) return '';
9743
- if (!Array.isArray(keys)) keys = [String(keys)];
9744
- var returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
9745
- var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
9746
- var _this$extractFromKey = this.extractFromKey(keys[keys.length - 1], options),
9747
- key = _this$extractFromKey.key,
9748
- namespaces = _this$extractFromKey.namespaces;
9749
- var namespace = namespaces[namespaces.length - 1];
9750
- var lng = options.lng || this.language;
9751
- var appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
9752
- if (lng && lng.toLowerCase() === 'cimode') {
9753
- if (appendNamespaceToCIMode) {
9754
- var nsSeparator = options.nsSeparator || this.options.nsSeparator;
9755
- if (returnDetails) {
9756
- return {
9757
- res: "".concat(namespace).concat(nsSeparator).concat(key),
9758
- usedKey: key,
9759
- exactUsedKey: key,
9760
- usedLng: lng,
9761
- usedNS: namespace
9762
- };
9763
- }
9764
- return "".concat(namespace).concat(nsSeparator).concat(key);
9765
- }
9766
- if (returnDetails) {
9767
- return {
9768
- res: key,
9769
- usedKey: key,
9770
- exactUsedKey: key,
9771
- usedLng: lng,
9772
- usedNS: namespace
9773
- };
9774
- }
9775
- return key;
9776
- }
9777
- var resolved = this.resolve(keys, options);
9778
- var res = resolved && resolved.res;
9779
- var resUsedKey = resolved && resolved.usedKey || key;
9780
- var resExactUsedKey = resolved && resolved.exactUsedKey || key;
9781
- var resType = Object.prototype.toString.apply(res);
9782
- var noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
9783
- var joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
9784
- var handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
9785
- var handleAsObject = typeof res !== 'string' && typeof res !== 'boolean' && typeof res !== 'number';
9786
- if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === 'string' && resType === '[object Array]')) {
9787
- if (!options.returnObjects && !this.options.returnObjects) {
9788
- if (!this.options.returnedObjectHandler) {
9789
- this.logger.warn('accessing an object - but returnObjects options is not enabled!');
9790
- }
9791
- var r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, _objectSpread$4(_objectSpread$4({}, options), {}, {
9792
- ns: namespaces
9793
- })) : "key '".concat(key, " (").concat(this.language, ")' returned an object instead of string.");
9794
- if (returnDetails) {
9795
- resolved.res = r;
9796
- return resolved;
9797
- }
9798
- return r;
9799
- }
9800
- if (keySeparator) {
9801
- var resTypeIsArray = resType === '[object Array]';
9802
- var copy = resTypeIsArray ? [] : {};
9803
- var newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
9804
- for (var m in res) {
9805
- if (Object.prototype.hasOwnProperty.call(res, m)) {
9806
- var deepKey = "".concat(newKeyToUse).concat(keySeparator).concat(m);
9807
- copy[m] = this.translate(deepKey, _objectSpread$4(_objectSpread$4({}, options), {
9808
- joinArrays: false,
9809
- ns: namespaces
9810
- }));
9811
- if (copy[m] === deepKey) copy[m] = res[m];
9812
- }
9813
- }
9814
- res = copy;
9815
- }
9816
- } else if (handleAsObjectInI18nFormat && typeof joinArrays === 'string' && resType === '[object Array]') {
9817
- res = res.join(joinArrays);
9818
- if (res) res = this.extendTranslation(res, keys, options, lastKey);
9819
- } else {
9820
- var usedDefault = false;
9821
- var usedKey = false;
9822
- var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
9823
- var hasDefaultValue = Translator.hasDefaultValue(options);
9824
- var defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : '';
9825
- var defaultValue = options["defaultValue".concat(defaultValueSuffix)] || options.defaultValue;
9826
- if (!this.isValidLookup(res) && hasDefaultValue) {
9827
- usedDefault = true;
9828
- res = defaultValue;
9829
- }
9830
- if (!this.isValidLookup(res)) {
9831
- usedKey = true;
9832
- res = key;
9833
- }
9834
- var missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
9835
- var resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
9836
- var updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
9837
- if (usedKey || usedDefault || updateMissing) {
9838
- this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
9839
- if (keySeparator) {
9840
- var fk = this.resolve(key, _objectSpread$4(_objectSpread$4({}, options), {}, {
9841
- keySeparator: false
9842
- }));
9843
- 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.');
9844
- }
9845
- var lngs = [];
9846
- var fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
9847
- if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
9848
- for (var i = 0; i < fallbackLngs.length; i++) {
9849
- lngs.push(fallbackLngs[i]);
9850
- }
9851
- } else if (this.options.saveMissingTo === 'all') {
9852
- lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
9853
- } else {
9854
- lngs.push(options.lng || this.language);
9855
- }
9856
- var send = function send(l, k, specificDefaultValue) {
9857
- var defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
9858
- if (_this2.options.missingKeyHandler) {
9859
- _this2.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
9860
- } else if (_this2.backendConnector && _this2.backendConnector.saveMissing) {
9861
- _this2.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
9862
- }
9863
- _this2.emit('missingKey', l, namespace, k, res);
9864
- };
9865
- if (this.options.saveMissing) {
9866
- if (this.options.saveMissingPlurals && needsPluralHandling) {
9867
- lngs.forEach(function (language) {
9868
- _this2.pluralResolver.getSuffixes(language, options).forEach(function (suffix) {
9869
- send([language], key + suffix, options["defaultValue".concat(suffix)] || defaultValue);
9870
- });
9871
- });
9872
- } else {
9873
- send(lngs, key, defaultValue);
9874
- }
9875
- }
9876
- }
9877
- res = this.extendTranslation(res, keys, options, resolved, lastKey);
9878
- if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = "".concat(namespace, ":").concat(key);
9879
- if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
9880
- if (this.options.compatibilityAPI !== 'v1') {
9881
- res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? "".concat(namespace, ":").concat(key) : key, usedDefault ? res : undefined);
9882
- } else {
9883
- res = this.options.parseMissingKeyHandler(res);
9884
- }
9885
- }
9886
- }
9887
- if (returnDetails) {
9888
- resolved.res = res;
9889
- return resolved;
9890
- }
9891
- return res;
9892
- }
9893
- }, {
9894
- key: "extendTranslation",
9895
- value: function extendTranslation(res, key, options, resolved, lastKey) {
9896
- var _this3 = this;
9897
- if (this.i18nFormat && this.i18nFormat.parse) {
9898
- res = this.i18nFormat.parse(res, _objectSpread$4(_objectSpread$4({}, this.options.interpolation.defaultVariables), options), resolved.usedLng, resolved.usedNS, resolved.usedKey, {
9899
- resolved: resolved
9900
- });
9901
- } else if (!options.skipInterpolation) {
9902
- if (options.interpolation) this.interpolator.init(_objectSpread$4(_objectSpread$4({}, options), {
9903
- interpolation: _objectSpread$4(_objectSpread$4({}, this.options.interpolation), options.interpolation)
9904
- }));
9905
- var skipOnVariables = typeof res === 'string' && (options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
9906
- var nestBef;
9907
- if (skipOnVariables) {
9908
- var nb = res.match(this.interpolator.nestingRegexp);
9909
- nestBef = nb && nb.length;
9910
- }
9911
- var data = options.replace && typeof options.replace !== 'string' ? options.replace : options;
9912
- if (this.options.interpolation.defaultVariables) data = _objectSpread$4(_objectSpread$4({}, this.options.interpolation.defaultVariables), data);
9913
- res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
9914
- if (skipOnVariables) {
9915
- var na = res.match(this.interpolator.nestingRegexp);
9916
- var nestAft = na && na.length;
9917
- if (nestBef < nestAft) options.nest = false;
9918
- }
9919
- if (options.nest !== false) res = this.interpolator.nest(res, function () {
9920
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
9921
- args[_key] = arguments[_key];
9922
- }
9923
- if (lastKey && lastKey[0] === args[0] && !options.context) {
9924
- _this3.logger.warn("It seems you are nesting recursively key: ".concat(args[0], " in key: ").concat(key[0]));
9925
- return null;
9926
- }
9927
- return _this3.translate.apply(_this3, args.concat([key]));
9928
- }, options);
9929
- if (options.interpolation) this.interpolator.reset();
9930
- }
9931
- var postProcess = options.postProcess || this.options.postProcess;
9932
- var postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess;
9933
- if (res !== undefined && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
9934
- res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? _objectSpread$4({
9935
- i18nResolved: resolved
9936
- }, options) : options, this);
9937
- }
9938
- return res;
9939
- }
9940
- }, {
9941
- key: "resolve",
9942
- value: function resolve(keys) {
9943
- var _this4 = this;
9944
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
9945
- var found;
9946
- var usedKey;
9947
- var exactUsedKey;
9948
- var usedLng;
9949
- var usedNS;
9950
- if (typeof keys === 'string') keys = [keys];
9951
- keys.forEach(function (k) {
9952
- if (_this4.isValidLookup(found)) return;
9953
- var extracted = _this4.extractFromKey(k, options);
9954
- var key = extracted.key;
9955
- usedKey = key;
9956
- var namespaces = extracted.namespaces;
9957
- if (_this4.options.fallbackNS) namespaces = namespaces.concat(_this4.options.fallbackNS);
9958
- var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
9959
- var needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && _this4.pluralResolver.shouldUseIntlApi();
9960
- var needsContextHandling = options.context !== undefined && (typeof options.context === 'string' || typeof options.context === 'number') && options.context !== '';
9961
- var codes = options.lngs ? options.lngs : _this4.languageUtils.toResolveHierarchy(options.lng || _this4.language, options.fallbackLng);
9962
- namespaces.forEach(function (ns) {
9963
- if (_this4.isValidLookup(found)) return;
9964
- usedNS = ns;
9965
- if (!checkedLoadedFor["".concat(codes[0], "-").concat(ns)] && _this4.utils && _this4.utils.hasLoadedNamespace && !_this4.utils.hasLoadedNamespace(usedNS)) {
9966
- checkedLoadedFor["".concat(codes[0], "-").concat(ns)] = true;
9967
- _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!!!');
9968
- }
9969
- codes.forEach(function (code) {
9970
- if (_this4.isValidLookup(found)) return;
9971
- usedLng = code;
9972
- var finalKeys = [key];
9973
- if (_this4.i18nFormat && _this4.i18nFormat.addLookupKeys) {
9974
- _this4.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
9975
- } else {
9976
- var pluralSuffix;
9977
- if (needsPluralHandling) pluralSuffix = _this4.pluralResolver.getSuffix(code, options.count, options);
9978
- var zeroSuffix = "".concat(_this4.options.pluralSeparator, "zero");
9979
- if (needsPluralHandling) {
9980
- finalKeys.push(key + pluralSuffix);
9981
- if (needsZeroSuffixLookup) {
9982
- finalKeys.push(key + zeroSuffix);
9983
- }
9984
- }
9985
- if (needsContextHandling) {
9986
- var contextKey = "".concat(key).concat(_this4.options.contextSeparator).concat(options.context);
9987
- finalKeys.push(contextKey);
9988
- if (needsPluralHandling) {
9989
- finalKeys.push(contextKey + pluralSuffix);
9990
- if (needsZeroSuffixLookup) {
9991
- finalKeys.push(contextKey + zeroSuffix);
9992
- }
9993
- }
9994
- }
9995
- }
9996
- var possibleKey;
9997
- while (possibleKey = finalKeys.pop()) {
9998
- if (!_this4.isValidLookup(found)) {
9999
- exactUsedKey = possibleKey;
10000
- found = _this4.getResource(code, ns, possibleKey, options);
10001
- }
10002
- }
10003
- });
10004
- });
10005
- });
10006
- return {
10007
- res: found,
10008
- usedKey: usedKey,
10009
- exactUsedKey: exactUsedKey,
10010
- usedLng: usedLng,
10011
- usedNS: usedNS
10012
- };
10013
- }
10014
- }, {
10015
- key: "isValidLookup",
10016
- value: function isValidLookup(res) {
10017
- return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
10018
- }
10019
- }, {
10020
- key: "getResource",
10021
- value: function getResource(code, ns, key) {
10022
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
10023
- if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
10024
- return this.resourceStore.getResource(code, ns, key, options);
10025
- }
10026
- }], [{
10027
- key: "hasDefaultValue",
10028
- value: function hasDefaultValue(options) {
10029
- var prefix = 'defaultValue';
10030
- for (var option in options) {
10031
- if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
10032
- return true;
10033
- }
10034
- }
10035
- return false;
10036
- }
10037
- }]);
10038
- return Translator;
10039
- }(EventEmitter);
10040
-
10041
- function capitalize(string) {
10042
- return string.charAt(0).toUpperCase() + string.slice(1);
10043
- }
10044
- var LanguageUtil = function () {
10045
- function LanguageUtil(options) {
10046
- _classCallCheck(this, LanguageUtil);
10047
- this.options = options;
10048
- this.supportedLngs = this.options.supportedLngs || false;
10049
- this.logger = baseLogger.create('languageUtils');
10050
- }
10051
- _createClass(LanguageUtil, [{
10052
- key: "getScriptPartFromCode",
10053
- value: function getScriptPartFromCode(code) {
10054
- if (!code || code.indexOf('-') < 0) return null;
10055
- var p = code.split('-');
10056
- if (p.length === 2) return null;
10057
- p.pop();
10058
- if (p[p.length - 1].toLowerCase() === 'x') return null;
10059
- return this.formatLanguageCode(p.join('-'));
10060
- }
10061
- }, {
10062
- key: "getLanguagePartFromCode",
10063
- value: function getLanguagePartFromCode(code) {
10064
- if (!code || code.indexOf('-') < 0) return code;
10065
- var p = code.split('-');
10066
- return this.formatLanguageCode(p[0]);
10067
- }
10068
- }, {
10069
- key: "formatLanguageCode",
10070
- value: function formatLanguageCode(code) {
10071
- if (typeof code === 'string' && code.indexOf('-') > -1) {
10072
- var specialCases = ['hans', 'hant', 'latn', 'cyrl', 'cans', 'mong', 'arab'];
10073
- var p = code.split('-');
10074
- if (this.options.lowerCaseLng) {
10075
- p = p.map(function (part) {
10076
- return part.toLowerCase();
10077
- });
10078
- } else if (p.length === 2) {
10079
- p[0] = p[0].toLowerCase();
10080
- p[1] = p[1].toUpperCase();
10081
- if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
10082
- } else if (p.length === 3) {
10083
- p[0] = p[0].toLowerCase();
10084
- if (p[1].length === 2) p[1] = p[1].toUpperCase();
10085
- if (p[0] !== 'sgn' && p[2].length === 2) p[2] = p[2].toUpperCase();
10086
- if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
10087
- if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
10088
- }
10089
- return p.join('-');
10090
- }
10091
- return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
10092
- }
10093
- }, {
10094
- key: "isSupportedCode",
10095
- value: function isSupportedCode(code) {
10096
- if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
10097
- code = this.getLanguagePartFromCode(code);
10098
- }
10099
- return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
10100
- }
10101
- }, {
10102
- key: "getBestMatchFromCodes",
10103
- value: function getBestMatchFromCodes(codes) {
10104
- var _this = this;
10105
- if (!codes) return null;
10106
- var found;
10107
- codes.forEach(function (code) {
10108
- if (found) return;
10109
- var cleanedLng = _this.formatLanguageCode(code);
10110
- if (!_this.options.supportedLngs || _this.isSupportedCode(cleanedLng)) found = cleanedLng;
10111
- });
10112
- if (!found && this.options.supportedLngs) {
10113
- codes.forEach(function (code) {
10114
- if (found) return;
10115
- var lngOnly = _this.getLanguagePartFromCode(code);
10116
- if (_this.isSupportedCode(lngOnly)) return found = lngOnly;
10117
- found = _this.options.supportedLngs.find(function (supportedLng) {
10118
- if (supportedLng.indexOf(lngOnly) === 0) return supportedLng;
10119
- });
10120
- });
10121
- }
10122
- if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
10123
- return found;
10124
- }
10125
- }, {
10126
- key: "getFallbackCodes",
10127
- value: function getFallbackCodes(fallbacks, code) {
10128
- if (!fallbacks) return [];
10129
- if (typeof fallbacks === 'function') fallbacks = fallbacks(code);
10130
- if (typeof fallbacks === 'string') fallbacks = [fallbacks];
10131
- if (Object.prototype.toString.apply(fallbacks) === '[object Array]') return fallbacks;
10132
- if (!code) return fallbacks["default"] || [];
10133
- var found = fallbacks[code];
10134
- if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
10135
- if (!found) found = fallbacks[this.formatLanguageCode(code)];
10136
- if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
10137
- if (!found) found = fallbacks["default"];
10138
- return found || [];
10139
- }
10140
- }, {
10141
- key: "toResolveHierarchy",
10142
- value: function toResolveHierarchy(code, fallbackCode) {
10143
- var _this2 = this;
10144
- var fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
10145
- var codes = [];
10146
- var addCode = function addCode(c) {
10147
- if (!c) return;
10148
- if (_this2.isSupportedCode(c)) {
10149
- codes.push(c);
10150
- } else {
10151
- _this2.logger.warn("rejecting language code not found in supportedLngs: ".concat(c));
10152
- }
10153
- };
10154
- if (typeof code === 'string' && code.indexOf('-') > -1) {
10155
- if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
10156
- if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
10157
- if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
10158
- } else if (typeof code === 'string') {
10159
- addCode(this.formatLanguageCode(code));
10160
- }
10161
- fallbackCodes.forEach(function (fc) {
10162
- if (codes.indexOf(fc) < 0) addCode(_this2.formatLanguageCode(fc));
10163
- });
10164
- return codes;
10165
- }
10166
- }]);
10167
- return LanguageUtil;
10168
- }();
10169
-
10170
- var sets = [{
10171
- lngs: ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'gun', 'ln', 'mfe', 'mg', 'mi', 'oc', 'pt', 'pt-BR', 'tg', 'tl', 'ti', 'tr', 'uz', 'wa'],
10172
- nr: [1, 2],
10173
- fc: 1
10174
- }, {
10175
- lngs: ['af', 'an', 'ast', 'az', 'bg', 'bn', 'ca', 'da', 'de', 'dev', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fi', 'fo', 'fur', 'fy', 'gl', 'gu', 'ha', 'hi', 'hu', 'hy', 'ia', 'it', 'kk', 'kn', 'ku', 'lb', 'mai', 'ml', 'mn', 'mr', 'nah', 'nap', 'nb', 'ne', 'nl', 'nn', 'no', 'nso', 'pa', 'pap', 'pms', 'ps', 'pt-PT', 'rm', 'sco', 'se', 'si', 'so', 'son', 'sq', 'sv', 'sw', 'ta', 'te', 'tk', 'ur', 'yo'],
10176
- nr: [1, 2],
10177
- fc: 2
10178
- }, {
10179
- lngs: ['ay', 'bo', 'cgg', 'fa', 'ht', 'id', 'ja', 'jbo', 'ka', 'km', 'ko', 'ky', 'lo', 'ms', 'sah', 'su', 'th', 'tt', 'ug', 'vi', 'wo', 'zh'],
10180
- nr: [1],
10181
- fc: 3
10182
- }, {
10183
- lngs: ['be', 'bs', 'cnr', 'dz', 'hr', 'ru', 'sr', 'uk'],
10184
- nr: [1, 2, 5],
10185
- fc: 4
10186
- }, {
10187
- lngs: ['ar'],
10188
- nr: [0, 1, 2, 3, 11, 100],
10189
- fc: 5
10190
- }, {
10191
- lngs: ['cs', 'sk'],
10192
- nr: [1, 2, 5],
10193
- fc: 6
10194
- }, {
10195
- lngs: ['csb', 'pl'],
10196
- nr: [1, 2, 5],
10197
- fc: 7
10198
- }, {
10199
- lngs: ['cy'],
10200
- nr: [1, 2, 3, 8],
10201
- fc: 8
10202
- }, {
10203
- lngs: ['fr'],
10204
- nr: [1, 2],
10205
- fc: 9
10206
- }, {
10207
- lngs: ['ga'],
10208
- nr: [1, 2, 3, 7, 11],
10209
- fc: 10
10210
- }, {
10211
- lngs: ['gd'],
10212
- nr: [1, 2, 3, 20],
10213
- fc: 11
10214
- }, {
10215
- lngs: ['is'],
10216
- nr: [1, 2],
10217
- fc: 12
10218
- }, {
10219
- lngs: ['jv'],
10220
- nr: [0, 1],
10221
- fc: 13
10222
- }, {
10223
- lngs: ['kw'],
10224
- nr: [1, 2, 3, 4],
10225
- fc: 14
10226
- }, {
10227
- lngs: ['lt'],
10228
- nr: [1, 2, 10],
10229
- fc: 15
10230
- }, {
10231
- lngs: ['lv'],
10232
- nr: [1, 2, 0],
10233
- fc: 16
10234
- }, {
10235
- lngs: ['mk'],
10236
- nr: [1, 2],
10237
- fc: 17
10238
- }, {
10239
- lngs: ['mnk'],
10240
- nr: [0, 1, 2],
10241
- fc: 18
10242
- }, {
10243
- lngs: ['mt'],
10244
- nr: [1, 2, 11, 20],
10245
- fc: 19
10246
- }, {
10247
- lngs: ['or'],
10248
- nr: [2, 1],
10249
- fc: 2
10250
- }, {
10251
- lngs: ['ro'],
10252
- nr: [1, 2, 20],
10253
- fc: 20
10254
- }, {
10255
- lngs: ['sl'],
10256
- nr: [5, 1, 2, 3],
10257
- fc: 21
10258
- }, {
10259
- lngs: ['he', 'iw'],
10260
- nr: [1, 2, 20, 21],
10261
- fc: 22
10262
- }];
10263
- var _rulesPluralsTypes = {
10264
- 1: function _(n) {
10265
- return Number(n > 1);
10266
- },
10267
- 2: function _(n) {
10268
- return Number(n != 1);
10269
- },
10270
- 3: function _(n) {
10271
- return 0;
10272
- },
10273
- 4: function _(n) {
10274
- return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
10275
- },
10276
- 5: function _(n) {
10277
- return Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5);
10278
- },
10279
- 6: function _(n) {
10280
- return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2);
10281
- },
10282
- 7: function _(n) {
10283
- return Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
10284
- },
10285
- 8: function _(n) {
10286
- return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3);
10287
- },
10288
- 9: function _(n) {
10289
- return Number(n >= 2);
10290
- },
10291
- 10: function _(n) {
10292
- return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4);
10293
- },
10294
- 11: function _(n) {
10295
- return Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3);
10296
- },
10297
- 12: function _(n) {
10298
- return Number(n % 10 != 1 || n % 100 == 11);
10299
- },
10300
- 13: function _(n) {
10301
- return Number(n !== 0);
10302
- },
10303
- 14: function _(n) {
10304
- return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3);
10305
- },
10306
- 15: function _(n) {
10307
- return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
10308
- },
10309
- 16: function _(n) {
10310
- return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2);
10311
- },
10312
- 17: function _(n) {
10313
- return Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1);
10314
- },
10315
- 18: function _(n) {
10316
- return Number(n == 0 ? 0 : n == 1 ? 1 : 2);
10317
- },
10318
- 19: function _(n) {
10319
- return Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3);
10320
- },
10321
- 20: function _(n) {
10322
- return Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2);
10323
- },
10324
- 21: function _(n) {
10325
- return Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0);
10326
- },
10327
- 22: function _(n) {
10328
- return Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3);
10329
- }
10330
- };
10331
- var deprecatedJsonVersions = ['v1', 'v2', 'v3'];
10332
- var suffixesOrder = {
10333
- zero: 0,
10334
- one: 1,
10335
- two: 2,
10336
- few: 3,
10337
- many: 4,
10338
- other: 5
10339
- };
10340
- function createRules() {
10341
- var rules = {};
10342
- sets.forEach(function (set) {
10343
- set.lngs.forEach(function (l) {
10344
- rules[l] = {
10345
- numbers: set.nr,
10346
- plurals: _rulesPluralsTypes[set.fc]
10347
- };
10348
- });
10349
- });
10350
- return rules;
10351
- }
10352
- var PluralResolver = function () {
10353
- function PluralResolver(languageUtils) {
10354
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10355
- _classCallCheck(this, PluralResolver);
10356
- this.languageUtils = languageUtils;
10357
- this.options = options;
10358
- this.logger = baseLogger.create('pluralResolver');
10359
- if ((!this.options.compatibilityJSON || this.options.compatibilityJSON === 'v4') && (typeof Intl === 'undefined' || !Intl.PluralRules)) {
10360
- this.options.compatibilityJSON = 'v3';
10361
- 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.');
10362
- }
10363
- this.rules = createRules();
10364
- }
10365
- _createClass(PluralResolver, [{
10366
- key: "addRule",
10367
- value: function addRule(lng, obj) {
10368
- this.rules[lng] = obj;
10369
- }
10370
- }, {
10371
- key: "getRule",
10372
- value: function getRule(code) {
10373
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10374
- if (this.shouldUseIntlApi()) {
10375
- try {
10376
- return new Intl.PluralRules(code, {
10377
- type: options.ordinal ? 'ordinal' : 'cardinal'
10378
- });
10379
- } catch (_unused) {
10380
- return;
10381
- }
10382
- }
10383
- return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
10384
- }
10385
- }, {
10386
- key: "needsPlural",
10387
- value: function needsPlural(code) {
10388
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10389
- var rule = this.getRule(code, options);
10390
- if (this.shouldUseIntlApi()) {
10391
- return rule && rule.resolvedOptions().pluralCategories.length > 1;
10392
- }
10393
- return rule && rule.numbers.length > 1;
10394
- }
10395
- }, {
10396
- key: "getPluralFormsOfKey",
10397
- value: function getPluralFormsOfKey(code, key) {
10398
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
10399
- return this.getSuffixes(code, options).map(function (suffix) {
10400
- return "".concat(key).concat(suffix);
10401
- });
10402
- }
10403
- }, {
10404
- key: "getSuffixes",
10405
- value: function getSuffixes(code) {
10406
- var _this = this;
10407
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10408
- var rule = this.getRule(code, options);
10409
- if (!rule) {
10410
- return [];
10411
- }
10412
- if (this.shouldUseIntlApi()) {
10413
- return rule.resolvedOptions().pluralCategories.sort(function (pluralCategory1, pluralCategory2) {
10414
- return suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2];
10415
- }).map(function (pluralCategory) {
10416
- return "".concat(_this.options.prepend).concat(pluralCategory);
10417
- });
10418
- }
10419
- return rule.numbers.map(function (number) {
10420
- return _this.getSuffix(code, number, options);
10421
- });
10422
- }
10423
- }, {
10424
- key: "getSuffix",
10425
- value: function getSuffix(code, count) {
10426
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
10427
- var rule = this.getRule(code, options);
10428
- if (rule) {
10429
- if (this.shouldUseIntlApi()) {
10430
- return "".concat(this.options.prepend).concat(rule.select(count));
10431
- }
10432
- return this.getSuffixRetroCompatible(rule, count);
10433
- }
10434
- this.logger.warn("no plural rule found for: ".concat(code));
10435
- return '';
10436
- }
10437
- }, {
10438
- key: "getSuffixRetroCompatible",
10439
- value: function getSuffixRetroCompatible(rule, count) {
10440
- var _this2 = this;
10441
- var idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
10442
- var suffix = rule.numbers[idx];
10443
- if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
10444
- if (suffix === 2) {
10445
- suffix = 'plural';
10446
- } else if (suffix === 1) {
10447
- suffix = '';
10448
- }
10449
- }
10450
- var returnSuffix = function returnSuffix() {
10451
- return _this2.options.prepend && suffix.toString() ? _this2.options.prepend + suffix.toString() : suffix.toString();
10452
- };
10453
- if (this.options.compatibilityJSON === 'v1') {
10454
- if (suffix === 1) return '';
10455
- if (typeof suffix === 'number') return "_plural_".concat(suffix.toString());
10456
- return returnSuffix();
10457
- } else if (this.options.compatibilityJSON === 'v2') {
10458
- return returnSuffix();
10459
- } else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
10460
- return returnSuffix();
10461
- }
10462
- return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
10463
- }
10464
- }, {
10465
- key: "shouldUseIntlApi",
10466
- value: function shouldUseIntlApi() {
10467
- return !deprecatedJsonVersions.includes(this.options.compatibilityJSON);
10468
- }
10469
- }]);
10470
- return PluralResolver;
10471
- }();
10472
-
10473
- 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; }
10474
- 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; }
10475
- var Interpolator = function () {
10476
- function Interpolator() {
10477
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10478
- _classCallCheck(this, Interpolator);
10479
- this.logger = baseLogger.create('interpolator');
10480
- this.options = options;
10481
- this.format = options.interpolation && options.interpolation.format || function (value) {
10482
- return value;
10483
- };
10484
- this.init(options);
10485
- }
10486
- _createClass(Interpolator, [{
10487
- key: "init",
10488
- value: function init() {
10489
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10490
- if (!options.interpolation) options.interpolation = {
10491
- escapeValue: true
10492
- };
10493
- var iOpts = options.interpolation;
10494
- this.escape = iOpts.escape !== undefined ? iOpts.escape : escape$1;
10495
- this.escapeValue = iOpts.escapeValue !== undefined ? iOpts.escapeValue : true;
10496
- this.useRawValueToEscape = iOpts.useRawValueToEscape !== undefined ? iOpts.useRawValueToEscape : false;
10497
- this.prefix = iOpts.prefix ? regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{';
10498
- this.suffix = iOpts.suffix ? regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}';
10499
- this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
10500
- this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-';
10501
- this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || '';
10502
- this.nestingPrefix = iOpts.nestingPrefix ? regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || regexEscape('$t(');
10503
- this.nestingSuffix = iOpts.nestingSuffix ? regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || regexEscape(')');
10504
- this.nestingOptionsSeparator = iOpts.nestingOptionsSeparator ? iOpts.nestingOptionsSeparator : iOpts.nestingOptionsSeparator || ',';
10505
- this.maxReplaces = iOpts.maxReplaces ? iOpts.maxReplaces : 1000;
10506
- this.alwaysFormat = iOpts.alwaysFormat !== undefined ? iOpts.alwaysFormat : false;
10507
- this.resetRegExp();
10508
- }
10509
- }, {
10510
- key: "reset",
10511
- value: function reset() {
10512
- if (this.options) this.init(this.options);
10513
- }
10514
- }, {
10515
- key: "resetRegExp",
10516
- value: function resetRegExp() {
10517
- var regexpStr = "".concat(this.prefix, "(.+?)").concat(this.suffix);
10518
- this.regexp = new RegExp(regexpStr, 'g');
10519
- var regexpUnescapeStr = "".concat(this.prefix).concat(this.unescapePrefix, "(.+?)").concat(this.unescapeSuffix).concat(this.suffix);
10520
- this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g');
10521
- var nestingRegexpStr = "".concat(this.nestingPrefix, "(.+?)").concat(this.nestingSuffix);
10522
- this.nestingRegexp = new RegExp(nestingRegexpStr, 'g');
10523
- }
10524
- }, {
10525
- key: "interpolate",
10526
- value: function interpolate(str, data, lng, options) {
10527
- var _this = this;
10528
- var match;
10529
- var value;
10530
- var replaces;
10531
- var defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
10532
- function regexSafe(val) {
10533
- return val.replace(/\$/g, '$$$$');
10534
- }
10535
- var handleFormat = function handleFormat(key) {
10536
- if (key.indexOf(_this.formatSeparator) < 0) {
10537
- var path = getPathWithDefaults(data, defaultData, key);
10538
- return _this.alwaysFormat ? _this.format(path, undefined, lng, _objectSpread$3(_objectSpread$3(_objectSpread$3({}, options), data), {}, {
10539
- interpolationkey: key
10540
- })) : path;
10541
- }
10542
- var p = key.split(_this.formatSeparator);
10543
- var k = p.shift().trim();
10544
- var f = p.join(_this.formatSeparator).trim();
10545
- return _this.format(getPathWithDefaults(data, defaultData, k), f, lng, _objectSpread$3(_objectSpread$3(_objectSpread$3({}, options), data), {}, {
10546
- interpolationkey: k
10547
- }));
10548
- };
10549
- this.resetRegExp();
10550
- var missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
10551
- var skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
10552
- var todos = [{
10553
- regex: this.regexpUnescape,
10554
- safeValue: function safeValue(val) {
10555
- return regexSafe(val);
10556
- }
10557
- }, {
10558
- regex: this.regexp,
10559
- safeValue: function safeValue(val) {
10560
- return _this.escapeValue ? regexSafe(_this.escape(val)) : regexSafe(val);
10561
- }
10562
- }];
10563
- todos.forEach(function (todo) {
10564
- replaces = 0;
10565
- while (match = todo.regex.exec(str)) {
10566
- var matchedVar = match[1].trim();
10567
- value = handleFormat(matchedVar);
10568
- if (value === undefined) {
10569
- if (typeof missingInterpolationHandler === 'function') {
10570
- var temp = missingInterpolationHandler(str, match, options);
10571
- value = typeof temp === 'string' ? temp : '';
10572
- } else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
10573
- value = '';
10574
- } else if (skipOnVariables) {
10575
- value = match[0];
10576
- continue;
10577
- } else {
10578
- _this.logger.warn("missed to pass in variable ".concat(matchedVar, " for interpolating ").concat(str));
10579
- value = '';
10580
- }
10581
- } else if (typeof value !== 'string' && !_this.useRawValueToEscape) {
10582
- value = makeString(value);
10583
- }
10584
- var safeValue = todo.safeValue(value);
10585
- str = str.replace(match[0], safeValue);
10586
- if (skipOnVariables) {
10587
- todo.regex.lastIndex += value.length;
10588
- todo.regex.lastIndex -= match[0].length;
10589
- } else {
10590
- todo.regex.lastIndex = 0;
10591
- }
10592
- replaces++;
10593
- if (replaces >= _this.maxReplaces) {
10594
- break;
10595
- }
10596
- }
10597
- });
10598
- return str;
10599
- }
10600
- }, {
10601
- key: "nest",
10602
- value: function nest(str, fc) {
10603
- var _this2 = this;
10604
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
10605
- var match;
10606
- var value;
10607
- var clonedOptions;
10608
- function handleHasOptions(key, inheritedOptions) {
10609
- var sep = this.nestingOptionsSeparator;
10610
- if (key.indexOf(sep) < 0) return key;
10611
- var c = key.split(new RegExp("".concat(sep, "[ ]*{")));
10612
- var optionsString = "{".concat(c[1]);
10613
- key = c[0];
10614
- optionsString = this.interpolate(optionsString, clonedOptions);
10615
- var matchedSingleQuotes = optionsString.match(/'/g);
10616
- var matchedDoubleQuotes = optionsString.match(/"/g);
10617
- if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
10618
- optionsString = optionsString.replace(/'/g, '"');
10619
- }
10620
- try {
10621
- clonedOptions = JSON.parse(optionsString);
10622
- if (inheritedOptions) clonedOptions = _objectSpread$3(_objectSpread$3({}, inheritedOptions), clonedOptions);
10623
- } catch (e) {
10624
- this.logger.warn("failed parsing options string in nesting for key ".concat(key), e);
10625
- return "".concat(key).concat(sep).concat(optionsString);
10626
- }
10627
- delete clonedOptions.defaultValue;
10628
- return key;
10629
- }
10630
- while (match = this.nestingRegexp.exec(str)) {
10631
- var formatters = [];
10632
- clonedOptions = _objectSpread$3({}, options);
10633
- clonedOptions = clonedOptions.replace && typeof clonedOptions.replace !== 'string' ? clonedOptions.replace : clonedOptions;
10634
- clonedOptions.applyPostProcessor = false;
10635
- delete clonedOptions.defaultValue;
10636
- var doReduce = false;
10637
- if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
10638
- var r = match[1].split(this.formatSeparator).map(function (elem) {
10639
- return elem.trim();
10640
- });
10641
- match[1] = r.shift();
10642
- formatters = r;
10643
- doReduce = true;
10644
- }
10645
- value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
10646
- if (value && match[0] === str && typeof value !== 'string') return value;
10647
- if (typeof value !== 'string') value = makeString(value);
10648
- if (!value) {
10649
- this.logger.warn("missed to resolve ".concat(match[1], " for nesting ").concat(str));
10650
- value = '';
10651
- }
10652
- if (doReduce) {
10653
- value = formatters.reduce(function (v, f) {
10654
- return _this2.format(v, f, options.lng, _objectSpread$3(_objectSpread$3({}, options), {}, {
10655
- interpolationkey: match[1].trim()
10656
- }));
10657
- }, value.trim());
10658
- }
10659
- str = str.replace(match[0], value);
10660
- this.regexp.lastIndex = 0;
10661
- }
10662
- return str;
10663
- }
10664
- }]);
10665
- return Interpolator;
10666
- }();
10667
-
10668
- 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; }
10669
- 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; }
10670
- function parseFormatStr(formatStr) {
10671
- var formatName = formatStr.toLowerCase().trim();
10672
- var formatOptions = {};
10673
- if (formatStr.indexOf('(') > -1) {
10674
- var p = formatStr.split('(');
10675
- formatName = p[0].toLowerCase().trim();
10676
- var optStr = p[1].substring(0, p[1].length - 1);
10677
- if (formatName === 'currency' && optStr.indexOf(':') < 0) {
10678
- if (!formatOptions.currency) formatOptions.currency = optStr.trim();
10679
- } else if (formatName === 'relativetime' && optStr.indexOf(':') < 0) {
10680
- if (!formatOptions.range) formatOptions.range = optStr.trim();
10681
- } else {
10682
- var opts = optStr.split(';');
10683
- opts.forEach(function (opt) {
10684
- if (!opt) return;
10685
- var _opt$split = opt.split(':'),
10686
- _opt$split2 = _toArray(_opt$split),
10687
- key = _opt$split2[0],
10688
- rest = _opt$split2.slice(1);
10689
- var val = rest.join(':').trim().replace(/^'+|'+$/g, '');
10690
- if (!formatOptions[key.trim()]) formatOptions[key.trim()] = val;
10691
- if (val === 'false') formatOptions[key.trim()] = false;
10692
- if (val === 'true') formatOptions[key.trim()] = true;
10693
- if (!isNaN(val)) formatOptions[key.trim()] = parseInt(val, 10);
10694
- });
10695
- }
10696
- }
10697
- return {
10698
- formatName: formatName,
10699
- formatOptions: formatOptions
10700
- };
10701
- }
10702
- function createCachedFormatter(fn) {
10703
- var cache = {};
10704
- return function invokeFormatter(val, lng, options) {
10705
- var key = lng + JSON.stringify(options);
10706
- var formatter = cache[key];
10707
- if (!formatter) {
10708
- formatter = fn(lng, options);
10709
- cache[key] = formatter;
10710
- }
10711
- return formatter(val);
10712
- };
10713
- }
10714
- var Formatter = function () {
10715
- function Formatter() {
10716
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10717
- _classCallCheck(this, Formatter);
10718
- this.logger = baseLogger.create('formatter');
10719
- this.options = options;
10720
- this.formats = {
10721
- number: createCachedFormatter(function (lng, opt) {
10722
- var formatter = new Intl.NumberFormat(lng, _objectSpread$2({}, opt));
10723
- return function (val) {
10724
- return formatter.format(val);
10725
- };
10726
- }),
10727
- currency: createCachedFormatter(function (lng, opt) {
10728
- var formatter = new Intl.NumberFormat(lng, _objectSpread$2(_objectSpread$2({}, opt), {}, {
10729
- style: 'currency'
10730
- }));
10731
- return function (val) {
10732
- return formatter.format(val);
10733
- };
10734
- }),
10735
- datetime: createCachedFormatter(function (lng, opt) {
10736
- var formatter = new Intl.DateTimeFormat(lng, _objectSpread$2({}, opt));
10737
- return function (val) {
10738
- return formatter.format(val);
10739
- };
10740
- }),
10741
- relativetime: createCachedFormatter(function (lng, opt) {
10742
- var formatter = new Intl.RelativeTimeFormat(lng, _objectSpread$2({}, opt));
10743
- return function (val) {
10744
- return formatter.format(val, opt.range || 'day');
10745
- };
10746
- }),
10747
- list: createCachedFormatter(function (lng, opt) {
10748
- var formatter = new Intl.ListFormat(lng, _objectSpread$2({}, opt));
10749
- return function (val) {
10750
- return formatter.format(val);
10751
- };
10752
- })
10753
- };
10754
- this.init(options);
10755
- }
10756
- _createClass(Formatter, [{
10757
- key: "init",
10758
- value: function init(services) {
10759
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
10760
- interpolation: {}
10761
- };
10762
- var iOpts = options.interpolation;
10763
- this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
10764
- }
10765
- }, {
10766
- key: "add",
10767
- value: function add(name, fc) {
10768
- this.formats[name.toLowerCase().trim()] = fc;
10769
- }
10770
- }, {
10771
- key: "addCached",
10772
- value: function addCached(name, fc) {
10773
- this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
10774
- }
10775
- }, {
10776
- key: "format",
10777
- value: function format(value, _format, lng) {
10778
- var _this = this;
10779
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
10780
- var formats = _format.split(this.formatSeparator);
10781
- var result = formats.reduce(function (mem, f) {
10782
- var _parseFormatStr = parseFormatStr(f),
10783
- formatName = _parseFormatStr.formatName,
10784
- formatOptions = _parseFormatStr.formatOptions;
10785
- if (_this.formats[formatName]) {
10786
- var formatted = mem;
10787
- try {
10788
- var valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
10789
- var l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
10790
- formatted = _this.formats[formatName](mem, l, _objectSpread$2(_objectSpread$2(_objectSpread$2({}, formatOptions), options), valOptions));
10791
- } catch (error) {
10792
- _this.logger.warn(error);
10793
- }
10794
- return formatted;
10795
- } else {
10796
- _this.logger.warn("there was no format function for ".concat(formatName));
10797
- }
10798
- return mem;
10799
- }, value);
10800
- return result;
10801
- }
10802
- }]);
10803
- return Formatter;
10804
- }();
10805
-
10806
- 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; }
10807
- 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; }
10808
- 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); }; }
10809
- 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; } }
10810
- function removePending(q, name) {
10811
- if (q.pending[name] !== undefined) {
10812
- delete q.pending[name];
10813
- q.pendingCount--;
10814
- }
10815
- }
10816
- var Connector = function (_EventEmitter) {
10817
- _inherits(Connector, _EventEmitter);
10818
- var _super = _createSuper$1(Connector);
10819
- function Connector(backend, store, services) {
10820
- var _this;
10821
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
10822
- _classCallCheck(this, Connector);
10823
- _this = _super.call(this);
10824
- if (isIE10) {
10825
- EventEmitter.call(_assertThisInitialized(_this));
10826
- }
10827
- _this.backend = backend;
10828
- _this.store = store;
10829
- _this.services = services;
10830
- _this.languageUtils = services.languageUtils;
10831
- _this.options = options;
10832
- _this.logger = baseLogger.create('backendConnector');
10833
- _this.waitingReads = [];
10834
- _this.maxParallelReads = options.maxParallelReads || 10;
10835
- _this.readingCalls = 0;
10836
- _this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
10837
- _this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
10838
- _this.state = {};
10839
- _this.queue = [];
10840
- if (_this.backend && _this.backend.init) {
10841
- _this.backend.init(services, options.backend, options);
10842
- }
10843
- return _this;
10844
- }
10845
- _createClass(Connector, [{
10846
- key: "queueLoad",
10847
- value: function queueLoad(languages, namespaces, options, callback) {
10848
- var _this2 = this;
10849
- var toLoad = {};
10850
- var pending = {};
10851
- var toLoadLanguages = {};
10852
- var toLoadNamespaces = {};
10853
- languages.forEach(function (lng) {
10854
- var hasAllNamespaces = true;
10855
- namespaces.forEach(function (ns) {
10856
- var name = "".concat(lng, "|").concat(ns);
10857
- if (!options.reload && _this2.store.hasResourceBundle(lng, ns)) {
10858
- _this2.state[name] = 2;
10859
- } else if (_this2.state[name] < 0) ; else if (_this2.state[name] === 1) {
10860
- if (pending[name] === undefined) pending[name] = true;
10861
- } else {
10862
- _this2.state[name] = 1;
10863
- hasAllNamespaces = false;
10864
- if (pending[name] === undefined) pending[name] = true;
10865
- if (toLoad[name] === undefined) toLoad[name] = true;
10866
- if (toLoadNamespaces[ns] === undefined) toLoadNamespaces[ns] = true;
10867
- }
10868
- });
10869
- if (!hasAllNamespaces) toLoadLanguages[lng] = true;
10870
- });
10871
- if (Object.keys(toLoad).length || Object.keys(pending).length) {
10872
- this.queue.push({
10873
- pending: pending,
10874
- pendingCount: Object.keys(pending).length,
10875
- loaded: {},
10876
- errors: [],
10877
- callback: callback
10878
- });
10879
- }
10880
- return {
10881
- toLoad: Object.keys(toLoad),
10882
- pending: Object.keys(pending),
10883
- toLoadLanguages: Object.keys(toLoadLanguages),
10884
- toLoadNamespaces: Object.keys(toLoadNamespaces)
10885
- };
10886
- }
10887
- }, {
10888
- key: "loaded",
10889
- value: function loaded(name, err, data) {
10890
- var s = name.split('|');
10891
- var lng = s[0];
10892
- var ns = s[1];
10893
- if (err) this.emit('failedLoading', lng, ns, err);
10894
- if (data) {
10895
- this.store.addResourceBundle(lng, ns, data);
10896
- }
10897
- this.state[name] = err ? -1 : 2;
10898
- var loaded = {};
10899
- this.queue.forEach(function (q) {
10900
- pushPath(q.loaded, [lng], ns);
10901
- removePending(q, name);
10902
- if (err) q.errors.push(err);
10903
- if (q.pendingCount === 0 && !q.done) {
10904
- Object.keys(q.loaded).forEach(function (l) {
10905
- if (!loaded[l]) loaded[l] = {};
10906
- var loadedKeys = q.loaded[l];
10907
- if (loadedKeys.length) {
10908
- loadedKeys.forEach(function (n) {
10909
- if (loaded[l][n] === undefined) loaded[l][n] = true;
10910
- });
10911
- }
10912
- });
10913
- q.done = true;
10914
- if (q.errors.length) {
10915
- q.callback(q.errors);
10916
- } else {
10917
- q.callback();
10918
- }
10919
- }
10920
- });
10921
- this.emit('loaded', loaded);
10922
- this.queue = this.queue.filter(function (q) {
10923
- return !q.done;
10924
- });
10925
- }
10926
- }, {
10927
- key: "read",
10928
- value: function read(lng, ns, fcName) {
10929
- var _this3 = this;
10930
- var tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
10931
- var wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
10932
- var callback = arguments.length > 5 ? arguments[5] : undefined;
10933
- if (!lng.length) return callback(null, {});
10934
- if (this.readingCalls >= this.maxParallelReads) {
10935
- this.waitingReads.push({
10936
- lng: lng,
10937
- ns: ns,
10938
- fcName: fcName,
10939
- tried: tried,
10940
- wait: wait,
10941
- callback: callback
10942
- });
10943
- return;
10944
- }
10945
- this.readingCalls++;
10946
- var resolver = function resolver(err, data) {
10947
- _this3.readingCalls--;
10948
- if (_this3.waitingReads.length > 0) {
10949
- var next = _this3.waitingReads.shift();
10950
- _this3.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
10951
- }
10952
- if (err && data && tried < _this3.maxRetries) {
10953
- setTimeout(function () {
10954
- _this3.read.call(_this3, lng, ns, fcName, tried + 1, wait * 2, callback);
10955
- }, wait);
10956
- return;
10957
- }
10958
- callback(err, data);
10959
- };
10960
- var fc = this.backend[fcName].bind(this.backend);
10961
- if (fc.length === 2) {
10962
- try {
10963
- var r = fc(lng, ns);
10964
- if (r && typeof r.then === 'function') {
10965
- r.then(function (data) {
10966
- return resolver(null, data);
10967
- })["catch"](resolver);
10968
- } else {
10969
- resolver(null, r);
10970
- }
10971
- } catch (err) {
10972
- resolver(err);
10973
- }
10974
- return;
10975
- }
10976
- return fc(lng, ns, resolver);
10977
- }
10978
- }, {
10979
- key: "prepareLoading",
10980
- value: function prepareLoading(languages, namespaces) {
10981
- var _this4 = this;
10982
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
10983
- var callback = arguments.length > 3 ? arguments[3] : undefined;
10984
- if (!this.backend) {
10985
- this.logger.warn('No backend was added via i18next.use. Will not load resources.');
10986
- return callback && callback();
10987
- }
10988
- if (typeof languages === 'string') languages = this.languageUtils.toResolveHierarchy(languages);
10989
- if (typeof namespaces === 'string') namespaces = [namespaces];
10990
- var toLoad = this.queueLoad(languages, namespaces, options, callback);
10991
- if (!toLoad.toLoad.length) {
10992
- if (!toLoad.pending.length) callback();
10993
- return null;
10994
- }
10995
- toLoad.toLoad.forEach(function (name) {
10996
- _this4.loadOne(name);
10997
- });
10998
- }
10999
- }, {
11000
- key: "load",
11001
- value: function load(languages, namespaces, callback) {
11002
- this.prepareLoading(languages, namespaces, {}, callback);
11003
- }
11004
- }, {
11005
- key: "reload",
11006
- value: function reload(languages, namespaces, callback) {
11007
- this.prepareLoading(languages, namespaces, {
11008
- reload: true
11009
- }, callback);
11010
- }
11011
- }, {
11012
- key: "loadOne",
11013
- value: function loadOne(name) {
11014
- var _this5 = this;
11015
- var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
11016
- var s = name.split('|');
11017
- var lng = s[0];
11018
- var ns = s[1];
11019
- this.read(lng, ns, 'read', undefined, undefined, function (err, data) {
11020
- if (err) _this5.logger.warn("".concat(prefix, "loading namespace ").concat(ns, " for language ").concat(lng, " failed"), err);
11021
- if (!err && data) _this5.logger.log("".concat(prefix, "loaded namespace ").concat(ns, " for language ").concat(lng), data);
11022
- _this5.loaded(name, err, data);
11023
- });
11024
- }
11025
- }, {
11026
- key: "saveMissing",
11027
- value: function saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
11028
- var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
11029
- var clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : function () {};
11030
- if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
11031
- 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!!!');
11032
- return;
11033
- }
11034
- if (key === undefined || key === null || key === '') return;
11035
- if (this.backend && this.backend.create) {
11036
- var opts = _objectSpread$1(_objectSpread$1({}, options), {}, {
11037
- isUpdate: isUpdate
11038
- });
11039
- var fc = this.backend.create.bind(this.backend);
11040
- if (fc.length < 6) {
11041
- try {
11042
- var r;
11043
- if (fc.length === 5) {
11044
- r = fc(languages, namespace, key, fallbackValue, opts);
11045
- } else {
11046
- r = fc(languages, namespace, key, fallbackValue);
11047
- }
11048
- if (r && typeof r.then === 'function') {
11049
- r.then(function (data) {
11050
- return clb(null, data);
11051
- })["catch"](clb);
11052
- } else {
11053
- clb(null, r);
11054
- }
11055
- } catch (err) {
11056
- clb(err);
11057
- }
11058
- } else {
11059
- fc(languages, namespace, key, fallbackValue, clb, opts);
11060
- }
11061
- }
11062
- if (!languages || !languages[0]) return;
11063
- this.store.addResource(languages[0], namespace, key, fallbackValue);
11064
- }
11065
- }]);
11066
- return Connector;
11067
- }(EventEmitter);
11068
-
11069
- function get() {
11070
- return {
11071
- debug: false,
11072
- initImmediate: true,
11073
- ns: ['translation'],
11074
- defaultNS: ['translation'],
11075
- fallbackLng: ['dev'],
11076
- fallbackNS: false,
11077
- supportedLngs: false,
11078
- nonExplicitSupportedLngs: false,
11079
- load: 'all',
11080
- preload: false,
11081
- simplifyPluralSuffix: true,
11082
- keySeparator: '.',
11083
- nsSeparator: ':',
11084
- pluralSeparator: '_',
11085
- contextSeparator: '_',
11086
- partialBundledLanguages: false,
11087
- saveMissing: false,
11088
- updateMissing: false,
11089
- saveMissingTo: 'fallback',
11090
- saveMissingPlurals: true,
11091
- missingKeyHandler: false,
11092
- missingInterpolationHandler: false,
11093
- postProcess: false,
11094
- postProcessPassResolved: false,
11095
- returnNull: true,
11096
- returnEmptyString: true,
11097
- returnObjects: false,
11098
- joinArrays: false,
11099
- returnedObjectHandler: false,
11100
- parseMissingKeyHandler: false,
11101
- appendNamespaceToMissingKey: false,
11102
- appendNamespaceToCIMode: false,
11103
- overloadTranslationOptionHandler: function handle(args) {
11104
- var ret = {};
11105
- if (_typeof(args[1]) === 'object') ret = args[1];
11106
- if (typeof args[1] === 'string') ret.defaultValue = args[1];
11107
- if (typeof args[2] === 'string') ret.tDescription = args[2];
11108
- if (_typeof(args[2]) === 'object' || _typeof(args[3]) === 'object') {
11109
- var options = args[3] || args[2];
11110
- Object.keys(options).forEach(function (key) {
11111
- ret[key] = options[key];
11112
- });
11113
- }
11114
- return ret;
11115
- },
11116
- interpolation: {
11117
- escapeValue: true,
11118
- format: function format(value, _format, lng, options) {
11119
- return value;
11120
- },
11121
- prefix: '{{',
11122
- suffix: '}}',
11123
- formatSeparator: ',',
11124
- unescapePrefix: '-',
11125
- nestingPrefix: '$t(',
11126
- nestingSuffix: ')',
11127
- nestingOptionsSeparator: ',',
11128
- maxReplaces: 1000,
11129
- skipOnVariables: true
11130
- }
11131
- };
11132
- }
11133
- function transformOptions(options) {
11134
- if (typeof options.ns === 'string') options.ns = [options.ns];
11135
- if (typeof options.fallbackLng === 'string') options.fallbackLng = [options.fallbackLng];
11136
- if (typeof options.fallbackNS === 'string') options.fallbackNS = [options.fallbackNS];
11137
- if (options.supportedLngs && options.supportedLngs.indexOf('cimode') < 0) {
11138
- options.supportedLngs = options.supportedLngs.concat(['cimode']);
11139
- }
11140
- return options;
11141
- }
11142
-
11143
- 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; }
11144
- 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; }
11145
- 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); }; }
11146
- 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; } }
11147
- function noop() {}
11148
- function bindMemberFunctions(inst) {
11149
- var mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
11150
- mems.forEach(function (mem) {
11151
- if (typeof inst[mem] === 'function') {
11152
- inst[mem] = inst[mem].bind(inst);
11153
- }
11154
- });
11155
- }
11156
- var I18n = function (_EventEmitter) {
11157
- _inherits(I18n, _EventEmitter);
11158
- var _super = _createSuper(I18n);
11159
- function I18n() {
11160
- var _this;
11161
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
11162
- var callback = arguments.length > 1 ? arguments[1] : undefined;
11163
- _classCallCheck(this, I18n);
11164
- _this = _super.call(this);
11165
- if (isIE10) {
11166
- EventEmitter.call(_assertThisInitialized(_this));
11167
- }
11168
- _this.options = transformOptions(options);
11169
- _this.services = {};
11170
- _this.logger = baseLogger;
11171
- _this.modules = {
11172
- external: []
11173
- };
11174
- bindMemberFunctions(_assertThisInitialized(_this));
11175
- if (callback && !_this.isInitialized && !options.isClone) {
11176
- if (!_this.options.initImmediate) {
11177
- _this.init(options, callback);
11178
- return _possibleConstructorReturn(_this, _assertThisInitialized(_this));
11179
- }
11180
- setTimeout(function () {
11181
- _this.init(options, callback);
11182
- }, 0);
11183
- }
11184
- return _this;
11185
- }
11186
- _createClass(I18n, [{
11187
- key: "init",
11188
- value: function init() {
11189
- var _this2 = this;
11190
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
11191
- var callback = arguments.length > 1 ? arguments[1] : undefined;
11192
- if (typeof options === 'function') {
11193
- callback = options;
11194
- options = {};
11195
- }
11196
- if (!options.defaultNS && options.defaultNS !== false && options.ns) {
11197
- if (typeof options.ns === 'string') {
11198
- options.defaultNS = options.ns;
11199
- } else if (options.ns.indexOf('translation') < 0) {
11200
- options.defaultNS = options.ns[0];
11201
- }
11202
- }
11203
- var defOpts = get();
11204
- this.options = _objectSpread(_objectSpread(_objectSpread({}, defOpts), this.options), transformOptions(options));
11205
- if (this.options.compatibilityAPI !== 'v1') {
11206
- this.options.interpolation = _objectSpread(_objectSpread({}, defOpts.interpolation), this.options.interpolation);
11207
- }
11208
- if (options.keySeparator !== undefined) {
11209
- this.options.userDefinedKeySeparator = options.keySeparator;
11210
- }
11211
- if (options.nsSeparator !== undefined) {
11212
- this.options.userDefinedNsSeparator = options.nsSeparator;
11213
- }
11214
- function createClassOnDemand(ClassOrObject) {
11215
- if (!ClassOrObject) return null;
11216
- if (typeof ClassOrObject === 'function') return new ClassOrObject();
11217
- return ClassOrObject;
11218
- }
11219
- if (!this.options.isClone) {
11220
- if (this.modules.logger) {
11221
- baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
11222
- } else {
11223
- baseLogger.init(null, this.options);
11224
- }
11225
- var formatter;
11226
- if (this.modules.formatter) {
11227
- formatter = this.modules.formatter;
11228
- } else if (typeof Intl !== 'undefined') {
11229
- formatter = Formatter;
11230
- }
11231
- var lu = new LanguageUtil(this.options);
11232
- this.store = new ResourceStore(this.options.resources, this.options);
11233
- var s = this.services;
11234
- s.logger = baseLogger;
11235
- s.resourceStore = this.store;
11236
- s.languageUtils = lu;
11237
- s.pluralResolver = new PluralResolver(lu, {
11238
- prepend: this.options.pluralSeparator,
11239
- compatibilityJSON: this.options.compatibilityJSON,
11240
- simplifyPluralSuffix: this.options.simplifyPluralSuffix
11241
- });
11242
- if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
11243
- s.formatter = createClassOnDemand(formatter);
11244
- s.formatter.init(s, this.options);
11245
- this.options.interpolation.format = s.formatter.format.bind(s.formatter);
11246
- }
11247
- s.interpolator = new Interpolator(this.options);
11248
- s.utils = {
11249
- hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
11250
- };
11251
- s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
11252
- s.backendConnector.on('*', function (event) {
11253
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
11254
- args[_key - 1] = arguments[_key];
11255
- }
11256
- _this2.emit.apply(_this2, [event].concat(args));
11257
- });
11258
- if (this.modules.languageDetector) {
11259
- s.languageDetector = createClassOnDemand(this.modules.languageDetector);
11260
- if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
11261
- }
11262
- if (this.modules.i18nFormat) {
11263
- s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
11264
- if (s.i18nFormat.init) s.i18nFormat.init(this);
11265
- }
11266
- this.translator = new Translator(this.services, this.options);
11267
- this.translator.on('*', function (event) {
11268
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
11269
- args[_key2 - 1] = arguments[_key2];
11270
- }
11271
- _this2.emit.apply(_this2, [event].concat(args));
11272
- });
11273
- this.modules.external.forEach(function (m) {
11274
- if (m.init) m.init(_this2);
11275
- });
11276
- }
11277
- this.format = this.options.interpolation.format;
11278
- if (!callback) callback = noop;
11279
- if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
11280
- var codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
11281
- if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
11282
- }
11283
- if (!this.services.languageDetector && !this.options.lng) {
11284
- this.logger.warn('init: no languageDetector is used and no lng is defined');
11285
- }
11286
- var storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
11287
- storeApi.forEach(function (fcName) {
11288
- _this2[fcName] = function () {
11289
- var _this2$store;
11290
- return (_this2$store = _this2.store)[fcName].apply(_this2$store, arguments);
11291
- };
11292
- });
11293
- var storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
11294
- storeApiChained.forEach(function (fcName) {
11295
- _this2[fcName] = function () {
11296
- var _this2$store2;
11297
- (_this2$store2 = _this2.store)[fcName].apply(_this2$store2, arguments);
11298
- return _this2;
11299
- };
11300
- });
11301
- var deferred = defer();
11302
- var load = function load() {
11303
- var finish = function finish(err, t) {
11304
- if (_this2.isInitialized && !_this2.initializedStoreOnce) _this2.logger.warn('init: i18next is already initialized. You should call init just once!');
11305
- _this2.isInitialized = true;
11306
- if (!_this2.options.isClone) _this2.logger.log('initialized', _this2.options);
11307
- _this2.emit('initialized', _this2.options);
11308
- deferred.resolve(t);
11309
- callback(err, t);
11310
- };
11311
- if (_this2.languages && _this2.options.compatibilityAPI !== 'v1' && !_this2.isInitialized) return finish(null, _this2.t.bind(_this2));
11312
- _this2.changeLanguage(_this2.options.lng, finish);
11313
- };
11314
- if (this.options.resources || !this.options.initImmediate) {
11315
- load();
11316
- } else {
11317
- setTimeout(load, 0);
11318
- }
11319
- return deferred;
11320
- }
11321
- }, {
11322
- key: "loadResources",
11323
- value: function loadResources(language) {
11324
- var _this3 = this;
11325
- var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
11326
- var usedCallback = callback;
11327
- var usedLng = typeof language === 'string' ? language : this.language;
11328
- if (typeof language === 'function') usedCallback = language;
11329
- if (!this.options.resources || this.options.partialBundledLanguages) {
11330
- if (usedLng && usedLng.toLowerCase() === 'cimode') return usedCallback();
11331
- var toLoad = [];
11332
- var append = function append(lng) {
11333
- if (!lng) return;
11334
- var lngs = _this3.services.languageUtils.toResolveHierarchy(lng);
11335
- lngs.forEach(function (l) {
11336
- if (toLoad.indexOf(l) < 0) toLoad.push(l);
11337
- });
11338
- };
11339
- if (!usedLng) {
11340
- var fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
11341
- fallbacks.forEach(function (l) {
11342
- return append(l);
11343
- });
11344
- } else {
11345
- append(usedLng);
11346
- }
11347
- if (this.options.preload) {
11348
- this.options.preload.forEach(function (l) {
11349
- return append(l);
11350
- });
11351
- }
11352
- this.services.backendConnector.load(toLoad, this.options.ns, function (e) {
11353
- if (!e && !_this3.resolvedLanguage && _this3.language) _this3.setResolvedLanguage(_this3.language);
11354
- usedCallback(e);
11355
- });
11356
- } else {
11357
- usedCallback(null);
11358
- }
11359
- }
11360
- }, {
11361
- key: "reloadResources",
11362
- value: function reloadResources(lngs, ns, callback) {
11363
- var deferred = defer();
11364
- if (!lngs) lngs = this.languages;
11365
- if (!ns) ns = this.options.ns;
11366
- if (!callback) callback = noop;
11367
- this.services.backendConnector.reload(lngs, ns, function (err) {
11368
- deferred.resolve();
11369
- callback(err);
11370
- });
11371
- return deferred;
11372
- }
11373
- }, {
11374
- key: "use",
11375
- value: function use(module) {
11376
- if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
11377
- if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
11378
- if (module.type === 'backend') {
11379
- this.modules.backend = module;
11380
- }
11381
- if (module.type === 'logger' || module.log && module.warn && module.error) {
11382
- this.modules.logger = module;
11383
- }
11384
- if (module.type === 'languageDetector') {
11385
- this.modules.languageDetector = module;
11386
- }
11387
- if (module.type === 'i18nFormat') {
11388
- this.modules.i18nFormat = module;
11389
- }
11390
- if (module.type === 'postProcessor') {
11391
- postProcessor.addPostProcessor(module);
11392
- }
11393
- if (module.type === 'formatter') {
11394
- this.modules.formatter = module;
11395
- }
11396
- if (module.type === '3rdParty') {
11397
- this.modules.external.push(module);
11398
- }
11399
- return this;
11400
- }
11401
- }, {
11402
- key: "setResolvedLanguage",
11403
- value: function setResolvedLanguage(l) {
11404
- if (!l || !this.languages) return;
11405
- if (['cimode', 'dev'].indexOf(l) > -1) return;
11406
- for (var li = 0; li < this.languages.length; li++) {
11407
- var lngInLngs = this.languages[li];
11408
- if (['cimode', 'dev'].indexOf(lngInLngs) > -1) continue;
11409
- if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
11410
- this.resolvedLanguage = lngInLngs;
11411
- break;
11412
- }
11413
- }
11414
- }
11415
- }, {
11416
- key: "changeLanguage",
11417
- value: function changeLanguage(lng, callback) {
11418
- var _this4 = this;
11419
- this.isLanguageChangingTo = lng;
11420
- var deferred = defer();
11421
- this.emit('languageChanging', lng);
11422
- var setLngProps = function setLngProps(l) {
11423
- _this4.language = l;
11424
- _this4.languages = _this4.services.languageUtils.toResolveHierarchy(l);
11425
- _this4.resolvedLanguage = undefined;
11426
- _this4.setResolvedLanguage(l);
11427
- };
11428
- var done = function done(err, l) {
11429
- if (l) {
11430
- setLngProps(l);
11431
- _this4.translator.changeLanguage(l);
11432
- _this4.isLanguageChangingTo = undefined;
11433
- _this4.emit('languageChanged', l);
11434
- _this4.logger.log('languageChanged', l);
11435
- } else {
11436
- _this4.isLanguageChangingTo = undefined;
11437
- }
11438
- deferred.resolve(function () {
11439
- return _this4.t.apply(_this4, arguments);
11440
- });
11441
- if (callback) callback(err, function () {
11442
- return _this4.t.apply(_this4, arguments);
11443
- });
11444
- };
11445
- var setLng = function setLng(lngs) {
11446
- if (!lng && !lngs && _this4.services.languageDetector) lngs = [];
11447
- var l = typeof lngs === 'string' ? lngs : _this4.services.languageUtils.getBestMatchFromCodes(lngs);
11448
- if (l) {
11449
- if (!_this4.language) {
11450
- setLngProps(l);
11451
- }
11452
- if (!_this4.translator.language) _this4.translator.changeLanguage(l);
11453
- if (_this4.services.languageDetector && _this4.services.languageDetector.cacheUserLanguage) _this4.services.languageDetector.cacheUserLanguage(l);
11454
- }
11455
- _this4.loadResources(l, function (err) {
11456
- done(err, l);
11457
- });
11458
- };
11459
- if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
11460
- setLng(this.services.languageDetector.detect());
11461
- } else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
11462
- if (this.services.languageDetector.detect.length === 0) {
11463
- this.services.languageDetector.detect().then(setLng);
11464
- } else {
11465
- this.services.languageDetector.detect(setLng);
11466
- }
11467
- } else {
11468
- setLng(lng);
11469
- }
11470
- return deferred;
11471
- }
11472
- }, {
11473
- key: "getFixedT",
11474
- value: function getFixedT(lng, ns, keyPrefix) {
11475
- var _this5 = this;
11476
- var fixedT = function fixedT(key, opts) {
11477
- var options;
11478
- if (_typeof(opts) !== 'object') {
11479
- for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
11480
- rest[_key3 - 2] = arguments[_key3];
11481
- }
11482
- options = _this5.options.overloadTranslationOptionHandler([key, opts].concat(rest));
11483
- } else {
11484
- options = _objectSpread({}, opts);
11485
- }
11486
- options.lng = options.lng || fixedT.lng;
11487
- options.lngs = options.lngs || fixedT.lngs;
11488
- options.ns = options.ns || fixedT.ns;
11489
- options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
11490
- var keySeparator = _this5.options.keySeparator || '.';
11491
- var resultKey;
11492
- if (options.keyPrefix && Array.isArray(key)) {
11493
- resultKey = key.map(function (k) {
11494
- return "".concat(options.keyPrefix).concat(keySeparator).concat(k);
11495
- });
11496
- } else {
11497
- resultKey = options.keyPrefix ? "".concat(options.keyPrefix).concat(keySeparator).concat(key) : key;
11498
- }
11499
- return _this5.t(resultKey, options);
11500
- };
11501
- if (typeof lng === 'string') {
11502
- fixedT.lng = lng;
11503
- } else {
11504
- fixedT.lngs = lng;
11505
- }
11506
- fixedT.ns = ns;
11507
- fixedT.keyPrefix = keyPrefix;
11508
- return fixedT;
11509
- }
11510
- }, {
11511
- key: "t",
11512
- value: function t() {
11513
- var _this$translator;
11514
- return this.translator && (_this$translator = this.translator).translate.apply(_this$translator, arguments);
11515
- }
11516
- }, {
11517
- key: "exists",
11518
- value: function exists() {
11519
- var _this$translator2;
11520
- return this.translator && (_this$translator2 = this.translator).exists.apply(_this$translator2, arguments);
11521
- }
11522
- }, {
11523
- key: "setDefaultNamespace",
11524
- value: function setDefaultNamespace(ns) {
11525
- this.options.defaultNS = ns;
11526
- }
11527
- }, {
11528
- key: "hasLoadedNamespace",
11529
- value: function hasLoadedNamespace(ns) {
11530
- var _this6 = this;
11531
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
11532
- if (!this.isInitialized) {
11533
- this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
11534
- return false;
11535
- }
11536
- if (!this.languages || !this.languages.length) {
11537
- this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages);
11538
- return false;
11539
- }
11540
- var lng = this.resolvedLanguage || this.languages[0];
11541
- var fallbackLng = this.options ? this.options.fallbackLng : false;
11542
- var lastLng = this.languages[this.languages.length - 1];
11543
- if (lng.toLowerCase() === 'cimode') return true;
11544
- var loadNotPending = function loadNotPending(l, n) {
11545
- var loadState = _this6.services.backendConnector.state["".concat(l, "|").concat(n)];
11546
- return loadState === -1 || loadState === 2;
11547
- };
11548
- if (options.precheck) {
11549
- var preResult = options.precheck(this, loadNotPending);
11550
- if (preResult !== undefined) return preResult;
11551
- }
11552
- if (this.hasResourceBundle(lng, ns)) return true;
11553
- if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
11554
- if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
11555
- return false;
11556
- }
11557
- }, {
11558
- key: "loadNamespaces",
11559
- value: function loadNamespaces(ns, callback) {
11560
- var _this7 = this;
11561
- var deferred = defer();
11562
- if (!this.options.ns) {
11563
- if (callback) callback();
11564
- return Promise.resolve();
11565
- }
11566
- if (typeof ns === 'string') ns = [ns];
11567
- ns.forEach(function (n) {
11568
- if (_this7.options.ns.indexOf(n) < 0) _this7.options.ns.push(n);
11569
- });
11570
- this.loadResources(function (err) {
11571
- deferred.resolve();
11572
- if (callback) callback(err);
11573
- });
11574
- return deferred;
11575
- }
11576
- }, {
11577
- key: "loadLanguages",
11578
- value: function loadLanguages(lngs, callback) {
11579
- var deferred = defer();
11580
- if (typeof lngs === 'string') lngs = [lngs];
11581
- var preloaded = this.options.preload || [];
11582
- var newLngs = lngs.filter(function (lng) {
11583
- return preloaded.indexOf(lng) < 0;
11584
- });
11585
- if (!newLngs.length) {
11586
- if (callback) callback();
11587
- return Promise.resolve();
11588
- }
11589
- this.options.preload = preloaded.concat(newLngs);
11590
- this.loadResources(function (err) {
11591
- deferred.resolve();
11592
- if (callback) callback(err);
11593
- });
11594
- return deferred;
11595
- }
11596
- }, {
11597
- key: "dir",
11598
- value: function dir(lng) {
11599
- if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
11600
- if (!lng) return 'rtl';
11601
- 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'];
11602
- var languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
11603
- return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
11604
- }
11605
- }, {
11606
- key: "cloneInstance",
11607
- value: function cloneInstance() {
11608
- var _this8 = this;
11609
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
11610
- var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
11611
- var mergedOptions = _objectSpread(_objectSpread(_objectSpread({}, this.options), options), {
11612
- isClone: true
11613
- });
11614
- var clone = new I18n(mergedOptions);
11615
- if (options.debug !== undefined || options.prefix !== undefined) {
11616
- clone.logger = clone.logger.clone(options);
11617
- }
11618
- var membersToCopy = ['store', 'services', 'language'];
11619
- membersToCopy.forEach(function (m) {
11620
- clone[m] = _this8[m];
11621
- });
11622
- clone.services = _objectSpread({}, this.services);
11623
- clone.services.utils = {
11624
- hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
11625
- };
11626
- clone.translator = new Translator(clone.services, clone.options);
11627
- clone.translator.on('*', function (event) {
11628
- for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
11629
- args[_key4 - 1] = arguments[_key4];
11630
- }
11631
- clone.emit.apply(clone, [event].concat(args));
11632
- });
11633
- clone.init(mergedOptions, callback);
11634
- clone.translator.options = clone.options;
11635
- clone.translator.backendConnector.services.utils = {
11636
- hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
11637
- };
11638
- return clone;
11639
- }
11640
- }, {
11641
- key: "toJSON",
11642
- value: function toJSON() {
11643
- return {
11644
- options: this.options,
11645
- store: this.store,
11646
- language: this.language,
11647
- languages: this.languages,
11648
- resolvedLanguage: this.resolvedLanguage
11649
- };
11650
- }
11651
- }]);
11652
- return I18n;
11653
- }(EventEmitter);
11654
- _defineProperty(I18n, "createInstance", function () {
11655
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
11656
- var callback = arguments.length > 1 ? arguments[1] : undefined;
11657
- return new I18n(options, callback);
11658
- });
11659
- var instance = I18n.createInstance();
11660
- instance.createInstance = I18n.createInstance;
11661
-
11662
- instance.createInstance;
11663
- instance.dir;
11664
- instance.init;
11665
- instance.loadResources;
11666
- instance.reloadResources;
11667
- instance.use;
11668
- instance.changeLanguage;
11669
- instance.getFixedT;
11670
- instance.t;
11671
- instance.exists;
11672
- instance.setDefaultNamespace;
11673
- instance.hasLoadedNamespace;
11674
- instance.loadNamespaces;
11675
- instance.loadLanguages;
11676
-
11677
9132
  var arr = [];
11678
9133
  var each = arr.forEach;
11679
9134
  var slice = arr.slice;
@@ -12025,7 +9480,7 @@ Browser.type = 'languageDetector';
12025
9480
 
12026
9481
  const useI18n = ({ resources }) => {
12027
9482
  return useMemo(() => {
12028
- return instance.createInstance(
9483
+ return i18n.createInstance(
12029
9484
  {
12030
9485
  defaultNS: "common",
12031
9486
  fallbackLng: "en",