stream-engine-widgets 0.3.23 → 0.3.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{blaze-CFK3LEal.js → blaze-CKjlj6PD.js} +72 -15
- package/dist/{blaze-CFK3LEal.js.map → blaze-CKjlj6PD.js.map} +1 -1
- package/dist/getPrototypeOf-a55cCBEE.js +32 -0
- package/dist/getPrototypeOf-a55cCBEE.js.map +1 -0
- package/dist/{story-Cpvsn3p0.js → story-CUXTTEzQ.js} +2 -31
- package/dist/story-CUXTTEzQ.js.map +1 -0
- package/dist/stream-engine-widgets.css +3 -0
- package/dist/stream-engine-widgets.js +2454 -1872
- package/dist/stream-engine-widgets.js.map +1 -1
- package/package.json +1 -1
- package/dist/story-Cpvsn3p0.js.map +0 -1
|
@@ -3,6 +3,7 @@ import { r as reactDomExports } from './index-BsDK2hqc.js';
|
|
|
3
3
|
import { g as getDefaultExportFromCjs } from './index-DxAI6Tai.js';
|
|
4
4
|
import { P as Player } from './player-static--rFjcMT2.js';
|
|
5
5
|
import { L as Loader } from './loader-C6xf7J_T.js';
|
|
6
|
+
import { _ as _assertThisInitialized, a as _inherits, b as _getPrototypeOf } from './getPrototypeOf-a55cCBEE.js';
|
|
6
7
|
|
|
7
8
|
function _mergeNamespaces(n, m) {
|
|
8
9
|
for (var i = 0; i < m.length; i++) {
|
|
@@ -989,8 +990,59 @@ const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
|
|
|
989
990
|
});
|
|
990
991
|
};
|
|
991
992
|
|
|
992
|
-
|
|
993
|
-
|
|
993
|
+
function _typeof(o) {
|
|
994
|
+
"@babel/helpers - typeof";
|
|
995
|
+
|
|
996
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
997
|
+
return typeof o;
|
|
998
|
+
} : function (o) {
|
|
999
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
1000
|
+
}, _typeof(o);
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
function toPrimitive(t, r) {
|
|
1004
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
1005
|
+
var e = t[Symbol.toPrimitive];
|
|
1006
|
+
if (void 0 !== e) {
|
|
1007
|
+
var i = e.call(t, r);
|
|
1008
|
+
if ("object" != _typeof(i)) return i;
|
|
1009
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1010
|
+
}
|
|
1011
|
+
return ("string" === r ? String : Number)(t);
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
function toPropertyKey(t) {
|
|
1015
|
+
var i = toPrimitive(t, "string");
|
|
1016
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
function _defineProperty(e, r, t) {
|
|
1020
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
1021
|
+
value: t,
|
|
1022
|
+
enumerable: true,
|
|
1023
|
+
configurable: true,
|
|
1024
|
+
writable: true
|
|
1025
|
+
}) : e[r] = t, e;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
function _classCallCheck(a, n) {
|
|
1029
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
function _defineProperties(e, r) {
|
|
1033
|
+
for (var t = 0; t < r.length; t++) {
|
|
1034
|
+
var o = r[t];
|
|
1035
|
+
o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, toPropertyKey(o.key), o);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
function _createClass(e, r, t) {
|
|
1039
|
+
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
1040
|
+
writable: false
|
|
1041
|
+
}), e;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
var matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
|
|
1045
|
+
var htmlEntities = {
|
|
994
1046
|
'&': '&',
|
|
995
1047
|
'&': '&',
|
|
996
1048
|
'<': '<',
|
|
@@ -1012,10 +1064,21 @@ const htmlEntities = {
|
|
|
1012
1064
|
'/': '/',
|
|
1013
1065
|
'/': '/'
|
|
1014
1066
|
};
|
|
1015
|
-
const unescapeHtmlEntity = m => htmlEntities[m];
|
|
1016
|
-
const unescape = text => text.replace(matchHtmlEntity, unescapeHtmlEntity);
|
|
1017
1067
|
|
|
1018
|
-
|
|
1068
|
+
var unescapeHtmlEntity = function unescapeHtmlEntity(m) {
|
|
1069
|
+
return htmlEntities[m];
|
|
1070
|
+
};
|
|
1071
|
+
|
|
1072
|
+
var unescape = function unescape(text) {
|
|
1073
|
+
return text.replace(matchHtmlEntity, unescapeHtmlEntity);
|
|
1074
|
+
};
|
|
1075
|
+
|
|
1076
|
+
function ownKeys$7(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
1077
|
+
|
|
1078
|
+
function _objectSpread$7(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$7(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$7(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
1079
|
+
|
|
1080
|
+
const {createContext} = await importShared('react');
|
|
1081
|
+
var defaultOptions = {
|
|
1019
1082
|
bindI18n: 'languageChanged',
|
|
1020
1083
|
bindI18nStore: '',
|
|
1021
1084
|
transEmptyNodeValue: '',
|
|
@@ -1023,163 +1086,268 @@ let defaultOptions = {
|
|
|
1023
1086
|
transWrapTextNodes: '',
|
|
1024
1087
|
transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
|
|
1025
1088
|
useSuspense: true,
|
|
1026
|
-
unescape
|
|
1027
|
-
};
|
|
1028
|
-
const setDefaults = function () {
|
|
1029
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1030
|
-
defaultOptions = {
|
|
1031
|
-
...defaultOptions,
|
|
1032
|
-
...options
|
|
1033
|
-
};
|
|
1089
|
+
unescape: unescape
|
|
1034
1090
|
};
|
|
1091
|
+
var I18nContext = createContext();
|
|
1092
|
+
function setDefaults() {
|
|
1093
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1094
|
+
defaultOptions = _objectSpread$7(_objectSpread$7({}, defaultOptions), options);
|
|
1095
|
+
}
|
|
1096
|
+
(function () {
|
|
1097
|
+
function ReportNamespaces() {
|
|
1098
|
+
_classCallCheck(this, ReportNamespaces);
|
|
1099
|
+
|
|
1100
|
+
this.usedNamespaces = {};
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
_createClass(ReportNamespaces, [{
|
|
1104
|
+
key: "addUsedNamespaces",
|
|
1105
|
+
value: function addUsedNamespaces(namespaces) {
|
|
1106
|
+
var _this = this;
|
|
1107
|
+
|
|
1108
|
+
namespaces.forEach(function (ns) {
|
|
1109
|
+
if (!_this.usedNamespaces[ns]) _this.usedNamespaces[ns] = true;
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
}, {
|
|
1113
|
+
key: "getUsedNamespaces",
|
|
1114
|
+
value: function getUsedNamespaces() {
|
|
1115
|
+
return Object.keys(this.usedNamespaces);
|
|
1116
|
+
}
|
|
1117
|
+
}]);
|
|
1035
1118
|
|
|
1036
|
-
|
|
1119
|
+
return ReportNamespaces;
|
|
1120
|
+
})();
|
|
1121
|
+
var initReactI18next = {
|
|
1037
1122
|
type: '3rdParty',
|
|
1038
|
-
init(instance) {
|
|
1123
|
+
init: function init(instance) {
|
|
1039
1124
|
setDefaults(instance.options.react);
|
|
1040
1125
|
}
|
|
1041
1126
|
};
|
|
1042
1127
|
|
|
1043
|
-
|
|
1044
|
-
|
|
1128
|
+
function _arrayWithHoles(r) {
|
|
1129
|
+
if (Array.isArray(r)) return r;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
function _arrayLikeToArray(r, a) {
|
|
1133
|
+
(null == a || a > r.length) && (a = r.length);
|
|
1134
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
1135
|
+
return n;
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
function _unsupportedIterableToArray(r, a) {
|
|
1139
|
+
if (r) {
|
|
1140
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
1141
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
1142
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
function _nonIterableRest() {
|
|
1147
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1148
|
+
}
|
|
1045
1149
|
|
|
1046
|
-
const {createElement,useMemo} = await importShared('react');
|
|
1150
|
+
const {createElement,useMemo: useMemo$1} = await importShared('react');
|
|
1047
1151
|
function I18nextProvider(_ref) {
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
}
|
|
1152
|
+
var i18n = _ref.i18n,
|
|
1153
|
+
defaultNS = _ref.defaultNS,
|
|
1154
|
+
children = _ref.children;
|
|
1155
|
+
var value = useMemo$1(function () {
|
|
1156
|
+
return {
|
|
1157
|
+
i18n: i18n,
|
|
1158
|
+
defaultNS: defaultNS
|
|
1159
|
+
};
|
|
1160
|
+
}, [i18n, defaultNS]);
|
|
1057
1161
|
return createElement(I18nContext.Provider, {
|
|
1058
|
-
value
|
|
1162
|
+
value: value
|
|
1059
1163
|
}, children);
|
|
1060
1164
|
}
|
|
1061
1165
|
|
|
1062
|
-
|
|
1166
|
+
function _possibleConstructorReturn(t, e) {
|
|
1167
|
+
if (e && ("object" == _typeof(e) || "function" == typeof e)) return e;
|
|
1168
|
+
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
|
|
1169
|
+
return _assertThisInitialized(t);
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
function _iterableToArray(r) {
|
|
1173
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
function _toArray(r) {
|
|
1177
|
+
return _arrayWithHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableRest();
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
1181
|
+
|
|
1182
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
1183
|
+
|
|
1184
|
+
var consoleLogger = {
|
|
1063
1185
|
type: 'logger',
|
|
1064
|
-
log(args) {
|
|
1186
|
+
log: function log(args) {
|
|
1065
1187
|
this.output('log', args);
|
|
1066
1188
|
},
|
|
1067
|
-
warn(args) {
|
|
1189
|
+
warn: function warn(args) {
|
|
1068
1190
|
this.output('warn', args);
|
|
1069
1191
|
},
|
|
1070
|
-
error(args) {
|
|
1192
|
+
error: function error(args) {
|
|
1071
1193
|
this.output('error', args);
|
|
1072
1194
|
},
|
|
1073
|
-
output(type, args) {
|
|
1195
|
+
output: function output(type, args) {
|
|
1074
1196
|
if (console && console[type]) console[type].apply(console, args);
|
|
1075
1197
|
}
|
|
1076
1198
|
};
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1199
|
+
|
|
1200
|
+
var Logger = function () {
|
|
1201
|
+
function Logger(concreteLogger) {
|
|
1202
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1203
|
+
|
|
1204
|
+
_classCallCheck(this, Logger);
|
|
1205
|
+
|
|
1080
1206
|
this.init(concreteLogger, options);
|
|
1081
1207
|
}
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1208
|
+
|
|
1209
|
+
_createClass(Logger, [{
|
|
1210
|
+
key: "init",
|
|
1211
|
+
value: function init(concreteLogger) {
|
|
1212
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1213
|
+
this.prefix = options.prefix || 'i18next:';
|
|
1214
|
+
this.logger = concreteLogger || consoleLogger;
|
|
1215
|
+
this.options = options;
|
|
1216
|
+
this.debug = options.debug;
|
|
1217
|
+
}
|
|
1218
|
+
}, {
|
|
1219
|
+
key: "setDebug",
|
|
1220
|
+
value: function setDebug(bool) {
|
|
1221
|
+
this.debug = bool;
|
|
1222
|
+
}
|
|
1223
|
+
}, {
|
|
1224
|
+
key: "log",
|
|
1225
|
+
value: function log() {
|
|
1226
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1227
|
+
args[_key] = arguments[_key];
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
return this.forward(args, 'log', '', true);
|
|
1098
1231
|
}
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1232
|
+
}, {
|
|
1233
|
+
key: "warn",
|
|
1234
|
+
value: function warn() {
|
|
1235
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1236
|
+
args[_key2] = arguments[_key2];
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
return this.forward(args, 'warn', '', true);
|
|
1104
1240
|
}
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1241
|
+
}, {
|
|
1242
|
+
key: "error",
|
|
1243
|
+
value: function error() {
|
|
1244
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
1245
|
+
args[_key3] = arguments[_key3];
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
return this.forward(args, 'error', '');
|
|
1110
1249
|
}
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1250
|
+
}, {
|
|
1251
|
+
key: "deprecate",
|
|
1252
|
+
value: function deprecate() {
|
|
1253
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
1254
|
+
args[_key4] = arguments[_key4];
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
|
|
1258
|
+
}
|
|
1259
|
+
}, {
|
|
1260
|
+
key: "forward",
|
|
1261
|
+
value: function forward(args, lvl, prefix, debugOnly) {
|
|
1262
|
+
if (debugOnly && !this.debug) return null;
|
|
1263
|
+
if (typeof args[0] === 'string') args[0] = "".concat(prefix).concat(this.prefix, " ").concat(args[0]);
|
|
1264
|
+
return this.logger[lvl](args);
|
|
1265
|
+
}
|
|
1266
|
+
}, {
|
|
1267
|
+
key: "create",
|
|
1268
|
+
value: function create(moduleName) {
|
|
1269
|
+
return new Logger(this.logger, _objectSpread(_objectSpread({}, {
|
|
1270
|
+
prefix: "".concat(this.prefix, ":").concat(moduleName, ":")
|
|
1271
|
+
}), this.options));
|
|
1272
|
+
}
|
|
1273
|
+
}, {
|
|
1274
|
+
key: "clone",
|
|
1275
|
+
value: function clone(options) {
|
|
1276
|
+
options = options || this.options;
|
|
1277
|
+
options.prefix = options.prefix || this.prefix;
|
|
1278
|
+
return new Logger(this.logger, options);
|
|
1279
|
+
}
|
|
1280
|
+
}]);
|
|
1281
|
+
|
|
1282
|
+
return Logger;
|
|
1283
|
+
}();
|
|
1284
|
+
|
|
1132
1285
|
var baseLogger = new Logger();
|
|
1133
1286
|
|
|
1134
|
-
|
|
1135
|
-
|
|
1287
|
+
var EventEmitter = function () {
|
|
1288
|
+
function EventEmitter() {
|
|
1289
|
+
_classCallCheck(this, EventEmitter);
|
|
1290
|
+
|
|
1136
1291
|
this.observers = {};
|
|
1137
1292
|
}
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
if (!listener) {
|
|
1149
|
-
delete this.observers[event];
|
|
1150
|
-
return;
|
|
1151
|
-
}
|
|
1152
|
-
this.observers[event].delete(listener);
|
|
1153
|
-
}
|
|
1154
|
-
emit(event) {
|
|
1155
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1156
|
-
args[_key - 1] = arguments[_key];
|
|
1157
|
-
}
|
|
1158
|
-
if (this.observers[event]) {
|
|
1159
|
-
const cloned = Array.from(this.observers[event].entries());
|
|
1160
|
-
cloned.forEach(_ref => {
|
|
1161
|
-
let [observer, numTimesAdded] = _ref;
|
|
1162
|
-
for (let i = 0; i < numTimesAdded; i++) {
|
|
1163
|
-
observer(...args);
|
|
1164
|
-
}
|
|
1293
|
+
|
|
1294
|
+
_createClass(EventEmitter, [{
|
|
1295
|
+
key: "on",
|
|
1296
|
+
value: function on(events, listener) {
|
|
1297
|
+
var _this = this;
|
|
1298
|
+
|
|
1299
|
+
events.split(' ').forEach(function (event) {
|
|
1300
|
+
_this.observers[event] = _this.observers[event] || [];
|
|
1301
|
+
|
|
1302
|
+
_this.observers[event].push(listener);
|
|
1165
1303
|
});
|
|
1304
|
+
return this;
|
|
1166
1305
|
}
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1306
|
+
}, {
|
|
1307
|
+
key: "off",
|
|
1308
|
+
value: function off(event, listener) {
|
|
1309
|
+
if (!this.observers[event]) return;
|
|
1310
|
+
|
|
1311
|
+
if (!listener) {
|
|
1312
|
+
delete this.observers[event];
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
this.observers[event] = this.observers[event].filter(function (l) {
|
|
1317
|
+
return l !== listener;
|
|
1174
1318
|
});
|
|
1175
1319
|
}
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1320
|
+
}, {
|
|
1321
|
+
key: "emit",
|
|
1322
|
+
value: function emit(event) {
|
|
1323
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1324
|
+
args[_key - 1] = arguments[_key];
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
if (this.observers[event]) {
|
|
1328
|
+
var cloned = [].concat(this.observers[event]);
|
|
1329
|
+
cloned.forEach(function (observer) {
|
|
1330
|
+
observer.apply(void 0, args);
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
if (this.observers['*']) {
|
|
1335
|
+
var _cloned = [].concat(this.observers['*']);
|
|
1336
|
+
|
|
1337
|
+
_cloned.forEach(function (observer) {
|
|
1338
|
+
observer.apply(observer, [event].concat(args));
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
}]);
|
|
1343
|
+
|
|
1344
|
+
return EventEmitter;
|
|
1345
|
+
}();
|
|
1178
1346
|
|
|
1179
1347
|
function defer() {
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1348
|
+
var res;
|
|
1349
|
+
var rej;
|
|
1350
|
+
var promise = new Promise(function (resolve, reject) {
|
|
1183
1351
|
res = resolve;
|
|
1184
1352
|
rej = reject;
|
|
1185
1353
|
});
|
|
@@ -1192,84 +1360,75 @@ function makeString(object) {
|
|
|
1192
1360
|
return '' + object;
|
|
1193
1361
|
}
|
|
1194
1362
|
function copy(a, s, t) {
|
|
1195
|
-
a.forEach(m
|
|
1363
|
+
a.forEach(function (m) {
|
|
1196
1364
|
if (s[m]) t[m] = s[m];
|
|
1197
1365
|
});
|
|
1198
1366
|
}
|
|
1199
|
-
|
|
1367
|
+
|
|
1200
1368
|
function getLastOfPath(object, path, Empty) {
|
|
1201
1369
|
function cleanKey(key) {
|
|
1202
|
-
return key && key.indexOf('###') > -1 ? key.replace(
|
|
1370
|
+
return key && key.indexOf('###') > -1 ? key.replace(/###/g, '.') : key;
|
|
1203
1371
|
}
|
|
1372
|
+
|
|
1204
1373
|
function canNotTraverseDeeper() {
|
|
1205
1374
|
return !object || typeof object === 'string';
|
|
1206
1375
|
}
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1376
|
+
|
|
1377
|
+
var stack = typeof path !== 'string' ? [].concat(path) : path.split('.');
|
|
1378
|
+
|
|
1379
|
+
while (stack.length > 1) {
|
|
1210
1380
|
if (canNotTraverseDeeper()) return {};
|
|
1211
|
-
|
|
1381
|
+
var key = cleanKey(stack.shift());
|
|
1212
1382
|
if (!object[key] && Empty) object[key] = new Empty();
|
|
1383
|
+
|
|
1213
1384
|
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
1214
1385
|
object = object[key];
|
|
1215
1386
|
} else {
|
|
1216
1387
|
object = {};
|
|
1217
1388
|
}
|
|
1218
|
-
++stackIndex;
|
|
1219
1389
|
}
|
|
1390
|
+
|
|
1220
1391
|
if (canNotTraverseDeeper()) return {};
|
|
1221
1392
|
return {
|
|
1222
1393
|
obj: object,
|
|
1223
|
-
k: cleanKey(stack
|
|
1394
|
+
k: cleanKey(stack.shift())
|
|
1224
1395
|
};
|
|
1225
1396
|
}
|
|
1397
|
+
|
|
1226
1398
|
function setPath(object, path, newValue) {
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
obj[k] = newValue;
|
|
1233
|
-
return;
|
|
1234
|
-
}
|
|
1235
|
-
let e = path[path.length - 1];
|
|
1236
|
-
let p = path.slice(0, path.length - 1);
|
|
1237
|
-
let last = getLastOfPath(object, p, Object);
|
|
1238
|
-
while (last.obj === undefined && p.length) {
|
|
1239
|
-
e = `${p[p.length - 1]}.${e}`;
|
|
1240
|
-
p = p.slice(0, p.length - 1);
|
|
1241
|
-
last = getLastOfPath(object, p, Object);
|
|
1242
|
-
if (last && last.obj && typeof last.obj[`${last.k}.${e}`] !== 'undefined') {
|
|
1243
|
-
last.obj = undefined;
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
last.obj[`${last.k}.${e}`] = newValue;
|
|
1399
|
+
var _getLastOfPath = getLastOfPath(object, path, Object),
|
|
1400
|
+
obj = _getLastOfPath.obj,
|
|
1401
|
+
k = _getLastOfPath.k;
|
|
1402
|
+
|
|
1403
|
+
obj[k] = newValue;
|
|
1247
1404
|
}
|
|
1248
1405
|
function pushPath(object, path, newValue, concat) {
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1406
|
+
var _getLastOfPath2 = getLastOfPath(object, path, Object),
|
|
1407
|
+
obj = _getLastOfPath2.obj,
|
|
1408
|
+
k = _getLastOfPath2.k;
|
|
1409
|
+
|
|
1253
1410
|
obj[k] = obj[k] || [];
|
|
1254
1411
|
obj[k].push(newValue);
|
|
1255
1412
|
}
|
|
1256
1413
|
function getPath(object, path) {
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1414
|
+
var _getLastOfPath3 = getLastOfPath(object, path),
|
|
1415
|
+
obj = _getLastOfPath3.obj,
|
|
1416
|
+
k = _getLastOfPath3.k;
|
|
1417
|
+
|
|
1261
1418
|
if (!obj) return undefined;
|
|
1262
1419
|
return obj[k];
|
|
1263
1420
|
}
|
|
1264
1421
|
function getPathWithDefaults(data, defaultData, key) {
|
|
1265
|
-
|
|
1422
|
+
var value = getPath(data, key);
|
|
1423
|
+
|
|
1266
1424
|
if (value !== undefined) {
|
|
1267
1425
|
return value;
|
|
1268
1426
|
}
|
|
1427
|
+
|
|
1269
1428
|
return getPath(defaultData, key);
|
|
1270
1429
|
}
|
|
1271
1430
|
function deepExtend(target, source, overwrite) {
|
|
1272
|
-
for (
|
|
1431
|
+
for (var prop in source) {
|
|
1273
1432
|
if (prop !== '__proto__' && prop !== 'constructor') {
|
|
1274
1433
|
if (prop in target) {
|
|
1275
1434
|
if (typeof target[prop] === 'string' || target[prop] instanceof String || typeof source[prop] === 'string' || source[prop] instanceof String) {
|
|
@@ -1282,6 +1441,7 @@ function deepExtend(target, source, overwrite) {
|
|
|
1282
1441
|
}
|
|
1283
1442
|
}
|
|
1284
1443
|
}
|
|
1444
|
+
|
|
1285
1445
|
return target;
|
|
1286
1446
|
}
|
|
1287
1447
|
function regexEscape(str) {
|
|
@@ -1297,758 +1457,880 @@ var _entityMap = {
|
|
|
1297
1457
|
};
|
|
1298
1458
|
function escape(data) {
|
|
1299
1459
|
if (typeof data === 'string') {
|
|
1300
|
-
return data.replace(/[&<>"'\/]/g,
|
|
1460
|
+
return data.replace(/[&<>"'\/]/g, function (s) {
|
|
1461
|
+
return _entityMap[s];
|
|
1462
|
+
});
|
|
1301
1463
|
}
|
|
1464
|
+
|
|
1302
1465
|
return data;
|
|
1303
1466
|
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
this.capacity = capacity;
|
|
1307
|
-
this.regExpMap = new Map();
|
|
1308
|
-
this.regExpQueue = [];
|
|
1309
|
-
}
|
|
1310
|
-
getRegExp(pattern) {
|
|
1311
|
-
const regExpFromCache = this.regExpMap.get(pattern);
|
|
1312
|
-
if (regExpFromCache !== undefined) {
|
|
1313
|
-
return regExpFromCache;
|
|
1314
|
-
}
|
|
1315
|
-
const regExpNew = new RegExp(pattern);
|
|
1316
|
-
if (this.regExpQueue.length === this.capacity) {
|
|
1317
|
-
this.regExpMap.delete(this.regExpQueue.shift());
|
|
1318
|
-
}
|
|
1319
|
-
this.regExpMap.set(pattern, regExpNew);
|
|
1320
|
-
this.regExpQueue.push(pattern);
|
|
1321
|
-
return regExpNew;
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
const chars = [' ', ',', '?', '!', ';'];
|
|
1325
|
-
const looksLikeObjectPathRegExpCache = new RegExpCache(20);
|
|
1467
|
+
var isIE10 = typeof window !== 'undefined' && window.navigator && typeof window.navigator.userAgentData === 'undefined' && window.navigator.userAgent && window.navigator.userAgent.indexOf('MSIE') > -1;
|
|
1468
|
+
var chars = [' ', ',', '?', '!', ';'];
|
|
1326
1469
|
function looksLikeObjectPath(key, nsSeparator, keySeparator) {
|
|
1327
1470
|
nsSeparator = nsSeparator || '';
|
|
1328
1471
|
keySeparator = keySeparator || '';
|
|
1329
|
-
|
|
1472
|
+
var possibleChars = chars.filter(function (c) {
|
|
1473
|
+
return nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0;
|
|
1474
|
+
});
|
|
1330
1475
|
if (possibleChars.length === 0) return true;
|
|
1331
|
-
|
|
1332
|
-
|
|
1476
|
+
var r = new RegExp("(".concat(possibleChars.map(function (c) {
|
|
1477
|
+
return c === '?' ? '\\?' : c;
|
|
1478
|
+
}).join('|'), ")"));
|
|
1479
|
+
var matched = !r.test(key);
|
|
1480
|
+
|
|
1333
1481
|
if (!matched) {
|
|
1334
|
-
|
|
1482
|
+
var ki = key.indexOf(keySeparator);
|
|
1483
|
+
|
|
1335
1484
|
if (ki > 0 && !r.test(key.substring(0, ki))) {
|
|
1336
1485
|
matched = true;
|
|
1337
1486
|
}
|
|
1338
1487
|
}
|
|
1488
|
+
|
|
1339
1489
|
return matched;
|
|
1340
1490
|
}
|
|
1491
|
+
|
|
1492
|
+
function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
1493
|
+
|
|
1494
|
+
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
1495
|
+
|
|
1496
|
+
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); }; }
|
|
1497
|
+
|
|
1498
|
+
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; } }
|
|
1499
|
+
|
|
1341
1500
|
function deepFind(obj, path) {
|
|
1342
|
-
|
|
1501
|
+
var keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
|
|
1343
1502
|
if (!obj) return undefined;
|
|
1344
1503
|
if (obj[path]) return obj[path];
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1504
|
+
var paths = path.split(keySeparator);
|
|
1505
|
+
var current = obj;
|
|
1506
|
+
|
|
1507
|
+
for (var i = 0; i < paths.length; ++i) {
|
|
1508
|
+
if (!current) return undefined;
|
|
1509
|
+
|
|
1510
|
+
if (typeof current[paths[i]] === 'string' && i + 1 < paths.length) {
|
|
1349
1511
|
return undefined;
|
|
1350
1512
|
}
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1513
|
+
|
|
1514
|
+
if (current[paths[i]] === undefined) {
|
|
1515
|
+
var j = 2;
|
|
1516
|
+
var p = paths.slice(i, i + j).join(keySeparator);
|
|
1517
|
+
var mix = current[p];
|
|
1518
|
+
|
|
1519
|
+
while (mix === undefined && paths.length > i + j) {
|
|
1520
|
+
j++;
|
|
1521
|
+
p = paths.slice(i, i + j).join(keySeparator);
|
|
1522
|
+
mix = current[p];
|
|
1356
1523
|
}
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
if (
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
break;
|
|
1524
|
+
|
|
1525
|
+
if (mix === undefined) return undefined;
|
|
1526
|
+
if (mix === null) return null;
|
|
1527
|
+
|
|
1528
|
+
if (path.endsWith(p)) {
|
|
1529
|
+
if (typeof mix === 'string') return mix;
|
|
1530
|
+
if (p && typeof mix[p] === 'string') return mix[p];
|
|
1365
1531
|
}
|
|
1532
|
+
|
|
1533
|
+
var joinedPath = paths.slice(i + j).join(keySeparator);
|
|
1534
|
+
if (joinedPath) return deepFind(mix, joinedPath, keySeparator);
|
|
1535
|
+
return undefined;
|
|
1366
1536
|
}
|
|
1367
|
-
|
|
1537
|
+
|
|
1538
|
+
current = current[paths[i]];
|
|
1368
1539
|
}
|
|
1540
|
+
|
|
1369
1541
|
return current;
|
|
1370
1542
|
}
|
|
1371
|
-
function getCleanedCode(code) {
|
|
1372
|
-
if (code && code.indexOf('_') > 0) return code.replace('_', '-');
|
|
1373
|
-
return code;
|
|
1374
|
-
}
|
|
1375
1543
|
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1544
|
+
var ResourceStore = function (_EventEmitter) {
|
|
1545
|
+
_inherits(ResourceStore, _EventEmitter);
|
|
1546
|
+
|
|
1547
|
+
var _super = _createSuper(ResourceStore);
|
|
1548
|
+
|
|
1549
|
+
function ResourceStore(data) {
|
|
1550
|
+
var _this;
|
|
1551
|
+
|
|
1552
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
1379
1553
|
ns: ['translation'],
|
|
1380
1554
|
defaultNS: 'translation'
|
|
1381
1555
|
};
|
|
1382
|
-
|
|
1383
|
-
this
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
this.options.ignoreJSONStructure = true;
|
|
1556
|
+
|
|
1557
|
+
_classCallCheck(this, ResourceStore);
|
|
1558
|
+
|
|
1559
|
+
_this = _super.call(this);
|
|
1560
|
+
|
|
1561
|
+
if (isIE10) {
|
|
1562
|
+
EventEmitter.call(_assertThisInitialized(_this));
|
|
1390
1563
|
}
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1564
|
+
|
|
1565
|
+
_this.data = data || {};
|
|
1566
|
+
_this.options = options;
|
|
1567
|
+
|
|
1568
|
+
if (_this.options.keySeparator === undefined) {
|
|
1569
|
+
_this.options.keySeparator = '.';
|
|
1395
1570
|
}
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
if (index > -1) {
|
|
1400
|
-
this.options.ns.splice(index, 1);
|
|
1571
|
+
|
|
1572
|
+
if (_this.options.ignoreJSONStructure === undefined) {
|
|
1573
|
+
_this.options.ignoreJSONStructure = true;
|
|
1401
1574
|
}
|
|
1575
|
+
|
|
1576
|
+
return _this;
|
|
1402
1577
|
}
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
path = lng.split('.');
|
|
1410
|
-
} else {
|
|
1411
|
-
path = [lng, ns];
|
|
1412
|
-
if (key) {
|
|
1413
|
-
if (Array.isArray(key)) {
|
|
1414
|
-
path.push(...key);
|
|
1415
|
-
} else if (typeof key === 'string' && keySeparator) {
|
|
1416
|
-
path.push(...key.split(keySeparator));
|
|
1417
|
-
} else {
|
|
1418
|
-
path.push(key);
|
|
1419
|
-
}
|
|
1578
|
+
|
|
1579
|
+
_createClass(ResourceStore, [{
|
|
1580
|
+
key: "addNamespaces",
|
|
1581
|
+
value: function addNamespaces(ns) {
|
|
1582
|
+
if (this.options.ns.indexOf(ns) < 0) {
|
|
1583
|
+
this.options.ns.push(ns);
|
|
1420
1584
|
}
|
|
1421
1585
|
}
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1586
|
+
}, {
|
|
1587
|
+
key: "removeNamespaces",
|
|
1588
|
+
value: function removeNamespaces(ns) {
|
|
1589
|
+
var index = this.options.ns.indexOf(ns);
|
|
1590
|
+
|
|
1591
|
+
if (index > -1) {
|
|
1592
|
+
this.options.ns.splice(index, 1);
|
|
1593
|
+
}
|
|
1427
1594
|
}
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1595
|
+
}, {
|
|
1596
|
+
key: "getResource",
|
|
1597
|
+
value: function getResource(lng, ns, key) {
|
|
1598
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1599
|
+
var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
1600
|
+
var ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
1601
|
+
var path = [lng, ns];
|
|
1602
|
+
if (key && typeof key !== 'string') path = path.concat(key);
|
|
1603
|
+
if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
1604
|
+
|
|
1605
|
+
if (lng.indexOf('.') > -1) {
|
|
1606
|
+
path = lng.split('.');
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
var result = getPath(this.data, path);
|
|
1610
|
+
if (result || !ignoreJSONStructure || typeof key !== 'string') return result;
|
|
1611
|
+
return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
|
|
1612
|
+
}
|
|
1613
|
+
}, {
|
|
1614
|
+
key: "addResource",
|
|
1615
|
+
value: function addResource(lng, ns, key, value) {
|
|
1616
|
+
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
|
1617
|
+
silent: false
|
|
1618
|
+
};
|
|
1619
|
+
var keySeparator = this.options.keySeparator;
|
|
1620
|
+
if (keySeparator === undefined) keySeparator = '.';
|
|
1621
|
+
var path = [lng, ns];
|
|
1622
|
+
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
1623
|
+
|
|
1624
|
+
if (lng.indexOf('.') > -1) {
|
|
1625
|
+
path = lng.split('.');
|
|
1626
|
+
value = ns;
|
|
1627
|
+
ns = path[1];
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
this.addNamespaces(ns);
|
|
1631
|
+
setPath(this.data, path, value);
|
|
1632
|
+
if (!options.silent) this.emit('added', lng, ns, key, value);
|
|
1633
|
+
}
|
|
1634
|
+
}, {
|
|
1635
|
+
key: "addResources",
|
|
1636
|
+
value: function addResources(lng, ns, resources) {
|
|
1637
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
1638
|
+
silent: false
|
|
1639
|
+
};
|
|
1640
|
+
|
|
1641
|
+
for (var m in resources) {
|
|
1642
|
+
if (typeof resources[m] === 'string' || Object.prototype.toString.apply(resources[m]) === '[object Array]') this.addResource(lng, ns, m, resources[m], {
|
|
1643
|
+
silent: true
|
|
1644
|
+
});
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
1455
1648
|
}
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
skipCopy: false
|
|
1462
|
-
};
|
|
1463
|
-
let path = [lng, ns];
|
|
1464
|
-
if (lng.indexOf('.') > -1) {
|
|
1465
|
-
path = lng.split('.');
|
|
1466
|
-
deep = resources;
|
|
1467
|
-
resources = ns;
|
|
1468
|
-
ns = path[1];
|
|
1469
|
-
}
|
|
1470
|
-
this.addNamespaces(ns);
|
|
1471
|
-
let pack = getPath(this.data, path) || {};
|
|
1472
|
-
if (!options.skipCopy) resources = JSON.parse(JSON.stringify(resources));
|
|
1473
|
-
if (deep) {
|
|
1474
|
-
deepExtend(pack, resources, overwrite);
|
|
1475
|
-
} else {
|
|
1476
|
-
pack = {
|
|
1477
|
-
...pack,
|
|
1478
|
-
...resources
|
|
1649
|
+
}, {
|
|
1650
|
+
key: "addResourceBundle",
|
|
1651
|
+
value: function addResourceBundle(lng, ns, resources, deep, overwrite) {
|
|
1652
|
+
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
|
|
1653
|
+
silent: false
|
|
1479
1654
|
};
|
|
1655
|
+
var path = [lng, ns];
|
|
1656
|
+
|
|
1657
|
+
if (lng.indexOf('.') > -1) {
|
|
1658
|
+
path = lng.split('.');
|
|
1659
|
+
deep = resources;
|
|
1660
|
+
resources = ns;
|
|
1661
|
+
ns = path[1];
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
this.addNamespaces(ns);
|
|
1665
|
+
var pack = getPath(this.data, path) || {};
|
|
1666
|
+
|
|
1667
|
+
if (deep) {
|
|
1668
|
+
deepExtend(pack, resources, overwrite);
|
|
1669
|
+
} else {
|
|
1670
|
+
pack = _objectSpread$1(_objectSpread$1({}, pack), resources);
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
setPath(this.data, path, pack);
|
|
1674
|
+
if (!options.silent) this.emit('added', lng, ns, resources);
|
|
1675
|
+
}
|
|
1676
|
+
}, {
|
|
1677
|
+
key: "removeResourceBundle",
|
|
1678
|
+
value: function removeResourceBundle(lng, ns) {
|
|
1679
|
+
if (this.hasResourceBundle(lng, ns)) {
|
|
1680
|
+
delete this.data[lng][ns];
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
this.removeNamespaces(ns);
|
|
1684
|
+
this.emit('removed', lng, ns);
|
|
1685
|
+
}
|
|
1686
|
+
}, {
|
|
1687
|
+
key: "hasResourceBundle",
|
|
1688
|
+
value: function hasResourceBundle(lng, ns) {
|
|
1689
|
+
return this.getResource(lng, ns) !== undefined;
|
|
1690
|
+
}
|
|
1691
|
+
}, {
|
|
1692
|
+
key: "getResourceBundle",
|
|
1693
|
+
value: function getResourceBundle(lng, ns) {
|
|
1694
|
+
if (!ns) ns = this.options.defaultNS;
|
|
1695
|
+
if (this.options.compatibilityAPI === 'v1') return _objectSpread$1(_objectSpread$1({}, {}), this.getResource(lng, ns));
|
|
1696
|
+
return this.getResource(lng, ns);
|
|
1697
|
+
}
|
|
1698
|
+
}, {
|
|
1699
|
+
key: "getDataByLanguage",
|
|
1700
|
+
value: function getDataByLanguage(lng) {
|
|
1701
|
+
return this.data[lng];
|
|
1702
|
+
}
|
|
1703
|
+
}, {
|
|
1704
|
+
key: "hasLanguageSomeTranslations",
|
|
1705
|
+
value: function hasLanguageSomeTranslations(lng) {
|
|
1706
|
+
var data = this.getDataByLanguage(lng);
|
|
1707
|
+
var n = data && Object.keys(data) || [];
|
|
1708
|
+
return !!n.find(function (v) {
|
|
1709
|
+
return data[v] && Object.keys(data[v]).length > 0;
|
|
1710
|
+
});
|
|
1480
1711
|
}
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
if (this.hasResourceBundle(lng, ns)) {
|
|
1486
|
-
delete this.data[lng][ns];
|
|
1712
|
+
}, {
|
|
1713
|
+
key: "toJSON",
|
|
1714
|
+
value: function toJSON() {
|
|
1715
|
+
return this.data;
|
|
1487
1716
|
}
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
return this.getResource(lng, ns) !== undefined;
|
|
1493
|
-
}
|
|
1494
|
-
getResourceBundle(lng, ns) {
|
|
1495
|
-
if (!ns) ns = this.options.defaultNS;
|
|
1496
|
-
if (this.options.compatibilityAPI === 'v1') return {
|
|
1497
|
-
...{},
|
|
1498
|
-
...this.getResource(lng, ns)
|
|
1499
|
-
};
|
|
1500
|
-
return this.getResource(lng, ns);
|
|
1501
|
-
}
|
|
1502
|
-
getDataByLanguage(lng) {
|
|
1503
|
-
return this.data[lng];
|
|
1504
|
-
}
|
|
1505
|
-
hasLanguageSomeTranslations(lng) {
|
|
1506
|
-
const data = this.getDataByLanguage(lng);
|
|
1507
|
-
const n = data && Object.keys(data) || [];
|
|
1508
|
-
return !!n.find(v => data[v] && Object.keys(data[v]).length > 0);
|
|
1509
|
-
}
|
|
1510
|
-
toJSON() {
|
|
1511
|
-
return this.data;
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1717
|
+
}]);
|
|
1718
|
+
|
|
1719
|
+
return ResourceStore;
|
|
1720
|
+
}(EventEmitter);
|
|
1514
1721
|
|
|
1515
1722
|
var postProcessor = {
|
|
1516
1723
|
processors: {},
|
|
1517
|
-
addPostProcessor(module) {
|
|
1724
|
+
addPostProcessor: function addPostProcessor(module) {
|
|
1518
1725
|
this.processors[module.name] = module;
|
|
1519
1726
|
},
|
|
1520
|
-
handle(processors, value, key, options, translator) {
|
|
1521
|
-
|
|
1522
|
-
|
|
1727
|
+
handle: function handle(processors, value, key, options, translator) {
|
|
1728
|
+
var _this = this;
|
|
1729
|
+
|
|
1730
|
+
processors.forEach(function (processor) {
|
|
1731
|
+
if (_this.processors[processor]) value = _this.processors[processor].process(value, key, options, translator);
|
|
1523
1732
|
});
|
|
1524
1733
|
return value;
|
|
1525
1734
|
}
|
|
1526
1735
|
};
|
|
1527
1736
|
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1737
|
+
function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
1738
|
+
|
|
1739
|
+
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$2(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
1740
|
+
|
|
1741
|
+
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); }; }
|
|
1742
|
+
|
|
1743
|
+
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; } }
|
|
1744
|
+
var checkedLoadedFor = {};
|
|
1745
|
+
|
|
1746
|
+
var Translator = function (_EventEmitter) {
|
|
1747
|
+
_inherits(Translator, _EventEmitter);
|
|
1748
|
+
|
|
1749
|
+
var _super = _createSuper$1(Translator);
|
|
1750
|
+
|
|
1751
|
+
function Translator(services) {
|
|
1752
|
+
var _this;
|
|
1753
|
+
|
|
1754
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1755
|
+
|
|
1756
|
+
_classCallCheck(this, Translator);
|
|
1757
|
+
|
|
1758
|
+
_this = _super.call(this);
|
|
1759
|
+
|
|
1760
|
+
if (isIE10) {
|
|
1761
|
+
EventEmitter.call(_assertThisInitialized(_this));
|
|
1537
1762
|
}
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
1545
|
-
interpolation: {}
|
|
1546
|
-
};
|
|
1547
|
-
if (key === undefined || key === null) {
|
|
1548
|
-
return false;
|
|
1763
|
+
|
|
1764
|
+
copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector', 'i18nFormat', 'utils'], services, _assertThisInitialized(_this));
|
|
1765
|
+
_this.options = options;
|
|
1766
|
+
|
|
1767
|
+
if (_this.options.keySeparator === undefined) {
|
|
1768
|
+
_this.options.keySeparator = '.';
|
|
1549
1769
|
}
|
|
1550
|
-
|
|
1551
|
-
|
|
1770
|
+
|
|
1771
|
+
_this.logger = baseLogger.create('translator');
|
|
1772
|
+
return _this;
|
|
1552
1773
|
}
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1774
|
+
|
|
1775
|
+
_createClass(Translator, [{
|
|
1776
|
+
key: "changeLanguage",
|
|
1777
|
+
value: function changeLanguage(lng) {
|
|
1778
|
+
if (lng) this.language = lng;
|
|
1779
|
+
}
|
|
1780
|
+
}, {
|
|
1781
|
+
key: "exists",
|
|
1782
|
+
value: function exists(key) {
|
|
1783
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
1784
|
+
interpolation: {}
|
|
1785
|
+
};
|
|
1786
|
+
|
|
1787
|
+
if (key === undefined || key === null) {
|
|
1788
|
+
return false;
|
|
1567
1789
|
}
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
}
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
if (keys === undefined || keys === null) return '';
|
|
1587
|
-
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
1588
|
-
const returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
|
|
1589
|
-
const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
1590
|
-
const {
|
|
1591
|
-
key,
|
|
1592
|
-
namespaces
|
|
1593
|
-
} = this.extractFromKey(keys[keys.length - 1], options);
|
|
1594
|
-
const namespace = namespaces[namespaces.length - 1];
|
|
1595
|
-
const lng = options.lng || this.language;
|
|
1596
|
-
const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
1597
|
-
if (lng && lng.toLowerCase() === 'cimode') {
|
|
1598
|
-
if (appendNamespaceToCIMode) {
|
|
1599
|
-
const nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
1600
|
-
if (returnDetails) {
|
|
1790
|
+
|
|
1791
|
+
var resolved = this.resolve(key, options);
|
|
1792
|
+
return resolved && resolved.res !== undefined;
|
|
1793
|
+
}
|
|
1794
|
+
}, {
|
|
1795
|
+
key: "extractFromKey",
|
|
1796
|
+
value: function extractFromKey(key, options) {
|
|
1797
|
+
var nsSeparator = options.nsSeparator !== undefined ? options.nsSeparator : this.options.nsSeparator;
|
|
1798
|
+
if (nsSeparator === undefined) nsSeparator = ':';
|
|
1799
|
+
var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
1800
|
+
var namespaces = options.ns || this.options.defaultNS || [];
|
|
1801
|
+
var wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
1802
|
+
var seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
1803
|
+
|
|
1804
|
+
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
1805
|
+
var m = key.match(this.interpolator.nestingRegexp);
|
|
1806
|
+
|
|
1807
|
+
if (m && m.length > 0) {
|
|
1601
1808
|
return {
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
exactUsedKey: key,
|
|
1605
|
-
usedLng: lng,
|
|
1606
|
-
usedNS: namespace,
|
|
1607
|
-
usedParams: this.getUsedParamsDetails(options)
|
|
1809
|
+
key: key,
|
|
1810
|
+
namespaces: namespaces
|
|
1608
1811
|
};
|
|
1609
1812
|
}
|
|
1610
|
-
|
|
1813
|
+
|
|
1814
|
+
var parts = key.split(nsSeparator);
|
|
1815
|
+
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
|
|
1816
|
+
key = parts.join(keySeparator);
|
|
1611
1817
|
}
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1818
|
+
|
|
1819
|
+
if (typeof namespaces === 'string') namespaces = [namespaces];
|
|
1820
|
+
return {
|
|
1821
|
+
key: key,
|
|
1822
|
+
namespaces: namespaces
|
|
1823
|
+
};
|
|
1824
|
+
}
|
|
1825
|
+
}, {
|
|
1826
|
+
key: "translate",
|
|
1827
|
+
value: function translate(keys, options, lastKey) {
|
|
1828
|
+
var _this2 = this;
|
|
1829
|
+
|
|
1830
|
+
if (_typeof(options) !== 'object' && this.options.overloadTranslationOptionHandler) {
|
|
1831
|
+
options = this.options.overloadTranslationOptionHandler(arguments);
|
|
1621
1832
|
}
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
resolved.usedParams = this.getUsedParamsDetails(options);
|
|
1645
|
-
return resolved;
|
|
1646
|
-
}
|
|
1647
|
-
return r;
|
|
1648
|
-
}
|
|
1649
|
-
if (keySeparator) {
|
|
1650
|
-
const resTypeIsArray = Array.isArray(res);
|
|
1651
|
-
const copy = resTypeIsArray ? [] : {};
|
|
1652
|
-
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
1653
|
-
for (const m in res) {
|
|
1654
|
-
if (Object.prototype.hasOwnProperty.call(res, m)) {
|
|
1655
|
-
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
1656
|
-
copy[m] = this.translate(deepKey, {
|
|
1657
|
-
...options,
|
|
1658
|
-
...{
|
|
1659
|
-
joinArrays: false,
|
|
1660
|
-
ns: namespaces
|
|
1661
|
-
}
|
|
1662
|
-
});
|
|
1663
|
-
if (copy[m] === deepKey) copy[m] = res[m];
|
|
1833
|
+
|
|
1834
|
+
if (!options) options = {};
|
|
1835
|
+
if (keys === undefined || keys === null) return '';
|
|
1836
|
+
if (!Array.isArray(keys)) keys = [String(keys)];
|
|
1837
|
+
var returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
|
|
1838
|
+
var keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
|
|
1839
|
+
|
|
1840
|
+
var _this$extractFromKey = this.extractFromKey(keys[keys.length - 1], options),
|
|
1841
|
+
key = _this$extractFromKey.key,
|
|
1842
|
+
namespaces = _this$extractFromKey.namespaces;
|
|
1843
|
+
|
|
1844
|
+
var namespace = namespaces[namespaces.length - 1];
|
|
1845
|
+
var lng = options.lng || this.language;
|
|
1846
|
+
var appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
1847
|
+
|
|
1848
|
+
if (lng && lng.toLowerCase() === 'cimode') {
|
|
1849
|
+
if (appendNamespaceToCIMode) {
|
|
1850
|
+
var nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
1851
|
+
|
|
1852
|
+
if (returnDetails) {
|
|
1853
|
+
resolved.res = "".concat(namespace).concat(nsSeparator).concat(key);
|
|
1854
|
+
return resolved;
|
|
1664
1855
|
}
|
|
1856
|
+
|
|
1857
|
+
return "".concat(namespace).concat(nsSeparator).concat(key);
|
|
1665
1858
|
}
|
|
1666
|
-
|
|
1859
|
+
|
|
1860
|
+
if (returnDetails) {
|
|
1861
|
+
resolved.res = key;
|
|
1862
|
+
return resolved;
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1865
|
+
return key;
|
|
1667
1866
|
}
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1867
|
+
|
|
1868
|
+
var resolved = this.resolve(keys, options);
|
|
1869
|
+
var res = resolved && resolved.res;
|
|
1870
|
+
var resUsedKey = resolved && resolved.usedKey || key;
|
|
1871
|
+
var resExactUsedKey = resolved && resolved.exactUsedKey || key;
|
|
1872
|
+
var resType = Object.prototype.toString.apply(res);
|
|
1873
|
+
var noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
|
|
1874
|
+
var joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
|
|
1875
|
+
var handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
1876
|
+
var handleAsObject = typeof res !== 'string' && typeof res !== 'boolean' && typeof res !== 'number';
|
|
1877
|
+
|
|
1878
|
+
if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === 'string' && resType === '[object Array]')) {
|
|
1879
|
+
if (!options.returnObjects && !this.options.returnObjects) {
|
|
1880
|
+
if (!this.options.returnedObjectHandler) {
|
|
1881
|
+
this.logger.warn('accessing an object - but returnObjects options is not enabled!');
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
var r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, _objectSpread$2(_objectSpread$2({}, options), {}, {
|
|
1885
|
+
ns: namespaces
|
|
1886
|
+
})) : "key '".concat(key, " (").concat(this.language, ")' returned an object instead of string.");
|
|
1887
|
+
|
|
1888
|
+
if (returnDetails) {
|
|
1889
|
+
resolved.res = r;
|
|
1890
|
+
return resolved;
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
return r;
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1695
1896
|
if (keySeparator) {
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1897
|
+
var resTypeIsArray = resType === '[object Array]';
|
|
1898
|
+
var copy = resTypeIsArray ? [] : {};
|
|
1899
|
+
var newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
1900
|
+
|
|
1901
|
+
for (var m in res) {
|
|
1902
|
+
if (Object.prototype.hasOwnProperty.call(res, m)) {
|
|
1903
|
+
var deepKey = "".concat(newKeyToUse).concat(keySeparator).concat(m);
|
|
1904
|
+
copy[m] = this.translate(deepKey, _objectSpread$2(_objectSpread$2({}, options), {
|
|
1905
|
+
joinArrays: false,
|
|
1906
|
+
ns: namespaces
|
|
1907
|
+
}));
|
|
1908
|
+
if (copy[m] === deepKey) copy[m] = res[m];
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
res = copy;
|
|
1913
|
+
}
|
|
1914
|
+
} else if (handleAsObjectInI18nFormat && typeof joinArrays === 'string' && resType === '[object Array]') {
|
|
1915
|
+
res = res.join(joinArrays);
|
|
1916
|
+
if (res) res = this.extendTranslation(res, keys, options, lastKey);
|
|
1917
|
+
} else {
|
|
1918
|
+
var usedDefault = false;
|
|
1919
|
+
var usedKey = false;
|
|
1920
|
+
var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
|
|
1921
|
+
var hasDefaultValue = Translator.hasDefaultValue(options);
|
|
1922
|
+
var defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : '';
|
|
1923
|
+
var defaultValue = options["defaultValue".concat(defaultValueSuffix)] || options.defaultValue;
|
|
1924
|
+
|
|
1925
|
+
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
1926
|
+
usedDefault = true;
|
|
1927
|
+
res = defaultValue;
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
if (!this.isValidLookup(res)) {
|
|
1931
|
+
usedKey = true;
|
|
1932
|
+
res = key;
|
|
1701
1933
|
}
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1934
|
+
|
|
1935
|
+
var missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
1936
|
+
var resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
|
|
1937
|
+
var updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
1938
|
+
|
|
1939
|
+
if (usedKey || usedDefault || updateMissing) {
|
|
1940
|
+
this.logger.log(updateMissing ? 'updateKey' : 'missingKey', lng, namespace, key, updateMissing ? defaultValue : res);
|
|
1941
|
+
|
|
1942
|
+
if (keySeparator) {
|
|
1943
|
+
var fk = this.resolve(key, _objectSpread$2(_objectSpread$2({}, options), {}, {
|
|
1944
|
+
keySeparator: false
|
|
1945
|
+
}));
|
|
1946
|
+
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.');
|
|
1707
1947
|
}
|
|
1708
|
-
|
|
1709
|
-
lngs =
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1948
|
+
|
|
1949
|
+
var lngs = [];
|
|
1950
|
+
var fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
|
|
1951
|
+
|
|
1952
|
+
if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
|
|
1953
|
+
for (var i = 0; i < fallbackLngs.length; i++) {
|
|
1954
|
+
lngs.push(fallbackLngs[i]);
|
|
1955
|
+
}
|
|
1956
|
+
} else if (this.options.saveMissingTo === 'all') {
|
|
1957
|
+
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
|
|
1958
|
+
} else {
|
|
1959
|
+
lngs.push(options.lng || this.language);
|
|
1719
1960
|
}
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1961
|
+
|
|
1962
|
+
var send = function send(l, k, specificDefaultValue) {
|
|
1963
|
+
var defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
1964
|
+
|
|
1965
|
+
if (_this2.options.missingKeyHandler) {
|
|
1966
|
+
_this2.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
1967
|
+
} else if (_this2.backendConnector && _this2.backendConnector.saveMissing) {
|
|
1968
|
+
_this2.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
_this2.emit('missingKey', l, namespace, k, res);
|
|
1972
|
+
};
|
|
1973
|
+
|
|
1974
|
+
if (this.options.saveMissing) {
|
|
1975
|
+
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
1976
|
+
lngs.forEach(function (language) {
|
|
1977
|
+
_this2.pluralResolver.getSuffixes(language, options).forEach(function (suffix) {
|
|
1978
|
+
send([language], key + suffix, options["defaultValue".concat(suffix)] || defaultValue);
|
|
1979
|
+
});
|
|
1731
1980
|
});
|
|
1732
|
-
}
|
|
1981
|
+
} else {
|
|
1982
|
+
send(lngs, key, defaultValue);
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
res = this.extendTranslation(res, keys, options, resolved, lastKey);
|
|
1988
|
+
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = "".concat(namespace, ":").concat(key);
|
|
1989
|
+
|
|
1990
|
+
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
1991
|
+
if (this.options.compatibilityAPI !== 'v1') {
|
|
1992
|
+
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? "".concat(namespace, ":").concat(key) : key, usedDefault ? res : undefined);
|
|
1733
1993
|
} else {
|
|
1734
|
-
|
|
1994
|
+
res = this.options.parseMissingKeyHandler(res);
|
|
1735
1995
|
}
|
|
1736
1996
|
}
|
|
1737
1997
|
}
|
|
1738
|
-
|
|
1739
|
-
if (
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : undefined);
|
|
1743
|
-
} else {
|
|
1744
|
-
res = this.options.parseMissingKeyHandler(res);
|
|
1745
|
-
}
|
|
1998
|
+
|
|
1999
|
+
if (returnDetails) {
|
|
2000
|
+
resolved.res = res;
|
|
2001
|
+
return resolved;
|
|
1746
2002
|
}
|
|
2003
|
+
|
|
2004
|
+
return res;
|
|
1747
2005
|
}
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
...{
|
|
1768
|
-
interpolation: {
|
|
1769
|
-
...this.options.interpolation,
|
|
1770
|
-
...options.interpolation
|
|
1771
|
-
}
|
|
2006
|
+
}, {
|
|
2007
|
+
key: "extendTranslation",
|
|
2008
|
+
value: function extendTranslation(res, key, options, resolved, lastKey) {
|
|
2009
|
+
var _this3 = this;
|
|
2010
|
+
|
|
2011
|
+
if (this.i18nFormat && this.i18nFormat.parse) {
|
|
2012
|
+
res = this.i18nFormat.parse(res, _objectSpread$2(_objectSpread$2({}, this.options.interpolation.defaultVariables), options), resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
2013
|
+
resolved: resolved
|
|
2014
|
+
});
|
|
2015
|
+
} else if (!options.skipInterpolation) {
|
|
2016
|
+
if (options.interpolation) this.interpolator.init(_objectSpread$2(_objectSpread$2({}, options), {
|
|
2017
|
+
interpolation: _objectSpread$2(_objectSpread$2({}, this.options.interpolation), options.interpolation)
|
|
2018
|
+
}));
|
|
2019
|
+
var skipOnVariables = typeof res === 'string' && (options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
2020
|
+
var nestBef;
|
|
2021
|
+
|
|
2022
|
+
if (skipOnVariables) {
|
|
2023
|
+
var nb = res.match(this.interpolator.nestingRegexp);
|
|
2024
|
+
nestBef = nb && nb.length;
|
|
1772
2025
|
}
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
...this.options.interpolation.defaultVariables,
|
|
1783
|
-
...data
|
|
1784
|
-
};
|
|
1785
|
-
res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
|
|
1786
|
-
if (skipOnVariables) {
|
|
1787
|
-
const na = res.match(this.interpolator.nestingRegexp);
|
|
1788
|
-
const nestAft = na && na.length;
|
|
1789
|
-
if (nestBef < nestAft) options.nest = false;
|
|
1790
|
-
}
|
|
1791
|
-
if (!options.lng && this.options.compatibilityAPI !== 'v1' && resolved && resolved.res) options.lng = resolved.usedLng;
|
|
1792
|
-
if (options.nest !== false) res = this.interpolator.nest(res, function () {
|
|
1793
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1794
|
-
args[_key] = arguments[_key];
|
|
1795
|
-
}
|
|
1796
|
-
if (lastKey && lastKey[0] === args[0] && !options.context) {
|
|
1797
|
-
_this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
1798
|
-
return null;
|
|
2026
|
+
|
|
2027
|
+
var data = options.replace && typeof options.replace !== 'string' ? options.replace : options;
|
|
2028
|
+
if (this.options.interpolation.defaultVariables) data = _objectSpread$2(_objectSpread$2({}, this.options.interpolation.defaultVariables), data);
|
|
2029
|
+
res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
|
|
2030
|
+
|
|
2031
|
+
if (skipOnVariables) {
|
|
2032
|
+
var na = res.match(this.interpolator.nestingRegexp);
|
|
2033
|
+
var nestAft = na && na.length;
|
|
2034
|
+
if (nestBef < nestAft) options.nest = false;
|
|
1799
2035
|
}
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
2036
|
+
|
|
2037
|
+
if (options.nest !== false) res = this.interpolator.nest(res, function () {
|
|
2038
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2039
|
+
args[_key] = arguments[_key];
|
|
2040
|
+
}
|
|
2041
|
+
|
|
2042
|
+
if (lastKey && lastKey[0] === args[0] && !options.context) {
|
|
2043
|
+
_this3.logger.warn("It seems you are nesting recursively key: ".concat(args[0], " in key: ").concat(key[0]));
|
|
2044
|
+
|
|
2045
|
+
return null;
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
return _this3.translate.apply(_this3, args.concat([key]));
|
|
2049
|
+
}, options);
|
|
2050
|
+
if (options.interpolation) this.interpolator.reset();
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
var postProcess = options.postProcess || this.options.postProcess;
|
|
2054
|
+
var postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess;
|
|
2055
|
+
|
|
2056
|
+
if (res !== undefined && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
|
|
2057
|
+
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? _objectSpread$2({
|
|
2058
|
+
i18nResolved: resolved
|
|
2059
|
+
}, options) : options, this);
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
return res;
|
|
1814
2063
|
}
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
if (
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
|
|
1865
|
-
finalKeys.push(contextKey);
|
|
2064
|
+
}, {
|
|
2065
|
+
key: "resolve",
|
|
2066
|
+
value: function resolve(keys) {
|
|
2067
|
+
var _this4 = this;
|
|
2068
|
+
|
|
2069
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2070
|
+
var found;
|
|
2071
|
+
var usedKey;
|
|
2072
|
+
var exactUsedKey;
|
|
2073
|
+
var usedLng;
|
|
2074
|
+
var usedNS;
|
|
2075
|
+
if (typeof keys === 'string') keys = [keys];
|
|
2076
|
+
keys.forEach(function (k) {
|
|
2077
|
+
if (_this4.isValidLookup(found)) return;
|
|
2078
|
+
|
|
2079
|
+
var extracted = _this4.extractFromKey(k, options);
|
|
2080
|
+
|
|
2081
|
+
var key = extracted.key;
|
|
2082
|
+
usedKey = key;
|
|
2083
|
+
var namespaces = extracted.namespaces;
|
|
2084
|
+
if (_this4.options.fallbackNS) namespaces = namespaces.concat(_this4.options.fallbackNS);
|
|
2085
|
+
var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
|
|
2086
|
+
|
|
2087
|
+
var needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && _this4.pluralResolver.shouldUseIntlApi();
|
|
2088
|
+
|
|
2089
|
+
var needsContextHandling = options.context !== undefined && (typeof options.context === 'string' || typeof options.context === 'number') && options.context !== '';
|
|
2090
|
+
var codes = options.lngs ? options.lngs : _this4.languageUtils.toResolveHierarchy(options.lng || _this4.language, options.fallbackLng);
|
|
2091
|
+
namespaces.forEach(function (ns) {
|
|
2092
|
+
if (_this4.isValidLookup(found)) return;
|
|
2093
|
+
usedNS = ns;
|
|
2094
|
+
|
|
2095
|
+
if (!checkedLoadedFor["".concat(codes[0], "-").concat(ns)] && _this4.utils && _this4.utils.hasLoadedNamespace && !_this4.utils.hasLoadedNamespace(usedNS)) {
|
|
2096
|
+
checkedLoadedFor["".concat(codes[0], "-").concat(ns)] = true;
|
|
2097
|
+
|
|
2098
|
+
_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!!!');
|
|
2099
|
+
}
|
|
2100
|
+
|
|
2101
|
+
codes.forEach(function (code) {
|
|
2102
|
+
if (_this4.isValidLookup(found)) return;
|
|
2103
|
+
usedLng = code;
|
|
2104
|
+
var finalKeys = [key];
|
|
2105
|
+
|
|
2106
|
+
if (_this4.i18nFormat && _this4.i18nFormat.addLookupKeys) {
|
|
2107
|
+
_this4.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
|
|
2108
|
+
} else {
|
|
2109
|
+
var pluralSuffix;
|
|
2110
|
+
if (needsPluralHandling) pluralSuffix = _this4.pluralResolver.getSuffix(code, options.count, options);
|
|
2111
|
+
var zeroSuffix = "".concat(_this4.options.pluralSeparator, "zero");
|
|
2112
|
+
|
|
1866
2113
|
if (needsPluralHandling) {
|
|
1867
|
-
finalKeys.push(
|
|
1868
|
-
|
|
1869
|
-
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
1870
|
-
}
|
|
2114
|
+
finalKeys.push(key + pluralSuffix);
|
|
2115
|
+
|
|
1871
2116
|
if (needsZeroSuffixLookup) {
|
|
1872
|
-
finalKeys.push(
|
|
2117
|
+
finalKeys.push(key + zeroSuffix);
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
if (needsContextHandling) {
|
|
2122
|
+
var contextKey = "".concat(key).concat(_this4.options.contextSeparator).concat(options.context);
|
|
2123
|
+
finalKeys.push(contextKey);
|
|
2124
|
+
|
|
2125
|
+
if (needsPluralHandling) {
|
|
2126
|
+
finalKeys.push(contextKey + pluralSuffix);
|
|
2127
|
+
|
|
2128
|
+
if (needsZeroSuffixLookup) {
|
|
2129
|
+
finalKeys.push(contextKey + zeroSuffix);
|
|
2130
|
+
}
|
|
1873
2131
|
}
|
|
1874
2132
|
}
|
|
1875
2133
|
}
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
2134
|
+
|
|
2135
|
+
var possibleKey;
|
|
2136
|
+
|
|
2137
|
+
while (possibleKey = finalKeys.pop()) {
|
|
2138
|
+
if (!_this4.isValidLookup(found)) {
|
|
2139
|
+
exactUsedKey = possibleKey;
|
|
2140
|
+
found = _this4.getResource(code, ns, possibleKey, options);
|
|
2141
|
+
}
|
|
1882
2142
|
}
|
|
1883
|
-
}
|
|
2143
|
+
});
|
|
1884
2144
|
});
|
|
1885
2145
|
});
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
usedNS
|
|
1893
|
-
};
|
|
1894
|
-
}
|
|
1895
|
-
isValidLookup(res) {
|
|
1896
|
-
return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
|
|
1897
|
-
}
|
|
1898
|
-
getResource(code, ns, key) {
|
|
1899
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1900
|
-
if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
1901
|
-
return this.resourceStore.getResource(code, ns, key, options);
|
|
1902
|
-
}
|
|
1903
|
-
getUsedParamsDetails() {
|
|
1904
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1905
|
-
const optionsKeys = ['defaultValue', 'ordinal', 'context', 'replace', 'lng', 'lngs', 'fallbackLng', 'ns', 'keySeparator', 'nsSeparator', 'returnObjects', 'returnDetails', 'joinArrays', 'postProcess', 'interpolation'];
|
|
1906
|
-
const useOptionsReplaceForData = options.replace && typeof options.replace !== 'string';
|
|
1907
|
-
let data = useOptionsReplaceForData ? options.replace : options;
|
|
1908
|
-
if (useOptionsReplaceForData && typeof options.count !== 'undefined') {
|
|
1909
|
-
data.count = options.count;
|
|
1910
|
-
}
|
|
1911
|
-
if (this.options.interpolation.defaultVariables) {
|
|
1912
|
-
data = {
|
|
1913
|
-
...this.options.interpolation.defaultVariables,
|
|
1914
|
-
...data
|
|
1915
|
-
};
|
|
1916
|
-
}
|
|
1917
|
-
if (!useOptionsReplaceForData) {
|
|
1918
|
-
data = {
|
|
1919
|
-
...data
|
|
2146
|
+
return {
|
|
2147
|
+
res: found,
|
|
2148
|
+
usedKey: usedKey,
|
|
2149
|
+
exactUsedKey: exactUsedKey,
|
|
2150
|
+
usedLng: usedLng,
|
|
2151
|
+
usedNS: usedNS
|
|
1920
2152
|
};
|
|
1921
|
-
for (const key of optionsKeys) {
|
|
1922
|
-
delete data[key];
|
|
1923
|
-
}
|
|
1924
2153
|
}
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
2154
|
+
}, {
|
|
2155
|
+
key: "isValidLookup",
|
|
2156
|
+
value: function isValidLookup(res) {
|
|
2157
|
+
return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
|
|
2158
|
+
}
|
|
2159
|
+
}, {
|
|
2160
|
+
key: "getResource",
|
|
2161
|
+
value: function getResource(code, ns, key) {
|
|
2162
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
2163
|
+
if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
|
|
2164
|
+
return this.resourceStore.getResource(code, ns, key, options);
|
|
2165
|
+
}
|
|
2166
|
+
}], [{
|
|
2167
|
+
key: "hasDefaultValue",
|
|
2168
|
+
value: function hasDefaultValue(options) {
|
|
2169
|
+
var prefix = 'defaultValue';
|
|
2170
|
+
|
|
2171
|
+
for (var option in options) {
|
|
2172
|
+
if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && undefined !== options[option]) {
|
|
2173
|
+
return true;
|
|
2174
|
+
}
|
|
1932
2175
|
}
|
|
2176
|
+
|
|
2177
|
+
return false;
|
|
1933
2178
|
}
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
2179
|
+
}]);
|
|
2180
|
+
|
|
2181
|
+
return Translator;
|
|
2182
|
+
}(EventEmitter);
|
|
1937
2183
|
|
|
1938
2184
|
function capitalize(string) {
|
|
1939
2185
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
1940
2186
|
}
|
|
1941
|
-
|
|
1942
|
-
|
|
2187
|
+
|
|
2188
|
+
var LanguageUtil = function () {
|
|
2189
|
+
function LanguageUtil(options) {
|
|
2190
|
+
_classCallCheck(this, LanguageUtil);
|
|
2191
|
+
|
|
1943
2192
|
this.options = options;
|
|
1944
2193
|
this.supportedLngs = this.options.supportedLngs || false;
|
|
1945
2194
|
this.logger = baseLogger.create('languageUtils');
|
|
1946
2195
|
}
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
p
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
if (
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
2196
|
+
|
|
2197
|
+
_createClass(LanguageUtil, [{
|
|
2198
|
+
key: "getScriptPartFromCode",
|
|
2199
|
+
value: function getScriptPartFromCode(code) {
|
|
2200
|
+
if (!code || code.indexOf('-') < 0) return null;
|
|
2201
|
+
var p = code.split('-');
|
|
2202
|
+
if (p.length === 2) return null;
|
|
2203
|
+
p.pop();
|
|
2204
|
+
if (p[p.length - 1].toLowerCase() === 'x') return null;
|
|
2205
|
+
return this.formatLanguageCode(p.join('-'));
|
|
2206
|
+
}
|
|
2207
|
+
}, {
|
|
2208
|
+
key: "getLanguagePartFromCode",
|
|
2209
|
+
value: function getLanguagePartFromCode(code) {
|
|
2210
|
+
if (!code || code.indexOf('-') < 0) return code;
|
|
2211
|
+
var p = code.split('-');
|
|
2212
|
+
return this.formatLanguageCode(p[0]);
|
|
2213
|
+
}
|
|
2214
|
+
}, {
|
|
2215
|
+
key: "formatLanguageCode",
|
|
2216
|
+
value: function formatLanguageCode(code) {
|
|
2217
|
+
if (typeof code === 'string' && code.indexOf('-') > -1) {
|
|
2218
|
+
var specialCases = ['hans', 'hant', 'latn', 'cyrl', 'cans', 'mong', 'arab'];
|
|
2219
|
+
var p = code.split('-');
|
|
2220
|
+
|
|
2221
|
+
if (this.options.lowerCaseLng) {
|
|
2222
|
+
p = p.map(function (part) {
|
|
2223
|
+
return part.toLowerCase();
|
|
2224
|
+
});
|
|
2225
|
+
} else if (p.length === 2) {
|
|
2226
|
+
p[0] = p[0].toLowerCase();
|
|
2227
|
+
p[1] = p[1].toUpperCase();
|
|
2228
|
+
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
|
|
2229
|
+
} else if (p.length === 3) {
|
|
2230
|
+
p[0] = p[0].toLowerCase();
|
|
2231
|
+
if (p[1].length === 2) p[1] = p[1].toUpperCase();
|
|
2232
|
+
if (p[0] !== 'sgn' && p[2].length === 2) p[2] = p[2].toUpperCase();
|
|
2233
|
+
if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
|
|
2234
|
+
if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
return p.join('-');
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
1986
2241
|
}
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
2242
|
+
}, {
|
|
2243
|
+
key: "isSupportedCode",
|
|
2244
|
+
value: function isSupportedCode(code) {
|
|
2245
|
+
if (this.options.load === 'languageOnly' || this.options.nonExplicitSupportedLngs) {
|
|
2246
|
+
code = this.getLanguagePartFromCode(code);
|
|
2247
|
+
}
|
|
2248
|
+
|
|
2249
|
+
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
2250
|
+
}
|
|
2251
|
+
}, {
|
|
2252
|
+
key: "getBestMatchFromCodes",
|
|
2253
|
+
value: function getBestMatchFromCodes(codes) {
|
|
2254
|
+
var _this = this;
|
|
2255
|
+
|
|
2256
|
+
if (!codes) return null;
|
|
2257
|
+
var found;
|
|
2258
|
+
codes.forEach(function (code) {
|
|
1999
2259
|
if (found) return;
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2260
|
+
|
|
2261
|
+
var cleanedLng = _this.formatLanguageCode(code);
|
|
2262
|
+
|
|
2263
|
+
if (!_this.options.supportedLngs || _this.isSupportedCode(cleanedLng)) found = cleanedLng;
|
|
2264
|
+
});
|
|
2265
|
+
|
|
2266
|
+
if (!found && this.options.supportedLngs) {
|
|
2267
|
+
codes.forEach(function (code) {
|
|
2268
|
+
if (found) return;
|
|
2269
|
+
|
|
2270
|
+
var lngOnly = _this.getLanguagePartFromCode(code);
|
|
2271
|
+
|
|
2272
|
+
if (_this.isSupportedCode(lngOnly)) return found = lngOnly;
|
|
2273
|
+
found = _this.options.supportedLngs.find(function (supportedLng) {
|
|
2274
|
+
if (supportedLng.indexOf(lngOnly) === 0) return supportedLng;
|
|
2275
|
+
});
|
|
2007
2276
|
});
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
2280
|
+
return found;
|
|
2281
|
+
}
|
|
2282
|
+
}, {
|
|
2283
|
+
key: "getFallbackCodes",
|
|
2284
|
+
value: function getFallbackCodes(fallbacks, code) {
|
|
2285
|
+
if (!fallbacks) return [];
|
|
2286
|
+
if (typeof fallbacks === 'function') fallbacks = fallbacks(code);
|
|
2287
|
+
if (typeof fallbacks === 'string') fallbacks = [fallbacks];
|
|
2288
|
+
if (Object.prototype.toString.apply(fallbacks) === '[object Array]') return fallbacks;
|
|
2289
|
+
if (!code) return fallbacks["default"] || [];
|
|
2290
|
+
var found = fallbacks[code];
|
|
2291
|
+
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
2292
|
+
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
2293
|
+
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
2294
|
+
if (!found) found = fallbacks["default"];
|
|
2295
|
+
return found || [];
|
|
2296
|
+
}
|
|
2297
|
+
}, {
|
|
2298
|
+
key: "toResolveHierarchy",
|
|
2299
|
+
value: function toResolveHierarchy(code, fallbackCode) {
|
|
2300
|
+
var _this2 = this;
|
|
2301
|
+
|
|
2302
|
+
var fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
2303
|
+
var codes = [];
|
|
2304
|
+
|
|
2305
|
+
var addCode = function addCode(c) {
|
|
2306
|
+
if (!c) return;
|
|
2307
|
+
|
|
2308
|
+
if (_this2.isSupportedCode(c)) {
|
|
2309
|
+
codes.push(c);
|
|
2310
|
+
} else {
|
|
2311
|
+
_this2.logger.warn("rejecting language code not found in supportedLngs: ".concat(c));
|
|
2312
|
+
}
|
|
2313
|
+
};
|
|
2314
|
+
|
|
2315
|
+
if (typeof code === 'string' && code.indexOf('-') > -1) {
|
|
2316
|
+
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
|
|
2317
|
+
if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
|
|
2318
|
+
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
|
|
2319
|
+
} else if (typeof code === 'string') {
|
|
2320
|
+
addCode(this.formatLanguageCode(code));
|
|
2321
|
+
}
|
|
2322
|
+
|
|
2323
|
+
fallbackCodes.forEach(function (fc) {
|
|
2324
|
+
if (codes.indexOf(fc) < 0) addCode(_this2.formatLanguageCode(fc));
|
|
2008
2325
|
});
|
|
2326
|
+
return codes;
|
|
2009
2327
|
}
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
if (!fallbacks) return [];
|
|
2015
|
-
if (typeof fallbacks === 'function') fallbacks = fallbacks(code);
|
|
2016
|
-
if (typeof fallbacks === 'string') fallbacks = [fallbacks];
|
|
2017
|
-
if (Array.isArray(fallbacks)) return fallbacks;
|
|
2018
|
-
if (!code) return fallbacks.default || [];
|
|
2019
|
-
let found = fallbacks[code];
|
|
2020
|
-
if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
|
|
2021
|
-
if (!found) found = fallbacks[this.formatLanguageCode(code)];
|
|
2022
|
-
if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
2023
|
-
if (!found) found = fallbacks.default;
|
|
2024
|
-
return found || [];
|
|
2025
|
-
}
|
|
2026
|
-
toResolveHierarchy(code, fallbackCode) {
|
|
2027
|
-
const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
2028
|
-
const codes = [];
|
|
2029
|
-
const addCode = c => {
|
|
2030
|
-
if (!c) return;
|
|
2031
|
-
if (this.isSupportedCode(c)) {
|
|
2032
|
-
codes.push(c);
|
|
2033
|
-
} else {
|
|
2034
|
-
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
2035
|
-
}
|
|
2036
|
-
};
|
|
2037
|
-
if (typeof code === 'string' && (code.indexOf('-') > -1 || code.indexOf('_') > -1)) {
|
|
2038
|
-
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code));
|
|
2039
|
-
if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code));
|
|
2040
|
-
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
|
|
2041
|
-
} else if (typeof code === 'string') {
|
|
2042
|
-
addCode(this.formatLanguageCode(code));
|
|
2043
|
-
}
|
|
2044
|
-
fallbackCodes.forEach(fc => {
|
|
2045
|
-
if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
|
|
2046
|
-
});
|
|
2047
|
-
return codes;
|
|
2048
|
-
}
|
|
2049
|
-
}
|
|
2328
|
+
}]);
|
|
2329
|
+
|
|
2330
|
+
return LanguageUtil;
|
|
2331
|
+
}();
|
|
2050
2332
|
|
|
2051
|
-
|
|
2333
|
+
var sets = [{
|
|
2052
2334
|
lngs: ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'gun', 'ln', 'mfe', 'mg', 'mi', 'oc', 'pt', 'pt-BR', 'tg', 'tl', 'ti', 'tr', 'uz', 'wa'],
|
|
2053
2335
|
nr: [1, 2],
|
|
2054
2336
|
fc: 1
|
|
@@ -2141,77 +2423,76 @@ let sets = [{
|
|
|
2141
2423
|
nr: [1, 2, 20, 21],
|
|
2142
2424
|
fc: 22
|
|
2143
2425
|
}];
|
|
2144
|
-
|
|
2145
|
-
1: function (n) {
|
|
2426
|
+
var _rulesPluralsTypes = {
|
|
2427
|
+
1: function _(n) {
|
|
2146
2428
|
return Number(n > 1);
|
|
2147
2429
|
},
|
|
2148
|
-
2: function (n) {
|
|
2430
|
+
2: function _(n) {
|
|
2149
2431
|
return Number(n != 1);
|
|
2150
2432
|
},
|
|
2151
|
-
3: function (n) {
|
|
2433
|
+
3: function _(n) {
|
|
2152
2434
|
return 0;
|
|
2153
2435
|
},
|
|
2154
|
-
4: function (n) {
|
|
2436
|
+
4: function _(n) {
|
|
2155
2437
|
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
2156
2438
|
},
|
|
2157
|
-
5: function (n) {
|
|
2439
|
+
5: function _(n) {
|
|
2158
2440
|
return Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5);
|
|
2159
2441
|
},
|
|
2160
|
-
6: function (n) {
|
|
2442
|
+
6: function _(n) {
|
|
2161
2443
|
return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2);
|
|
2162
2444
|
},
|
|
2163
|
-
7: function (n) {
|
|
2445
|
+
7: function _(n) {
|
|
2164
2446
|
return Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
2165
2447
|
},
|
|
2166
|
-
8: function (n) {
|
|
2448
|
+
8: function _(n) {
|
|
2167
2449
|
return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3);
|
|
2168
2450
|
},
|
|
2169
|
-
9: function (n) {
|
|
2451
|
+
9: function _(n) {
|
|
2170
2452
|
return Number(n >= 2);
|
|
2171
2453
|
},
|
|
2172
|
-
10: function (n) {
|
|
2454
|
+
10: function _(n) {
|
|
2173
2455
|
return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4);
|
|
2174
2456
|
},
|
|
2175
|
-
11: function (n) {
|
|
2457
|
+
11: function _(n) {
|
|
2176
2458
|
return Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3);
|
|
2177
2459
|
},
|
|
2178
|
-
12: function (n) {
|
|
2460
|
+
12: function _(n) {
|
|
2179
2461
|
return Number(n % 10 != 1 || n % 100 == 11);
|
|
2180
2462
|
},
|
|
2181
|
-
13: function (n) {
|
|
2463
|
+
13: function _(n) {
|
|
2182
2464
|
return Number(n !== 0);
|
|
2183
2465
|
},
|
|
2184
|
-
14: function (n) {
|
|
2466
|
+
14: function _(n) {
|
|
2185
2467
|
return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3);
|
|
2186
2468
|
},
|
|
2187
|
-
15: function (n) {
|
|
2469
|
+
15: function _(n) {
|
|
2188
2470
|
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
2189
2471
|
},
|
|
2190
|
-
16: function (n) {
|
|
2472
|
+
16: function _(n) {
|
|
2191
2473
|
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2);
|
|
2192
2474
|
},
|
|
2193
|
-
17: function (n) {
|
|
2475
|
+
17: function _(n) {
|
|
2194
2476
|
return Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1);
|
|
2195
2477
|
},
|
|
2196
|
-
18: function (n) {
|
|
2478
|
+
18: function _(n) {
|
|
2197
2479
|
return Number(n == 0 ? 0 : n == 1 ? 1 : 2);
|
|
2198
2480
|
},
|
|
2199
|
-
19: function (n) {
|
|
2481
|
+
19: function _(n) {
|
|
2200
2482
|
return Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3);
|
|
2201
2483
|
},
|
|
2202
|
-
20: function (n) {
|
|
2484
|
+
20: function _(n) {
|
|
2203
2485
|
return Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2);
|
|
2204
2486
|
},
|
|
2205
|
-
21: function (n) {
|
|
2487
|
+
21: function _(n) {
|
|
2206
2488
|
return Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0);
|
|
2207
2489
|
},
|
|
2208
|
-
22: function (n) {
|
|
2490
|
+
22: function _(n) {
|
|
2209
2491
|
return Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3);
|
|
2210
2492
|
}
|
|
2211
2493
|
};
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
const suffixesOrder = {
|
|
2494
|
+
var deprecatedJsonVersions = ['v1', 'v2', 'v3'];
|
|
2495
|
+
var suffixesOrder = {
|
|
2215
2496
|
zero: 0,
|
|
2216
2497
|
one: 1,
|
|
2217
2498
|
two: 2,
|
|
@@ -2219,10 +2500,11 @@ const suffixesOrder = {
|
|
|
2219
2500
|
many: 4,
|
|
2220
2501
|
other: 5
|
|
2221
2502
|
};
|
|
2503
|
+
|
|
2222
2504
|
function createRules() {
|
|
2223
|
-
|
|
2224
|
-
sets.forEach(set
|
|
2225
|
-
set.lngs.forEach(l
|
|
2505
|
+
var rules = {};
|
|
2506
|
+
sets.forEach(function (set) {
|
|
2507
|
+
set.lngs.forEach(function (l) {
|
|
2226
2508
|
rules[l] = {
|
|
2227
2509
|
numbers: set.nr,
|
|
2228
2510
|
plurals: _rulesPluralsTypes[set.fc]
|
|
@@ -2231,432 +2513,542 @@ function createRules() {
|
|
|
2231
2513
|
});
|
|
2232
2514
|
return rules;
|
|
2233
2515
|
}
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2516
|
+
|
|
2517
|
+
var PluralResolver = function () {
|
|
2518
|
+
function PluralResolver(languageUtils) {
|
|
2519
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2520
|
+
|
|
2521
|
+
_classCallCheck(this, PluralResolver);
|
|
2522
|
+
|
|
2237
2523
|
this.languageUtils = languageUtils;
|
|
2238
2524
|
this.options = options;
|
|
2239
2525
|
this.logger = baseLogger.create('pluralResolver');
|
|
2240
|
-
|
|
2526
|
+
|
|
2527
|
+
if ((!this.options.compatibilityJSON || this.options.compatibilityJSON === 'v4') && (typeof Intl === 'undefined' || !Intl.PluralRules)) {
|
|
2241
2528
|
this.options.compatibilityJSON = 'v3';
|
|
2242
2529
|
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.');
|
|
2243
2530
|
}
|
|
2531
|
+
|
|
2244
2532
|
this.rules = createRules();
|
|
2245
2533
|
}
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2534
|
+
|
|
2535
|
+
_createClass(PluralResolver, [{
|
|
2536
|
+
key: "addRule",
|
|
2537
|
+
value: function addRule(lng, obj) {
|
|
2538
|
+
this.rules[lng] = obj;
|
|
2539
|
+
}
|
|
2540
|
+
}, {
|
|
2541
|
+
key: "getRule",
|
|
2542
|
+
value: function getRule(code) {
|
|
2543
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2544
|
+
|
|
2545
|
+
if (this.shouldUseIntlApi()) {
|
|
2546
|
+
try {
|
|
2547
|
+
return new Intl.PluralRules(code, {
|
|
2548
|
+
type: options.ordinal ? 'ordinal' : 'cardinal'
|
|
2549
|
+
});
|
|
2550
|
+
} catch (_unused) {
|
|
2551
|
+
return;
|
|
2552
|
+
}
|
|
2258
2553
|
}
|
|
2554
|
+
|
|
2555
|
+
return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
|
|
2259
2556
|
}
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2557
|
+
}, {
|
|
2558
|
+
key: "needsPlural",
|
|
2559
|
+
value: function needsPlural(code) {
|
|
2560
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2561
|
+
var rule = this.getRule(code, options);
|
|
2562
|
+
|
|
2563
|
+
if (this.shouldUseIntlApi()) {
|
|
2564
|
+
return rule && rule.resolvedOptions().pluralCategories.length > 1;
|
|
2565
|
+
}
|
|
2566
|
+
|
|
2567
|
+
return rule && rule.numbers.length > 1;
|
|
2568
|
+
}
|
|
2569
|
+
}, {
|
|
2570
|
+
key: "getPluralFormsOfKey",
|
|
2571
|
+
value: function getPluralFormsOfKey(code, key) {
|
|
2572
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2573
|
+
return this.getSuffixes(code, options).map(function (suffix) {
|
|
2574
|
+
return "".concat(key).concat(suffix);
|
|
2575
|
+
});
|
|
2267
2576
|
}
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2577
|
+
}, {
|
|
2578
|
+
key: "getSuffixes",
|
|
2579
|
+
value: function getSuffixes(code) {
|
|
2580
|
+
var _this = this;
|
|
2581
|
+
|
|
2582
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2583
|
+
var rule = this.getRule(code, options);
|
|
2584
|
+
|
|
2585
|
+
if (!rule) {
|
|
2586
|
+
return [];
|
|
2587
|
+
}
|
|
2588
|
+
|
|
2589
|
+
if (this.shouldUseIntlApi()) {
|
|
2590
|
+
return rule.resolvedOptions().pluralCategories.sort(function (pluralCategory1, pluralCategory2) {
|
|
2591
|
+
return suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2];
|
|
2592
|
+
}).map(function (pluralCategory) {
|
|
2593
|
+
return "".concat(_this.options.prepend).concat(pluralCategory);
|
|
2594
|
+
});
|
|
2595
|
+
}
|
|
2596
|
+
|
|
2597
|
+
return rule.numbers.map(function (number) {
|
|
2598
|
+
return _this.getSuffix(code, number, options);
|
|
2599
|
+
});
|
|
2279
2600
|
}
|
|
2280
|
-
|
|
2281
|
-
|
|
2601
|
+
}, {
|
|
2602
|
+
key: "getSuffix",
|
|
2603
|
+
value: function getSuffix(code, count) {
|
|
2604
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2605
|
+
var rule = this.getRule(code, options);
|
|
2606
|
+
|
|
2607
|
+
if (rule) {
|
|
2608
|
+
if (this.shouldUseIntlApi()) {
|
|
2609
|
+
return "".concat(this.options.prepend).concat(rule.select(count));
|
|
2610
|
+
}
|
|
2611
|
+
|
|
2612
|
+
return this.getSuffixRetroCompatible(rule, count);
|
|
2613
|
+
}
|
|
2614
|
+
|
|
2615
|
+
this.logger.warn("no plural rule found for: ".concat(code));
|
|
2616
|
+
return '';
|
|
2282
2617
|
}
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2618
|
+
}, {
|
|
2619
|
+
key: "getSuffixRetroCompatible",
|
|
2620
|
+
value: function getSuffixRetroCompatible(rule, count) {
|
|
2621
|
+
var _this2 = this;
|
|
2622
|
+
|
|
2623
|
+
var idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
|
|
2624
|
+
var suffix = rule.numbers[idx];
|
|
2625
|
+
|
|
2626
|
+
if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
2627
|
+
if (suffix === 2) {
|
|
2628
|
+
suffix = 'plural';
|
|
2629
|
+
} else if (suffix === 1) {
|
|
2630
|
+
suffix = '';
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2634
|
+
var returnSuffix = function returnSuffix() {
|
|
2635
|
+
return _this2.options.prepend && suffix.toString() ? _this2.options.prepend + suffix.toString() : suffix.toString();
|
|
2636
|
+
};
|
|
2637
|
+
|
|
2638
|
+
if (this.options.compatibilityJSON === 'v1') {
|
|
2639
|
+
if (suffix === 1) return '';
|
|
2640
|
+
if (typeof suffix === 'number') return "_plural_".concat(suffix.toString());
|
|
2641
|
+
return returnSuffix();
|
|
2642
|
+
} else if (this.options.compatibilityJSON === 'v2') {
|
|
2643
|
+
return returnSuffix();
|
|
2644
|
+
} else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
2645
|
+
return returnSuffix();
|
|
2291
2646
|
}
|
|
2292
|
-
|
|
2647
|
+
|
|
2648
|
+
return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
|
|
2293
2649
|
}
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
return returnSuffix();
|
|
2314
|
-
} else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
2315
|
-
return returnSuffix();
|
|
2316
|
-
}
|
|
2317
|
-
return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
|
|
2318
|
-
}
|
|
2319
|
-
shouldUseIntlApi() {
|
|
2320
|
-
return !nonIntlVersions.includes(this.options.compatibilityJSON);
|
|
2321
|
-
}
|
|
2322
|
-
}
|
|
2650
|
+
}, {
|
|
2651
|
+
key: "shouldUseIntlApi",
|
|
2652
|
+
value: function shouldUseIntlApi() {
|
|
2653
|
+
return !deprecatedJsonVersions.includes(this.options.compatibilityJSON);
|
|
2654
|
+
}
|
|
2655
|
+
}]);
|
|
2656
|
+
|
|
2657
|
+
return PluralResolver;
|
|
2658
|
+
}();
|
|
2659
|
+
|
|
2660
|
+
function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
2661
|
+
|
|
2662
|
+
function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$3(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
2663
|
+
|
|
2664
|
+
var Interpolator = function () {
|
|
2665
|
+
function Interpolator() {
|
|
2666
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2667
|
+
|
|
2668
|
+
_classCallCheck(this, Interpolator);
|
|
2323
2669
|
|
|
2324
|
-
function deepFindWithDefaults(data, defaultData, key) {
|
|
2325
|
-
let keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.';
|
|
2326
|
-
let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
2327
|
-
let path = getPathWithDefaults(data, defaultData, key);
|
|
2328
|
-
if (!path && ignoreJSONStructure && typeof key === 'string') {
|
|
2329
|
-
path = deepFind(data, key, keySeparator);
|
|
2330
|
-
if (path === undefined) path = deepFind(defaultData, key, keySeparator);
|
|
2331
|
-
}
|
|
2332
|
-
return path;
|
|
2333
|
-
}
|
|
2334
|
-
class Interpolator {
|
|
2335
|
-
constructor() {
|
|
2336
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2337
2670
|
this.logger = baseLogger.create('interpolator');
|
|
2338
2671
|
this.options = options;
|
|
2339
|
-
|
|
2340
|
-
this.
|
|
2341
|
-
|
|
2342
|
-
init() {
|
|
2343
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2344
|
-
if (!options.interpolation) options.interpolation = {
|
|
2345
|
-
escapeValue: true
|
|
2672
|
+
|
|
2673
|
+
this.format = options.interpolation && options.interpolation.format || function (value) {
|
|
2674
|
+
return value;
|
|
2346
2675
|
};
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
escapeValue,
|
|
2350
|
-
useRawValueToEscape,
|
|
2351
|
-
prefix,
|
|
2352
|
-
prefixEscaped,
|
|
2353
|
-
suffix,
|
|
2354
|
-
suffixEscaped,
|
|
2355
|
-
formatSeparator,
|
|
2356
|
-
unescapeSuffix,
|
|
2357
|
-
unescapePrefix,
|
|
2358
|
-
nestingPrefix,
|
|
2359
|
-
nestingPrefixEscaped,
|
|
2360
|
-
nestingSuffix,
|
|
2361
|
-
nestingSuffixEscaped,
|
|
2362
|
-
nestingOptionsSeparator,
|
|
2363
|
-
maxReplaces,
|
|
2364
|
-
alwaysFormat
|
|
2365
|
-
} = options.interpolation;
|
|
2366
|
-
this.escape = escape$1 !== undefined ? escape$1 : escape;
|
|
2367
|
-
this.escapeValue = escapeValue !== undefined ? escapeValue : true;
|
|
2368
|
-
this.useRawValueToEscape = useRawValueToEscape !== undefined ? useRawValueToEscape : false;
|
|
2369
|
-
this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || '{{';
|
|
2370
|
-
this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || '}}';
|
|
2371
|
-
this.formatSeparator = formatSeparator || ',';
|
|
2372
|
-
this.unescapePrefix = unescapeSuffix ? '' : unescapePrefix || '-';
|
|
2373
|
-
this.unescapeSuffix = this.unescapePrefix ? '' : unescapeSuffix || '';
|
|
2374
|
-
this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape('$t(');
|
|
2375
|
-
this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(')');
|
|
2376
|
-
this.nestingOptionsSeparator = nestingOptionsSeparator || ',';
|
|
2377
|
-
this.maxReplaces = maxReplaces || 1000;
|
|
2378
|
-
this.alwaysFormat = alwaysFormat !== undefined ? alwaysFormat : false;
|
|
2379
|
-
this.resetRegExp();
|
|
2380
|
-
}
|
|
2381
|
-
reset() {
|
|
2382
|
-
if (this.options) this.init(this.options);
|
|
2676
|
+
|
|
2677
|
+
this.init(options);
|
|
2383
2678
|
}
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2679
|
+
|
|
2680
|
+
_createClass(Interpolator, [{
|
|
2681
|
+
key: "init",
|
|
2682
|
+
value: function init() {
|
|
2683
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2684
|
+
if (!options.interpolation) options.interpolation = {
|
|
2685
|
+
escapeValue: true
|
|
2686
|
+
};
|
|
2687
|
+
var iOpts = options.interpolation;
|
|
2688
|
+
this.escape = iOpts.escape !== undefined ? iOpts.escape : escape;
|
|
2689
|
+
this.escapeValue = iOpts.escapeValue !== undefined ? iOpts.escapeValue : true;
|
|
2690
|
+
this.useRawValueToEscape = iOpts.useRawValueToEscape !== undefined ? iOpts.useRawValueToEscape : false;
|
|
2691
|
+
this.prefix = iOpts.prefix ? regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{';
|
|
2692
|
+
this.suffix = iOpts.suffix ? regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}';
|
|
2693
|
+
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
|
|
2694
|
+
this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-';
|
|
2695
|
+
this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || '';
|
|
2696
|
+
this.nestingPrefix = iOpts.nestingPrefix ? regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || regexEscape('$t(');
|
|
2697
|
+
this.nestingSuffix = iOpts.nestingSuffix ? regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || regexEscape(')');
|
|
2698
|
+
this.nestingOptionsSeparator = iOpts.nestingOptionsSeparator ? iOpts.nestingOptionsSeparator : iOpts.nestingOptionsSeparator || ',';
|
|
2699
|
+
this.maxReplaces = iOpts.maxReplaces ? iOpts.maxReplaces : 1000;
|
|
2700
|
+
this.alwaysFormat = iOpts.alwaysFormat !== undefined ? iOpts.alwaysFormat : false;
|
|
2701
|
+
this.resetRegExp();
|
|
2702
|
+
}
|
|
2703
|
+
}, {
|
|
2704
|
+
key: "reset",
|
|
2705
|
+
value: function reset() {
|
|
2706
|
+
if (this.options) this.init(this.options);
|
|
2707
|
+
}
|
|
2708
|
+
}, {
|
|
2709
|
+
key: "resetRegExp",
|
|
2710
|
+
value: function resetRegExp() {
|
|
2711
|
+
var regexpStr = "".concat(this.prefix, "(.+?)").concat(this.suffix);
|
|
2712
|
+
this.regexp = new RegExp(regexpStr, 'g');
|
|
2713
|
+
var regexpUnescapeStr = "".concat(this.prefix).concat(this.unescapePrefix, "(.+?)").concat(this.unescapeSuffix).concat(this.suffix);
|
|
2714
|
+
this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g');
|
|
2715
|
+
var nestingRegexpStr = "".concat(this.nestingPrefix, "(.+?)").concat(this.nestingSuffix);
|
|
2716
|
+
this.nestingRegexp = new RegExp(nestingRegexpStr, 'g');
|
|
2717
|
+
}
|
|
2718
|
+
}, {
|
|
2719
|
+
key: "interpolate",
|
|
2720
|
+
value: function interpolate(str, data, lng, options) {
|
|
2721
|
+
var _this = this;
|
|
2722
|
+
|
|
2723
|
+
var match;
|
|
2724
|
+
var value;
|
|
2725
|
+
var replaces;
|
|
2726
|
+
var defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
2727
|
+
|
|
2728
|
+
function regexSafe(val) {
|
|
2729
|
+
return val.replace(/\$/g, '$$$$');
|
|
2389
2730
|
}
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
}
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2731
|
+
|
|
2732
|
+
var handleFormat = function handleFormat(key) {
|
|
2733
|
+
if (key.indexOf(_this.formatSeparator) < 0) {
|
|
2734
|
+
var path = getPathWithDefaults(data, defaultData, key);
|
|
2735
|
+
return _this.alwaysFormat ? _this.format(path, undefined, lng, _objectSpread$3(_objectSpread$3(_objectSpread$3({}, options), data), {}, {
|
|
2736
|
+
interpolationkey: key
|
|
2737
|
+
})) : path;
|
|
2738
|
+
}
|
|
2739
|
+
|
|
2740
|
+
var p = key.split(_this.formatSeparator);
|
|
2741
|
+
var k = p.shift().trim();
|
|
2742
|
+
var f = p.join(_this.formatSeparator).trim();
|
|
2743
|
+
return _this.format(getPathWithDefaults(data, defaultData, k), f, lng, _objectSpread$3(_objectSpread$3(_objectSpread$3({}, options), data), {}, {
|
|
2744
|
+
interpolationkey: k
|
|
2745
|
+
}));
|
|
2746
|
+
};
|
|
2747
|
+
|
|
2748
|
+
this.resetRegExp();
|
|
2749
|
+
var missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
2750
|
+
var skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
2751
|
+
var todos = [{
|
|
2752
|
+
regex: this.regexpUnescape,
|
|
2753
|
+
safeValue: function safeValue(val) {
|
|
2754
|
+
return regexSafe(val);
|
|
2755
|
+
}
|
|
2756
|
+
}, {
|
|
2757
|
+
regex: this.regexp,
|
|
2758
|
+
safeValue: function safeValue(val) {
|
|
2759
|
+
return _this.escapeValue ? regexSafe(_this.escape(val)) : regexSafe(val);
|
|
2760
|
+
}
|
|
2761
|
+
}];
|
|
2762
|
+
todos.forEach(function (todo) {
|
|
2763
|
+
replaces = 0;
|
|
2764
|
+
|
|
2765
|
+
while (match = todo.regex.exec(str)) {
|
|
2766
|
+
var matchedVar = match[1].trim();
|
|
2767
|
+
value = handleFormat(matchedVar);
|
|
2768
|
+
|
|
2769
|
+
if (value === undefined) {
|
|
2770
|
+
if (typeof missingInterpolationHandler === 'function') {
|
|
2771
|
+
var temp = missingInterpolationHandler(str, match, options);
|
|
2772
|
+
value = typeof temp === 'string' ? temp : '';
|
|
2773
|
+
} else if (options && options.hasOwnProperty(matchedVar)) {
|
|
2774
|
+
value = '';
|
|
2775
|
+
} else if (skipOnVariables) {
|
|
2776
|
+
value = match[0];
|
|
2777
|
+
continue;
|
|
2778
|
+
} else {
|
|
2779
|
+
_this.logger.warn("missed to pass in variable ".concat(matchedVar, " for interpolating ").concat(str));
|
|
2780
|
+
|
|
2781
|
+
value = '';
|
|
2782
|
+
}
|
|
2783
|
+
} else if (typeof value !== 'string' && !_this.useRawValueToEscape) {
|
|
2784
|
+
value = makeString(value);
|
|
2785
|
+
}
|
|
2786
|
+
|
|
2787
|
+
var safeValue = todo.safeValue(value);
|
|
2788
|
+
str = str.replace(match[0], safeValue);
|
|
2789
|
+
|
|
2790
|
+
if (skipOnVariables) {
|
|
2791
|
+
todo.regex.lastIndex += value.length;
|
|
2792
|
+
todo.regex.lastIndex -= match[0].length;
|
|
2446
2793
|
} else {
|
|
2447
|
-
|
|
2448
|
-
|
|
2794
|
+
todo.regex.lastIndex = 0;
|
|
2795
|
+
}
|
|
2796
|
+
|
|
2797
|
+
replaces++;
|
|
2798
|
+
|
|
2799
|
+
if (replaces >= _this.maxReplaces) {
|
|
2800
|
+
break;
|
|
2449
2801
|
}
|
|
2450
|
-
} else if (typeof value !== 'string' && !this.useRawValueToEscape) {
|
|
2451
|
-
value = makeString(value);
|
|
2452
2802
|
}
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2803
|
+
});
|
|
2804
|
+
return str;
|
|
2805
|
+
}
|
|
2806
|
+
}, {
|
|
2807
|
+
key: "nest",
|
|
2808
|
+
value: function nest(str, fc) {
|
|
2809
|
+
var _this2 = this;
|
|
2810
|
+
|
|
2811
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
2812
|
+
var match;
|
|
2813
|
+
var value;
|
|
2814
|
+
|
|
2815
|
+
var clonedOptions = _objectSpread$3({}, options);
|
|
2816
|
+
|
|
2817
|
+
clonedOptions.applyPostProcessor = false;
|
|
2818
|
+
delete clonedOptions.defaultValue;
|
|
2819
|
+
|
|
2820
|
+
function handleHasOptions(key, inheritedOptions) {
|
|
2821
|
+
var sep = this.nestingOptionsSeparator;
|
|
2822
|
+
if (key.indexOf(sep) < 0) return key;
|
|
2823
|
+
var c = key.split(new RegExp("".concat(sep, "[ ]*{")));
|
|
2824
|
+
var optionsString = "{".concat(c[1]);
|
|
2825
|
+
key = c[0];
|
|
2826
|
+
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
2827
|
+
var matchedSingleQuotes = optionsString.match(/'/g);
|
|
2828
|
+
var matchedDoubleQuotes = optionsString.match(/"/g);
|
|
2829
|
+
|
|
2830
|
+
if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
|
|
2831
|
+
optionsString = optionsString.replace(/'/g, '"');
|
|
2460
2832
|
}
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2833
|
+
|
|
2834
|
+
try {
|
|
2835
|
+
clonedOptions = JSON.parse(optionsString);
|
|
2836
|
+
if (inheritedOptions) clonedOptions = _objectSpread$3(_objectSpread$3({}, inheritedOptions), clonedOptions);
|
|
2837
|
+
} catch (e) {
|
|
2838
|
+
this.logger.warn("failed parsing options string in nesting for key ".concat(key), e);
|
|
2839
|
+
return "".concat(key).concat(sep).concat(optionsString);
|
|
2464
2840
|
}
|
|
2841
|
+
|
|
2842
|
+
delete clonedOptions.defaultValue;
|
|
2843
|
+
return key;
|
|
2465
2844
|
}
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2845
|
+
|
|
2846
|
+
while (match = this.nestingRegexp.exec(str)) {
|
|
2847
|
+
var formatters = [];
|
|
2848
|
+
var doReduce = false;
|
|
2849
|
+
|
|
2850
|
+
if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
|
|
2851
|
+
var r = match[1].split(this.formatSeparator).map(function (elem) {
|
|
2852
|
+
return elem.trim();
|
|
2853
|
+
});
|
|
2854
|
+
match[1] = r.shift();
|
|
2855
|
+
formatters = r;
|
|
2856
|
+
doReduce = true;
|
|
2857
|
+
}
|
|
2858
|
+
|
|
2859
|
+
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
2860
|
+
if (value && match[0] === str && typeof value !== 'string') return value;
|
|
2861
|
+
if (typeof value !== 'string') value = makeString(value);
|
|
2862
|
+
|
|
2863
|
+
if (!value) {
|
|
2864
|
+
this.logger.warn("missed to resolve ".concat(match[1], " for nesting ").concat(str));
|
|
2865
|
+
value = '';
|
|
2866
|
+
}
|
|
2867
|
+
|
|
2868
|
+
if (doReduce) {
|
|
2869
|
+
value = formatters.reduce(function (v, f) {
|
|
2870
|
+
return _this2.format(v, f, options.lng, _objectSpread$3(_objectSpread$3({}, options), {}, {
|
|
2871
|
+
interpolationkey: match[1].trim()
|
|
2872
|
+
}));
|
|
2873
|
+
}, value.trim());
|
|
2874
|
+
}
|
|
2875
|
+
|
|
2876
|
+
str = str.replace(match[0], value);
|
|
2877
|
+
this.regexp.lastIndex = 0;
|
|
2495
2878
|
}
|
|
2496
|
-
|
|
2497
|
-
return
|
|
2879
|
+
|
|
2880
|
+
return str;
|
|
2498
2881
|
}
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
let doReduce = false;
|
|
2508
|
-
if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
|
|
2509
|
-
const r = match[1].split(this.formatSeparator).map(elem => elem.trim());
|
|
2510
|
-
match[1] = r.shift();
|
|
2511
|
-
formatters = r;
|
|
2512
|
-
doReduce = true;
|
|
2513
|
-
}
|
|
2514
|
-
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
2515
|
-
if (value && match[0] === str && typeof value !== 'string') return value;
|
|
2516
|
-
if (typeof value !== 'string') value = makeString(value);
|
|
2517
|
-
if (!value) {
|
|
2518
|
-
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
2519
|
-
value = '';
|
|
2520
|
-
}
|
|
2521
|
-
if (doReduce) {
|
|
2522
|
-
value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
2523
|
-
...options,
|
|
2524
|
-
interpolationkey: match[1].trim()
|
|
2525
|
-
}), value.trim());
|
|
2526
|
-
}
|
|
2527
|
-
str = str.replace(match[0], value);
|
|
2528
|
-
this.regexp.lastIndex = 0;
|
|
2529
|
-
}
|
|
2530
|
-
return str;
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2882
|
+
}]);
|
|
2883
|
+
|
|
2884
|
+
return Interpolator;
|
|
2885
|
+
}();
|
|
2886
|
+
|
|
2887
|
+
function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
2888
|
+
|
|
2889
|
+
function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$4(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
2533
2890
|
|
|
2534
2891
|
function parseFormatStr(formatStr) {
|
|
2535
|
-
|
|
2536
|
-
|
|
2892
|
+
var formatName = formatStr.toLowerCase().trim();
|
|
2893
|
+
var formatOptions = {};
|
|
2894
|
+
|
|
2537
2895
|
if (formatStr.indexOf('(') > -1) {
|
|
2538
|
-
|
|
2896
|
+
var p = formatStr.split('(');
|
|
2539
2897
|
formatName = p[0].toLowerCase().trim();
|
|
2540
|
-
|
|
2898
|
+
var optStr = p[1].substring(0, p[1].length - 1);
|
|
2899
|
+
|
|
2541
2900
|
if (formatName === 'currency' && optStr.indexOf(':') < 0) {
|
|
2542
2901
|
if (!formatOptions.currency) formatOptions.currency = optStr.trim();
|
|
2543
2902
|
} else if (formatName === 'relativetime' && optStr.indexOf(':') < 0) {
|
|
2544
2903
|
if (!formatOptions.range) formatOptions.range = optStr.trim();
|
|
2545
2904
|
} else {
|
|
2546
|
-
|
|
2547
|
-
opts.forEach(opt
|
|
2548
|
-
if (opt)
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2905
|
+
var opts = optStr.split(';');
|
|
2906
|
+
opts.forEach(function (opt) {
|
|
2907
|
+
if (!opt) return;
|
|
2908
|
+
|
|
2909
|
+
var _opt$split = opt.split(':'),
|
|
2910
|
+
_opt$split2 = _toArray(_opt$split),
|
|
2911
|
+
key = _opt$split2[0],
|
|
2912
|
+
rest = _opt$split2.slice(1);
|
|
2913
|
+
|
|
2914
|
+
var val = rest.join(':').trim().replace(/^'+|'+$/g, '');
|
|
2915
|
+
if (!formatOptions[key.trim()]) formatOptions[key.trim()] = val;
|
|
2916
|
+
if (val === 'false') formatOptions[key.trim()] = false;
|
|
2917
|
+
if (val === 'true') formatOptions[key.trim()] = true;
|
|
2918
|
+
if (!isNaN(val)) formatOptions[key.trim()] = parseInt(val, 10);
|
|
2557
2919
|
});
|
|
2558
2920
|
}
|
|
2559
2921
|
}
|
|
2922
|
+
|
|
2560
2923
|
return {
|
|
2561
|
-
formatName,
|
|
2562
|
-
formatOptions
|
|
2924
|
+
formatName: formatName,
|
|
2925
|
+
formatOptions: formatOptions
|
|
2563
2926
|
};
|
|
2564
2927
|
}
|
|
2928
|
+
|
|
2565
2929
|
function createCachedFormatter(fn) {
|
|
2566
|
-
|
|
2930
|
+
var cache = {};
|
|
2567
2931
|
return function invokeFormatter(val, lng, options) {
|
|
2568
|
-
|
|
2569
|
-
|
|
2932
|
+
var key = lng + JSON.stringify(options);
|
|
2933
|
+
var formatter = cache[key];
|
|
2934
|
+
|
|
2570
2935
|
if (!formatter) {
|
|
2571
|
-
formatter = fn(
|
|
2936
|
+
formatter = fn(lng, options);
|
|
2572
2937
|
cache[key] = formatter;
|
|
2573
2938
|
}
|
|
2939
|
+
|
|
2574
2940
|
return formatter(val);
|
|
2575
2941
|
};
|
|
2576
2942
|
}
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2943
|
+
|
|
2944
|
+
var Formatter = function () {
|
|
2945
|
+
function Formatter() {
|
|
2946
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2947
|
+
|
|
2948
|
+
_classCallCheck(this, Formatter);
|
|
2949
|
+
|
|
2580
2950
|
this.logger = baseLogger.create('formatter');
|
|
2581
2951
|
this.options = options;
|
|
2582
2952
|
this.formats = {
|
|
2583
|
-
number: createCachedFormatter((lng,
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2953
|
+
number: createCachedFormatter(function (lng, options) {
|
|
2954
|
+
var formatter = new Intl.NumberFormat(lng, options);
|
|
2955
|
+
return function (val) {
|
|
2956
|
+
return formatter.format(val);
|
|
2957
|
+
};
|
|
2588
2958
|
}),
|
|
2589
|
-
currency: createCachedFormatter((lng,
|
|
2590
|
-
|
|
2591
|
-
...opt,
|
|
2959
|
+
currency: createCachedFormatter(function (lng, options) {
|
|
2960
|
+
var formatter = new Intl.NumberFormat(lng, _objectSpread$4(_objectSpread$4({}, options), {}, {
|
|
2592
2961
|
style: 'currency'
|
|
2593
|
-
});
|
|
2594
|
-
return
|
|
2962
|
+
}));
|
|
2963
|
+
return function (val) {
|
|
2964
|
+
return formatter.format(val);
|
|
2965
|
+
};
|
|
2595
2966
|
}),
|
|
2596
|
-
datetime: createCachedFormatter((lng,
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2967
|
+
datetime: createCachedFormatter(function (lng, options) {
|
|
2968
|
+
var formatter = new Intl.DateTimeFormat(lng, _objectSpread$4({}, options));
|
|
2969
|
+
return function (val) {
|
|
2970
|
+
return formatter.format(val);
|
|
2971
|
+
};
|
|
2601
2972
|
}),
|
|
2602
|
-
relativetime: createCachedFormatter((lng,
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2973
|
+
relativetime: createCachedFormatter(function (lng, options) {
|
|
2974
|
+
var formatter = new Intl.RelativeTimeFormat(lng, _objectSpread$4({}, options));
|
|
2975
|
+
return function (val) {
|
|
2976
|
+
return formatter.format(val, options.range || 'day');
|
|
2977
|
+
};
|
|
2607
2978
|
}),
|
|
2608
|
-
list: createCachedFormatter((lng,
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2979
|
+
list: createCachedFormatter(function (lng, options) {
|
|
2980
|
+
var formatter = new Intl.ListFormat(lng, _objectSpread$4({}, options));
|
|
2981
|
+
return function (val) {
|
|
2982
|
+
return formatter.format(val);
|
|
2983
|
+
};
|
|
2613
2984
|
})
|
|
2614
2985
|
};
|
|
2615
2986
|
this.init(options);
|
|
2616
2987
|
}
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2988
|
+
|
|
2989
|
+
_createClass(Formatter, [{
|
|
2990
|
+
key: "init",
|
|
2991
|
+
value: function init(services) {
|
|
2992
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
2993
|
+
interpolation: {}
|
|
2994
|
+
};
|
|
2995
|
+
var iOpts = options.interpolation;
|
|
2996
|
+
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
|
|
2997
|
+
}
|
|
2998
|
+
}, {
|
|
2999
|
+
key: "add",
|
|
3000
|
+
value: function add(name, fc) {
|
|
3001
|
+
this.formats[name.toLowerCase().trim()] = fc;
|
|
3002
|
+
}
|
|
3003
|
+
}, {
|
|
3004
|
+
key: "addCached",
|
|
3005
|
+
value: function addCached(name, fc) {
|
|
3006
|
+
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
3007
|
+
}
|
|
3008
|
+
}, {
|
|
3009
|
+
key: "format",
|
|
3010
|
+
value: function format(value, _format, lng, options) {
|
|
3011
|
+
var _this = this;
|
|
3012
|
+
|
|
3013
|
+
var formats = _format.split(this.formatSeparator);
|
|
3014
|
+
|
|
3015
|
+
var result = formats.reduce(function (mem, f) {
|
|
3016
|
+
var _parseFormatStr = parseFormatStr(f),
|
|
3017
|
+
formatName = _parseFormatStr.formatName,
|
|
3018
|
+
formatOptions = _parseFormatStr.formatOptions;
|
|
3019
|
+
|
|
3020
|
+
if (_this.formats[formatName]) {
|
|
3021
|
+
var formatted = mem;
|
|
3022
|
+
|
|
3023
|
+
try {
|
|
3024
|
+
var valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
|
|
3025
|
+
var l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
3026
|
+
formatted = _this.formats[formatName](mem, l, _objectSpread$4(_objectSpread$4(_objectSpread$4({}, formatOptions), options), valOptions));
|
|
3027
|
+
} catch (error) {
|
|
3028
|
+
_this.logger.warn(error);
|
|
3029
|
+
}
|
|
3030
|
+
|
|
3031
|
+
return formatted;
|
|
3032
|
+
} else {
|
|
3033
|
+
_this.logger.warn("there was no format function for ".concat(formatName));
|
|
2650
3034
|
}
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
}
|
|
3035
|
+
|
|
3036
|
+
return mem;
|
|
3037
|
+
}, value);
|
|
3038
|
+
return result;
|
|
3039
|
+
}
|
|
3040
|
+
}]);
|
|
3041
|
+
|
|
3042
|
+
return Formatter;
|
|
3043
|
+
}();
|
|
3044
|
+
|
|
3045
|
+
function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
3046
|
+
|
|
3047
|
+
function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$5(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
3048
|
+
|
|
3049
|
+
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); }; }
|
|
3050
|
+
|
|
3051
|
+
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; } }
|
|
2660
3052
|
|
|
2661
3053
|
function removePending(q, name) {
|
|
2662
3054
|
if (q.pending[name] !== undefined) {
|
|
@@ -2664,225 +3056,257 @@ function removePending(q, name) {
|
|
|
2664
3056
|
q.pendingCount--;
|
|
2665
3057
|
}
|
|
2666
3058
|
}
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
this
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
if (this.backend && this.backend.init) {
|
|
2685
|
-
this.backend.init(services, options.backend, options);
|
|
3059
|
+
|
|
3060
|
+
var Connector = function (_EventEmitter) {
|
|
3061
|
+
_inherits(Connector, _EventEmitter);
|
|
3062
|
+
|
|
3063
|
+
var _super = _createSuper$2(Connector);
|
|
3064
|
+
|
|
3065
|
+
function Connector(backend, store, services) {
|
|
3066
|
+
var _this;
|
|
3067
|
+
|
|
3068
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
3069
|
+
|
|
3070
|
+
_classCallCheck(this, Connector);
|
|
3071
|
+
|
|
3072
|
+
_this = _super.call(this);
|
|
3073
|
+
|
|
3074
|
+
if (isIE10) {
|
|
3075
|
+
EventEmitter.call(_assertThisInitialized(_this));
|
|
2686
3076
|
}
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
if (pending[name] === undefined) pending[name] = true;
|
|
2705
|
-
if (toLoad[name] === undefined) toLoad[name] = true;
|
|
2706
|
-
if (toLoadNamespaces[ns] === undefined) toLoadNamespaces[ns] = true;
|
|
2707
|
-
}
|
|
2708
|
-
});
|
|
2709
|
-
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
2710
|
-
});
|
|
2711
|
-
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
2712
|
-
this.queue.push({
|
|
2713
|
-
pending,
|
|
2714
|
-
pendingCount: Object.keys(pending).length,
|
|
2715
|
-
loaded: {},
|
|
2716
|
-
errors: [],
|
|
2717
|
-
callback
|
|
2718
|
-
});
|
|
3077
|
+
|
|
3078
|
+
_this.backend = backend;
|
|
3079
|
+
_this.store = store;
|
|
3080
|
+
_this.services = services;
|
|
3081
|
+
_this.languageUtils = services.languageUtils;
|
|
3082
|
+
_this.options = options;
|
|
3083
|
+
_this.logger = baseLogger.create('backendConnector');
|
|
3084
|
+
_this.waitingReads = [];
|
|
3085
|
+
_this.maxParallelReads = options.maxParallelReads || 10;
|
|
3086
|
+
_this.readingCalls = 0;
|
|
3087
|
+
_this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
3088
|
+
_this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
3089
|
+
_this.state = {};
|
|
3090
|
+
_this.queue = [];
|
|
3091
|
+
|
|
3092
|
+
if (_this.backend && _this.backend.init) {
|
|
3093
|
+
_this.backend.init(services, options.backend, options);
|
|
2719
3094
|
}
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
pending: Object.keys(pending),
|
|
2723
|
-
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
2724
|
-
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
2725
|
-
};
|
|
3095
|
+
|
|
3096
|
+
return _this;
|
|
2726
3097
|
}
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
3098
|
+
|
|
3099
|
+
_createClass(Connector, [{
|
|
3100
|
+
key: "queueLoad",
|
|
3101
|
+
value: function queueLoad(languages, namespaces, options, callback) {
|
|
3102
|
+
var _this2 = this;
|
|
3103
|
+
|
|
3104
|
+
var toLoad = {};
|
|
3105
|
+
var pending = {};
|
|
3106
|
+
var toLoadLanguages = {};
|
|
3107
|
+
var toLoadNamespaces = {};
|
|
3108
|
+
languages.forEach(function (lng) {
|
|
3109
|
+
var hasAllNamespaces = true;
|
|
3110
|
+
namespaces.forEach(function (ns) {
|
|
3111
|
+
var name = "".concat(lng, "|").concat(ns);
|
|
3112
|
+
|
|
3113
|
+
if (!options.reload && _this2.store.hasResourceBundle(lng, ns)) {
|
|
3114
|
+
_this2.state[name] = 2;
|
|
3115
|
+
} else if (_this2.state[name] < 0) ; else if (_this2.state[name] === 1) {
|
|
3116
|
+
if (pending[name] === undefined) pending[name] = true;
|
|
3117
|
+
} else {
|
|
3118
|
+
_this2.state[name] = 1;
|
|
3119
|
+
hasAllNamespaces = false;
|
|
3120
|
+
if (pending[name] === undefined) pending[name] = true;
|
|
3121
|
+
if (toLoad[name] === undefined) toLoad[name] = true;
|
|
3122
|
+
if (toLoadNamespaces[ns] === undefined) toLoadNamespaces[ns] = true;
|
|
3123
|
+
}
|
|
3124
|
+
});
|
|
3125
|
+
if (!hasAllNamespaces) toLoadLanguages[lng] = true;
|
|
2735
3126
|
});
|
|
3127
|
+
|
|
3128
|
+
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
3129
|
+
this.queue.push({
|
|
3130
|
+
pending: pending,
|
|
3131
|
+
pendingCount: Object.keys(pending).length,
|
|
3132
|
+
loaded: {},
|
|
3133
|
+
errors: [],
|
|
3134
|
+
callback: callback
|
|
3135
|
+
});
|
|
3136
|
+
}
|
|
3137
|
+
|
|
3138
|
+
return {
|
|
3139
|
+
toLoad: Object.keys(toLoad),
|
|
3140
|
+
pending: Object.keys(pending),
|
|
3141
|
+
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
3142
|
+
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
3143
|
+
};
|
|
2736
3144
|
}
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
if (
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
3145
|
+
}, {
|
|
3146
|
+
key: "loaded",
|
|
3147
|
+
value: function loaded(name, err, data) {
|
|
3148
|
+
var s = name.split('|');
|
|
3149
|
+
var lng = s[0];
|
|
3150
|
+
var ns = s[1];
|
|
3151
|
+
if (err) this.emit('failedLoading', lng, ns, err);
|
|
3152
|
+
|
|
3153
|
+
if (data) {
|
|
3154
|
+
this.store.addResourceBundle(lng, ns, data);
|
|
3155
|
+
}
|
|
3156
|
+
|
|
3157
|
+
this.state[name] = err ? -1 : 2;
|
|
3158
|
+
var loaded = {};
|
|
3159
|
+
this.queue.forEach(function (q) {
|
|
3160
|
+
pushPath(q.loaded, [lng], ns);
|
|
3161
|
+
removePending(q, name);
|
|
3162
|
+
if (err) q.errors.push(err);
|
|
3163
|
+
|
|
3164
|
+
if (q.pendingCount === 0 && !q.done) {
|
|
3165
|
+
Object.keys(q.loaded).forEach(function (l) {
|
|
3166
|
+
if (!loaded[l]) loaded[l] = {};
|
|
3167
|
+
var loadedKeys = q.loaded[l];
|
|
3168
|
+
|
|
3169
|
+
if (loadedKeys.length) {
|
|
3170
|
+
loadedKeys.forEach(function (ns) {
|
|
3171
|
+
if (loaded[l][ns] === undefined) loaded[l][ns] = true;
|
|
3172
|
+
});
|
|
3173
|
+
}
|
|
3174
|
+
});
|
|
3175
|
+
q.done = true;
|
|
3176
|
+
|
|
3177
|
+
if (q.errors.length) {
|
|
3178
|
+
q.callback(q.errors);
|
|
3179
|
+
} else {
|
|
3180
|
+
q.callback();
|
|
2751
3181
|
}
|
|
2752
|
-
});
|
|
2753
|
-
q.done = true;
|
|
2754
|
-
if (q.errors.length) {
|
|
2755
|
-
q.callback(q.errors);
|
|
2756
|
-
} else {
|
|
2757
|
-
q.callback();
|
|
2758
3182
|
}
|
|
2759
|
-
}
|
|
2760
|
-
});
|
|
2761
|
-
this.emit('loaded', loaded);
|
|
2762
|
-
this.queue = this.queue.filter(q => !q.done);
|
|
2763
|
-
}
|
|
2764
|
-
read(lng, ns, fcName) {
|
|
2765
|
-
let tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
2766
|
-
let wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
|
|
2767
|
-
let callback = arguments.length > 5 ? arguments[5] : undefined;
|
|
2768
|
-
if (!lng.length) return callback(null, {});
|
|
2769
|
-
if (this.readingCalls >= this.maxParallelReads) {
|
|
2770
|
-
this.waitingReads.push({
|
|
2771
|
-
lng,
|
|
2772
|
-
ns,
|
|
2773
|
-
fcName,
|
|
2774
|
-
tried,
|
|
2775
|
-
wait,
|
|
2776
|
-
callback
|
|
2777
3183
|
});
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
3184
|
+
this.emit('loaded', loaded);
|
|
3185
|
+
this.queue = this.queue.filter(function (q) {
|
|
3186
|
+
return !q.done;
|
|
3187
|
+
});
|
|
3188
|
+
}
|
|
3189
|
+
}, {
|
|
3190
|
+
key: "read",
|
|
3191
|
+
value: function read(lng, ns, fcName) {
|
|
3192
|
+
var _this3 = this;
|
|
3193
|
+
|
|
3194
|
+
var tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
3195
|
+
var wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
|
|
3196
|
+
var callback = arguments.length > 5 ? arguments[5] : undefined;
|
|
3197
|
+
if (!lng.length) return callback(null, {});
|
|
3198
|
+
|
|
3199
|
+
if (this.readingCalls >= this.maxParallelReads) {
|
|
3200
|
+
this.waitingReads.push({
|
|
3201
|
+
lng: lng,
|
|
3202
|
+
ns: ns,
|
|
3203
|
+
fcName: fcName,
|
|
3204
|
+
tried: tried,
|
|
3205
|
+
wait: wait,
|
|
3206
|
+
callback: callback
|
|
3207
|
+
});
|
|
2791
3208
|
return;
|
|
2792
3209
|
}
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
resolver(null, r);
|
|
3210
|
+
|
|
3211
|
+
this.readingCalls++;
|
|
3212
|
+
return this.backend[fcName](lng, ns, function (err, data) {
|
|
3213
|
+
_this3.readingCalls--;
|
|
3214
|
+
|
|
3215
|
+
if (_this3.waitingReads.length > 0) {
|
|
3216
|
+
var next = _this3.waitingReads.shift();
|
|
3217
|
+
|
|
3218
|
+
_this3.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
2803
3219
|
}
|
|
2804
|
-
|
|
2805
|
-
|
|
3220
|
+
|
|
3221
|
+
if (err && data && tried < _this3.maxRetries) {
|
|
3222
|
+
setTimeout(function () {
|
|
3223
|
+
_this3.read.call(_this3, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
3224
|
+
}, wait);
|
|
3225
|
+
return;
|
|
3226
|
+
}
|
|
3227
|
+
|
|
3228
|
+
callback(err, data);
|
|
3229
|
+
});
|
|
3230
|
+
}
|
|
3231
|
+
}, {
|
|
3232
|
+
key: "prepareLoading",
|
|
3233
|
+
value: function prepareLoading(languages, namespaces) {
|
|
3234
|
+
var _this4 = this;
|
|
3235
|
+
|
|
3236
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
3237
|
+
var callback = arguments.length > 3 ? arguments[3] : undefined;
|
|
3238
|
+
|
|
3239
|
+
if (!this.backend) {
|
|
3240
|
+
this.logger.warn('No backend was added via i18next.use. Will not load resources.');
|
|
3241
|
+
return callback && callback();
|
|
3242
|
+
}
|
|
3243
|
+
|
|
3244
|
+
if (typeof languages === 'string') languages = this.languageUtils.toResolveHierarchy(languages);
|
|
3245
|
+
if (typeof namespaces === 'string') namespaces = [namespaces];
|
|
3246
|
+
var toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
3247
|
+
|
|
3248
|
+
if (!toLoad.toLoad.length) {
|
|
3249
|
+
if (!toLoad.pending.length) callback();
|
|
3250
|
+
return null;
|
|
2806
3251
|
}
|
|
2807
|
-
|
|
3252
|
+
|
|
3253
|
+
toLoad.toLoad.forEach(function (name) {
|
|
3254
|
+
_this4.loadOne(name);
|
|
3255
|
+
});
|
|
2808
3256
|
}
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
3257
|
+
}, {
|
|
3258
|
+
key: "load",
|
|
3259
|
+
value: function load(languages, namespaces, callback) {
|
|
3260
|
+
this.prepareLoading(languages, namespaces, {}, callback);
|
|
3261
|
+
}
|
|
3262
|
+
}, {
|
|
3263
|
+
key: "reload",
|
|
3264
|
+
value: function reload(languages, namespaces, callback) {
|
|
3265
|
+
this.prepareLoading(languages, namespaces, {
|
|
3266
|
+
reload: true
|
|
3267
|
+
}, callback);
|
|
3268
|
+
}
|
|
3269
|
+
}, {
|
|
3270
|
+
key: "loadOne",
|
|
3271
|
+
value: function loadOne(name) {
|
|
3272
|
+
var _this5 = this;
|
|
3273
|
+
|
|
3274
|
+
var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
3275
|
+
var s = name.split('|');
|
|
3276
|
+
var lng = s[0];
|
|
3277
|
+
var ns = s[1];
|
|
3278
|
+
this.read(lng, ns, 'read', undefined, undefined, function (err, data) {
|
|
3279
|
+
if (err) _this5.logger.warn("".concat(prefix, "loading namespace ").concat(ns, " for language ").concat(lng, " failed"), err);
|
|
3280
|
+
if (!err && data) _this5.logger.log("".concat(prefix, "loaded namespace ").concat(ns, " for language ").concat(lng), data);
|
|
3281
|
+
|
|
3282
|
+
_this5.loaded(name, err, data);
|
|
3283
|
+
});
|
|
2824
3284
|
}
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
this.prepareLoading(languages, namespaces, {
|
|
2834
|
-
reload: true
|
|
2835
|
-
}, callback);
|
|
2836
|
-
}
|
|
2837
|
-
loadOne(name) {
|
|
2838
|
-
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
2839
|
-
const s = name.split('|');
|
|
2840
|
-
const lng = s[0];
|
|
2841
|
-
const ns = s[1];
|
|
2842
|
-
this.read(lng, ns, 'read', undefined, undefined, (err, data) => {
|
|
2843
|
-
if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
2844
|
-
if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
2845
|
-
this.loaded(name, err, data);
|
|
2846
|
-
});
|
|
2847
|
-
}
|
|
2848
|
-
saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
2849
|
-
let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
2850
|
-
let clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : () => {};
|
|
2851
|
-
if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
|
|
2852
|
-
this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, 'This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!');
|
|
2853
|
-
return;
|
|
2854
|
-
}
|
|
2855
|
-
if (key === undefined || key === null || key === '') return;
|
|
2856
|
-
if (this.backend && this.backend.create) {
|
|
2857
|
-
const opts = {
|
|
2858
|
-
...options,
|
|
2859
|
-
isUpdate
|
|
2860
|
-
};
|
|
2861
|
-
const fc = this.backend.create.bind(this.backend);
|
|
2862
|
-
if (fc.length < 6) {
|
|
2863
|
-
try {
|
|
2864
|
-
let r;
|
|
2865
|
-
if (fc.length === 5) {
|
|
2866
|
-
r = fc(languages, namespace, key, fallbackValue, opts);
|
|
2867
|
-
} else {
|
|
2868
|
-
r = fc(languages, namespace, key, fallbackValue);
|
|
2869
|
-
}
|
|
2870
|
-
if (r && typeof r.then === 'function') {
|
|
2871
|
-
r.then(data => clb(null, data)).catch(clb);
|
|
2872
|
-
} else {
|
|
2873
|
-
clb(null, r);
|
|
2874
|
-
}
|
|
2875
|
-
} catch (err) {
|
|
2876
|
-
clb(err);
|
|
2877
|
-
}
|
|
2878
|
-
} else {
|
|
2879
|
-
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
3285
|
+
}, {
|
|
3286
|
+
key: "saveMissing",
|
|
3287
|
+
value: function saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
3288
|
+
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
3289
|
+
|
|
3290
|
+
if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
|
|
3291
|
+
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!!!');
|
|
3292
|
+
return;
|
|
2880
3293
|
}
|
|
3294
|
+
|
|
3295
|
+
if (key === undefined || key === null || key === '') return;
|
|
3296
|
+
|
|
3297
|
+
if (this.backend && this.backend.create) {
|
|
3298
|
+
this.backend.create(languages, namespace, key, fallbackValue, null, _objectSpread$5(_objectSpread$5({}, options), {}, {
|
|
3299
|
+
isUpdate: isUpdate
|
|
3300
|
+
}));
|
|
3301
|
+
}
|
|
3302
|
+
|
|
3303
|
+
if (!languages || !languages[0]) return;
|
|
3304
|
+
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
2881
3305
|
}
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
}
|
|
3306
|
+
}]);
|
|
3307
|
+
|
|
3308
|
+
return Connector;
|
|
3309
|
+
}(EventEmitter);
|
|
2886
3310
|
|
|
2887
3311
|
function get() {
|
|
2888
3312
|
return {
|
|
@@ -2910,7 +3334,7 @@ function get() {
|
|
|
2910
3334
|
missingInterpolationHandler: false,
|
|
2911
3335
|
postProcess: false,
|
|
2912
3336
|
postProcessPassResolved: false,
|
|
2913
|
-
returnNull:
|
|
3337
|
+
returnNull: true,
|
|
2914
3338
|
returnEmptyString: true,
|
|
2915
3339
|
returnObjects: false,
|
|
2916
3340
|
joinArrays: false,
|
|
@@ -2919,21 +3343,25 @@ function get() {
|
|
|
2919
3343
|
appendNamespaceToMissingKey: false,
|
|
2920
3344
|
appendNamespaceToCIMode: false,
|
|
2921
3345
|
overloadTranslationOptionHandler: function handle(args) {
|
|
2922
|
-
|
|
2923
|
-
if (
|
|
3346
|
+
var ret = {};
|
|
3347
|
+
if (_typeof(args[1]) === 'object') ret = args[1];
|
|
2924
3348
|
if (typeof args[1] === 'string') ret.defaultValue = args[1];
|
|
2925
3349
|
if (typeof args[2] === 'string') ret.tDescription = args[2];
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
3350
|
+
|
|
3351
|
+
if (_typeof(args[2]) === 'object' || _typeof(args[3]) === 'object') {
|
|
3352
|
+
var options = args[3] || args[2];
|
|
3353
|
+
Object.keys(options).forEach(function (key) {
|
|
2929
3354
|
ret[key] = options[key];
|
|
2930
3355
|
});
|
|
2931
3356
|
}
|
|
3357
|
+
|
|
2932
3358
|
return ret;
|
|
2933
3359
|
},
|
|
2934
3360
|
interpolation: {
|
|
2935
3361
|
escapeValue: true,
|
|
2936
|
-
format: value
|
|
3362
|
+
format: function format(value, _format, lng, options) {
|
|
3363
|
+
return value;
|
|
3364
|
+
},
|
|
2937
3365
|
prefix: '{{',
|
|
2938
3366
|
suffix: '}}',
|
|
2939
3367
|
formatSeparator: ',',
|
|
@@ -2950,496 +3378,636 @@ function transformOptions(options) {
|
|
|
2950
3378
|
if (typeof options.ns === 'string') options.ns = [options.ns];
|
|
2951
3379
|
if (typeof options.fallbackLng === 'string') options.fallbackLng = [options.fallbackLng];
|
|
2952
3380
|
if (typeof options.fallbackNS === 'string') options.fallbackNS = [options.fallbackNS];
|
|
3381
|
+
|
|
2953
3382
|
if (options.supportedLngs && options.supportedLngs.indexOf('cimode') < 0) {
|
|
2954
3383
|
options.supportedLngs = options.supportedLngs.concat(['cimode']);
|
|
2955
3384
|
}
|
|
3385
|
+
|
|
2956
3386
|
return options;
|
|
2957
3387
|
}
|
|
2958
3388
|
|
|
3389
|
+
function ownKeys$6(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
3390
|
+
|
|
3391
|
+
function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$6(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$6(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
3392
|
+
|
|
3393
|
+
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); }; }
|
|
3394
|
+
|
|
3395
|
+
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; } }
|
|
3396
|
+
|
|
2959
3397
|
function noop() {}
|
|
3398
|
+
|
|
2960
3399
|
function bindMemberFunctions(inst) {
|
|
2961
|
-
|
|
2962
|
-
mems.forEach(mem
|
|
3400
|
+
var mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
3401
|
+
mems.forEach(function (mem) {
|
|
2963
3402
|
if (typeof inst[mem] === 'function') {
|
|
2964
3403
|
inst[mem] = inst[mem].bind(inst);
|
|
2965
3404
|
}
|
|
2966
3405
|
});
|
|
2967
3406
|
}
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
this.init(options, callback);
|
|
2987
|
-
}, 0);
|
|
3407
|
+
|
|
3408
|
+
var I18n = function (_EventEmitter) {
|
|
3409
|
+
_inherits(I18n, _EventEmitter);
|
|
3410
|
+
|
|
3411
|
+
var _super = _createSuper$3(I18n);
|
|
3412
|
+
|
|
3413
|
+
function I18n() {
|
|
3414
|
+
var _this;
|
|
3415
|
+
|
|
3416
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3417
|
+
var callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
3418
|
+
|
|
3419
|
+
_classCallCheck(this, I18n);
|
|
3420
|
+
|
|
3421
|
+
_this = _super.call(this);
|
|
3422
|
+
|
|
3423
|
+
if (isIE10) {
|
|
3424
|
+
EventEmitter.call(_assertThisInitialized(_this));
|
|
2988
3425
|
}
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
if (typeof options === 'function') {
|
|
2996
|
-
callback = options;
|
|
2997
|
-
options = {};
|
|
2998
|
-
}
|
|
2999
|
-
if (!options.defaultNS && options.defaultNS !== false && options.ns) {
|
|
3000
|
-
if (typeof options.ns === 'string') {
|
|
3001
|
-
options.defaultNS = options.ns;
|
|
3002
|
-
} else if (options.ns.indexOf('translation') < 0) {
|
|
3003
|
-
options.defaultNS = options.ns[0];
|
|
3004
|
-
}
|
|
3005
|
-
}
|
|
3006
|
-
const defOpts = get();
|
|
3007
|
-
this.options = {
|
|
3008
|
-
...defOpts,
|
|
3009
|
-
...this.options,
|
|
3010
|
-
...transformOptions(options)
|
|
3426
|
+
|
|
3427
|
+
_this.options = transformOptions(options);
|
|
3428
|
+
_this.services = {};
|
|
3429
|
+
_this.logger = baseLogger;
|
|
3430
|
+
_this.modules = {
|
|
3431
|
+
external: []
|
|
3011
3432
|
};
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
function createClassOnDemand(ClassOrObject) {
|
|
3025
|
-
if (!ClassOrObject) return null;
|
|
3026
|
-
if (typeof ClassOrObject === 'function') return new ClassOrObject();
|
|
3027
|
-
return ClassOrObject;
|
|
3433
|
+
bindMemberFunctions(_assertThisInitialized(_this));
|
|
3434
|
+
|
|
3435
|
+
if (callback && !_this.isInitialized && !options.isClone) {
|
|
3436
|
+
if (!_this.options.initImmediate) {
|
|
3437
|
+
_this.init(options, callback);
|
|
3438
|
+
|
|
3439
|
+
return _possibleConstructorReturn(_this, _assertThisInitialized(_this));
|
|
3440
|
+
}
|
|
3441
|
+
|
|
3442
|
+
setTimeout(function () {
|
|
3443
|
+
_this.init(options, callback);
|
|
3444
|
+
}, 0);
|
|
3028
3445
|
}
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
});
|
|
3052
|
-
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
3053
|
-
s.formatter = createClassOnDemand(formatter);
|
|
3054
|
-
s.formatter.init(s, this.options);
|
|
3055
|
-
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
3056
|
-
}
|
|
3057
|
-
s.interpolator = new Interpolator(this.options);
|
|
3058
|
-
s.utils = {
|
|
3059
|
-
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
3060
|
-
};
|
|
3061
|
-
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
3062
|
-
s.backendConnector.on('*', function (event) {
|
|
3063
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
3064
|
-
args[_key - 1] = arguments[_key];
|
|
3446
|
+
|
|
3447
|
+
return _this;
|
|
3448
|
+
}
|
|
3449
|
+
|
|
3450
|
+
_createClass(I18n, [{
|
|
3451
|
+
key: "init",
|
|
3452
|
+
value: function init() {
|
|
3453
|
+
var _this2 = this;
|
|
3454
|
+
|
|
3455
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3456
|
+
var callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
3457
|
+
|
|
3458
|
+
if (typeof options === 'function') {
|
|
3459
|
+
callback = options;
|
|
3460
|
+
options = {};
|
|
3461
|
+
}
|
|
3462
|
+
|
|
3463
|
+
if (!options.defaultNS && options.defaultNS !== false && options.ns) {
|
|
3464
|
+
if (typeof options.ns === 'string') {
|
|
3465
|
+
options.defaultNS = options.ns;
|
|
3466
|
+
} else if (options.ns.indexOf('translation') < 0) {
|
|
3467
|
+
options.defaultNS = options.ns[0];
|
|
3065
3468
|
}
|
|
3066
|
-
_this.emit(event, ...args);
|
|
3067
|
-
});
|
|
3068
|
-
if (this.modules.languageDetector) {
|
|
3069
|
-
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
3070
|
-
if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
|
|
3071
3469
|
}
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3470
|
+
|
|
3471
|
+
var defOpts = get();
|
|
3472
|
+
this.options = _objectSpread$6(_objectSpread$6(_objectSpread$6({}, defOpts), this.options), transformOptions(options));
|
|
3473
|
+
|
|
3474
|
+
if (this.options.compatibilityAPI !== 'v1') {
|
|
3475
|
+
this.options.interpolation = _objectSpread$6(_objectSpread$6({}, defOpts.interpolation), this.options.interpolation);
|
|
3476
|
+
}
|
|
3477
|
+
|
|
3478
|
+
if (options.keySeparator !== undefined) {
|
|
3479
|
+
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
3480
|
+
}
|
|
3481
|
+
|
|
3482
|
+
if (options.nsSeparator !== undefined) {
|
|
3483
|
+
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
3484
|
+
}
|
|
3485
|
+
|
|
3486
|
+
function createClassOnDemand(ClassOrObject) {
|
|
3487
|
+
if (!ClassOrObject) return null;
|
|
3488
|
+
if (typeof ClassOrObject === 'function') return new ClassOrObject();
|
|
3489
|
+
return ClassOrObject;
|
|
3075
3490
|
}
|
|
3076
|
-
|
|
3077
|
-
this.
|
|
3078
|
-
|
|
3079
|
-
|
|
3491
|
+
|
|
3492
|
+
if (!this.options.isClone) {
|
|
3493
|
+
if (this.modules.logger) {
|
|
3494
|
+
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
3495
|
+
} else {
|
|
3496
|
+
baseLogger.init(null, this.options);
|
|
3497
|
+
}
|
|
3498
|
+
|
|
3499
|
+
var formatter;
|
|
3500
|
+
|
|
3501
|
+
if (this.modules.formatter) {
|
|
3502
|
+
formatter = this.modules.formatter;
|
|
3503
|
+
} else if (typeof Intl !== 'undefined') {
|
|
3504
|
+
formatter = Formatter;
|
|
3505
|
+
}
|
|
3506
|
+
|
|
3507
|
+
var lu = new LanguageUtil(this.options);
|
|
3508
|
+
this.store = new ResourceStore(this.options.resources, this.options);
|
|
3509
|
+
var s = this.services;
|
|
3510
|
+
s.logger = baseLogger;
|
|
3511
|
+
s.resourceStore = this.store;
|
|
3512
|
+
s.languageUtils = lu;
|
|
3513
|
+
s.pluralResolver = new PluralResolver(lu, {
|
|
3514
|
+
prepend: this.options.pluralSeparator,
|
|
3515
|
+
compatibilityJSON: this.options.compatibilityJSON,
|
|
3516
|
+
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
3517
|
+
});
|
|
3518
|
+
|
|
3519
|
+
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
3520
|
+
s.formatter = createClassOnDemand(formatter);
|
|
3521
|
+
s.formatter.init(s, this.options);
|
|
3522
|
+
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
3523
|
+
}
|
|
3524
|
+
|
|
3525
|
+
s.interpolator = new Interpolator(this.options);
|
|
3526
|
+
s.utils = {
|
|
3527
|
+
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
3528
|
+
};
|
|
3529
|
+
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
3530
|
+
s.backendConnector.on('*', function (event) {
|
|
3531
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
3532
|
+
args[_key - 1] = arguments[_key];
|
|
3533
|
+
}
|
|
3534
|
+
|
|
3535
|
+
_this2.emit.apply(_this2, [event].concat(args));
|
|
3536
|
+
});
|
|
3537
|
+
|
|
3538
|
+
if (this.modules.languageDetector) {
|
|
3539
|
+
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
3540
|
+
s.languageDetector.init(s, this.options.detection, this.options);
|
|
3541
|
+
}
|
|
3542
|
+
|
|
3543
|
+
if (this.modules.i18nFormat) {
|
|
3544
|
+
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
3545
|
+
if (s.i18nFormat.init) s.i18nFormat.init(this);
|
|
3080
3546
|
}
|
|
3081
|
-
|
|
3547
|
+
|
|
3548
|
+
this.translator = new Translator(this.services, this.options);
|
|
3549
|
+
this.translator.on('*', function (event) {
|
|
3550
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
3551
|
+
args[_key2 - 1] = arguments[_key2];
|
|
3552
|
+
}
|
|
3553
|
+
|
|
3554
|
+
_this2.emit.apply(_this2, [event].concat(args));
|
|
3555
|
+
});
|
|
3556
|
+
this.modules.external.forEach(function (m) {
|
|
3557
|
+
if (m.init) m.init(_this2);
|
|
3558
|
+
});
|
|
3559
|
+
}
|
|
3560
|
+
|
|
3561
|
+
this.format = this.options.interpolation.format;
|
|
3562
|
+
if (!callback) callback = noop;
|
|
3563
|
+
|
|
3564
|
+
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
3565
|
+
var codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
3566
|
+
if (codes.length > 0 && codes[0] !== 'dev') this.options.lng = codes[0];
|
|
3567
|
+
}
|
|
3568
|
+
|
|
3569
|
+
if (!this.services.languageDetector && !this.options.lng) {
|
|
3570
|
+
this.logger.warn('init: no languageDetector is used and no lng is defined');
|
|
3571
|
+
}
|
|
3572
|
+
|
|
3573
|
+
var storeApi = ['getResource', 'hasResourceBundle', 'getResourceBundle', 'getDataByLanguage'];
|
|
3574
|
+
storeApi.forEach(function (fcName) {
|
|
3575
|
+
_this2[fcName] = function () {
|
|
3576
|
+
var _this2$store;
|
|
3577
|
+
|
|
3578
|
+
return (_this2$store = _this2.store)[fcName].apply(_this2$store, arguments);
|
|
3579
|
+
};
|
|
3082
3580
|
});
|
|
3083
|
-
|
|
3084
|
-
|
|
3581
|
+
var storeApiChained = ['addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle'];
|
|
3582
|
+
storeApiChained.forEach(function (fcName) {
|
|
3583
|
+
_this2[fcName] = function () {
|
|
3584
|
+
var _this2$store2;
|
|
3585
|
+
|
|
3586
|
+
(_this2$store2 = _this2.store)[fcName].apply(_this2$store2, arguments);
|
|
3587
|
+
|
|
3588
|
+
return _this2;
|
|
3589
|
+
};
|
|
3085
3590
|
});
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
storeApiChained.forEach(fcName => {
|
|
3104
|
-
this[fcName] = function () {
|
|
3105
|
-
_this.store[fcName](...arguments);
|
|
3106
|
-
return _this;
|
|
3107
|
-
};
|
|
3108
|
-
});
|
|
3109
|
-
const deferred = defer();
|
|
3110
|
-
const load = () => {
|
|
3111
|
-
const finish = (err, t) => {
|
|
3112
|
-
this.isInitializing = false;
|
|
3113
|
-
if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn('init: i18next is already initialized. You should call init just once!');
|
|
3114
|
-
this.isInitialized = true;
|
|
3115
|
-
if (!this.options.isClone) this.logger.log('initialized', this.options);
|
|
3116
|
-
this.emit('initialized', this.options);
|
|
3117
|
-
deferred.resolve(t);
|
|
3118
|
-
callback(err, t);
|
|
3591
|
+
var deferred = defer();
|
|
3592
|
+
|
|
3593
|
+
var load = function load() {
|
|
3594
|
+
var finish = function finish(err, t) {
|
|
3595
|
+
if (_this2.isInitialized && !_this2.initializedStoreOnce) _this2.logger.warn('init: i18next is already initialized. You should call init just once!');
|
|
3596
|
+
_this2.isInitialized = true;
|
|
3597
|
+
if (!_this2.options.isClone) _this2.logger.log('initialized', _this2.options);
|
|
3598
|
+
|
|
3599
|
+
_this2.emit('initialized', _this2.options);
|
|
3600
|
+
|
|
3601
|
+
deferred.resolve(t);
|
|
3602
|
+
callback(err, t);
|
|
3603
|
+
};
|
|
3604
|
+
|
|
3605
|
+
if (_this2.languages && _this2.options.compatibilityAPI !== 'v1' && !_this2.isInitialized) return finish(null, _this2.t.bind(_this2));
|
|
3606
|
+
|
|
3607
|
+
_this2.changeLanguage(_this2.options.lng, finish);
|
|
3119
3608
|
};
|
|
3120
|
-
|
|
3121
|
-
this.
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3609
|
+
|
|
3610
|
+
if (this.options.resources || !this.options.initImmediate) {
|
|
3611
|
+
load();
|
|
3612
|
+
} else {
|
|
3613
|
+
setTimeout(load, 0);
|
|
3614
|
+
}
|
|
3615
|
+
|
|
3616
|
+
return deferred;
|
|
3127
3617
|
}
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
if (
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
if (
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
if (
|
|
3144
|
-
|
|
3618
|
+
}, {
|
|
3619
|
+
key: "loadResources",
|
|
3620
|
+
value: function loadResources(language) {
|
|
3621
|
+
var _this3 = this;
|
|
3622
|
+
|
|
3623
|
+
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
3624
|
+
var usedCallback = callback;
|
|
3625
|
+
var usedLng = typeof language === 'string' ? language : this.language;
|
|
3626
|
+
if (typeof language === 'function') usedCallback = language;
|
|
3627
|
+
|
|
3628
|
+
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
3629
|
+
if (usedLng && usedLng.toLowerCase() === 'cimode') return usedCallback();
|
|
3630
|
+
var toLoad = [];
|
|
3631
|
+
|
|
3632
|
+
var append = function append(lng) {
|
|
3633
|
+
if (!lng) return;
|
|
3634
|
+
|
|
3635
|
+
var lngs = _this3.services.languageUtils.toResolveHierarchy(lng);
|
|
3636
|
+
|
|
3637
|
+
lngs.forEach(function (l) {
|
|
3638
|
+
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
|
3639
|
+
});
|
|
3640
|
+
};
|
|
3641
|
+
|
|
3642
|
+
if (!usedLng) {
|
|
3643
|
+
var fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
3644
|
+
fallbacks.forEach(function (l) {
|
|
3645
|
+
return append(l);
|
|
3646
|
+
});
|
|
3647
|
+
} else {
|
|
3648
|
+
append(usedLng);
|
|
3649
|
+
}
|
|
3650
|
+
|
|
3651
|
+
if (this.options.preload) {
|
|
3652
|
+
this.options.preload.forEach(function (l) {
|
|
3653
|
+
return append(l);
|
|
3654
|
+
});
|
|
3655
|
+
}
|
|
3656
|
+
|
|
3657
|
+
this.services.backendConnector.load(toLoad, this.options.ns, function (e) {
|
|
3658
|
+
if (!e && !_this3.resolvedLanguage && _this3.language) _this3.setResolvedLanguage(_this3.language);
|
|
3659
|
+
usedCallback(e);
|
|
3145
3660
|
});
|
|
3146
|
-
};
|
|
3147
|
-
if (!usedLng) {
|
|
3148
|
-
const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
3149
|
-
fallbacks.forEach(l => append(l));
|
|
3150
3661
|
} else {
|
|
3151
|
-
|
|
3152
|
-
}
|
|
3153
|
-
if (this.options.preload) {
|
|
3154
|
-
this.options.preload.forEach(l => append(l));
|
|
3662
|
+
usedCallback(null);
|
|
3155
3663
|
}
|
|
3156
|
-
this.services.backendConnector.load(toLoad, this.options.ns, e => {
|
|
3157
|
-
if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
|
|
3158
|
-
usedCallback(e);
|
|
3159
|
-
});
|
|
3160
|
-
} else {
|
|
3161
|
-
usedCallback(null);
|
|
3162
3664
|
}
|
|
3163
|
-
}
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
use(module) {
|
|
3176
|
-
if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
|
|
3177
|
-
if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
|
|
3178
|
-
if (module.type === 'backend') {
|
|
3179
|
-
this.modules.backend = module;
|
|
3180
|
-
}
|
|
3181
|
-
if (module.type === 'logger' || module.log && module.warn && module.error) {
|
|
3182
|
-
this.modules.logger = module;
|
|
3183
|
-
}
|
|
3184
|
-
if (module.type === 'languageDetector') {
|
|
3185
|
-
this.modules.languageDetector = module;
|
|
3186
|
-
}
|
|
3187
|
-
if (module.type === 'i18nFormat') {
|
|
3188
|
-
this.modules.i18nFormat = module;
|
|
3189
|
-
}
|
|
3190
|
-
if (module.type === 'postProcessor') {
|
|
3191
|
-
postProcessor.addPostProcessor(module);
|
|
3192
|
-
}
|
|
3193
|
-
if (module.type === 'formatter') {
|
|
3194
|
-
this.modules.formatter = module;
|
|
3195
|
-
}
|
|
3196
|
-
if (module.type === '3rdParty') {
|
|
3197
|
-
this.modules.external.push(module);
|
|
3665
|
+
}, {
|
|
3666
|
+
key: "reloadResources",
|
|
3667
|
+
value: function reloadResources(lngs, ns, callback) {
|
|
3668
|
+
var deferred = defer();
|
|
3669
|
+
if (!lngs) lngs = this.languages;
|
|
3670
|
+
if (!ns) ns = this.options.ns;
|
|
3671
|
+
if (!callback) callback = noop;
|
|
3672
|
+
this.services.backendConnector.reload(lngs, ns, function (err) {
|
|
3673
|
+
deferred.resolve();
|
|
3674
|
+
callback(err);
|
|
3675
|
+
});
|
|
3676
|
+
return deferred;
|
|
3198
3677
|
}
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3678
|
+
}, {
|
|
3679
|
+
key: "use",
|
|
3680
|
+
value: function use(module) {
|
|
3681
|
+
if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()');
|
|
3682
|
+
if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()');
|
|
3683
|
+
|
|
3684
|
+
if (module.type === 'backend') {
|
|
3685
|
+
this.modules.backend = module;
|
|
3686
|
+
}
|
|
3687
|
+
|
|
3688
|
+
if (module.type === 'logger' || module.log && module.warn && module.error) {
|
|
3689
|
+
this.modules.logger = module;
|
|
3690
|
+
}
|
|
3691
|
+
|
|
3692
|
+
if (module.type === 'languageDetector') {
|
|
3693
|
+
this.modules.languageDetector = module;
|
|
3210
3694
|
}
|
|
3695
|
+
|
|
3696
|
+
if (module.type === 'i18nFormat') {
|
|
3697
|
+
this.modules.i18nFormat = module;
|
|
3698
|
+
}
|
|
3699
|
+
|
|
3700
|
+
if (module.type === 'postProcessor') {
|
|
3701
|
+
postProcessor.addPostProcessor(module);
|
|
3702
|
+
}
|
|
3703
|
+
|
|
3704
|
+
if (module.type === 'formatter') {
|
|
3705
|
+
this.modules.formatter = module;
|
|
3706
|
+
}
|
|
3707
|
+
|
|
3708
|
+
if (module.type === '3rdParty') {
|
|
3709
|
+
this.modules.external.push(module);
|
|
3710
|
+
}
|
|
3711
|
+
|
|
3712
|
+
return this;
|
|
3211
3713
|
}
|
|
3212
|
-
}
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
setLngProps(l);
|
|
3227
|
-
this.translator.changeLanguage(l);
|
|
3228
|
-
this.isLanguageChangingTo = undefined;
|
|
3229
|
-
this.emit('languageChanged', l);
|
|
3230
|
-
this.logger.log('languageChanged', l);
|
|
3231
|
-
} else {
|
|
3232
|
-
this.isLanguageChangingTo = undefined;
|
|
3714
|
+
}, {
|
|
3715
|
+
key: "setResolvedLanguage",
|
|
3716
|
+
value: function setResolvedLanguage(l) {
|
|
3717
|
+
if (!l || !this.languages) return;
|
|
3718
|
+
if (['cimode', 'dev'].indexOf(l) > -1) return;
|
|
3719
|
+
|
|
3720
|
+
for (var li = 0; li < this.languages.length; li++) {
|
|
3721
|
+
var lngInLngs = this.languages[li];
|
|
3722
|
+
if (['cimode', 'dev'].indexOf(lngInLngs) > -1) continue;
|
|
3723
|
+
|
|
3724
|
+
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
3725
|
+
this.resolvedLanguage = lngInLngs;
|
|
3726
|
+
break;
|
|
3727
|
+
}
|
|
3233
3728
|
}
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3729
|
+
}
|
|
3730
|
+
}, {
|
|
3731
|
+
key: "changeLanguage",
|
|
3732
|
+
value: function changeLanguage(lng, callback) {
|
|
3733
|
+
var _this4 = this;
|
|
3734
|
+
|
|
3735
|
+
this.isLanguageChangingTo = lng;
|
|
3736
|
+
var deferred = defer();
|
|
3737
|
+
this.emit('languageChanging', lng);
|
|
3738
|
+
|
|
3739
|
+
var setLngProps = function setLngProps(l) {
|
|
3740
|
+
_this4.language = l;
|
|
3741
|
+
_this4.languages = _this4.services.languageUtils.toResolveHierarchy(l);
|
|
3742
|
+
_this4.resolvedLanguage = undefined;
|
|
3743
|
+
|
|
3744
|
+
_this4.setResolvedLanguage(l);
|
|
3745
|
+
};
|
|
3746
|
+
|
|
3747
|
+
var done = function done(err, l) {
|
|
3748
|
+
if (l) {
|
|
3246
3749
|
setLngProps(l);
|
|
3750
|
+
|
|
3751
|
+
_this4.translator.changeLanguage(l);
|
|
3752
|
+
|
|
3753
|
+
_this4.isLanguageChangingTo = undefined;
|
|
3754
|
+
|
|
3755
|
+
_this4.emit('languageChanged', l);
|
|
3756
|
+
|
|
3757
|
+
_this4.logger.log('languageChanged', l);
|
|
3758
|
+
} else {
|
|
3759
|
+
_this4.isLanguageChangingTo = undefined;
|
|
3247
3760
|
}
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3761
|
+
|
|
3762
|
+
deferred.resolve(function () {
|
|
3763
|
+
return _this4.t.apply(_this4, arguments);
|
|
3764
|
+
});
|
|
3765
|
+
if (callback) callback(err, function () {
|
|
3766
|
+
return _this4.t.apply(_this4, arguments);
|
|
3767
|
+
});
|
|
3768
|
+
};
|
|
3769
|
+
|
|
3770
|
+
var setLng = function setLng(lngs) {
|
|
3771
|
+
if (!lng && !lngs && _this4.services.languageDetector) lngs = [];
|
|
3772
|
+
var l = typeof lngs === 'string' ? lngs : _this4.services.languageUtils.getBestMatchFromCodes(lngs);
|
|
3773
|
+
|
|
3774
|
+
if (l) {
|
|
3775
|
+
if (!_this4.language) {
|
|
3776
|
+
setLngProps(l);
|
|
3777
|
+
}
|
|
3778
|
+
|
|
3779
|
+
if (!_this4.translator.language) _this4.translator.changeLanguage(l);
|
|
3780
|
+
if (_this4.services.languageDetector) _this4.services.languageDetector.cacheUserLanguage(l);
|
|
3781
|
+
}
|
|
3782
|
+
|
|
3783
|
+
_this4.loadResources(l, function (err) {
|
|
3784
|
+
done(err, l);
|
|
3785
|
+
});
|
|
3786
|
+
};
|
|
3787
|
+
|
|
3788
|
+
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
3789
|
+
setLng(this.services.languageDetector.detect());
|
|
3790
|
+
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
3261
3791
|
this.services.languageDetector.detect(setLng);
|
|
3262
|
-
}
|
|
3263
|
-
} else {
|
|
3264
|
-
setLng(lng);
|
|
3265
|
-
}
|
|
3266
|
-
return deferred;
|
|
3267
|
-
}
|
|
3268
|
-
getFixedT(lng, ns, keyPrefix) {
|
|
3269
|
-
var _this3 = this;
|
|
3270
|
-
const fixedT = function (key, opts) {
|
|
3271
|
-
let options;
|
|
3272
|
-
if (typeof opts !== 'object') {
|
|
3273
|
-
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
3274
|
-
rest[_key3 - 2] = arguments[_key3];
|
|
3275
|
-
}
|
|
3276
|
-
options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
3277
3792
|
} else {
|
|
3278
|
-
|
|
3279
|
-
...opts
|
|
3280
|
-
};
|
|
3793
|
+
setLng(lng);
|
|
3281
3794
|
}
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3795
|
+
|
|
3796
|
+
return deferred;
|
|
3797
|
+
}
|
|
3798
|
+
}, {
|
|
3799
|
+
key: "getFixedT",
|
|
3800
|
+
value: function getFixedT(lng, ns, keyPrefix) {
|
|
3801
|
+
var _this5 = this;
|
|
3802
|
+
|
|
3803
|
+
var fixedT = function fixedT(key, opts) {
|
|
3804
|
+
var options;
|
|
3805
|
+
|
|
3806
|
+
if (_typeof(opts) !== 'object') {
|
|
3807
|
+
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
3808
|
+
rest[_key3 - 2] = arguments[_key3];
|
|
3809
|
+
}
|
|
3810
|
+
|
|
3811
|
+
options = _this5.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
3812
|
+
} else {
|
|
3813
|
+
options = _objectSpread$6({}, opts);
|
|
3814
|
+
}
|
|
3815
|
+
|
|
3816
|
+
options.lng = options.lng || fixedT.lng;
|
|
3817
|
+
options.lngs = options.lngs || fixedT.lngs;
|
|
3818
|
+
options.ns = options.ns || fixedT.ns;
|
|
3819
|
+
options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
3820
|
+
var keySeparator = _this5.options.keySeparator || '.';
|
|
3821
|
+
var resultKey = options.keyPrefix ? "".concat(options.keyPrefix).concat(keySeparator).concat(key) : key;
|
|
3822
|
+
return _this5.t(resultKey, options);
|
|
3823
|
+
};
|
|
3824
|
+
|
|
3825
|
+
if (typeof lng === 'string') {
|
|
3826
|
+
fixedT.lng = lng;
|
|
3290
3827
|
} else {
|
|
3291
|
-
|
|
3828
|
+
fixedT.lngs = lng;
|
|
3292
3829
|
}
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
fixedT
|
|
3297
|
-
}
|
|
3298
|
-
|
|
3830
|
+
|
|
3831
|
+
fixedT.ns = ns;
|
|
3832
|
+
fixedT.keyPrefix = keyPrefix;
|
|
3833
|
+
return fixedT;
|
|
3834
|
+
}
|
|
3835
|
+
}, {
|
|
3836
|
+
key: "t",
|
|
3837
|
+
value: function t() {
|
|
3838
|
+
var _this$translator;
|
|
3839
|
+
|
|
3840
|
+
return this.translator && (_this$translator = this.translator).translate.apply(_this$translator, arguments);
|
|
3299
3841
|
}
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
}
|
|
3307
|
-
exists() {
|
|
3308
|
-
return this.translator && this.translator.exists(...arguments);
|
|
3309
|
-
}
|
|
3310
|
-
setDefaultNamespace(ns) {
|
|
3311
|
-
this.options.defaultNS = ns;
|
|
3312
|
-
}
|
|
3313
|
-
hasLoadedNamespace(ns) {
|
|
3314
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3315
|
-
if (!this.isInitialized) {
|
|
3316
|
-
this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
|
|
3317
|
-
return false;
|
|
3842
|
+
}, {
|
|
3843
|
+
key: "exists",
|
|
3844
|
+
value: function exists() {
|
|
3845
|
+
var _this$translator2;
|
|
3846
|
+
|
|
3847
|
+
return this.translator && (_this$translator2 = this.translator).exists.apply(_this$translator2, arguments);
|
|
3318
3848
|
}
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3849
|
+
}, {
|
|
3850
|
+
key: "setDefaultNamespace",
|
|
3851
|
+
value: function setDefaultNamespace(ns) {
|
|
3852
|
+
this.options.defaultNS = ns;
|
|
3322
3853
|
}
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3854
|
+
}, {
|
|
3855
|
+
key: "hasLoadedNamespace",
|
|
3856
|
+
value: function hasLoadedNamespace(ns) {
|
|
3857
|
+
var _this6 = this;
|
|
3858
|
+
|
|
3859
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3860
|
+
|
|
3861
|
+
if (!this.isInitialized) {
|
|
3862
|
+
this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
|
|
3863
|
+
return false;
|
|
3864
|
+
}
|
|
3865
|
+
|
|
3866
|
+
if (!this.languages || !this.languages.length) {
|
|
3867
|
+
this.logger.warn('hasLoadedNamespace: i18n.languages were undefined or empty', this.languages);
|
|
3868
|
+
return false;
|
|
3869
|
+
}
|
|
3870
|
+
|
|
3871
|
+
var lng = this.resolvedLanguage || this.languages[0];
|
|
3872
|
+
var fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
3873
|
+
var lastLng = this.languages[this.languages.length - 1];
|
|
3874
|
+
if (lng.toLowerCase() === 'cimode') return true;
|
|
3875
|
+
|
|
3876
|
+
var loadNotPending = function loadNotPending(l, n) {
|
|
3877
|
+
var loadState = _this6.services.backendConnector.state["".concat(l, "|").concat(n)];
|
|
3878
|
+
|
|
3879
|
+
return loadState === -1 || loadState === 2;
|
|
3880
|
+
};
|
|
3881
|
+
|
|
3882
|
+
if (options.precheck) {
|
|
3883
|
+
var preResult = options.precheck(this, loadNotPending);
|
|
3884
|
+
if (preResult !== undefined) return preResult;
|
|
3885
|
+
}
|
|
3886
|
+
|
|
3887
|
+
if (this.hasResourceBundle(lng, ns)) return true;
|
|
3888
|
+
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
|
|
3889
|
+
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
|
|
3890
|
+
return false;
|
|
3334
3891
|
}
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3892
|
+
}, {
|
|
3893
|
+
key: "loadNamespaces",
|
|
3894
|
+
value: function loadNamespaces(ns, callback) {
|
|
3895
|
+
var _this7 = this;
|
|
3896
|
+
|
|
3897
|
+
var deferred = defer();
|
|
3898
|
+
|
|
3899
|
+
if (!this.options.ns) {
|
|
3900
|
+
callback && callback();
|
|
3901
|
+
return Promise.resolve();
|
|
3902
|
+
}
|
|
3903
|
+
|
|
3904
|
+
if (typeof ns === 'string') ns = [ns];
|
|
3905
|
+
ns.forEach(function (n) {
|
|
3906
|
+
if (_this7.options.ns.indexOf(n) < 0) _this7.options.ns.push(n);
|
|
3907
|
+
});
|
|
3908
|
+
this.loadResources(function (err) {
|
|
3909
|
+
deferred.resolve();
|
|
3910
|
+
if (callback) callback(err);
|
|
3911
|
+
});
|
|
3912
|
+
return deferred;
|
|
3913
|
+
}
|
|
3914
|
+
}, {
|
|
3915
|
+
key: "loadLanguages",
|
|
3916
|
+
value: function loadLanguages(lngs, callback) {
|
|
3917
|
+
var deferred = defer();
|
|
3918
|
+
if (typeof lngs === 'string') lngs = [lngs];
|
|
3919
|
+
var preloaded = this.options.preload || [];
|
|
3920
|
+
var newLngs = lngs.filter(function (lng) {
|
|
3921
|
+
return preloaded.indexOf(lng) < 0;
|
|
3922
|
+
});
|
|
3923
|
+
|
|
3924
|
+
if (!newLngs.length) {
|
|
3925
|
+
if (callback) callback();
|
|
3926
|
+
return Promise.resolve();
|
|
3927
|
+
}
|
|
3928
|
+
|
|
3929
|
+
this.options.preload = preloaded.concat(newLngs);
|
|
3930
|
+
this.loadResources(function (err) {
|
|
3931
|
+
deferred.resolve();
|
|
3932
|
+
if (callback) callback(err);
|
|
3933
|
+
});
|
|
3934
|
+
return deferred;
|
|
3935
|
+
}
|
|
3936
|
+
}, {
|
|
3937
|
+
key: "dir",
|
|
3938
|
+
value: function dir(lng) {
|
|
3939
|
+
if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
|
|
3940
|
+
if (!lng) return 'rtl';
|
|
3941
|
+
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'];
|
|
3942
|
+
return rtlLngs.indexOf(this.services.languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf('-arab') > 1 ? 'rtl' : 'ltr';
|
|
3943
|
+
}
|
|
3944
|
+
}, {
|
|
3945
|
+
key: "cloneInstance",
|
|
3946
|
+
value: function cloneInstance() {
|
|
3947
|
+
var _this8 = this;
|
|
3948
|
+
|
|
3949
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3950
|
+
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
3951
|
+
|
|
3952
|
+
var mergedOptions = _objectSpread$6(_objectSpread$6(_objectSpread$6({}, this.options), options), {
|
|
3393
3953
|
isClone: true
|
|
3954
|
+
});
|
|
3955
|
+
|
|
3956
|
+
var clone = new I18n(mergedOptions);
|
|
3957
|
+
|
|
3958
|
+
if (options.debug !== undefined || options.prefix !== undefined) {
|
|
3959
|
+
clone.logger = clone.logger.clone(options);
|
|
3394
3960
|
}
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3961
|
+
|
|
3962
|
+
var membersToCopy = ['store', 'services', 'language'];
|
|
3963
|
+
membersToCopy.forEach(function (m) {
|
|
3964
|
+
clone[m] = _this8[m];
|
|
3965
|
+
});
|
|
3966
|
+
clone.services = _objectSpread$6({}, this.services);
|
|
3967
|
+
clone.services.utils = {
|
|
3968
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
3969
|
+
};
|
|
3970
|
+
clone.translator = new Translator(clone.services, clone.options);
|
|
3971
|
+
clone.translator.on('*', function (event) {
|
|
3972
|
+
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
3973
|
+
args[_key4 - 1] = arguments[_key4];
|
|
3974
|
+
}
|
|
3975
|
+
|
|
3976
|
+
clone.emit.apply(clone, [event].concat(args));
|
|
3977
|
+
});
|
|
3978
|
+
clone.init(mergedOptions, callback);
|
|
3979
|
+
clone.translator.options = clone.options;
|
|
3980
|
+
clone.translator.backendConnector.services.utils = {
|
|
3981
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
3982
|
+
};
|
|
3983
|
+
return clone;
|
|
3399
3984
|
}
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
if (forkResourceStore) {
|
|
3411
|
-
clone.store = new ResourceStore(this.store.data, mergedOptions);
|
|
3412
|
-
clone.services.resourceStore = clone.store;
|
|
3985
|
+
}, {
|
|
3986
|
+
key: "toJSON",
|
|
3987
|
+
value: function toJSON() {
|
|
3988
|
+
return {
|
|
3989
|
+
options: this.options,
|
|
3990
|
+
store: this.store,
|
|
3991
|
+
language: this.language,
|
|
3992
|
+
languages: this.languages,
|
|
3993
|
+
resolvedLanguage: this.resolvedLanguage
|
|
3994
|
+
};
|
|
3413
3995
|
}
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
return clone;
|
|
3427
|
-
}
|
|
3428
|
-
toJSON() {
|
|
3429
|
-
return {
|
|
3430
|
-
options: this.options,
|
|
3431
|
-
store: this.store,
|
|
3432
|
-
language: this.language,
|
|
3433
|
-
languages: this.languages,
|
|
3434
|
-
resolvedLanguage: this.resolvedLanguage
|
|
3435
|
-
};
|
|
3436
|
-
}
|
|
3437
|
-
}
|
|
3438
|
-
const instance = I18n.createInstance();
|
|
3996
|
+
}]);
|
|
3997
|
+
|
|
3998
|
+
return I18n;
|
|
3999
|
+
}(EventEmitter);
|
|
4000
|
+
|
|
4001
|
+
_defineProperty(I18n, "createInstance", function () {
|
|
4002
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
4003
|
+
var callback = arguments.length > 1 ? arguments[1] : undefined;
|
|
4004
|
+
return new I18n(options, callback);
|
|
4005
|
+
});
|
|
4006
|
+
|
|
4007
|
+
var instance = I18n.createInstance();
|
|
3439
4008
|
instance.createInstance = I18n.createInstance;
|
|
3440
4009
|
|
|
3441
4010
|
instance.createInstance;
|
|
3442
|
-
instance.dir;
|
|
3443
4011
|
instance.init;
|
|
3444
4012
|
instance.loadResources;
|
|
3445
4013
|
instance.reloadResources;
|
|
@@ -3479,7 +4047,7 @@ const WidgetI18nProvider = ({ children }) => {
|
|
|
3479
4047
|
return /* @__PURE__ */ jsxRuntimeExports.jsx(I18nextProvider, { i18n: instance, children });
|
|
3480
4048
|
};
|
|
3481
4049
|
|
|
3482
|
-
const {Suspense: Suspense$1,lazy: lazy$1,useEffect: useEffect$1,useState: useState$1,useRef} = await importShared('react');
|
|
4050
|
+
const {Suspense: Suspense$1,lazy: lazy$1,useEffect: useEffect$1,useState: useState$1,useRef,useCallback,useMemo} = await importShared('react');
|
|
3483
4051
|
|
|
3484
4052
|
const __federation_var_VFCMFSectionGrid = await __federation_method_getRemote("VFCMF" , "./SectionGrid");
|
|
3485
4053
|
let SectionGrid = __federation_method_unwrapDefault(__federation_var_VFCMFSectionGrid);
|
|
@@ -3497,7 +4065,7 @@ const SECTION_COMPONENTS = {
|
|
|
3497
4065
|
scroll: SectionScroll,
|
|
3498
4066
|
default: SectionGrid
|
|
3499
4067
|
};
|
|
3500
|
-
const Widget = ({ token, apiurl, viewercountry, requireauth }) => {
|
|
4068
|
+
const Widget = ({ token, apiurl, viewercountry, requireauth, labels }) => {
|
|
3501
4069
|
const widgetRef = useRef(null);
|
|
3502
4070
|
const [widgetState, setWidgetState] = useState$1({
|
|
3503
4071
|
data: {},
|
|
@@ -3513,7 +4081,7 @@ const Widget = ({ token, apiurl, viewercountry, requireauth }) => {
|
|
|
3513
4081
|
});
|
|
3514
4082
|
const normalizedRequireAuth = requireauth === true || requireauth === "true";
|
|
3515
4083
|
const normalizedViewerCountry = viewercountry || "";
|
|
3516
|
-
const dispatchWidgetEvent = (eventType, eventData) => {
|
|
4084
|
+
const dispatchWidgetEvent = useCallback((eventType, eventData) => {
|
|
3517
4085
|
if (widgetRef?.current) {
|
|
3518
4086
|
const customEvent = new CustomEvent(`widget-${eventType}`, {
|
|
3519
4087
|
detail: {
|
|
@@ -3526,12 +4094,12 @@ const Widget = ({ token, apiurl, viewercountry, requireauth }) => {
|
|
|
3526
4094
|
});
|
|
3527
4095
|
widgetRef.current.dispatchEvent(customEvent);
|
|
3528
4096
|
}
|
|
3529
|
-
};
|
|
3530
|
-
const eventHandlers = {
|
|
4097
|
+
}, [token]);
|
|
4098
|
+
const eventHandlers = useMemo(() => ({
|
|
3531
4099
|
onError: (error2) => dispatchWidgetEvent("data-load-error", error2),
|
|
3532
4100
|
onDataLoadCompleted: (eventData) => dispatchWidgetEvent("data-loaded", eventData),
|
|
3533
4101
|
onWidgetItemClick: (itemData) => dispatchWidgetEvent("item-click", itemData)
|
|
3534
|
-
};
|
|
4102
|
+
}), [dispatchWidgetEvent]);
|
|
3535
4103
|
const handleClosePlayer = () => {
|
|
3536
4104
|
setPlayerState({
|
|
3537
4105
|
isOpen: false,
|
|
@@ -3539,7 +4107,7 @@ const Widget = ({ token, apiurl, viewercountry, requireauth }) => {
|
|
|
3539
4107
|
});
|
|
3540
4108
|
};
|
|
3541
4109
|
const apiUrl = apiurl || "https://apiv3.videoflow.io";
|
|
3542
|
-
const widgetDataToSectionData = (data2) => {
|
|
4110
|
+
const widgetDataToSectionData = useCallback((data2) => {
|
|
3543
4111
|
if (data2.type === VIDEO_SECTION_TYPE) {
|
|
3544
4112
|
return {
|
|
3545
4113
|
description: "",
|
|
@@ -3587,7 +4155,7 @@ const Widget = ({ token, apiurl, viewercountry, requireauth }) => {
|
|
|
3587
4155
|
apiUrl,
|
|
3588
4156
|
eventHandlers
|
|
3589
4157
|
};
|
|
3590
|
-
};
|
|
4158
|
+
}, [apiUrl, eventHandlers]);
|
|
3591
4159
|
const applyStyle = (css) => {
|
|
3592
4160
|
if (!css) return;
|
|
3593
4161
|
const style = document.createElement("style");
|
|
@@ -3601,14 +4169,15 @@ const Widget = ({ token, apiurl, viewercountry, requireauth }) => {
|
|
|
3601
4169
|
return SECTION_COMPONENTS[layout] || SECTION_COMPONENTS.default;
|
|
3602
4170
|
}
|
|
3603
4171
|
if (type2 === BLAZE_WIDGET_TYPE) {
|
|
3604
|
-
return lazy$1(() => import('./blaze-
|
|
4172
|
+
return lazy$1(() => import('./blaze-CKjlj6PD.js'));
|
|
3605
4173
|
}
|
|
3606
|
-
return lazy$1(() => __variableDynamicImportRuntimeHelper((/* #__PURE__ */ Object.assign({"./widgets/gallery/gallery.jsx": () => import('./gallery-BnwImwd1.js'),"./widgets/matches/matches.jsx": () => import('./matches-C8-8ztat.js'),"./widgets/matchesStandalone/matchesStandalone.jsx": () => import('./matchesStandalone-D5u5Zh1z.js'),"./widgets/player/player.jsx": () => import('./player-B4I31inR.js'),"./widgets/poster/poster.jsx": () => import('./poster-Dh_-i4eF.js'),"./widgets/poster/posterItem.jsx": () => import('./posterItem-DR1i18lq.js'),"./widgets/scroll/scroll.jsx": () => import('./scroll-D-CmUvAZ.js'),"./widgets/story/story.jsx": () => import('./story-
|
|
4174
|
+
return lazy$1(() => __variableDynamicImportRuntimeHelper((/* #__PURE__ */ Object.assign({"./widgets/gallery/gallery.jsx": () => import('./gallery-BnwImwd1.js'),"./widgets/matches/matches.jsx": () => import('./matches-C8-8ztat.js'),"./widgets/matchesStandalone/matchesStandalone.jsx": () => import('./matchesStandalone-D5u5Zh1z.js'),"./widgets/player/player.jsx": () => import('./player-B4I31inR.js'),"./widgets/poster/poster.jsx": () => import('./poster-Dh_-i4eF.js'),"./widgets/poster/posterItem.jsx": () => import('./posterItem-DR1i18lq.js'),"./widgets/scroll/scroll.jsx": () => import('./scroll-D-CmUvAZ.js'),"./widgets/story/story.jsx": () => import('./story-CUXTTEzQ.js')})), `./widgets/${type2}/${type2}.jsx`, 4));
|
|
3607
4175
|
};
|
|
3608
4176
|
useEffect$1(() => {
|
|
3609
|
-
const
|
|
4177
|
+
const fetchWidgetConfig = async () => {
|
|
3610
4178
|
try {
|
|
3611
|
-
const
|
|
4179
|
+
const url = `${apiUrl}/widgets/${token}`;
|
|
4180
|
+
const response = await fetch(url);
|
|
3612
4181
|
if (!response.ok) {
|
|
3613
4182
|
throw new Error(`${response.status}: ${response.statusText}`);
|
|
3614
4183
|
}
|
|
@@ -3635,8 +4204,8 @@ const Widget = ({ token, apiurl, viewercountry, requireauth }) => {
|
|
|
3635
4204
|
eventHandlers.onError("Content is not available");
|
|
3636
4205
|
}
|
|
3637
4206
|
};
|
|
3638
|
-
|
|
3639
|
-
}, [token, apiUrl]);
|
|
4207
|
+
fetchWidgetConfig();
|
|
4208
|
+
}, [token, apiUrl, eventHandlers, widgetDataToSectionData]);
|
|
3640
4209
|
const { data, loading, error, Component, type } = widgetState;
|
|
3641
4210
|
if (error) return null;
|
|
3642
4211
|
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: widgetRef, children: loading ? /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, {}) : /* @__PURE__ */ jsxRuntimeExports.jsx(Suspense$1, { fallback: /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, {}), children: Component && (type === VIDEO_SECTION_TYPE ? /* @__PURE__ */ jsxRuntimeExports.jsxs(WidgetI18nProvider, { children: [
|
|
@@ -3658,7 +4227,8 @@ const Widget = ({ token, apiurl, viewercountry, requireauth }) => {
|
|
|
3658
4227
|
apiUrl: data.apiUrl,
|
|
3659
4228
|
viewerCountry: normalizedViewerCountry,
|
|
3660
4229
|
requireAuth: normalizedRequireAuth,
|
|
3661
|
-
eventHandlers: data.eventHandlers
|
|
4230
|
+
eventHandlers: data.eventHandlers,
|
|
4231
|
+
labels
|
|
3662
4232
|
}
|
|
3663
4233
|
)) }) });
|
|
3664
4234
|
};
|
|
@@ -3696,11 +4266,23 @@ const ChannelWidget = ({ token, type }) => {
|
|
|
3696
4266
|
|
|
3697
4267
|
const React = await importShared('react');
|
|
3698
4268
|
|
|
4269
|
+
/**
|
|
4270
|
+
* Widget Component PropTypes
|
|
4271
|
+
* @property {string} token - Widget identifier for fetching configuration from API
|
|
4272
|
+
* @property {string} apiurl - Optional API URL override for widget data
|
|
4273
|
+
* @property {string} viewercountry - ISO country code for geo-based content filtering
|
|
4274
|
+
* @property {boolean|string} requireauth - Whether authentication is required to view content
|
|
4275
|
+
* @property {string} labels - JSON string for dynamic label filtering based on current video context
|
|
4276
|
+
* Format: '{"isAndGroup": boolean, "labels": string[]}'
|
|
4277
|
+
* When provided, overrides widget's static selector configuration
|
|
4278
|
+
* Example: '{"isAndGroup": false, "labels": ["sports", "football"]}'
|
|
4279
|
+
*/
|
|
3699
4280
|
Widget.propTypes = {
|
|
3700
|
-
token
|
|
3701
|
-
apiurl
|
|
3702
|
-
viewercountry
|
|
3703
|
-
requireauth
|
|
4281
|
+
token : PropTypes.string,
|
|
4282
|
+
apiurl : PropTypes.string,
|
|
4283
|
+
viewercountry : PropTypes.string,
|
|
4284
|
+
requireauth : PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
4285
|
+
labels : PropTypes.string,
|
|
3704
4286
|
};
|
|
3705
4287
|
|
|
3706
4288
|
ChannelWidget.propTypes = {
|