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