Comparing version 2.3.3 to 2.3.4
@@ -11,4 +11,2 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _utils = require('./utils'); | ||
@@ -30,2 +28,4 @@ | ||
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -35,3 +35,3 @@ | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } | ||
@@ -55,3 +55,3 @@ function remove(arr, what) { | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Connector).call(this)); | ||
var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); | ||
@@ -71,202 +71,195 @@ _this.backend = backend; | ||
_createClass(Connector, [{ | ||
key: 'queueLoad', | ||
value: function queueLoad(languages, namespaces, callback) { | ||
var _this2 = this; | ||
Connector.prototype.queueLoad = function queueLoad(languages, namespaces, callback) { | ||
var _this2 = this; | ||
// find what needs to be loaded | ||
var toLoad = [], | ||
pending = [], | ||
toLoadLanguages = [], | ||
toLoadNamespaces = []; | ||
// find what needs to be loaded | ||
var toLoad = [], | ||
pending = [], | ||
toLoadLanguages = [], | ||
toLoadNamespaces = []; | ||
languages.forEach(function (lng) { | ||
var hasAllNamespaces = true; | ||
languages.forEach(function (lng) { | ||
var hasAllNamespaces = true; | ||
namespaces.forEach(function (ns) { | ||
var name = lng + '|' + ns; | ||
namespaces.forEach(function (ns) { | ||
var name = lng + '|' + ns; | ||
if (_this2.store.hasResourceBundle(lng, ns)) { | ||
_this2.state[name] = 2; // loaded | ||
} else if (_this2.state[name] < 0) { | ||
// nothing to do for err | ||
} else if (_this2.state[name] === 1) { | ||
if (pending.indexOf(name) < 0) pending.push(name); | ||
} else { | ||
_this2.state[name] = 1; // pending | ||
if (_this2.store.hasResourceBundle(lng, ns)) { | ||
_this2.state[name] = 2; // loaded | ||
} else if (_this2.state[name] < 0) { | ||
// nothing to do for err | ||
} else if (_this2.state[name] === 1) { | ||
if (pending.indexOf(name) < 0) pending.push(name); | ||
} else { | ||
_this2.state[name] = 1; // pending | ||
hasAllNamespaces = false; | ||
hasAllNamespaces = false; | ||
if (pending.indexOf(name) < 0) pending.push(name); | ||
if (toLoad.indexOf(name) < 0) toLoad.push(name); | ||
if (toLoadNamespaces.indexOf(ns) < 0) toLoadNamespaces.push(ns); | ||
} | ||
}); | ||
if (!hasAllNamespaces) toLoadLanguages.push(lng); | ||
if (pending.indexOf(name) < 0) pending.push(name); | ||
if (toLoad.indexOf(name) < 0) toLoad.push(name); | ||
if (toLoadNamespaces.indexOf(ns) < 0) toLoadNamespaces.push(ns); | ||
} | ||
}); | ||
if (toLoad.length || pending.length) { | ||
this.queue.push({ | ||
pending: pending, | ||
loaded: {}, | ||
errors: [], | ||
callback: callback | ||
}); | ||
} | ||
if (!hasAllNamespaces) toLoadLanguages.push(lng); | ||
}); | ||
return { | ||
toLoad: toLoad, | ||
if (toLoad.length || pending.length) { | ||
this.queue.push({ | ||
pending: pending, | ||
toLoadLanguages: toLoadLanguages, | ||
toLoadNamespaces: toLoadNamespaces | ||
}; | ||
loaded: {}, | ||
errors: [], | ||
callback: callback | ||
}); | ||
} | ||
}, { | ||
key: 'loaded', | ||
value: function loaded(name, err, data) { | ||
var _this3 = this; | ||
var _name$split = name.split('|'); | ||
return { | ||
toLoad: toLoad, | ||
pending: pending, | ||
toLoadLanguages: toLoadLanguages, | ||
toLoadNamespaces: toLoadNamespaces | ||
}; | ||
}; | ||
var _name$split2 = _slicedToArray(_name$split, 2); | ||
Connector.prototype.loaded = function loaded(name, err, data) { | ||
var _this3 = this; | ||
var lng = _name$split2[0]; | ||
var ns = _name$split2[1]; | ||
var _name$split = name.split('|'); | ||
var _name$split2 = _slicedToArray(_name$split, 2); | ||
if (err) this.emit('failedLoading', lng, ns, err); | ||
var lng = _name$split2[0]; | ||
var ns = _name$split2[1]; | ||
if (data) { | ||
this.store.addResourceBundle(lng, ns, data); | ||
} | ||
// set loaded | ||
this.state[name] = err ? -1 : 2; | ||
// callback if ready | ||
this.queue.forEach(function (q) { | ||
utils.pushPath(q.loaded, [lng], ns); | ||
remove(q.pending, name); | ||
if (err) this.emit('failedLoading', lng, ns, err); | ||
if (err) q.errors.push(err); | ||
if (data) { | ||
this.store.addResourceBundle(lng, ns, data); | ||
} | ||
if (q.pending.length === 0 && !q.done) { | ||
q.errors.length ? q.callback(q.errors) : q.callback(); | ||
_this3.emit('loaded', q.loaded); | ||
q.done = true; | ||
} | ||
}); | ||
// set loaded | ||
this.state[name] = err ? -1 : 2; | ||
// callback if ready | ||
this.queue.forEach(function (q) { | ||
utils.pushPath(q.loaded, [lng], ns); | ||
remove(q.pending, name); | ||
// remove done load requests | ||
this.queue = this.queue.filter(function (q) { | ||
return !q.done; | ||
}); | ||
} | ||
}, { | ||
key: 'read', | ||
value: function read(lng, ns, fcName, tried, wait, callback) { | ||
var _this4 = this; | ||
if (err) q.errors.push(err); | ||
if (!tried) tried = 0; | ||
if (!wait) wait = 250; | ||
if (q.pending.length === 0 && !q.done) { | ||
q.errors.length ? q.callback(q.errors) : q.callback(); | ||
_this3.emit('loaded', q.loaded); | ||
q.done = true; | ||
} | ||
}); | ||
if (!lng.length) return callback(null, {}); // noting to load | ||
// remove done load requests | ||
this.queue = this.queue.filter(function (q) { | ||
return !q.done; | ||
}); | ||
}; | ||
this.backend[fcName](lng, ns, function (err, data) { | ||
if (err && data /* = retryFlag */ && tried < 5) { | ||
setTimeout(function () { | ||
_this4.read.call(_this4, lng, ns, fcName, ++tried, wait * 2, callback); | ||
}, wait); | ||
return; | ||
} | ||
callback(err, data); | ||
}); | ||
} | ||
}, { | ||
key: 'load', | ||
value: function load(languages, namespaces, callback) { | ||
var _this5 = this; | ||
Connector.prototype.read = function read(lng, ns, fcName, tried, wait, callback) { | ||
var _this4 = this; | ||
if (!this.backend) { | ||
this.logger.warn('No backend was added via i18next.use. Will not load resources.'); | ||
return callback && callback(); | ||
} | ||
var options = _extends({}, this.backend.options, this.options.backend); | ||
if (!tried) tried = 0; | ||
if (!wait) wait = 250; | ||
if (typeof languages === 'string') languages = this.services.languageUtils.toResolveHierarchy(languages); | ||
if (typeof namespaces === 'string') namespaces = [namespaces]; | ||
if (!lng.length) return callback(null, {}); // noting to load | ||
var toLoad = this.queueLoad(languages, namespaces, callback); | ||
if (!toLoad.toLoad.length) { | ||
if (!toLoad.pending.length) callback(); // nothing to load and no pendings...callback now | ||
return; // pendings will trigger callback | ||
this.backend[fcName](lng, ns, function (err, data) { | ||
if (err && data /* = retryFlag */ && tried < 5) { | ||
setTimeout(function () { | ||
_this4.read.call(_this4, lng, ns, fcName, ++tried, wait * 2, callback); | ||
}, wait); | ||
return; | ||
} | ||
callback(err, data); | ||
}); | ||
}; | ||
// load with multi-load | ||
if (options.allowMultiLoading && this.backend.readMulti) { | ||
this.read(toLoad.toLoadLanguages, toLoad.toLoadNamespaces, 'readMulti', null, null, function (err, data) { | ||
if (err) _this5.logger.warn('loading namespaces ' + toLoad.toLoadNamespaces.join(', ') + ' for languages ' + toLoad.toLoadLanguages.join(', ') + ' via multiloading failed', err); | ||
if (!err && data) _this5.logger.log('loaded namespaces ' + toLoad.toLoadNamespaces.join(', ') + ' for languages ' + toLoad.toLoadLanguages.join(', ') + ' via multiloading', data); | ||
Connector.prototype.load = function load(languages, namespaces, callback) { | ||
var _this5 = this; | ||
toLoad.toLoad.forEach(function (name) { | ||
var _name$split3 = name.split('|'); | ||
if (!this.backend) { | ||
this.logger.warn('No backend was added via i18next.use. Will not load resources.'); | ||
return callback && callback(); | ||
} | ||
var options = _extends({}, this.backend.options, this.options.backend); | ||
var _name$split4 = _slicedToArray(_name$split3, 2); | ||
if (typeof languages === 'string') languages = this.services.languageUtils.toResolveHierarchy(languages); | ||
if (typeof namespaces === 'string') namespaces = [namespaces]; | ||
var l = _name$split4[0]; | ||
var n = _name$split4[1]; | ||
var toLoad = this.queueLoad(languages, namespaces, callback); | ||
if (!toLoad.toLoad.length) { | ||
if (!toLoad.pending.length) callback(); // nothing to load and no pendings...callback now | ||
return; // pendings will trigger callback | ||
} | ||
// load with multi-load | ||
if (options.allowMultiLoading && this.backend.readMulti) { | ||
this.read(toLoad.toLoadLanguages, toLoad.toLoadNamespaces, 'readMulti', null, null, function (err, data) { | ||
if (err) _this5.logger.warn('loading namespaces ' + toLoad.toLoadNamespaces.join(', ') + ' for languages ' + toLoad.toLoadLanguages.join(', ') + ' via multiloading failed', err); | ||
if (!err && data) _this5.logger.log('loaded namespaces ' + toLoad.toLoadNamespaces.join(', ') + ' for languages ' + toLoad.toLoadLanguages.join(', ') + ' via multiloading', data); | ||
var bundle = utils.getPath(data, [l, n]); | ||
if (bundle) { | ||
_this5.loaded(name, err, bundle); | ||
} else { | ||
var _err = 'loading namespace ' + n + ' for language ' + l + ' via multiloading failed'; | ||
_this5.loaded(name, _err); | ||
_this5.logger.error(_err); | ||
} | ||
}); | ||
}); | ||
} | ||
toLoad.toLoad.forEach(function (name) { | ||
var _name$split3 = name.split('|'); | ||
// load one by one | ||
else { | ||
(function () { | ||
var read = function read(name) { | ||
var _this6 = this; | ||
var _name$split4 = _slicedToArray(_name$split3, 2); | ||
var _name$split5 = name.split('|'); | ||
var l = _name$split4[0]; | ||
var n = _name$split4[1]; | ||
var _name$split6 = _slicedToArray(_name$split5, 2); | ||
var lng = _name$split6[0]; | ||
var ns = _name$split6[1]; | ||
var bundle = utils.getPath(data, [l, n]); | ||
if (bundle) { | ||
_this5.loaded(name, err, bundle); | ||
} else { | ||
var _err = 'loading namespace ' + n + ' for language ' + l + ' via multiloading failed'; | ||
_this5.loaded(name, _err); | ||
_this5.logger.error(_err); | ||
} | ||
}); | ||
}); | ||
} | ||
// load one by one | ||
else { | ||
(function () { | ||
var read = function read(name) { | ||
var _this6 = this; | ||
this.read(lng, ns, 'read', null, null, function (err, data) { | ||
if (err) _this6.logger.warn('loading namespace ' + ns + ' for language ' + lng + ' failed', err); | ||
if (!err && data) _this6.logger.log('loaded namespace ' + ns + ' for language ' + lng, data); | ||
var _name$split5 = name.split('|'); | ||
_this6.loaded(name, err, data); | ||
}); | ||
}; | ||
var _name$split6 = _slicedToArray(_name$split5, 2); | ||
; | ||
var lng = _name$split6[0]; | ||
var ns = _name$split6[1]; | ||
toLoad.toLoad.forEach(function (name) { | ||
read.call(_this5, name); | ||
this.read(lng, ns, 'read', null, null, function (err, data) { | ||
if (err) _this6.logger.warn('loading namespace ' + ns + ' for language ' + lng + ' failed', err); | ||
if (!err && data) _this6.logger.log('loaded namespace ' + ns + ' for language ' + lng, data); | ||
_this6.loaded(name, err, data); | ||
}); | ||
})(); | ||
} | ||
} | ||
}, { | ||
key: 'saveMissing', | ||
value: function saveMissing(languages, namespace, key, fallbackValue) { | ||
if (this.backend && this.backend.create) this.backend.create(languages, namespace, key, fallbackValue); | ||
}; | ||
// write to store to avoid resending | ||
this.store.addResource(languages[0], namespace, key, fallbackValue); | ||
} | ||
}]); | ||
; | ||
toLoad.toLoad.forEach(function (name) { | ||
read.call(_this5, name); | ||
}); | ||
})(); | ||
} | ||
}; | ||
Connector.prototype.saveMissing = function saveMissing(languages, namespace, key, fallbackValue) { | ||
if (this.backend && this.backend.create) this.backend.create(languages, namespace, key, fallbackValue); | ||
// write to store to avoid resending | ||
this.store.addResource(languages[0], namespace, key, fallbackValue); | ||
}; | ||
return Connector; | ||
@@ -273,0 +266,0 @@ }(_EventEmitter3.default); |
@@ -9,4 +9,2 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _utils = require('./utils'); | ||
@@ -28,2 +26,4 @@ | ||
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -33,3 +33,3 @@ | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } | ||
@@ -44,3 +44,3 @@ var Connector = function (_EventEmitter) { | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Connector).call(this)); | ||
var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); | ||
@@ -57,38 +57,34 @@ _this.cache = cache; | ||
_createClass(Connector, [{ | ||
key: 'load', | ||
value: function load(languages, namespaces, callback) { | ||
var _this2 = this; | ||
Connector.prototype.load = function load(languages, namespaces, callback) { | ||
var _this2 = this; | ||
if (!this.cache) return callback && callback(); | ||
var options = _extends({}, this.cache.options, this.options.cache); | ||
if (!this.cache) return callback && callback(); | ||
var options = _extends({}, this.cache.options, this.options.cache); | ||
if (typeof languages === 'string') languages = this.services.languageUtils.toResolveHierarchy(languages); | ||
if (typeof namespaces === 'string') namespaces = [namespaces]; | ||
if (typeof languages === 'string') languages = this.services.languageUtils.toResolveHierarchy(languages); | ||
if (typeof namespaces === 'string') namespaces = [namespaces]; | ||
if (options.enabled) { | ||
this.cache.load(languages, function (err, data) { | ||
if (err) _this2.logger.error('loading languages ' + languages.join(', ') + ' from cache failed', err); | ||
if (data) { | ||
for (var l in data) { | ||
for (var n in data[l]) { | ||
if (n === 'i18nStamp') continue; | ||
var bundle = data[l][n]; | ||
if (bundle) _this2.store.addResourceBundle(l, n, bundle); | ||
} | ||
if (options.enabled) { | ||
this.cache.load(languages, function (err, data) { | ||
if (err) _this2.logger.error('loading languages ' + languages.join(', ') + ' from cache failed', err); | ||
if (data) { | ||
for (var l in data) { | ||
for (var n in data[l]) { | ||
if (n === 'i18nStamp') continue; | ||
var bundle = data[l][n]; | ||
if (bundle) _this2.store.addResourceBundle(l, n, bundle); | ||
} | ||
} | ||
if (callback) callback(); | ||
}); | ||
} else { | ||
} | ||
if (callback) callback(); | ||
} | ||
}); | ||
} else { | ||
if (callback) callback(); | ||
} | ||
}, { | ||
key: 'save', | ||
value: function save() { | ||
if (this.cache && this.options.cache && this.options.cache.enabled) this.cache.save(this.store.data); | ||
} | ||
}]); | ||
}; | ||
Connector.prototype.save = function save() { | ||
if (this.cache && this.options.cache && this.options.cache.enabled) this.cache.save(this.store.data); | ||
}; | ||
return Connector; | ||
@@ -95,0 +91,0 @@ }(_EventEmitter3.default); |
@@ -7,4 +7,2 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -19,54 +17,49 @@ | ||
_createClass(EventEmitter, [{ | ||
key: 'on', | ||
value: function on(events, listener) { | ||
var _this = this; | ||
EventEmitter.prototype.on = function on(events, listener) { | ||
var _this = this; | ||
events.split(' ').forEach(function (event) { | ||
_this.observers[event] = _this.observers[event] || []; | ||
_this.observers[event].push(listener); | ||
}); | ||
events.split(' ').forEach(function (event) { | ||
_this.observers[event] = _this.observers[event] || []; | ||
_this.observers[event].push(listener); | ||
}); | ||
}; | ||
EventEmitter.prototype.off = function off(event, listener) { | ||
var _this2 = this; | ||
if (!this.observers[event]) { | ||
return; | ||
} | ||
}, { | ||
key: 'off', | ||
value: function off(event, listener) { | ||
var _this2 = this; | ||
if (!this.observers[event]) { | ||
return; | ||
this.observers[event].forEach(function () { | ||
if (!listener) { | ||
delete _this2.observers[event]; | ||
} else { | ||
var index = _this2.observers[event].indexOf(listener); | ||
if (index > -1) { | ||
_this2.observers[event].splice(index, 1); | ||
} | ||
} | ||
}); | ||
}; | ||
this.observers[event].forEach(function () { | ||
if (!listener) { | ||
delete _this2.observers[event]; | ||
} else { | ||
var index = _this2.observers[event].indexOf(listener); | ||
if (index > -1) { | ||
_this2.observers[event].splice(index, 1); | ||
} | ||
} | ||
EventEmitter.prototype.emit = function emit(event) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
if (this.observers[event]) { | ||
this.observers[event].forEach(function (observer) { | ||
observer.apply(undefined, args); | ||
}); | ||
} | ||
}, { | ||
key: 'emit', | ||
value: function emit(event) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
if (this.observers[event]) { | ||
this.observers[event].forEach(function (observer) { | ||
observer.apply(undefined, args); | ||
}); | ||
} | ||
if (this.observers['*']) { | ||
this.observers['*'].forEach(function (observer) { | ||
var _ref; | ||
if (this.observers['*']) { | ||
this.observers['*'].forEach(function (observer) { | ||
var _ref; | ||
observer.apply(observer, (_ref = [event]).concat.apply(_ref, args)); | ||
}); | ||
} | ||
observer.apply(observer, (_ref = [event]).concat.apply(_ref, args)); | ||
}); | ||
} | ||
}]); | ||
}; | ||
@@ -73,0 +66,0 @@ return EventEmitter; |
@@ -11,4 +11,2 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _logger = require('./logger'); | ||
@@ -50,3 +48,3 @@ | ||
var _defaults = require('./defaults'); | ||
var _defaults2 = require('./defaults'); | ||
@@ -65,2 +63,4 @@ var _postProcessor = require('./postProcessor'); | ||
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -70,3 +70,3 @@ | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } | ||
@@ -82,5 +82,5 @@ var I18n = function (_EventEmitter) { | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(I18n).call(this)); | ||
var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); | ||
_this.options = (0, _defaults.transformOptions)(options); | ||
_this.options = (0, _defaults2.transformOptions)(options); | ||
_this.services = {}; | ||
@@ -94,296 +94,281 @@ _this.logger = _logger2.default; | ||
_createClass(I18n, [{ | ||
key: 'init', | ||
value: function init(options, callback) { | ||
var _this2 = this; | ||
I18n.prototype.init = function init(options, callback) { | ||
var _this2 = this; | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
if (!options) options = {}; | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
if (!options) options = {}; | ||
if (options.compatibilityAPI === 'v1') { | ||
this.options = _extends({}, (0, _defaults.get)(), (0, _defaults.transformOptions)(compat.convertAPIOptions(options)), {}); | ||
} else if (options.compatibilityJSON === 'v1') { | ||
this.options = _extends({}, (0, _defaults.get)(), (0, _defaults.transformOptions)(compat.convertJSONOptions(options)), {}); | ||
if (options.compatibilityAPI === 'v1') { | ||
this.options = _extends({}, (0, _defaults2.get)(), (0, _defaults2.transformOptions)(compat.convertAPIOptions(options)), {}); | ||
} else if (options.compatibilityJSON === 'v1') { | ||
this.options = _extends({}, (0, _defaults2.get)(), (0, _defaults2.transformOptions)(compat.convertJSONOptions(options)), {}); | ||
} else { | ||
this.options = _extends({}, (0, _defaults2.get)(), this.options, (0, _defaults2.transformOptions)(options)); | ||
} | ||
if (!callback) callback = function callback() {}; | ||
function createClassOnDemand(ClassOrObject) { | ||
if (!ClassOrObject) return; | ||
if (typeof ClassOrObject === 'function') return new ClassOrObject(); | ||
return ClassOrObject; | ||
} | ||
// init services | ||
if (!this.options.isClone) { | ||
if (this.modules.logger) { | ||
_logger2.default.init(createClassOnDemand(this.modules.logger), this.options); | ||
} else { | ||
this.options = _extends({}, (0, _defaults.get)(), this.options, (0, _defaults.transformOptions)(options)); | ||
_logger2.default.init(null, this.options); | ||
} | ||
if (!callback) callback = function callback() {}; | ||
function createClassOnDemand(ClassOrObject) { | ||
if (!ClassOrObject) return; | ||
if (typeof ClassOrObject === 'function') return new ClassOrObject(); | ||
return ClassOrObject; | ||
var lu = new _LanguageUtils2.default(this.options); | ||
this.store = new _ResourceStore2.default(this.options.resources, this.options); | ||
var s = this.services; | ||
s.logger = _logger2.default; | ||
s.resourceStore = this.store; | ||
s.resourceStore.on('added removed', function (lng, ns) { | ||
s.cacheConnector.save(); | ||
}); | ||
s.languageUtils = lu; | ||
s.pluralResolver = new _PluralResolver2.default(lu, { prepend: this.options.pluralSeparator, compatibilityJSON: this.options.compatibilityJSON }); | ||
s.interpolator = new _Interpolator2.default(this.options); | ||
s.backendConnector = new _BackendConnector2.default(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options); | ||
// pipe events from backendConnector | ||
s.backendConnector.on('*', function (event) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
_this2.emit.apply(_this2, [event].concat(args)); | ||
}); | ||
s.backendConnector.on('loaded', function (loaded) { | ||
s.cacheConnector.save(); | ||
}); | ||
s.cacheConnector = new _CacheConnector2.default(createClassOnDemand(this.modules.cache), s.resourceStore, s, this.options); | ||
// pipe events from backendConnector | ||
s.cacheConnector.on('*', function (event) { | ||
for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
_this2.emit.apply(_this2, [event].concat(args)); | ||
}); | ||
if (this.modules.languageDetector) { | ||
s.languageDetector = createClassOnDemand(this.modules.languageDetector); | ||
s.languageDetector.init(s, this.options.detection, this.options); | ||
} | ||
// init services | ||
if (!this.options.isClone) { | ||
if (this.modules.logger) { | ||
_logger2.default.init(createClassOnDemand(this.modules.logger), this.options); | ||
} else { | ||
_logger2.default.init(null, this.options); | ||
this.translator = new _Translator2.default(this.services, this.options); | ||
// pipe events from translator | ||
this.translator.on('*', function (event) { | ||
for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
args[_key3 - 1] = arguments[_key3]; | ||
} | ||
var lu = new _LanguageUtils2.default(this.options); | ||
this.store = new _ResourceStore2.default(this.options.resources, this.options); | ||
_this2.emit.apply(_this2, [event].concat(args)); | ||
}); | ||
} | ||
var s = this.services; | ||
s.logger = _logger2.default; | ||
s.resourceStore = this.store; | ||
s.resourceStore.on('added removed', function (lng, ns) { | ||
s.cacheConnector.save(); | ||
}); | ||
s.languageUtils = lu; | ||
s.pluralResolver = new _PluralResolver2.default(lu, { prepend: this.options.pluralSeparator, compatibilityJSON: this.options.compatibilityJSON }); | ||
s.interpolator = new _Interpolator2.default(this.options); | ||
// append api | ||
var storeApi = ['getResource', 'addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle', 'hasResourceBundle', 'getResourceBundle']; | ||
storeApi.forEach(function (fcName) { | ||
_this2[fcName] = function () { | ||
return this.store[fcName].apply(this.store, arguments); | ||
}; | ||
}); | ||
s.backendConnector = new _BackendConnector2.default(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options); | ||
// pipe events from backendConnector | ||
s.backendConnector.on('*', function (event) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
// TODO: COMPATIBILITY remove this | ||
if (this.options.compatibilityAPI === 'v1') compat.appendBackwardsAPI(this); | ||
_this2.emit.apply(_this2, [event].concat(args)); | ||
}); | ||
this.changeLanguage(this.options.lng, function (err, t) { | ||
_this2.emit('initialized', _this2.options); | ||
_this2.logger.log('initialized', _this2.options); | ||
s.backendConnector.on('loaded', function (loaded) { | ||
s.cacheConnector.save(); | ||
}); | ||
callback(err, t); | ||
}); | ||
s.cacheConnector = new _CacheConnector2.default(createClassOnDemand(this.modules.cache), s.resourceStore, s, this.options); | ||
// pipe events from backendConnector | ||
s.cacheConnector.on('*', function (event) { | ||
for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
return this; | ||
}; | ||
_this2.emit.apply(_this2, [event].concat(args)); | ||
}); | ||
I18n.prototype.loadResources = function loadResources(callback) { | ||
var _this3 = this; | ||
if (this.modules.languageDetector) { | ||
s.languageDetector = createClassOnDemand(this.modules.languageDetector); | ||
s.languageDetector.init(s, this.options.detection, this.options); | ||
} | ||
if (!callback) callback = function callback() {}; | ||
this.translator = new _Translator2.default(this.services, this.options); | ||
// pipe events from translator | ||
this.translator.on('*', function (event) { | ||
for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
args[_key3 - 1] = arguments[_key3]; | ||
} | ||
if (!this.options.resources) { | ||
var _ret = function () { | ||
if (_this3.language && _this3.language.toLowerCase() === 'cimode') return { | ||
v: callback() | ||
}; // avoid loading resources for cimode | ||
_this2.emit.apply(_this2, [event].concat(args)); | ||
}); | ||
} | ||
var toLoad = []; | ||
// append api | ||
var storeApi = ['getResource', 'addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle', 'hasResourceBundle', 'getResourceBundle']; | ||
storeApi.forEach(function (fcName) { | ||
_this2[fcName] = function () { | ||
return this.store[fcName].apply(this.store, arguments); | ||
var append = function append(lng) { | ||
var lngs = _this3.services.languageUtils.toResolveHierarchy(lng); | ||
lngs.forEach(function (l) { | ||
if (toLoad.indexOf(l) < 0) toLoad.push(l); | ||
}); | ||
}; | ||
}); | ||
// TODO: COMPATIBILITY remove this | ||
if (this.options.compatibilityAPI === 'v1') compat.appendBackwardsAPI(this); | ||
append(_this3.language); | ||
this.changeLanguage(this.options.lng, function (err, t) { | ||
_this2.emit('initialized', _this2.options); | ||
_this2.logger.log('initialized', _this2.options); | ||
if (_this3.options.preload) { | ||
_this3.options.preload.forEach(function (l) { | ||
append(l); | ||
}); | ||
} | ||
callback(err, t); | ||
}); | ||
_this3.services.cacheConnector.load(toLoad, _this3.options.ns, function () { | ||
_this3.services.backendConnector.load(toLoad, _this3.options.ns, callback); | ||
}); | ||
}(); | ||
return this; | ||
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; | ||
} else { | ||
callback(null); | ||
} | ||
}, { | ||
key: 'loadResources', | ||
value: function loadResources(callback) { | ||
var _this3 = this; | ||
}; | ||
if (!callback) callback = function callback() {}; | ||
I18n.prototype.use = function use(module) { | ||
if (module.type === 'backend') { | ||
this.modules.backend = module; | ||
} | ||
if (!this.options.resources) { | ||
var _ret = function () { | ||
if (_this3.language && _this3.language.toLowerCase() === 'cimode') return { | ||
v: callback() | ||
}; // avoid loading resources for cimode | ||
if (module.type === 'cache') { | ||
this.modules.cache = module; | ||
} | ||
var toLoad = []; | ||
if (module.type === 'logger' || module.log && module.warn && module.warn) { | ||
this.modules.logger = module; | ||
} | ||
var append = function append(lng) { | ||
var lngs = _this3.services.languageUtils.toResolveHierarchy(lng); | ||
lngs.forEach(function (l) { | ||
if (toLoad.indexOf(l) < 0) toLoad.push(l); | ||
}); | ||
}; | ||
if (module.type === 'languageDetector') { | ||
this.modules.languageDetector = module; | ||
} | ||
append(_this3.language); | ||
if (module.type === 'postProcessor') { | ||
_postProcessor2.default.addPostProcessor(module); | ||
} | ||
if (_this3.options.preload) { | ||
_this3.options.preload.forEach(function (l) { | ||
append(l); | ||
}); | ||
} | ||
return this; | ||
}; | ||
_this3.services.cacheConnector.load(toLoad, _this3.options.ns, function () { | ||
_this3.services.backendConnector.load(toLoad, _this3.options.ns, callback); | ||
}); | ||
}(); | ||
I18n.prototype.changeLanguage = function changeLanguage(lng, callback) { | ||
var _this4 = this; | ||
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; | ||
} else { | ||
callback(null); | ||
var done = function done(err) { | ||
if (lng) { | ||
_this4.emit('languageChanged', lng); | ||
_this4.logger.log('languageChanged', lng); | ||
} | ||
} | ||
}, { | ||
key: 'use', | ||
value: function use(module) { | ||
if (module.type === 'backend') { | ||
this.modules.backend = module; | ||
} | ||
if (module.type === 'cache') { | ||
this.modules.cache = module; | ||
} | ||
if (callback) callback(err, function () { | ||
for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
} | ||
if (module.type === 'logger' || module.log && module.warn && module.warn) { | ||
this.modules.logger = module; | ||
} | ||
return _this4.t.apply(_this4, args); | ||
}); | ||
}; | ||
if (module.type === 'languageDetector') { | ||
this.modules.languageDetector = module; | ||
} | ||
if (!lng && this.services.languageDetector) lng = this.services.languageDetector.detect(); | ||
if (module.type === 'postProcessor') { | ||
_postProcessor2.default.addPostProcessor(module); | ||
} | ||
if (lng) { | ||
this.language = lng; | ||
this.languages = this.services.languageUtils.toResolveHierarchy(lng); | ||
return this; | ||
this.translator.changeLanguage(lng); | ||
if (this.services.languageDetector) this.services.languageDetector.cacheUserLanguage(lng); | ||
} | ||
}, { | ||
key: 'changeLanguage', | ||
value: function changeLanguage(lng, callback) { | ||
var _this4 = this; | ||
var done = function done(err) { | ||
if (lng) { | ||
_this4.emit('languageChanged', lng); | ||
_this4.logger.log('languageChanged', lng); | ||
} | ||
this.loadResources(function (err) { | ||
done(err); | ||
}); | ||
}; | ||
if (callback) callback(err, function () { | ||
for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
} | ||
I18n.prototype.getFixedT = function getFixedT(lng, ns) { | ||
var _this5 = this; | ||
return _this4.t.apply(_this4, args); | ||
}); | ||
}; | ||
var fixedT = function fixedT(key, options) { | ||
options = options || {}; | ||
options.lng = options.lng || fixedT.lng; | ||
options.ns = options.ns || fixedT.ns; | ||
return _this5.t(key, options); | ||
}; | ||
fixedT.lng = lng; | ||
fixedT.ns = ns; | ||
return fixedT; | ||
}; | ||
if (!lng && this.services.languageDetector) lng = this.services.languageDetector.detect(); | ||
I18n.prototype.t = function t() { | ||
return this.translator && this.translator.translate.apply(this.translator, arguments); | ||
}; | ||
if (lng) { | ||
this.language = lng; | ||
this.languages = this.services.languageUtils.toResolveHierarchy(lng); | ||
I18n.prototype.exists = function exists() { | ||
return this.translator && this.translator.exists.apply(this.translator, arguments); | ||
}; | ||
this.translator.changeLanguage(lng); | ||
I18n.prototype.setDefaultNamespace = function setDefaultNamespace(ns) { | ||
this.options.defaultNS = ns; | ||
}; | ||
if (this.services.languageDetector) this.services.languageDetector.cacheUserLanguage(lng); | ||
} | ||
I18n.prototype.loadNamespaces = function loadNamespaces(ns, callback) { | ||
var _this6 = this; | ||
this.loadResources(function (err) { | ||
done(err); | ||
}); | ||
} | ||
}, { | ||
key: 'getFixedT', | ||
value: function getFixedT(lng, ns) { | ||
var _this5 = this; | ||
if (!this.options.ns) return callback && callback(); | ||
if (typeof ns === 'string') ns = [ns]; | ||
var fixedT = function fixedT(key, options) { | ||
options = options || {}; | ||
options.lng = options.lng || fixedT.lng; | ||
options.ns = options.ns || fixedT.ns; | ||
return _this5.t(key, options); | ||
}; | ||
fixedT.lng = lng; | ||
fixedT.ns = ns; | ||
return fixedT; | ||
} | ||
}, { | ||
key: 't', | ||
value: function t() { | ||
return this.translator && this.translator.translate.apply(this.translator, arguments); | ||
} | ||
}, { | ||
key: 'exists', | ||
value: function exists() { | ||
return this.translator && this.translator.exists.apply(this.translator, arguments); | ||
} | ||
}, { | ||
key: 'setDefaultNamespace', | ||
value: function setDefaultNamespace(ns) { | ||
this.options.defaultNS = ns; | ||
} | ||
}, { | ||
key: 'loadNamespaces', | ||
value: function loadNamespaces(ns, callback) { | ||
var _this6 = this; | ||
ns.forEach(function (n) { | ||
if (_this6.options.ns.indexOf(n) < 0) _this6.options.ns.push(n); | ||
}); | ||
if (!this.options.ns) return callback && callback(); | ||
if (typeof ns === 'string') ns = [ns]; | ||
this.loadResources(callback); | ||
}; | ||
ns.forEach(function (n) { | ||
if (_this6.options.ns.indexOf(n) < 0) _this6.options.ns.push(n); | ||
}); | ||
I18n.prototype.loadLanguages = function loadLanguages(lngs, callback) { | ||
if (typeof lngs === 'string') lngs = [lngs]; | ||
this.options.preload = this.options.preload ? this.options.preload.concat(lngs) : lngs; | ||
this.loadResources(callback); | ||
} | ||
}, { | ||
key: 'loadLanguages', | ||
value: function loadLanguages(lngs, callback) { | ||
if (typeof lngs === 'string') lngs = [lngs]; | ||
this.options.preload = this.options.preload ? this.options.preload.concat(lngs) : lngs; | ||
this.loadResources(callback); | ||
}; | ||
this.loadResources(callback); | ||
} | ||
}, { | ||
key: 'dir', | ||
value: function dir(lng) { | ||
if (!lng) lng = this.language; | ||
I18n.prototype.dir = function dir(lng) { | ||
if (!lng) lng = this.language; | ||
var ltrLngs = ['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', 'ur', 'ydd', 'yds', 'yih', 'ji', 'yi', 'hbo', 'men', 'xmn', 'fa', 'jpr', 'peo', 'pes', 'prs', 'dv', 'sam']; | ||
var ltrLngs = ['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', 'ur', 'ydd', 'yds', 'yih', 'ji', 'yi', 'hbo', 'men', 'xmn', 'fa', 'jpr', 'peo', 'pes', 'prs', 'dv', 'sam']; | ||
return ltrLngs.indexOf(this.services.languageUtils.getLanguagePartFromCode(lng)) ? 'ltr' : 'rtl'; | ||
} | ||
}, { | ||
key: 'createInstance', | ||
value: function createInstance() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var callback = arguments[1]; | ||
return ltrLngs.indexOf(this.services.languageUtils.getLanguagePartFromCode(lng)) ? 'ltr' : 'rtl'; | ||
}; | ||
return new I18n(options, callback); | ||
} | ||
}, { | ||
key: 'cloneInstance', | ||
value: function cloneInstance() { | ||
var _this7 = this; | ||
I18n.prototype.createInstance = function createInstance() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var callback = arguments[1]; | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var callback = arguments[1]; | ||
return new I18n(options, callback); | ||
}; | ||
var clone = new I18n(_extends({}, options, this.options, { isClone: true }), callback); | ||
var membersToCopy = ['store', 'translator', 'services', 'language']; | ||
membersToCopy.forEach(function (m) { | ||
clone[m] = _this7[m]; | ||
}); | ||
I18n.prototype.cloneInstance = function cloneInstance() { | ||
var _this7 = this; | ||
return clone; | ||
} | ||
}]); | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var callback = arguments[1]; | ||
var clone = new I18n(_extends({}, options, this.options, { isClone: true }), callback); | ||
var membersToCopy = ['store', 'translator', 'services', 'language']; | ||
membersToCopy.forEach(function (m) { | ||
clone[m] = _this7[m]; | ||
}); | ||
return clone; | ||
}; | ||
return I18n; | ||
@@ -390,0 +375,0 @@ }(_EventEmitter3.default); |
@@ -7,4 +7,2 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _utils = require('./utils'); | ||
@@ -35,117 +33,111 @@ | ||
_createClass(Interpolator, [{ | ||
key: 'init', | ||
value: function init() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var reset = arguments[1]; | ||
Interpolator.prototype.init = function init() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var reset = arguments[1]; | ||
if (reset) this.options = options; | ||
if (!options.interpolation) options.interpolation = { escapeValue: true }; | ||
if (reset) this.options = options; | ||
if (!options.interpolation) options.interpolation = { escapeValue: true }; | ||
var iOpts = options.interpolation; | ||
var iOpts = options.interpolation; | ||
this.escapeValue = iOpts.escapeValue; | ||
this.escapeValue = iOpts.escapeValue; | ||
this.prefix = iOpts.prefix ? utils.regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{'; | ||
this.suffix = iOpts.suffix ? utils.regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}'; | ||
this.prefix = iOpts.prefix ? utils.regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{'; | ||
this.suffix = iOpts.suffix ? utils.regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}'; | ||
this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-'; | ||
this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || ''; | ||
this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-'; | ||
this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || ''; | ||
this.nestingPrefix = iOpts.nestingPrefix ? utils.regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || utils.regexEscape('$t('); | ||
this.nestingSuffix = iOpts.nestingSuffix ? utils.regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || utils.regexEscape(')'); | ||
this.nestingPrefix = iOpts.nestingPrefix ? utils.regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || utils.regexEscape('$t('); | ||
this.nestingSuffix = iOpts.nestingSuffix ? utils.regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || utils.regexEscape(')'); | ||
// the regexp | ||
var regexpStr = this.prefix + '(.+?)' + this.suffix; | ||
this.regexp = new RegExp(regexpStr, 'g'); | ||
// the regexp | ||
var regexpStr = this.prefix + '(.+?)' + this.suffix; | ||
this.regexp = new RegExp(regexpStr, 'g'); | ||
var regexpUnescapeStr = this.prefix + this.unescapePrefix + '(.+?)' + this.unescapeSuffix + this.suffix; | ||
this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g'); | ||
var regexpUnescapeStr = this.prefix + this.unescapePrefix + '(.+?)' + this.unescapeSuffix + this.suffix; | ||
this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g'); | ||
var nestingRegexpStr = this.nestingPrefix + '(.+?)' + this.nestingSuffix; | ||
this.nestingRegexp = new RegExp(nestingRegexpStr, 'g'); | ||
var nestingRegexpStr = this.nestingPrefix + '(.+?)' + this.nestingSuffix; | ||
this.nestingRegexp = new RegExp(nestingRegexpStr, 'g'); | ||
}; | ||
Interpolator.prototype.reset = function reset() { | ||
if (this.options) this.init(this.options); | ||
}; | ||
Interpolator.prototype.interpolate = function interpolate(str, data) { | ||
var match = void 0, | ||
value = void 0; | ||
function regexSafe(val) { | ||
return val.replace(/\$/g, '$$$$'); | ||
} | ||
}, { | ||
key: 'reset', | ||
value: function reset() { | ||
if (this.options) this.init(this.options); | ||
// unescape if has unescapePrefix/Suffix | ||
while (match = this.regexpUnescape.exec(str)) { | ||
var _value = utils.getPath(data, match[1].trim()); | ||
str = str.replace(match[0], _value); | ||
} | ||
}, { | ||
key: 'interpolate', | ||
value: function interpolate(str, data) { | ||
var match = void 0, | ||
value = void 0; | ||
function regexSafe(val) { | ||
return val.replace(/\$/g, '$$$$'); | ||
// regular escape on demand | ||
while (match = this.regexp.exec(str)) { | ||
value = utils.getPath(data, match[1].trim()); | ||
if (typeof value !== 'string') value = utils.makeString(value); | ||
if (!value) { | ||
this.logger.warn('missed to pass in variable ' + match[1] + ' for interpolating ' + str); | ||
value = ''; | ||
} | ||
// unescape if has unescapePrefix/Suffix | ||
while (match = this.regexpUnescape.exec(str)) { | ||
var _value = utils.getPath(data, match[1].trim()); | ||
str = str.replace(match[0], _value); | ||
} | ||
// regular escape on demand | ||
while (match = this.regexp.exec(str)) { | ||
value = utils.getPath(data, match[1].trim()); | ||
if (typeof value !== 'string') value = utils.makeString(value); | ||
if (!value) { | ||
this.logger.warn('missed to pass in variable ' + match[1] + ' for interpolating ' + str); | ||
value = ''; | ||
} | ||
value = this.escapeValue ? regexSafe(utils.escape(value)) : regexSafe(value); | ||
str = str.replace(match[0], value); | ||
this.regexp.lastIndex = 0; | ||
} | ||
return str; | ||
value = this.escapeValue ? regexSafe(utils.escape(value)) : regexSafe(value); | ||
str = str.replace(match[0], value); | ||
this.regexp.lastIndex = 0; | ||
} | ||
}, { | ||
key: 'nest', | ||
value: function nest(str, fc) { | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
return str; | ||
}; | ||
var match = void 0, | ||
value = void 0; | ||
Interpolator.prototype.nest = function nest(str, fc) { | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var clonedOptions = JSON.parse(JSON.stringify(options)); | ||
clonedOptions.applyPostProcessor = false; // avoid post processing on nested lookup | ||
var match = void 0, | ||
value = void 0; | ||
function regexSafe(val) { | ||
return val.replace(/\$/g, '$$$$'); | ||
} | ||
var clonedOptions = JSON.parse(JSON.stringify(options)); | ||
clonedOptions.applyPostProcessor = false; // avoid post processing on nested lookup | ||
// if value is something like "myKey": "lorem $(anotherKey, { "count": {{aValueInOptions}} })" | ||
function handleHasOptions(key) { | ||
if (key.indexOf(',') < 0) return key; | ||
function regexSafe(val) { | ||
return val.replace(/\$/g, '$$$$'); | ||
} | ||
var p = key.split(','); | ||
key = p.shift(); | ||
var optionsString = p.join(','); | ||
optionsString = this.interpolate(optionsString, clonedOptions); | ||
// if value is something like "myKey": "lorem $(anotherKey, { "count": {{aValueInOptions}} })" | ||
function handleHasOptions(key) { | ||
if (key.indexOf(',') < 0) return key; | ||
try { | ||
clonedOptions = JSON.parse(optionsString); | ||
} catch (e) { | ||
this.logger.error('failed parsing options string in nesting for key ' + key, e); | ||
} | ||
var p = key.split(','); | ||
key = p.shift(); | ||
var optionsString = p.join(','); | ||
optionsString = this.interpolate(optionsString, clonedOptions); | ||
return key; | ||
try { | ||
clonedOptions = JSON.parse(optionsString); | ||
} catch (e) { | ||
this.logger.error('failed parsing options string in nesting for key ' + key, e); | ||
} | ||
// regular escape on demand | ||
while (match = this.nestingRegexp.exec(str)) { | ||
value = fc(handleHasOptions.call(this, match[1].trim()), clonedOptions); | ||
if (typeof value !== 'string') value = utils.makeString(value); | ||
if (!value) { | ||
this.logger.warn('missed to pass in variable ' + match[1] + ' for interpolating ' + str); | ||
value = ''; | ||
} | ||
value = this.escapeValue ? regexSafe(utils.escape(value)) : regexSafe(value); | ||
str = str.replace(match[0], value); | ||
this.regexp.lastIndex = 0; | ||
return key; | ||
} | ||
// regular escape on demand | ||
while (match = this.nestingRegexp.exec(str)) { | ||
value = fc(handleHasOptions.call(this, match[1].trim()), clonedOptions); | ||
if (typeof value !== 'string') value = utils.makeString(value); | ||
if (!value) { | ||
this.logger.warn('missed to pass in variable ' + match[1] + ' for interpolating ' + str); | ||
value = ''; | ||
} | ||
return str; | ||
value = this.escapeValue ? regexSafe(utils.escape(value)) : regexSafe(value); | ||
str = str.replace(match[0], value); | ||
this.regexp.lastIndex = 0; | ||
} | ||
}]); | ||
return str; | ||
}; | ||
@@ -152,0 +144,0 @@ return Interpolator; |
@@ -9,4 +9,2 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _logger = require('./logger'); | ||
@@ -30,65 +28,59 @@ | ||
_createClass(LanguageUtil, [{ | ||
key: 'getLanguagePartFromCode', | ||
value: function getLanguagePartFromCode(code) { | ||
if (code.indexOf('-') < 0) return code; | ||
LanguageUtil.prototype.getLanguagePartFromCode = function getLanguagePartFromCode(code) { | ||
if (code.indexOf('-') < 0) return code; | ||
var specialCases = ['nb-NO', 'nn-NO', 'nb-no', 'nn-no']; | ||
var p = code.split('-'); | ||
return this.formatLanguageCode(specialCases.indexOf(code) > -1 ? p[1].toLowerCase() : p[0]); | ||
} | ||
}, { | ||
key: 'formatLanguageCode', | ||
value: function formatLanguageCode(code) { | ||
if (typeof code === 'string' && code.indexOf('-') > -1) { | ||
var _code$split = code.split('-'); | ||
var specialCases = ['nb-NO', 'nn-NO', 'nb-no', 'nn-no']; | ||
var p = code.split('-'); | ||
return this.formatLanguageCode(specialCases.indexOf(code) > -1 ? p[1].toLowerCase() : p[0]); | ||
}; | ||
var _code$split2 = _slicedToArray(_code$split, 2); | ||
LanguageUtil.prototype.formatLanguageCode = function formatLanguageCode(code) { | ||
if (typeof code === 'string' && code.indexOf('-') > -1) { | ||
var _code$split = code.split('-'); | ||
var head = _code$split2[0]; | ||
var tail = _code$split2[1]; | ||
var _code$split2 = _slicedToArray(_code$split, 2); | ||
return this.options.lowerCaseLng ? head.toLowerCase() + '-' + tail.toLowerCase() : head.toLowerCase() + '-' + tail.toUpperCase(); | ||
} else { | ||
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code; | ||
} | ||
var head = _code$split2[0]; | ||
var tail = _code$split2[1]; | ||
return this.options.lowerCaseLng ? head.toLowerCase() + '-' + tail.toLowerCase() : head.toLowerCase() + '-' + tail.toUpperCase(); | ||
} else { | ||
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code; | ||
} | ||
}, { | ||
key: 'isWhitelisted', | ||
value: function isWhitelisted(code) { | ||
if (this.options.load === 'languageOnly') code = this.getLanguagePartFromCode(code); | ||
return !this.whitelist || !this.whitelist.length || this.whitelist.indexOf(code) > -1 ? true : false; | ||
} | ||
}, { | ||
key: 'toResolveHierarchy', | ||
value: function toResolveHierarchy(code, fallbackCode) { | ||
var _this = this; | ||
}; | ||
fallbackCode = fallbackCode || this.options.fallbackLng || []; | ||
if (typeof fallbackCode === 'string') fallbackCode = [fallbackCode]; | ||
LanguageUtil.prototype.isWhitelisted = function isWhitelisted(code) { | ||
if (this.options.load === 'languageOnly') code = this.getLanguagePartFromCode(code); | ||
return !this.whitelist || !this.whitelist.length || this.whitelist.indexOf(code) > -1 ? true : false; | ||
}; | ||
var codes = []; | ||
var addCode = function addCode(code) { | ||
if (_this.isWhitelisted(code)) { | ||
codes.push(code); | ||
} else { | ||
_this.logger.warn('rejecting non-whitelisted language code: ' + code); | ||
} | ||
}; | ||
LanguageUtil.prototype.toResolveHierarchy = function toResolveHierarchy(code, fallbackCode) { | ||
var _this = this; | ||
if (typeof code === 'string' && code.indexOf('-') > -1) { | ||
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code)); | ||
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code)); | ||
} else if (typeof code === 'string') { | ||
addCode(this.formatLanguageCode(code)); | ||
fallbackCode = fallbackCode || this.options.fallbackLng || []; | ||
if (typeof fallbackCode === 'string') fallbackCode = [fallbackCode]; | ||
var codes = []; | ||
var addCode = function addCode(code) { | ||
if (_this.isWhitelisted(code)) { | ||
codes.push(code); | ||
} else { | ||
_this.logger.warn('rejecting non-whitelisted language code: ' + code); | ||
} | ||
}; | ||
fallbackCode.forEach(function (fc) { | ||
if (codes.indexOf(fc) < 0) addCode(_this.formatLanguageCode(fc)); | ||
}); | ||
return codes; | ||
if (typeof code === 'string' && code.indexOf('-') > -1) { | ||
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code)); | ||
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code)); | ||
} else if (typeof code === 'string') { | ||
addCode(this.formatLanguageCode(code)); | ||
} | ||
}]); | ||
fallbackCode.forEach(function (fc) { | ||
if (codes.indexOf(fc) < 0) addCode(_this.formatLanguageCode(fc)); | ||
}); | ||
return codes; | ||
}; | ||
return LanguageUtil; | ||
@@ -95,0 +87,0 @@ }(); |
@@ -9,4 +9,2 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -41,62 +39,51 @@ | ||
_createClass(Logger, [{ | ||
key: 'init', | ||
value: function init(concreteLogger) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
Logger.prototype.init = function init(concreteLogger) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
this.prefix = options.prefix || 'i18next:'; | ||
this.logger = concreteLogger || consoleLogger; | ||
this.options = options; | ||
this.debug = options.debug === false ? false : true; | ||
} | ||
}, { | ||
key: 'setDebug', | ||
value: function setDebug(bool) { | ||
this.debug = bool; | ||
this.subs.forEach(function (sub) { | ||
sub.setDebug(bool); | ||
}); | ||
} | ||
}, { | ||
key: 'log', | ||
value: function log() { | ||
this.forward(arguments, 'log', '', true); | ||
} | ||
}, { | ||
key: 'warn', | ||
value: function warn() { | ||
this.forward(arguments, 'warn', '', true); | ||
} | ||
}, { | ||
key: 'error', | ||
value: function error() { | ||
this.forward(arguments, 'error', ''); | ||
} | ||
}, { | ||
key: 'deprecate', | ||
value: function deprecate() { | ||
this.forward(arguments, 'warn', 'WARNING DEPRECATED: ', true); | ||
} | ||
}, { | ||
key: 'forward', | ||
value: function forward(args, lvl, prefix, debugOnly) { | ||
if (debugOnly && !this.debug) return; | ||
if (typeof args[0] === 'string') args[0] = prefix + this.prefix + ' ' + args[0]; | ||
this.logger[lvl](args); | ||
} | ||
}, { | ||
key: 'create', | ||
value: function create(moduleName) { | ||
var sub = new Logger(this.logger, _extends({ prefix: this.prefix + ':' + moduleName + ':' }, this.options)); | ||
this.subs.push(sub); | ||
this.prefix = options.prefix || 'i18next:'; | ||
this.logger = concreteLogger || consoleLogger; | ||
this.options = options; | ||
this.debug = options.debug === false ? false : true; | ||
}; | ||
return sub; | ||
} | ||
Logger.prototype.setDebug = function setDebug(bool) { | ||
this.debug = bool; | ||
this.subs.forEach(function (sub) { | ||
sub.setDebug(bool); | ||
}); | ||
}; | ||
// createInstance(options = {}) { | ||
// return new Logger(options, callback); | ||
// } | ||
Logger.prototype.log = function log() { | ||
this.forward(arguments, 'log', '', true); | ||
}; | ||
}]); | ||
Logger.prototype.warn = function warn() { | ||
this.forward(arguments, 'warn', '', true); | ||
}; | ||
Logger.prototype.error = function error() { | ||
this.forward(arguments, 'error', ''); | ||
}; | ||
Logger.prototype.deprecate = function deprecate() { | ||
this.forward(arguments, 'warn', 'WARNING DEPRECATED: ', true); | ||
}; | ||
Logger.prototype.forward = function forward(args, lvl, prefix, debugOnly) { | ||
if (debugOnly && !this.debug) return; | ||
if (typeof args[0] === 'string') args[0] = prefix + this.prefix + ' ' + args[0]; | ||
this.logger[lvl](args); | ||
}; | ||
Logger.prototype.create = function create(moduleName) { | ||
var sub = new Logger(this.logger, _extends({ prefix: this.prefix + ':' + moduleName + ':' }, this.options)); | ||
this.subs.push(sub); | ||
return sub; | ||
}; | ||
// createInstance(options = {}) { | ||
// return new Logger(options, callback); | ||
// } | ||
return Logger; | ||
@@ -103,0 +90,0 @@ }(); |
@@ -7,4 +7,2 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _logger = require('./logger'); | ||
@@ -89,2 +87,16 @@ | ||
function createRules() { | ||
var l, | ||
rules = {}; | ||
sets.forEach(function (set) { | ||
set.lngs.forEach(function (l) { | ||
return rules[l] = { | ||
numbers: set.nr, | ||
plurals: _rulesPluralsTypes[set.fc] | ||
}; | ||
}); | ||
}); | ||
return rules; | ||
} | ||
var PluralResolver = function () { | ||
@@ -96,16 +108,2 @@ function PluralResolver(languageUtils) { | ||
this.rules = function () { | ||
var l, | ||
rules = {}; | ||
sets.forEach(function (set) { | ||
set.lngs.forEach(function (l) { | ||
return rules[l] = { | ||
numbers: set.nr, | ||
plurals: _rulesPluralsTypes[set.fc] | ||
}; | ||
}); | ||
}); | ||
return rules; | ||
}(); | ||
this.languageUtils = languageUtils; | ||
@@ -115,54 +113,50 @@ this.options = options; | ||
this.logger = _logger2.default.create('pluralResolver'); | ||
this.rules = createRules(); | ||
} | ||
_createClass(PluralResolver, [{ | ||
key: 'addRule', | ||
value: function addRule(lng, obj) { | ||
this.rules[lng] = obj; | ||
} | ||
}, { | ||
key: 'getRule', | ||
value: function getRule(code) { | ||
return this.rules[this.languageUtils.getLanguagePartFromCode(code)]; | ||
} | ||
}, { | ||
key: 'needsPlural', | ||
value: function needsPlural(code) { | ||
var rule = this.getRule(code); | ||
PluralResolver.prototype.addRule = function addRule(lng, obj) { | ||
this.rules[lng] = obj; | ||
}; | ||
return rule && rule.numbers.length <= 1 ? false : true; | ||
} | ||
}, { | ||
key: 'getSuffix', | ||
value: function getSuffix(code, count) { | ||
var rule = this.getRule(code); | ||
PluralResolver.prototype.getRule = function getRule(code) { | ||
return this.rules[this.languageUtils.getLanguagePartFromCode(code)]; | ||
}; | ||
if (rule) { | ||
if (rule.numbers.length === 1) return ''; // only singular | ||
PluralResolver.prototype.needsPlural = function needsPlural(code) { | ||
var rule = this.getRule(code); | ||
var idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count)); | ||
var suffix = rule.numbers[idx]; | ||
return rule && rule.numbers.length <= 1 ? false : true; | ||
}; | ||
// special treatment for lngs only having singular and plural | ||
if (rule.numbers.length === 2 && rule.numbers[0] === 1) { | ||
if (suffix === 2) { | ||
suffix = 'plural'; | ||
} else if (suffix === 1) { | ||
suffix = ''; | ||
} | ||
} | ||
PluralResolver.prototype.getSuffix = function getSuffix(code, count) { | ||
var rule = this.getRule(code); | ||
// COMPATIBILITY JSON | ||
if (this.options.compatibilityJSON === 'v1') { | ||
if (suffix === 1) return ''; | ||
if (typeof suffix === 'number') return '_plural_' + suffix.toString(); | ||
if (rule) { | ||
if (rule.numbers.length === 1) return ''; // only singular | ||
var idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count)); | ||
var suffix = rule.numbers[idx]; | ||
// special treatment for lngs only having singular and plural | ||
if (rule.numbers.length === 2 && rule.numbers[0] === 1) { | ||
if (suffix === 2) { | ||
suffix = 'plural'; | ||
} else if (suffix === 1) { | ||
suffix = ''; | ||
} | ||
} | ||
return this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString(); | ||
} else { | ||
this.logger.warn('no plural rule found for: ' + code); | ||
return ''; | ||
// COMPATIBILITY JSON | ||
if (this.options.compatibilityJSON === 'v1') { | ||
if (suffix === 1) return ''; | ||
if (typeof suffix === 'number') return '_plural_' + suffix.toString(); | ||
} | ||
return this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString(); | ||
} else { | ||
this.logger.warn('no plural rule found for: ' + code); | ||
return ''; | ||
} | ||
}]); | ||
}; | ||
@@ -169,0 +163,0 @@ return PluralResolver; |
@@ -9,4 +9,2 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _EventEmitter2 = require('./EventEmitter'); | ||
@@ -24,2 +22,4 @@ | ||
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -29,3 +29,3 @@ | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } | ||
@@ -41,3 +41,3 @@ var ResourceStore = function (_EventEmitter) { | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(ResourceStore).call(this)); | ||
var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); | ||
@@ -49,123 +49,111 @@ _this.data = data; | ||
_createClass(ResourceStore, [{ | ||
key: 'addNamespaces', | ||
value: function addNamespaces(ns) { | ||
if (this.options.ns.indexOf(ns) < 0) { | ||
this.options.ns.push(ns); | ||
} | ||
ResourceStore.prototype.addNamespaces = function addNamespaces(ns) { | ||
if (this.options.ns.indexOf(ns) < 0) { | ||
this.options.ns.push(ns); | ||
} | ||
}, { | ||
key: 'removeNamespaces', | ||
value: function removeNamespaces(ns) { | ||
var index = this.options.ns.indexOf(ns); | ||
if (index > -1) { | ||
this.options.ns.splice(index, 1); | ||
} | ||
}; | ||
ResourceStore.prototype.removeNamespaces = function removeNamespaces(ns) { | ||
var index = this.options.ns.indexOf(ns); | ||
if (index > -1) { | ||
this.options.ns.splice(index, 1); | ||
} | ||
}, { | ||
key: 'getResource', | ||
value: function getResource(lng, ns, key) { | ||
var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
}; | ||
var keySeparator = options.keySeparator || this.options.keySeparator; | ||
if (keySeparator === undefined) keySeparator = '.'; | ||
ResourceStore.prototype.getResource = function getResource(lng, ns, key) { | ||
var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
var path = [lng, ns]; | ||
if (key && typeof key !== 'string') path = path.concat(key); | ||
if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key); | ||
var keySeparator = options.keySeparator || this.options.keySeparator; | ||
if (keySeparator === undefined) keySeparator = '.'; | ||
if (lng.indexOf('.') > -1) { | ||
path = lng.split('.'); | ||
} | ||
var path = [lng, ns]; | ||
if (key && typeof key !== 'string') path = path.concat(key); | ||
if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key); | ||
return utils.getPath(this.data, path); | ||
if (lng.indexOf('.') > -1) { | ||
path = lng.split('.'); | ||
} | ||
}, { | ||
key: 'addResource', | ||
value: function addResource(lng, ns, key, value) { | ||
var options = arguments.length <= 4 || arguments[4] === undefined ? { silent: false } : arguments[4]; | ||
var keySeparator = this.options.keySeparator; | ||
if (keySeparator === undefined) keySeparator = '.'; | ||
return utils.getPath(this.data, path); | ||
}; | ||
var path = [lng, ns]; | ||
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key); | ||
ResourceStore.prototype.addResource = function addResource(lng, ns, key, value) { | ||
var options = arguments.length <= 4 || arguments[4] === undefined ? { silent: false } : arguments[4]; | ||
if (lng.indexOf('.') > -1) { | ||
path = lng.split('.'); | ||
value = ns; | ||
ns = path[1]; | ||
} | ||
var keySeparator = this.options.keySeparator; | ||
if (keySeparator === undefined) keySeparator = '.'; | ||
this.addNamespaces(ns); | ||
var path = [lng, ns]; | ||
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key); | ||
utils.setPath(this.data, path, value); | ||
if (!options.silent) this.emit('added', lng, ns, key, value); | ||
if (lng.indexOf('.') > -1) { | ||
path = lng.split('.'); | ||
value = ns; | ||
ns = path[1]; | ||
} | ||
}, { | ||
key: 'addResources', | ||
value: function addResources(lng, ns, resources) { | ||
for (var m in resources) { | ||
if (typeof resources[m] === 'string') this.addResource(lng, ns, m, resources[m], { silent: true }); | ||
} | ||
this.emit('added', lng, ns, resources); | ||
} | ||
}, { | ||
key: 'addResourceBundle', | ||
value: function addResourceBundle(lng, ns, resources, deep, overwrite) { | ||
var path = [lng, ns]; | ||
if (lng.indexOf('.') > -1) { | ||
path = lng.split('.'); | ||
deep = resources; | ||
resources = ns; | ||
ns = path[1]; | ||
} | ||
this.addNamespaces(ns); | ||
this.addNamespaces(ns); | ||
var pack = utils.getPath(this.data, path) || {}; | ||
utils.setPath(this.data, path, value); | ||
if (deep) { | ||
utils.deepExtend(pack, resources, overwrite); | ||
} else { | ||
pack = _extends({}, pack, resources); | ||
} | ||
if (!options.silent) this.emit('added', lng, ns, key, value); | ||
}; | ||
utils.setPath(this.data, path, pack); | ||
ResourceStore.prototype.addResources = function addResources(lng, ns, resources) { | ||
for (var m in resources) { | ||
if (typeof resources[m] === 'string') this.addResource(lng, ns, m, resources[m], { silent: true }); | ||
} | ||
this.emit('added', lng, ns, resources); | ||
}; | ||
this.emit('added', lng, ns, resources); | ||
ResourceStore.prototype.addResourceBundle = function addResourceBundle(lng, ns, resources, deep, overwrite) { | ||
var path = [lng, ns]; | ||
if (lng.indexOf('.') > -1) { | ||
path = lng.split('.'); | ||
deep = resources; | ||
resources = ns; | ||
ns = path[1]; | ||
} | ||
}, { | ||
key: 'removeResourceBundle', | ||
value: function removeResourceBundle(lng, ns) { | ||
if (this.hasResourceBundle(lng, ns)) { | ||
delete this.data[lng][ns]; | ||
} | ||
this.removeNamespaces(ns); | ||
this.emit('removed', lng, ns); | ||
this.addNamespaces(ns); | ||
var pack = utils.getPath(this.data, path) || {}; | ||
if (deep) { | ||
utils.deepExtend(pack, resources, overwrite); | ||
} else { | ||
pack = _extends({}, pack, resources); | ||
} | ||
}, { | ||
key: 'hasResourceBundle', | ||
value: function hasResourceBundle(lng, ns) { | ||
return this.getResource(lng, ns) !== undefined; | ||
} | ||
}, { | ||
key: 'getResourceBundle', | ||
value: function getResourceBundle(lng, ns) { | ||
if (!ns) ns = this.options.defaultNS; | ||
// TODO: COMPATIBILITY remove extend in v2.1.0 | ||
if (this.options.compatibilityAPI === 'v1') return _extends({}, this.getResource(lng, ns)); | ||
utils.setPath(this.data, path, pack); | ||
return this.getResource(lng, ns); | ||
this.emit('added', lng, ns, resources); | ||
}; | ||
ResourceStore.prototype.removeResourceBundle = function removeResourceBundle(lng, ns) { | ||
if (this.hasResourceBundle(lng, ns)) { | ||
delete this.data[lng][ns]; | ||
} | ||
}, { | ||
key: 'toJSON', | ||
value: function toJSON() { | ||
return this.data; | ||
} | ||
}]); | ||
this.removeNamespaces(ns); | ||
this.emit('removed', lng, ns); | ||
}; | ||
ResourceStore.prototype.hasResourceBundle = function hasResourceBundle(lng, ns) { | ||
return this.getResource(lng, ns) !== undefined; | ||
}; | ||
ResourceStore.prototype.getResourceBundle = function getResourceBundle(lng, ns) { | ||
if (!ns) ns = this.options.defaultNS; | ||
// TODO: COMPATIBILITY remove extend in v2.1.0 | ||
if (this.options.compatibilityAPI === 'v1') return _extends({}, this.getResource(lng, ns)); | ||
return this.getResource(lng, ns); | ||
}; | ||
ResourceStore.prototype.toJSON = function toJSON() { | ||
return this.data; | ||
}; | ||
return ResourceStore; | ||
@@ -172,0 +160,0 @@ }(_EventEmitter3.default); |
@@ -11,4 +11,2 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _logger = require('./logger'); | ||
@@ -38,2 +36,4 @@ | ||
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -43,3 +43,3 @@ | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } | ||
@@ -54,3 +54,3 @@ var Translator = function (_EventEmitter) { | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Translator).call(this)); | ||
var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); | ||
@@ -64,257 +64,247 @@ utils.copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector'], services, _this); | ||
_createClass(Translator, [{ | ||
key: 'changeLanguage', | ||
value: function changeLanguage(lng) { | ||
if (lng) this.language = lng; | ||
} | ||
}, { | ||
key: 'exists', | ||
value: function exists(key) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? { interpolation: {} } : arguments[1]; | ||
Translator.prototype.changeLanguage = function changeLanguage(lng) { | ||
if (lng) this.language = lng; | ||
}; | ||
if (this.options.compatibilityAPI === 'v1') { | ||
options = compat.convertTOptions(options); | ||
} | ||
Translator.prototype.exists = function exists(key) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? { interpolation: {} } : arguments[1]; | ||
return this.resolve(key, options) !== undefined; | ||
if (this.options.compatibilityAPI === 'v1') { | ||
options = compat.convertTOptions(options); | ||
} | ||
}, { | ||
key: 'extractFromKey', | ||
value: function extractFromKey(key, options) { | ||
var nsSeparator = options.nsSeparator || this.options.nsSeparator; | ||
if (nsSeparator === undefined) nsSeparator = ':'; | ||
var namespaces = options.ns || this.options.defaultNS; | ||
if (nsSeparator && key.indexOf(nsSeparator) > -1) { | ||
var parts = key.split(nsSeparator); | ||
namespaces = parts[0]; | ||
key = parts[1]; | ||
} | ||
if (typeof namespaces === 'string') namespaces = [namespaces]; | ||
return this.resolve(key, options) !== undefined; | ||
}; | ||
return { | ||
key: key, | ||
namespaces: namespaces | ||
}; | ||
Translator.prototype.extractFromKey = function extractFromKey(key, options) { | ||
var nsSeparator = options.nsSeparator || this.options.nsSeparator; | ||
if (nsSeparator === undefined) nsSeparator = ':'; | ||
var namespaces = options.ns || this.options.defaultNS; | ||
if (nsSeparator && key.indexOf(nsSeparator) > -1) { | ||
var parts = key.split(nsSeparator); | ||
namespaces = parts[0]; | ||
key = parts[1]; | ||
} | ||
}, { | ||
key: 'translate', | ||
value: function translate(keys) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
if (typeof namespaces === 'string') namespaces = [namespaces]; | ||
if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) !== 'object') { | ||
options = this.options.overloadTranslationOptionHandler(arguments); | ||
} else if (this.options.compatibilityAPI === 'v1') { | ||
options = compat.convertTOptions(options); | ||
} | ||
return { | ||
key: key, | ||
namespaces: namespaces | ||
}; | ||
}; | ||
// non valid keys handling | ||
if (keys === undefined || keys === null || keys === '') return ''; | ||
if (typeof keys === 'number') keys = String(keys); | ||
if (typeof keys === 'string') keys = [keys]; | ||
Translator.prototype.translate = function translate(keys) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
// return key on CIMode | ||
var lng = options.lng || this.language; | ||
if (lng && lng.toLowerCase() === 'cimode') return keys[keys.length - 1]; | ||
if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) !== 'object') { | ||
options = this.options.overloadTranslationOptionHandler(arguments); | ||
} else if (this.options.compatibilityAPI === 'v1') { | ||
options = compat.convertTOptions(options); | ||
} | ||
// separators | ||
var keySeparator = options.keySeparator || this.options.keySeparator || '.'; | ||
// non valid keys handling | ||
if (keys === undefined || keys === null || keys === '') return ''; | ||
if (typeof keys === 'number') keys = String(keys); | ||
if (typeof keys === 'string') keys = [keys]; | ||
// get namespace(s) | ||
// return key on CIMode | ||
var lng = options.lng || this.language; | ||
if (lng && lng.toLowerCase() === 'cimode') return keys[keys.length - 1]; | ||
var _extractFromKey = this.extractFromKey(keys[keys.length - 1], options); | ||
// separators | ||
var keySeparator = options.keySeparator || this.options.keySeparator || '.'; | ||
var key = _extractFromKey.key; | ||
var namespaces = _extractFromKey.namespaces; | ||
// get namespace(s) | ||
var namespace = namespaces[namespaces.length - 1]; | ||
var _extractFromKey = this.extractFromKey(keys[keys.length - 1], options); | ||
// resolve from store | ||
var res = this.resolve(keys, options); | ||
var key = _extractFromKey.key; | ||
var namespaces = _extractFromKey.namespaces; | ||
var resType = Object.prototype.toString.apply(res); | ||
var noObject = ['[object Number]', '[object Function]', '[object RegExp]']; | ||
var joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays; | ||
var namespace = namespaces[namespaces.length - 1]; | ||
// object | ||
if (res && typeof res !== 'string' && noObject.indexOf(resType) < 0 && !(joinArrays && resType === '[object Array]')) { | ||
if (!options.returnObjects && !this.options.returnObjects) { | ||
this.logger.warn('accessing an object - but returnObjects options is not enabled!'); | ||
return this.options.returnedObjectHandler ? this.options.returnedObjectHandler(key, res, options) : 'key \'' + key + ' (' + this.language + ')\' returned an object instead of string.'; | ||
} | ||
// resolve from store | ||
var res = this.resolve(keys, options); | ||
var copy = resType === '[object Array]' ? [] : {}; // apply child translation on a copy | ||
var resType = Object.prototype.toString.apply(res); | ||
var noObject = ['[object Number]', '[object Function]', '[object RegExp]']; | ||
var joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays; | ||
for (var m in res) { | ||
copy[m] = this.translate('' + key + keySeparator + m, _extends({ joinArrays: false, ns: namespaces }, options)); | ||
} | ||
res = copy; | ||
// object | ||
if (res && typeof res !== 'string' && noObject.indexOf(resType) < 0 && !(joinArrays && resType === '[object Array]')) { | ||
if (!options.returnObjects && !this.options.returnObjects) { | ||
this.logger.warn('accessing an object - but returnObjects options is not enabled!'); | ||
return this.options.returnedObjectHandler ? this.options.returnedObjectHandler(key, res, options) : 'key \'' + key + ' (' + this.language + ')\' returned an object instead of string.'; | ||
} | ||
// array special treatment | ||
else if (joinArrays && resType === '[object Array]') { | ||
res = res.join(joinArrays); | ||
if (res) res = this.extendTranslation(res, key, options); | ||
} | ||
// string, empty or null | ||
else { | ||
var usedDefault = false, | ||
usedKey = false; | ||
// fallback value | ||
if (!this.isValidLookup(res) && options.defaultValue) { | ||
usedDefault = true; | ||
res = options.defaultValue; | ||
} | ||
if (!this.isValidLookup(res)) { | ||
usedKey = true; | ||
res = key; | ||
} | ||
var copy = resType === '[object Array]' ? [] : {}; // apply child translation on a copy | ||
// save missing | ||
if (usedKey || usedDefault) { | ||
this.logger.log('missingKey', lng, namespace, key, res); | ||
for (var m in res) { | ||
copy[m] = this.translate('' + key + keySeparator + m, _extends({ joinArrays: false, ns: namespaces }, options)); | ||
} | ||
res = copy; | ||
} | ||
// array special treatment | ||
else if (joinArrays && resType === '[object Array]') { | ||
res = res.join(joinArrays); | ||
if (res) res = this.extendTranslation(res, key, options); | ||
} | ||
// string, empty or null | ||
else { | ||
var usedDefault = false, | ||
usedKey = false; | ||
if (this.options.saveMissing) { | ||
var lngs = []; | ||
if (this.options.saveMissingTo === 'fallback' && this.options.fallbackLng && this.options.fallbackLng[0]) { | ||
for (var i = 0; i < this.options.fallbackLng.length; i++) { | ||
lngs.push(this.options.fallbackLng[i]); | ||
} | ||
} else if (this.options.saveMissingTo === 'all') { | ||
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language); | ||
} else { | ||
//(this.options.saveMissingTo === 'current' || (this.options.saveMissingTo === 'fallback' && this.options.fallbackLng[0] === false) ) { | ||
lngs.push(options.lng || this.language); | ||
} | ||
// fallback value | ||
if (!this.isValidLookup(res) && options.defaultValue) { | ||
usedDefault = true; | ||
res = options.defaultValue; | ||
} | ||
if (!this.isValidLookup(res)) { | ||
usedKey = true; | ||
res = key; | ||
} | ||
if (this.options.missingKeyHandler) { | ||
this.options.missingKeyHandler(lngs, namespace, key, res); | ||
} else if (this.backendConnector && this.backendConnector.saveMissing) { | ||
this.backendConnector.saveMissing(lngs, namespace, key, res); | ||
// save missing | ||
if (usedKey || usedDefault) { | ||
this.logger.log('missingKey', lng, namespace, key, res); | ||
if (this.options.saveMissing) { | ||
var lngs = []; | ||
if (this.options.saveMissingTo === 'fallback' && this.options.fallbackLng && this.options.fallbackLng[0]) { | ||
for (var i = 0; i < this.options.fallbackLng.length; i++) { | ||
lngs.push(this.options.fallbackLng[i]); | ||
} | ||
} else if (this.options.saveMissingTo === 'all') { | ||
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language); | ||
} else { | ||
//(this.options.saveMissingTo === 'current' || (this.options.saveMissingTo === 'fallback' && this.options.fallbackLng[0] === false) ) { | ||
lngs.push(options.lng || this.language); | ||
} | ||
this.emit('missingKey', lngs, namespace, key, res); | ||
if (this.options.missingKeyHandler) { | ||
this.options.missingKeyHandler(lngs, namespace, key, res); | ||
} else if (this.backendConnector && this.backendConnector.saveMissing) { | ||
this.backendConnector.saveMissing(lngs, namespace, key, res); | ||
} | ||
this.emit('missingKey', lngs, namespace, key, res); | ||
} | ||
} | ||
// extend | ||
res = this.extendTranslation(res, key, options); | ||
// extend | ||
res = this.extendTranslation(res, key, options); | ||
// append namespace if still key | ||
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = namespace + ':' + key; | ||
// append namespace if still key | ||
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = namespace + ':' + key; | ||
// parseMissingKeyHandler | ||
if (usedKey && this.options.parseMissingKeyHandler) res = this.options.parseMissingKeyHandler(res); | ||
} | ||
// parseMissingKeyHandler | ||
if (usedKey && this.options.parseMissingKeyHandler) res = this.options.parseMissingKeyHandler(res); | ||
} | ||
// return | ||
return res; | ||
} | ||
}, { | ||
key: 'extendTranslation', | ||
value: function extendTranslation(res, key, options) { | ||
var _this2 = this; | ||
// return | ||
return res; | ||
}; | ||
if (options.interpolation) this.interpolator.init(options); | ||
Translator.prototype.extendTranslation = function extendTranslation(res, key, options) { | ||
var _this2 = this; | ||
// interpolate | ||
var data = options.replace && typeof options.replace !== 'string' ? options.replace : options; | ||
if (this.options.interpolation.defaultVariables) data = _extends({}, this.options.interpolation.defaultVariables, data); | ||
res = this.interpolator.interpolate(res, data); | ||
if (options.interpolation) this.interpolator.init(options); | ||
// nesting | ||
res = this.interpolator.nest(res, function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
// interpolate | ||
var data = options.replace && typeof options.replace !== 'string' ? options.replace : options; | ||
if (this.options.interpolation.defaultVariables) data = _extends({}, this.options.interpolation.defaultVariables, data); | ||
res = this.interpolator.interpolate(res, data); | ||
return _this2.translate.apply(_this2, args); | ||
}, options); | ||
// nesting | ||
res = this.interpolator.nest(res, function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
if (options.interpolation) this.interpolator.reset(); | ||
return _this2.translate.apply(_this2, args); | ||
}, options); | ||
// post process | ||
var postProcess = options.postProcess || this.options.postProcess; | ||
var postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess; | ||
if (options.interpolation) this.interpolator.reset(); | ||
if (res !== undefined && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) { | ||
res = _postProcessor2.default.handle(postProcessorNames, res, key, options, this); | ||
} | ||
// post process | ||
var postProcess = options.postProcess || this.options.postProcess; | ||
var postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess; | ||
return res; | ||
if (res !== undefined && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) { | ||
res = _postProcessor2.default.handle(postProcessorNames, res, key, options, this); | ||
} | ||
}, { | ||
key: 'resolve', | ||
value: function resolve(keys) { | ||
var _this3 = this; | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
return res; | ||
}; | ||
var found = void 0; | ||
Translator.prototype.resolve = function resolve(keys) { | ||
var _this3 = this; | ||
if (typeof keys === 'string') keys = [keys]; | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
// forEach possible key | ||
keys.forEach(function (k) { | ||
if (_this3.isValidLookup(found)) return; | ||
var found = void 0; | ||
var _extractFromKey2 = _this3.extractFromKey(k, options); | ||
if (typeof keys === 'string') keys = [keys]; | ||
var key = _extractFromKey2.key; | ||
var namespaces = _extractFromKey2.namespaces; | ||
// forEach possible key | ||
keys.forEach(function (k) { | ||
if (_this3.isValidLookup(found)) return; | ||
if (_this3.options.fallbackNS) namespaces = namespaces.concat(_this3.options.fallbackNS); | ||
var _extractFromKey2 = _this3.extractFromKey(k, options); | ||
var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string'; | ||
var needsContextHandling = options.context !== undefined && typeof options.context === 'string' && options.context !== ''; | ||
var key = _extractFromKey2.key; | ||
var namespaces = _extractFromKey2.namespaces; | ||
var codes = options.lngs ? options.lngs : _this3.languageUtils.toResolveHierarchy(options.lng || _this3.language); | ||
if (_this3.options.fallbackNS) namespaces = namespaces.concat(_this3.options.fallbackNS); | ||
namespaces.forEach(function (ns) { | ||
var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string'; | ||
var needsContextHandling = options.context !== undefined && typeof options.context === 'string' && options.context !== ''; | ||
var codes = options.lngs ? options.lngs : _this3.languageUtils.toResolveHierarchy(options.lng || _this3.language); | ||
namespaces.forEach(function (ns) { | ||
if (_this3.isValidLookup(found)) return; | ||
codes.forEach(function (code) { | ||
if (_this3.isValidLookup(found)) return; | ||
codes.forEach(function (code) { | ||
if (_this3.isValidLookup(found)) return; | ||
var finalKey = key; | ||
var finalKeys = [finalKey]; | ||
var finalKey = key; | ||
var finalKeys = [finalKey]; | ||
var pluralSuffix = void 0; | ||
if (needsPluralHandling) pluralSuffix = _this3.pluralResolver.getSuffix(code, options.count); | ||
var pluralSuffix = void 0; | ||
if (needsPluralHandling) pluralSuffix = _this3.pluralResolver.getSuffix(code, options.count); | ||
// fallback for plural if context not found | ||
if (needsPluralHandling && needsContextHandling) finalKeys.push(finalKey + pluralSuffix); | ||
// fallback for plural if context not found | ||
if (needsPluralHandling && needsContextHandling) finalKeys.push(finalKey + pluralSuffix); | ||
// get key for context if needed | ||
if (needsContextHandling) finalKeys.push(finalKey += '' + _this3.options.contextSeparator + options.context); | ||
// get key for context if needed | ||
if (needsContextHandling) finalKeys.push(finalKey += '' + _this3.options.contextSeparator + options.context); | ||
// get key for plural if needed | ||
if (needsPluralHandling) finalKeys.push(finalKey += pluralSuffix); | ||
// get key for plural if needed | ||
if (needsPluralHandling) finalKeys.push(finalKey += pluralSuffix); | ||
// iterate over finalKeys starting with most specific pluralkey (-> contextkey only) -> singularkey only | ||
var possibleKey = void 0; | ||
while (possibleKey = finalKeys.pop()) { | ||
if (_this3.isValidLookup(found)) continue; | ||
found = _this3.getResource(code, ns, possibleKey, options); | ||
} | ||
}); | ||
// iterate over finalKeys starting with most specific pluralkey (-> contextkey only) -> singularkey only | ||
var possibleKey = void 0; | ||
while (possibleKey = finalKeys.pop()) { | ||
if (_this3.isValidLookup(found)) continue; | ||
found = _this3.getResource(code, ns, possibleKey, options); | ||
} | ||
}); | ||
}); | ||
}); | ||
return found; | ||
} | ||
}, { | ||
key: 'isValidLookup', | ||
value: function isValidLookup(res) { | ||
return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === ''); | ||
} | ||
}, { | ||
key: 'getResource', | ||
value: function getResource(code, ns, key) { | ||
var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
return found; | ||
}; | ||
return this.resourceStore.getResource(code, ns, key, options); | ||
} | ||
}]); | ||
Translator.prototype.isValidLookup = function isValidLookup(res) { | ||
return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === ''); | ||
}; | ||
Translator.prototype.getResource = function getResource(code, ns, key) { | ||
var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
return this.resourceStore.getResource(code, ns, key, options); | ||
}; | ||
return Translator; | ||
@@ -321,0 +311,0 @@ }(_EventEmitter3.default); |
@@ -5,3 +5,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } | ||
@@ -12,3 +12,3 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } | ||
@@ -36,3 +36,3 @@ import * as utils from './utils'; | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Connector).call(this)); | ||
var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); | ||
@@ -52,202 +52,195 @@ _this.backend = backend; | ||
_createClass(Connector, [{ | ||
key: 'queueLoad', | ||
value: function queueLoad(languages, namespaces, callback) { | ||
var _this2 = this; | ||
Connector.prototype.queueLoad = function queueLoad(languages, namespaces, callback) { | ||
var _this2 = this; | ||
// find what needs to be loaded | ||
var toLoad = [], | ||
pending = [], | ||
toLoadLanguages = [], | ||
toLoadNamespaces = []; | ||
// find what needs to be loaded | ||
var toLoad = [], | ||
pending = [], | ||
toLoadLanguages = [], | ||
toLoadNamespaces = []; | ||
languages.forEach(function (lng) { | ||
var hasAllNamespaces = true; | ||
languages.forEach(function (lng) { | ||
var hasAllNamespaces = true; | ||
namespaces.forEach(function (ns) { | ||
var name = lng + '|' + ns; | ||
namespaces.forEach(function (ns) { | ||
var name = lng + '|' + ns; | ||
if (_this2.store.hasResourceBundle(lng, ns)) { | ||
_this2.state[name] = 2; // loaded | ||
} else if (_this2.state[name] < 0) { | ||
// nothing to do for err | ||
} else if (_this2.state[name] === 1) { | ||
if (pending.indexOf(name) < 0) pending.push(name); | ||
} else { | ||
_this2.state[name] = 1; // pending | ||
if (_this2.store.hasResourceBundle(lng, ns)) { | ||
_this2.state[name] = 2; // loaded | ||
} else if (_this2.state[name] < 0) { | ||
// nothing to do for err | ||
} else if (_this2.state[name] === 1) { | ||
if (pending.indexOf(name) < 0) pending.push(name); | ||
} else { | ||
_this2.state[name] = 1; // pending | ||
hasAllNamespaces = false; | ||
hasAllNamespaces = false; | ||
if (pending.indexOf(name) < 0) pending.push(name); | ||
if (toLoad.indexOf(name) < 0) toLoad.push(name); | ||
if (toLoadNamespaces.indexOf(ns) < 0) toLoadNamespaces.push(ns); | ||
} | ||
}); | ||
if (!hasAllNamespaces) toLoadLanguages.push(lng); | ||
if (pending.indexOf(name) < 0) pending.push(name); | ||
if (toLoad.indexOf(name) < 0) toLoad.push(name); | ||
if (toLoadNamespaces.indexOf(ns) < 0) toLoadNamespaces.push(ns); | ||
} | ||
}); | ||
if (toLoad.length || pending.length) { | ||
this.queue.push({ | ||
pending: pending, | ||
loaded: {}, | ||
errors: [], | ||
callback: callback | ||
}); | ||
} | ||
if (!hasAllNamespaces) toLoadLanguages.push(lng); | ||
}); | ||
return { | ||
toLoad: toLoad, | ||
if (toLoad.length || pending.length) { | ||
this.queue.push({ | ||
pending: pending, | ||
toLoadLanguages: toLoadLanguages, | ||
toLoadNamespaces: toLoadNamespaces | ||
}; | ||
loaded: {}, | ||
errors: [], | ||
callback: callback | ||
}); | ||
} | ||
}, { | ||
key: 'loaded', | ||
value: function loaded(name, err, data) { | ||
var _this3 = this; | ||
var _name$split = name.split('|'); | ||
return { | ||
toLoad: toLoad, | ||
pending: pending, | ||
toLoadLanguages: toLoadLanguages, | ||
toLoadNamespaces: toLoadNamespaces | ||
}; | ||
}; | ||
var _name$split2 = _slicedToArray(_name$split, 2); | ||
Connector.prototype.loaded = function loaded(name, err, data) { | ||
var _this3 = this; | ||
var lng = _name$split2[0]; | ||
var ns = _name$split2[1]; | ||
var _name$split = name.split('|'); | ||
var _name$split2 = _slicedToArray(_name$split, 2); | ||
if (err) this.emit('failedLoading', lng, ns, err); | ||
var lng = _name$split2[0]; | ||
var ns = _name$split2[1]; | ||
if (data) { | ||
this.store.addResourceBundle(lng, ns, data); | ||
} | ||
// set loaded | ||
this.state[name] = err ? -1 : 2; | ||
// callback if ready | ||
this.queue.forEach(function (q) { | ||
utils.pushPath(q.loaded, [lng], ns); | ||
remove(q.pending, name); | ||
if (err) this.emit('failedLoading', lng, ns, err); | ||
if (err) q.errors.push(err); | ||
if (data) { | ||
this.store.addResourceBundle(lng, ns, data); | ||
} | ||
if (q.pending.length === 0 && !q.done) { | ||
q.errors.length ? q.callback(q.errors) : q.callback(); | ||
_this3.emit('loaded', q.loaded); | ||
q.done = true; | ||
} | ||
}); | ||
// set loaded | ||
this.state[name] = err ? -1 : 2; | ||
// callback if ready | ||
this.queue.forEach(function (q) { | ||
utils.pushPath(q.loaded, [lng], ns); | ||
remove(q.pending, name); | ||
// remove done load requests | ||
this.queue = this.queue.filter(function (q) { | ||
return !q.done; | ||
}); | ||
} | ||
}, { | ||
key: 'read', | ||
value: function read(lng, ns, fcName, tried, wait, callback) { | ||
var _this4 = this; | ||
if (err) q.errors.push(err); | ||
if (!tried) tried = 0; | ||
if (!wait) wait = 250; | ||
if (q.pending.length === 0 && !q.done) { | ||
q.errors.length ? q.callback(q.errors) : q.callback(); | ||
_this3.emit('loaded', q.loaded); | ||
q.done = true; | ||
} | ||
}); | ||
if (!lng.length) return callback(null, {}); // noting to load | ||
// remove done load requests | ||
this.queue = this.queue.filter(function (q) { | ||
return !q.done; | ||
}); | ||
}; | ||
this.backend[fcName](lng, ns, function (err, data) { | ||
if (err && data /* = retryFlag */ && tried < 5) { | ||
setTimeout(function () { | ||
_this4.read.call(_this4, lng, ns, fcName, ++tried, wait * 2, callback); | ||
}, wait); | ||
return; | ||
} | ||
callback(err, data); | ||
}); | ||
} | ||
}, { | ||
key: 'load', | ||
value: function load(languages, namespaces, callback) { | ||
var _this5 = this; | ||
Connector.prototype.read = function read(lng, ns, fcName, tried, wait, callback) { | ||
var _this4 = this; | ||
if (!this.backend) { | ||
this.logger.warn('No backend was added via i18next.use. Will not load resources.'); | ||
return callback && callback(); | ||
} | ||
var options = _extends({}, this.backend.options, this.options.backend); | ||
if (!tried) tried = 0; | ||
if (!wait) wait = 250; | ||
if (typeof languages === 'string') languages = this.services.languageUtils.toResolveHierarchy(languages); | ||
if (typeof namespaces === 'string') namespaces = [namespaces]; | ||
if (!lng.length) return callback(null, {}); // noting to load | ||
var toLoad = this.queueLoad(languages, namespaces, callback); | ||
if (!toLoad.toLoad.length) { | ||
if (!toLoad.pending.length) callback(); // nothing to load and no pendings...callback now | ||
return; // pendings will trigger callback | ||
this.backend[fcName](lng, ns, function (err, data) { | ||
if (err && data /* = retryFlag */ && tried < 5) { | ||
setTimeout(function () { | ||
_this4.read.call(_this4, lng, ns, fcName, ++tried, wait * 2, callback); | ||
}, wait); | ||
return; | ||
} | ||
callback(err, data); | ||
}); | ||
}; | ||
// load with multi-load | ||
if (options.allowMultiLoading && this.backend.readMulti) { | ||
this.read(toLoad.toLoadLanguages, toLoad.toLoadNamespaces, 'readMulti', null, null, function (err, data) { | ||
if (err) _this5.logger.warn('loading namespaces ' + toLoad.toLoadNamespaces.join(', ') + ' for languages ' + toLoad.toLoadLanguages.join(', ') + ' via multiloading failed', err); | ||
if (!err && data) _this5.logger.log('loaded namespaces ' + toLoad.toLoadNamespaces.join(', ') + ' for languages ' + toLoad.toLoadLanguages.join(', ') + ' via multiloading', data); | ||
Connector.prototype.load = function load(languages, namespaces, callback) { | ||
var _this5 = this; | ||
toLoad.toLoad.forEach(function (name) { | ||
var _name$split3 = name.split('|'); | ||
if (!this.backend) { | ||
this.logger.warn('No backend was added via i18next.use. Will not load resources.'); | ||
return callback && callback(); | ||
} | ||
var options = _extends({}, this.backend.options, this.options.backend); | ||
var _name$split4 = _slicedToArray(_name$split3, 2); | ||
if (typeof languages === 'string') languages = this.services.languageUtils.toResolveHierarchy(languages); | ||
if (typeof namespaces === 'string') namespaces = [namespaces]; | ||
var l = _name$split4[0]; | ||
var n = _name$split4[1]; | ||
var toLoad = this.queueLoad(languages, namespaces, callback); | ||
if (!toLoad.toLoad.length) { | ||
if (!toLoad.pending.length) callback(); // nothing to load and no pendings...callback now | ||
return; // pendings will trigger callback | ||
} | ||
// load with multi-load | ||
if (options.allowMultiLoading && this.backend.readMulti) { | ||
this.read(toLoad.toLoadLanguages, toLoad.toLoadNamespaces, 'readMulti', null, null, function (err, data) { | ||
if (err) _this5.logger.warn('loading namespaces ' + toLoad.toLoadNamespaces.join(', ') + ' for languages ' + toLoad.toLoadLanguages.join(', ') + ' via multiloading failed', err); | ||
if (!err && data) _this5.logger.log('loaded namespaces ' + toLoad.toLoadNamespaces.join(', ') + ' for languages ' + toLoad.toLoadLanguages.join(', ') + ' via multiloading', data); | ||
var bundle = utils.getPath(data, [l, n]); | ||
if (bundle) { | ||
_this5.loaded(name, err, bundle); | ||
} else { | ||
var _err = 'loading namespace ' + n + ' for language ' + l + ' via multiloading failed'; | ||
_this5.loaded(name, _err); | ||
_this5.logger.error(_err); | ||
} | ||
}); | ||
}); | ||
} | ||
toLoad.toLoad.forEach(function (name) { | ||
var _name$split3 = name.split('|'); | ||
// load one by one | ||
else { | ||
(function () { | ||
var read = function read(name) { | ||
var _this6 = this; | ||
var _name$split4 = _slicedToArray(_name$split3, 2); | ||
var _name$split5 = name.split('|'); | ||
var l = _name$split4[0]; | ||
var n = _name$split4[1]; | ||
var _name$split6 = _slicedToArray(_name$split5, 2); | ||
var lng = _name$split6[0]; | ||
var ns = _name$split6[1]; | ||
var bundle = utils.getPath(data, [l, n]); | ||
if (bundle) { | ||
_this5.loaded(name, err, bundle); | ||
} else { | ||
var _err = 'loading namespace ' + n + ' for language ' + l + ' via multiloading failed'; | ||
_this5.loaded(name, _err); | ||
_this5.logger.error(_err); | ||
} | ||
}); | ||
}); | ||
} | ||
// load one by one | ||
else { | ||
(function () { | ||
var read = function read(name) { | ||
var _this6 = this; | ||
this.read(lng, ns, 'read', null, null, function (err, data) { | ||
if (err) _this6.logger.warn('loading namespace ' + ns + ' for language ' + lng + ' failed', err); | ||
if (!err && data) _this6.logger.log('loaded namespace ' + ns + ' for language ' + lng, data); | ||
var _name$split5 = name.split('|'); | ||
_this6.loaded(name, err, data); | ||
}); | ||
}; | ||
var _name$split6 = _slicedToArray(_name$split5, 2); | ||
; | ||
var lng = _name$split6[0]; | ||
var ns = _name$split6[1]; | ||
toLoad.toLoad.forEach(function (name) { | ||
read.call(_this5, name); | ||
this.read(lng, ns, 'read', null, null, function (err, data) { | ||
if (err) _this6.logger.warn('loading namespace ' + ns + ' for language ' + lng + ' failed', err); | ||
if (!err && data) _this6.logger.log('loaded namespace ' + ns + ' for language ' + lng, data); | ||
_this6.loaded(name, err, data); | ||
}); | ||
})(); | ||
} | ||
} | ||
}, { | ||
key: 'saveMissing', | ||
value: function saveMissing(languages, namespace, key, fallbackValue) { | ||
if (this.backend && this.backend.create) this.backend.create(languages, namespace, key, fallbackValue); | ||
}; | ||
// write to store to avoid resending | ||
this.store.addResource(languages[0], namespace, key, fallbackValue); | ||
} | ||
}]); | ||
; | ||
toLoad.toLoad.forEach(function (name) { | ||
read.call(_this5, name); | ||
}); | ||
})(); | ||
} | ||
}; | ||
Connector.prototype.saveMissing = function saveMissing(languages, namespace, key, fallbackValue) { | ||
if (this.backend && this.backend.create) this.backend.create(languages, namespace, key, fallbackValue); | ||
// write to store to avoid resending | ||
this.store.addResource(languages[0], namespace, key, fallbackValue); | ||
}; | ||
return Connector; | ||
@@ -254,0 +247,0 @@ }(EventEmitter); |
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } | ||
@@ -9,3 +9,3 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } | ||
@@ -24,3 +24,3 @@ import * as utils from './utils'; | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Connector).call(this)); | ||
var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); | ||
@@ -37,38 +37,34 @@ _this.cache = cache; | ||
_createClass(Connector, [{ | ||
key: 'load', | ||
value: function load(languages, namespaces, callback) { | ||
var _this2 = this; | ||
Connector.prototype.load = function load(languages, namespaces, callback) { | ||
var _this2 = this; | ||
if (!this.cache) return callback && callback(); | ||
var options = _extends({}, this.cache.options, this.options.cache); | ||
if (!this.cache) return callback && callback(); | ||
var options = _extends({}, this.cache.options, this.options.cache); | ||
if (typeof languages === 'string') languages = this.services.languageUtils.toResolveHierarchy(languages); | ||
if (typeof namespaces === 'string') namespaces = [namespaces]; | ||
if (typeof languages === 'string') languages = this.services.languageUtils.toResolveHierarchy(languages); | ||
if (typeof namespaces === 'string') namespaces = [namespaces]; | ||
if (options.enabled) { | ||
this.cache.load(languages, function (err, data) { | ||
if (err) _this2.logger.error('loading languages ' + languages.join(', ') + ' from cache failed', err); | ||
if (data) { | ||
for (var l in data) { | ||
for (var n in data[l]) { | ||
if (n === 'i18nStamp') continue; | ||
var bundle = data[l][n]; | ||
if (bundle) _this2.store.addResourceBundle(l, n, bundle); | ||
} | ||
if (options.enabled) { | ||
this.cache.load(languages, function (err, data) { | ||
if (err) _this2.logger.error('loading languages ' + languages.join(', ') + ' from cache failed', err); | ||
if (data) { | ||
for (var l in data) { | ||
for (var n in data[l]) { | ||
if (n === 'i18nStamp') continue; | ||
var bundle = data[l][n]; | ||
if (bundle) _this2.store.addResourceBundle(l, n, bundle); | ||
} | ||
} | ||
if (callback) callback(); | ||
}); | ||
} else { | ||
} | ||
if (callback) callback(); | ||
} | ||
}); | ||
} else { | ||
if (callback) callback(); | ||
} | ||
}, { | ||
key: 'save', | ||
value: function save() { | ||
if (this.cache && this.options.cache && this.options.cache.enabled) this.cache.save(this.store.data); | ||
} | ||
}]); | ||
}; | ||
Connector.prototype.save = function save() { | ||
if (this.cache && this.options.cache && this.options.cache.enabled) this.cache.save(this.store.data); | ||
}; | ||
return Connector; | ||
@@ -75,0 +71,0 @@ }(EventEmitter); |
@@ -1,3 +0,1 @@ | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -12,54 +10,49 @@ | ||
_createClass(EventEmitter, [{ | ||
key: 'on', | ||
value: function on(events, listener) { | ||
var _this = this; | ||
EventEmitter.prototype.on = function on(events, listener) { | ||
var _this = this; | ||
events.split(' ').forEach(function (event) { | ||
_this.observers[event] = _this.observers[event] || []; | ||
_this.observers[event].push(listener); | ||
}); | ||
events.split(' ').forEach(function (event) { | ||
_this.observers[event] = _this.observers[event] || []; | ||
_this.observers[event].push(listener); | ||
}); | ||
}; | ||
EventEmitter.prototype.off = function off(event, listener) { | ||
var _this2 = this; | ||
if (!this.observers[event]) { | ||
return; | ||
} | ||
}, { | ||
key: 'off', | ||
value: function off(event, listener) { | ||
var _this2 = this; | ||
if (!this.observers[event]) { | ||
return; | ||
this.observers[event].forEach(function () { | ||
if (!listener) { | ||
delete _this2.observers[event]; | ||
} else { | ||
var index = _this2.observers[event].indexOf(listener); | ||
if (index > -1) { | ||
_this2.observers[event].splice(index, 1); | ||
} | ||
} | ||
}); | ||
}; | ||
this.observers[event].forEach(function () { | ||
if (!listener) { | ||
delete _this2.observers[event]; | ||
} else { | ||
var index = _this2.observers[event].indexOf(listener); | ||
if (index > -1) { | ||
_this2.observers[event].splice(index, 1); | ||
} | ||
} | ||
EventEmitter.prototype.emit = function emit(event) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
if (this.observers[event]) { | ||
this.observers[event].forEach(function (observer) { | ||
observer.apply(undefined, args); | ||
}); | ||
} | ||
}, { | ||
key: 'emit', | ||
value: function emit(event) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
if (this.observers[event]) { | ||
this.observers[event].forEach(function (observer) { | ||
observer.apply(undefined, args); | ||
}); | ||
} | ||
if (this.observers['*']) { | ||
this.observers['*'].forEach(function (observer) { | ||
var _ref; | ||
if (this.observers['*']) { | ||
this.observers['*'].forEach(function (observer) { | ||
var _ref; | ||
observer.apply(observer, (_ref = [event]).concat.apply(_ref, args)); | ||
}); | ||
} | ||
observer.apply(observer, (_ref = [event]).concat.apply(_ref, args)); | ||
}); | ||
} | ||
}]); | ||
}; | ||
@@ -66,0 +59,0 @@ return EventEmitter; |
@@ -5,3 +5,3 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } | ||
@@ -12,3 +12,3 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } | ||
@@ -38,3 +38,3 @@ import baseLogger from './logger'; | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(I18n).call(this)); | ||
var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); | ||
@@ -50,296 +50,281 @@ _this.options = transformOptions(options); | ||
_createClass(I18n, [{ | ||
key: 'init', | ||
value: function init(options, callback) { | ||
var _this2 = this; | ||
I18n.prototype.init = function init(options, callback) { | ||
var _this2 = this; | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
if (!options) options = {}; | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
if (!options) options = {}; | ||
if (options.compatibilityAPI === 'v1') { | ||
this.options = _extends({}, getDefaults(), transformOptions(compat.convertAPIOptions(options)), {}); | ||
} else if (options.compatibilityJSON === 'v1') { | ||
this.options = _extends({}, getDefaults(), transformOptions(compat.convertJSONOptions(options)), {}); | ||
if (options.compatibilityAPI === 'v1') { | ||
this.options = _extends({}, getDefaults(), transformOptions(compat.convertAPIOptions(options)), {}); | ||
} else if (options.compatibilityJSON === 'v1') { | ||
this.options = _extends({}, getDefaults(), transformOptions(compat.convertJSONOptions(options)), {}); | ||
} else { | ||
this.options = _extends({}, getDefaults(), this.options, transformOptions(options)); | ||
} | ||
if (!callback) callback = function callback() {}; | ||
function createClassOnDemand(ClassOrObject) { | ||
if (!ClassOrObject) return; | ||
if (typeof ClassOrObject === 'function') return new ClassOrObject(); | ||
return ClassOrObject; | ||
} | ||
// init services | ||
if (!this.options.isClone) { | ||
if (this.modules.logger) { | ||
baseLogger.init(createClassOnDemand(this.modules.logger), this.options); | ||
} else { | ||
this.options = _extends({}, getDefaults(), this.options, transformOptions(options)); | ||
baseLogger.init(null, this.options); | ||
} | ||
if (!callback) callback = function callback() {}; | ||
function createClassOnDemand(ClassOrObject) { | ||
if (!ClassOrObject) return; | ||
if (typeof ClassOrObject === 'function') return new ClassOrObject(); | ||
return ClassOrObject; | ||
var lu = new LanguageUtils(this.options); | ||
this.store = new ResourceStore(this.options.resources, this.options); | ||
var s = this.services; | ||
s.logger = baseLogger; | ||
s.resourceStore = this.store; | ||
s.resourceStore.on('added removed', function (lng, ns) { | ||
s.cacheConnector.save(); | ||
}); | ||
s.languageUtils = lu; | ||
s.pluralResolver = new PluralResolver(lu, { prepend: this.options.pluralSeparator, compatibilityJSON: this.options.compatibilityJSON }); | ||
s.interpolator = new Interpolator(this.options); | ||
s.backendConnector = new BackendConnector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options); | ||
// pipe events from backendConnector | ||
s.backendConnector.on('*', function (event) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
_this2.emit.apply(_this2, [event].concat(args)); | ||
}); | ||
s.backendConnector.on('loaded', function (loaded) { | ||
s.cacheConnector.save(); | ||
}); | ||
s.cacheConnector = new CacheConnector(createClassOnDemand(this.modules.cache), s.resourceStore, s, this.options); | ||
// pipe events from backendConnector | ||
s.cacheConnector.on('*', function (event) { | ||
for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
_this2.emit.apply(_this2, [event].concat(args)); | ||
}); | ||
if (this.modules.languageDetector) { | ||
s.languageDetector = createClassOnDemand(this.modules.languageDetector); | ||
s.languageDetector.init(s, this.options.detection, this.options); | ||
} | ||
// init services | ||
if (!this.options.isClone) { | ||
if (this.modules.logger) { | ||
baseLogger.init(createClassOnDemand(this.modules.logger), this.options); | ||
} else { | ||
baseLogger.init(null, this.options); | ||
this.translator = new Translator(this.services, this.options); | ||
// pipe events from translator | ||
this.translator.on('*', function (event) { | ||
for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
args[_key3 - 1] = arguments[_key3]; | ||
} | ||
var lu = new LanguageUtils(this.options); | ||
this.store = new ResourceStore(this.options.resources, this.options); | ||
_this2.emit.apply(_this2, [event].concat(args)); | ||
}); | ||
} | ||
var s = this.services; | ||
s.logger = baseLogger; | ||
s.resourceStore = this.store; | ||
s.resourceStore.on('added removed', function (lng, ns) { | ||
s.cacheConnector.save(); | ||
}); | ||
s.languageUtils = lu; | ||
s.pluralResolver = new PluralResolver(lu, { prepend: this.options.pluralSeparator, compatibilityJSON: this.options.compatibilityJSON }); | ||
s.interpolator = new Interpolator(this.options); | ||
// append api | ||
var storeApi = ['getResource', 'addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle', 'hasResourceBundle', 'getResourceBundle']; | ||
storeApi.forEach(function (fcName) { | ||
_this2[fcName] = function () { | ||
return this.store[fcName].apply(this.store, arguments); | ||
}; | ||
}); | ||
s.backendConnector = new BackendConnector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options); | ||
// pipe events from backendConnector | ||
s.backendConnector.on('*', function (event) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
// TODO: COMPATIBILITY remove this | ||
if (this.options.compatibilityAPI === 'v1') compat.appendBackwardsAPI(this); | ||
_this2.emit.apply(_this2, [event].concat(args)); | ||
}); | ||
this.changeLanguage(this.options.lng, function (err, t) { | ||
_this2.emit('initialized', _this2.options); | ||
_this2.logger.log('initialized', _this2.options); | ||
s.backendConnector.on('loaded', function (loaded) { | ||
s.cacheConnector.save(); | ||
}); | ||
callback(err, t); | ||
}); | ||
s.cacheConnector = new CacheConnector(createClassOnDemand(this.modules.cache), s.resourceStore, s, this.options); | ||
// pipe events from backendConnector | ||
s.cacheConnector.on('*', function (event) { | ||
for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
return this; | ||
}; | ||
_this2.emit.apply(_this2, [event].concat(args)); | ||
}); | ||
I18n.prototype.loadResources = function loadResources(callback) { | ||
var _this3 = this; | ||
if (this.modules.languageDetector) { | ||
s.languageDetector = createClassOnDemand(this.modules.languageDetector); | ||
s.languageDetector.init(s, this.options.detection, this.options); | ||
} | ||
if (!callback) callback = function callback() {}; | ||
this.translator = new Translator(this.services, this.options); | ||
// pipe events from translator | ||
this.translator.on('*', function (event) { | ||
for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
args[_key3 - 1] = arguments[_key3]; | ||
} | ||
if (!this.options.resources) { | ||
var _ret = function () { | ||
if (_this3.language && _this3.language.toLowerCase() === 'cimode') return { | ||
v: callback() | ||
}; // avoid loading resources for cimode | ||
_this2.emit.apply(_this2, [event].concat(args)); | ||
}); | ||
} | ||
var toLoad = []; | ||
// append api | ||
var storeApi = ['getResource', 'addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle', 'hasResourceBundle', 'getResourceBundle']; | ||
storeApi.forEach(function (fcName) { | ||
_this2[fcName] = function () { | ||
return this.store[fcName].apply(this.store, arguments); | ||
var append = function append(lng) { | ||
var lngs = _this3.services.languageUtils.toResolveHierarchy(lng); | ||
lngs.forEach(function (l) { | ||
if (toLoad.indexOf(l) < 0) toLoad.push(l); | ||
}); | ||
}; | ||
}); | ||
// TODO: COMPATIBILITY remove this | ||
if (this.options.compatibilityAPI === 'v1') compat.appendBackwardsAPI(this); | ||
append(_this3.language); | ||
this.changeLanguage(this.options.lng, function (err, t) { | ||
_this2.emit('initialized', _this2.options); | ||
_this2.logger.log('initialized', _this2.options); | ||
if (_this3.options.preload) { | ||
_this3.options.preload.forEach(function (l) { | ||
append(l); | ||
}); | ||
} | ||
callback(err, t); | ||
}); | ||
_this3.services.cacheConnector.load(toLoad, _this3.options.ns, function () { | ||
_this3.services.backendConnector.load(toLoad, _this3.options.ns, callback); | ||
}); | ||
}(); | ||
return this; | ||
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; | ||
} else { | ||
callback(null); | ||
} | ||
}, { | ||
key: 'loadResources', | ||
value: function loadResources(callback) { | ||
var _this3 = this; | ||
}; | ||
if (!callback) callback = function callback() {}; | ||
I18n.prototype.use = function use(module) { | ||
if (module.type === 'backend') { | ||
this.modules.backend = module; | ||
} | ||
if (!this.options.resources) { | ||
var _ret = function () { | ||
if (_this3.language && _this3.language.toLowerCase() === 'cimode') return { | ||
v: callback() | ||
}; // avoid loading resources for cimode | ||
if (module.type === 'cache') { | ||
this.modules.cache = module; | ||
} | ||
var toLoad = []; | ||
if (module.type === 'logger' || module.log && module.warn && module.warn) { | ||
this.modules.logger = module; | ||
} | ||
var append = function append(lng) { | ||
var lngs = _this3.services.languageUtils.toResolveHierarchy(lng); | ||
lngs.forEach(function (l) { | ||
if (toLoad.indexOf(l) < 0) toLoad.push(l); | ||
}); | ||
}; | ||
if (module.type === 'languageDetector') { | ||
this.modules.languageDetector = module; | ||
} | ||
append(_this3.language); | ||
if (module.type === 'postProcessor') { | ||
postProcessor.addPostProcessor(module); | ||
} | ||
if (_this3.options.preload) { | ||
_this3.options.preload.forEach(function (l) { | ||
append(l); | ||
}); | ||
} | ||
return this; | ||
}; | ||
_this3.services.cacheConnector.load(toLoad, _this3.options.ns, function () { | ||
_this3.services.backendConnector.load(toLoad, _this3.options.ns, callback); | ||
}); | ||
}(); | ||
I18n.prototype.changeLanguage = function changeLanguage(lng, callback) { | ||
var _this4 = this; | ||
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; | ||
} else { | ||
callback(null); | ||
var done = function done(err) { | ||
if (lng) { | ||
_this4.emit('languageChanged', lng); | ||
_this4.logger.log('languageChanged', lng); | ||
} | ||
} | ||
}, { | ||
key: 'use', | ||
value: function use(module) { | ||
if (module.type === 'backend') { | ||
this.modules.backend = module; | ||
} | ||
if (module.type === 'cache') { | ||
this.modules.cache = module; | ||
} | ||
if (callback) callback(err, function () { | ||
for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
} | ||
if (module.type === 'logger' || module.log && module.warn && module.warn) { | ||
this.modules.logger = module; | ||
} | ||
return _this4.t.apply(_this4, args); | ||
}); | ||
}; | ||
if (module.type === 'languageDetector') { | ||
this.modules.languageDetector = module; | ||
} | ||
if (!lng && this.services.languageDetector) lng = this.services.languageDetector.detect(); | ||
if (module.type === 'postProcessor') { | ||
postProcessor.addPostProcessor(module); | ||
} | ||
if (lng) { | ||
this.language = lng; | ||
this.languages = this.services.languageUtils.toResolveHierarchy(lng); | ||
return this; | ||
this.translator.changeLanguage(lng); | ||
if (this.services.languageDetector) this.services.languageDetector.cacheUserLanguage(lng); | ||
} | ||
}, { | ||
key: 'changeLanguage', | ||
value: function changeLanguage(lng, callback) { | ||
var _this4 = this; | ||
var done = function done(err) { | ||
if (lng) { | ||
_this4.emit('languageChanged', lng); | ||
_this4.logger.log('languageChanged', lng); | ||
} | ||
this.loadResources(function (err) { | ||
done(err); | ||
}); | ||
}; | ||
if (callback) callback(err, function () { | ||
for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
} | ||
I18n.prototype.getFixedT = function getFixedT(lng, ns) { | ||
var _this5 = this; | ||
return _this4.t.apply(_this4, args); | ||
}); | ||
}; | ||
var fixedT = function fixedT(key, options) { | ||
options = options || {}; | ||
options.lng = options.lng || fixedT.lng; | ||
options.ns = options.ns || fixedT.ns; | ||
return _this5.t(key, options); | ||
}; | ||
fixedT.lng = lng; | ||
fixedT.ns = ns; | ||
return fixedT; | ||
}; | ||
if (!lng && this.services.languageDetector) lng = this.services.languageDetector.detect(); | ||
I18n.prototype.t = function t() { | ||
return this.translator && this.translator.translate.apply(this.translator, arguments); | ||
}; | ||
if (lng) { | ||
this.language = lng; | ||
this.languages = this.services.languageUtils.toResolveHierarchy(lng); | ||
I18n.prototype.exists = function exists() { | ||
return this.translator && this.translator.exists.apply(this.translator, arguments); | ||
}; | ||
this.translator.changeLanguage(lng); | ||
I18n.prototype.setDefaultNamespace = function setDefaultNamespace(ns) { | ||
this.options.defaultNS = ns; | ||
}; | ||
if (this.services.languageDetector) this.services.languageDetector.cacheUserLanguage(lng); | ||
} | ||
I18n.prototype.loadNamespaces = function loadNamespaces(ns, callback) { | ||
var _this6 = this; | ||
this.loadResources(function (err) { | ||
done(err); | ||
}); | ||
} | ||
}, { | ||
key: 'getFixedT', | ||
value: function getFixedT(lng, ns) { | ||
var _this5 = this; | ||
if (!this.options.ns) return callback && callback(); | ||
if (typeof ns === 'string') ns = [ns]; | ||
var fixedT = function fixedT(key, options) { | ||
options = options || {}; | ||
options.lng = options.lng || fixedT.lng; | ||
options.ns = options.ns || fixedT.ns; | ||
return _this5.t(key, options); | ||
}; | ||
fixedT.lng = lng; | ||
fixedT.ns = ns; | ||
return fixedT; | ||
} | ||
}, { | ||
key: 't', | ||
value: function t() { | ||
return this.translator && this.translator.translate.apply(this.translator, arguments); | ||
} | ||
}, { | ||
key: 'exists', | ||
value: function exists() { | ||
return this.translator && this.translator.exists.apply(this.translator, arguments); | ||
} | ||
}, { | ||
key: 'setDefaultNamespace', | ||
value: function setDefaultNamespace(ns) { | ||
this.options.defaultNS = ns; | ||
} | ||
}, { | ||
key: 'loadNamespaces', | ||
value: function loadNamespaces(ns, callback) { | ||
var _this6 = this; | ||
ns.forEach(function (n) { | ||
if (_this6.options.ns.indexOf(n) < 0) _this6.options.ns.push(n); | ||
}); | ||
if (!this.options.ns) return callback && callback(); | ||
if (typeof ns === 'string') ns = [ns]; | ||
this.loadResources(callback); | ||
}; | ||
ns.forEach(function (n) { | ||
if (_this6.options.ns.indexOf(n) < 0) _this6.options.ns.push(n); | ||
}); | ||
I18n.prototype.loadLanguages = function loadLanguages(lngs, callback) { | ||
if (typeof lngs === 'string') lngs = [lngs]; | ||
this.options.preload = this.options.preload ? this.options.preload.concat(lngs) : lngs; | ||
this.loadResources(callback); | ||
} | ||
}, { | ||
key: 'loadLanguages', | ||
value: function loadLanguages(lngs, callback) { | ||
if (typeof lngs === 'string') lngs = [lngs]; | ||
this.options.preload = this.options.preload ? this.options.preload.concat(lngs) : lngs; | ||
this.loadResources(callback); | ||
}; | ||
this.loadResources(callback); | ||
} | ||
}, { | ||
key: 'dir', | ||
value: function dir(lng) { | ||
if (!lng) lng = this.language; | ||
I18n.prototype.dir = function dir(lng) { | ||
if (!lng) lng = this.language; | ||
var ltrLngs = ['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', 'ur', 'ydd', 'yds', 'yih', 'ji', 'yi', 'hbo', 'men', 'xmn', 'fa', 'jpr', 'peo', 'pes', 'prs', 'dv', 'sam']; | ||
var ltrLngs = ['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', 'ur', 'ydd', 'yds', 'yih', 'ji', 'yi', 'hbo', 'men', 'xmn', 'fa', 'jpr', 'peo', 'pes', 'prs', 'dv', 'sam']; | ||
return ltrLngs.indexOf(this.services.languageUtils.getLanguagePartFromCode(lng)) ? 'ltr' : 'rtl'; | ||
} | ||
}, { | ||
key: 'createInstance', | ||
value: function createInstance() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var callback = arguments[1]; | ||
return ltrLngs.indexOf(this.services.languageUtils.getLanguagePartFromCode(lng)) ? 'ltr' : 'rtl'; | ||
}; | ||
return new I18n(options, callback); | ||
} | ||
}, { | ||
key: 'cloneInstance', | ||
value: function cloneInstance() { | ||
var _this7 = this; | ||
I18n.prototype.createInstance = function createInstance() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var callback = arguments[1]; | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var callback = arguments[1]; | ||
return new I18n(options, callback); | ||
}; | ||
var clone = new I18n(_extends({}, options, this.options, { isClone: true }), callback); | ||
var membersToCopy = ['store', 'translator', 'services', 'language']; | ||
membersToCopy.forEach(function (m) { | ||
clone[m] = _this7[m]; | ||
}); | ||
I18n.prototype.cloneInstance = function cloneInstance() { | ||
var _this7 = this; | ||
return clone; | ||
} | ||
}]); | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var callback = arguments[1]; | ||
var clone = new I18n(_extends({}, options, this.options, { isClone: true }), callback); | ||
var membersToCopy = ['store', 'translator', 'services', 'language']; | ||
membersToCopy.forEach(function (m) { | ||
clone[m] = _this7[m]; | ||
}); | ||
return clone; | ||
}; | ||
return I18n; | ||
@@ -346,0 +331,0 @@ }(EventEmitter); |
@@ -1,3 +0,1 @@ | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -19,117 +17,111 @@ | ||
_createClass(Interpolator, [{ | ||
key: 'init', | ||
value: function init() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var reset = arguments[1]; | ||
Interpolator.prototype.init = function init() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var reset = arguments[1]; | ||
if (reset) this.options = options; | ||
if (!options.interpolation) options.interpolation = { escapeValue: true }; | ||
if (reset) this.options = options; | ||
if (!options.interpolation) options.interpolation = { escapeValue: true }; | ||
var iOpts = options.interpolation; | ||
var iOpts = options.interpolation; | ||
this.escapeValue = iOpts.escapeValue; | ||
this.escapeValue = iOpts.escapeValue; | ||
this.prefix = iOpts.prefix ? utils.regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{'; | ||
this.suffix = iOpts.suffix ? utils.regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}'; | ||
this.prefix = iOpts.prefix ? utils.regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{'; | ||
this.suffix = iOpts.suffix ? utils.regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}'; | ||
this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-'; | ||
this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || ''; | ||
this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-'; | ||
this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || ''; | ||
this.nestingPrefix = iOpts.nestingPrefix ? utils.regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || utils.regexEscape('$t('); | ||
this.nestingSuffix = iOpts.nestingSuffix ? utils.regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || utils.regexEscape(')'); | ||
this.nestingPrefix = iOpts.nestingPrefix ? utils.regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || utils.regexEscape('$t('); | ||
this.nestingSuffix = iOpts.nestingSuffix ? utils.regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || utils.regexEscape(')'); | ||
// the regexp | ||
var regexpStr = this.prefix + '(.+?)' + this.suffix; | ||
this.regexp = new RegExp(regexpStr, 'g'); | ||
// the regexp | ||
var regexpStr = this.prefix + '(.+?)' + this.suffix; | ||
this.regexp = new RegExp(regexpStr, 'g'); | ||
var regexpUnescapeStr = this.prefix + this.unescapePrefix + '(.+?)' + this.unescapeSuffix + this.suffix; | ||
this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g'); | ||
var regexpUnescapeStr = this.prefix + this.unescapePrefix + '(.+?)' + this.unescapeSuffix + this.suffix; | ||
this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g'); | ||
var nestingRegexpStr = this.nestingPrefix + '(.+?)' + this.nestingSuffix; | ||
this.nestingRegexp = new RegExp(nestingRegexpStr, 'g'); | ||
var nestingRegexpStr = this.nestingPrefix + '(.+?)' + this.nestingSuffix; | ||
this.nestingRegexp = new RegExp(nestingRegexpStr, 'g'); | ||
}; | ||
Interpolator.prototype.reset = function reset() { | ||
if (this.options) this.init(this.options); | ||
}; | ||
Interpolator.prototype.interpolate = function interpolate(str, data) { | ||
var match = void 0, | ||
value = void 0; | ||
function regexSafe(val) { | ||
return val.replace(/\$/g, '$$$$'); | ||
} | ||
}, { | ||
key: 'reset', | ||
value: function reset() { | ||
if (this.options) this.init(this.options); | ||
// unescape if has unescapePrefix/Suffix | ||
while (match = this.regexpUnescape.exec(str)) { | ||
var _value = utils.getPath(data, match[1].trim()); | ||
str = str.replace(match[0], _value); | ||
} | ||
}, { | ||
key: 'interpolate', | ||
value: function interpolate(str, data) { | ||
var match = void 0, | ||
value = void 0; | ||
function regexSafe(val) { | ||
return val.replace(/\$/g, '$$$$'); | ||
// regular escape on demand | ||
while (match = this.regexp.exec(str)) { | ||
value = utils.getPath(data, match[1].trim()); | ||
if (typeof value !== 'string') value = utils.makeString(value); | ||
if (!value) { | ||
this.logger.warn('missed to pass in variable ' + match[1] + ' for interpolating ' + str); | ||
value = ''; | ||
} | ||
// unescape if has unescapePrefix/Suffix | ||
while (match = this.regexpUnescape.exec(str)) { | ||
var _value = utils.getPath(data, match[1].trim()); | ||
str = str.replace(match[0], _value); | ||
} | ||
// regular escape on demand | ||
while (match = this.regexp.exec(str)) { | ||
value = utils.getPath(data, match[1].trim()); | ||
if (typeof value !== 'string') value = utils.makeString(value); | ||
if (!value) { | ||
this.logger.warn('missed to pass in variable ' + match[1] + ' for interpolating ' + str); | ||
value = ''; | ||
} | ||
value = this.escapeValue ? regexSafe(utils.escape(value)) : regexSafe(value); | ||
str = str.replace(match[0], value); | ||
this.regexp.lastIndex = 0; | ||
} | ||
return str; | ||
value = this.escapeValue ? regexSafe(utils.escape(value)) : regexSafe(value); | ||
str = str.replace(match[0], value); | ||
this.regexp.lastIndex = 0; | ||
} | ||
}, { | ||
key: 'nest', | ||
value: function nest(str, fc) { | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
return str; | ||
}; | ||
var match = void 0, | ||
value = void 0; | ||
Interpolator.prototype.nest = function nest(str, fc) { | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var clonedOptions = JSON.parse(JSON.stringify(options)); | ||
clonedOptions.applyPostProcessor = false; // avoid post processing on nested lookup | ||
var match = void 0, | ||
value = void 0; | ||
function regexSafe(val) { | ||
return val.replace(/\$/g, '$$$$'); | ||
} | ||
var clonedOptions = JSON.parse(JSON.stringify(options)); | ||
clonedOptions.applyPostProcessor = false; // avoid post processing on nested lookup | ||
// if value is something like "myKey": "lorem $(anotherKey, { "count": {{aValueInOptions}} })" | ||
function handleHasOptions(key) { | ||
if (key.indexOf(',') < 0) return key; | ||
function regexSafe(val) { | ||
return val.replace(/\$/g, '$$$$'); | ||
} | ||
var p = key.split(','); | ||
key = p.shift(); | ||
var optionsString = p.join(','); | ||
optionsString = this.interpolate(optionsString, clonedOptions); | ||
// if value is something like "myKey": "lorem $(anotherKey, { "count": {{aValueInOptions}} })" | ||
function handleHasOptions(key) { | ||
if (key.indexOf(',') < 0) return key; | ||
try { | ||
clonedOptions = JSON.parse(optionsString); | ||
} catch (e) { | ||
this.logger.error('failed parsing options string in nesting for key ' + key, e); | ||
} | ||
var p = key.split(','); | ||
key = p.shift(); | ||
var optionsString = p.join(','); | ||
optionsString = this.interpolate(optionsString, clonedOptions); | ||
return key; | ||
try { | ||
clonedOptions = JSON.parse(optionsString); | ||
} catch (e) { | ||
this.logger.error('failed parsing options string in nesting for key ' + key, e); | ||
} | ||
// regular escape on demand | ||
while (match = this.nestingRegexp.exec(str)) { | ||
value = fc(handleHasOptions.call(this, match[1].trim()), clonedOptions); | ||
if (typeof value !== 'string') value = utils.makeString(value); | ||
if (!value) { | ||
this.logger.warn('missed to pass in variable ' + match[1] + ' for interpolating ' + str); | ||
value = ''; | ||
} | ||
value = this.escapeValue ? regexSafe(utils.escape(value)) : regexSafe(value); | ||
str = str.replace(match[0], value); | ||
this.regexp.lastIndex = 0; | ||
return key; | ||
} | ||
// regular escape on demand | ||
while (match = this.nestingRegexp.exec(str)) { | ||
value = fc(handleHasOptions.call(this, match[1].trim()), clonedOptions); | ||
if (typeof value !== 'string') value = utils.makeString(value); | ||
if (!value) { | ||
this.logger.warn('missed to pass in variable ' + match[1] + ' for interpolating ' + str); | ||
value = ''; | ||
} | ||
return str; | ||
value = this.escapeValue ? regexSafe(utils.escape(value)) : regexSafe(value); | ||
str = str.replace(match[0], value); | ||
this.regexp.lastIndex = 0; | ||
} | ||
}]); | ||
return str; | ||
}; | ||
@@ -136,0 +128,0 @@ return Interpolator; |
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -19,65 +17,59 @@ | ||
_createClass(LanguageUtil, [{ | ||
key: 'getLanguagePartFromCode', | ||
value: function getLanguagePartFromCode(code) { | ||
if (code.indexOf('-') < 0) return code; | ||
LanguageUtil.prototype.getLanguagePartFromCode = function getLanguagePartFromCode(code) { | ||
if (code.indexOf('-') < 0) return code; | ||
var specialCases = ['nb-NO', 'nn-NO', 'nb-no', 'nn-no']; | ||
var p = code.split('-'); | ||
return this.formatLanguageCode(specialCases.indexOf(code) > -1 ? p[1].toLowerCase() : p[0]); | ||
} | ||
}, { | ||
key: 'formatLanguageCode', | ||
value: function formatLanguageCode(code) { | ||
if (typeof code === 'string' && code.indexOf('-') > -1) { | ||
var _code$split = code.split('-'); | ||
var specialCases = ['nb-NO', 'nn-NO', 'nb-no', 'nn-no']; | ||
var p = code.split('-'); | ||
return this.formatLanguageCode(specialCases.indexOf(code) > -1 ? p[1].toLowerCase() : p[0]); | ||
}; | ||
var _code$split2 = _slicedToArray(_code$split, 2); | ||
LanguageUtil.prototype.formatLanguageCode = function formatLanguageCode(code) { | ||
if (typeof code === 'string' && code.indexOf('-') > -1) { | ||
var _code$split = code.split('-'); | ||
var head = _code$split2[0]; | ||
var tail = _code$split2[1]; | ||
var _code$split2 = _slicedToArray(_code$split, 2); | ||
return this.options.lowerCaseLng ? head.toLowerCase() + '-' + tail.toLowerCase() : head.toLowerCase() + '-' + tail.toUpperCase(); | ||
} else { | ||
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code; | ||
} | ||
var head = _code$split2[0]; | ||
var tail = _code$split2[1]; | ||
return this.options.lowerCaseLng ? head.toLowerCase() + '-' + tail.toLowerCase() : head.toLowerCase() + '-' + tail.toUpperCase(); | ||
} else { | ||
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code; | ||
} | ||
}, { | ||
key: 'isWhitelisted', | ||
value: function isWhitelisted(code) { | ||
if (this.options.load === 'languageOnly') code = this.getLanguagePartFromCode(code); | ||
return !this.whitelist || !this.whitelist.length || this.whitelist.indexOf(code) > -1 ? true : false; | ||
} | ||
}, { | ||
key: 'toResolveHierarchy', | ||
value: function toResolveHierarchy(code, fallbackCode) { | ||
var _this = this; | ||
}; | ||
fallbackCode = fallbackCode || this.options.fallbackLng || []; | ||
if (typeof fallbackCode === 'string') fallbackCode = [fallbackCode]; | ||
LanguageUtil.prototype.isWhitelisted = function isWhitelisted(code) { | ||
if (this.options.load === 'languageOnly') code = this.getLanguagePartFromCode(code); | ||
return !this.whitelist || !this.whitelist.length || this.whitelist.indexOf(code) > -1 ? true : false; | ||
}; | ||
var codes = []; | ||
var addCode = function addCode(code) { | ||
if (_this.isWhitelisted(code)) { | ||
codes.push(code); | ||
} else { | ||
_this.logger.warn('rejecting non-whitelisted language code: ' + code); | ||
} | ||
}; | ||
LanguageUtil.prototype.toResolveHierarchy = function toResolveHierarchy(code, fallbackCode) { | ||
var _this = this; | ||
if (typeof code === 'string' && code.indexOf('-') > -1) { | ||
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code)); | ||
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code)); | ||
} else if (typeof code === 'string') { | ||
addCode(this.formatLanguageCode(code)); | ||
fallbackCode = fallbackCode || this.options.fallbackLng || []; | ||
if (typeof fallbackCode === 'string') fallbackCode = [fallbackCode]; | ||
var codes = []; | ||
var addCode = function addCode(code) { | ||
if (_this.isWhitelisted(code)) { | ||
codes.push(code); | ||
} else { | ||
_this.logger.warn('rejecting non-whitelisted language code: ' + code); | ||
} | ||
}; | ||
fallbackCode.forEach(function (fc) { | ||
if (codes.indexOf(fc) < 0) addCode(_this.formatLanguageCode(fc)); | ||
}); | ||
return codes; | ||
if (typeof code === 'string' && code.indexOf('-') > -1) { | ||
if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code)); | ||
if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code)); | ||
} else if (typeof code === 'string') { | ||
addCode(this.formatLanguageCode(code)); | ||
} | ||
}]); | ||
fallbackCode.forEach(function (fc) { | ||
if (codes.indexOf(fc) < 0) addCode(_this.formatLanguageCode(fc)); | ||
}); | ||
return codes; | ||
}; | ||
return LanguageUtil; | ||
@@ -84,0 +76,0 @@ }(); |
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -34,62 +32,51 @@ | ||
_createClass(Logger, [{ | ||
key: 'init', | ||
value: function init(concreteLogger) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
Logger.prototype.init = function init(concreteLogger) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
this.prefix = options.prefix || 'i18next:'; | ||
this.logger = concreteLogger || consoleLogger; | ||
this.options = options; | ||
this.debug = options.debug === false ? false : true; | ||
} | ||
}, { | ||
key: 'setDebug', | ||
value: function setDebug(bool) { | ||
this.debug = bool; | ||
this.subs.forEach(function (sub) { | ||
sub.setDebug(bool); | ||
}); | ||
} | ||
}, { | ||
key: 'log', | ||
value: function log() { | ||
this.forward(arguments, 'log', '', true); | ||
} | ||
}, { | ||
key: 'warn', | ||
value: function warn() { | ||
this.forward(arguments, 'warn', '', true); | ||
} | ||
}, { | ||
key: 'error', | ||
value: function error() { | ||
this.forward(arguments, 'error', ''); | ||
} | ||
}, { | ||
key: 'deprecate', | ||
value: function deprecate() { | ||
this.forward(arguments, 'warn', 'WARNING DEPRECATED: ', true); | ||
} | ||
}, { | ||
key: 'forward', | ||
value: function forward(args, lvl, prefix, debugOnly) { | ||
if (debugOnly && !this.debug) return; | ||
if (typeof args[0] === 'string') args[0] = prefix + this.prefix + ' ' + args[0]; | ||
this.logger[lvl](args); | ||
} | ||
}, { | ||
key: 'create', | ||
value: function create(moduleName) { | ||
var sub = new Logger(this.logger, _extends({ prefix: this.prefix + ':' + moduleName + ':' }, this.options)); | ||
this.subs.push(sub); | ||
this.prefix = options.prefix || 'i18next:'; | ||
this.logger = concreteLogger || consoleLogger; | ||
this.options = options; | ||
this.debug = options.debug === false ? false : true; | ||
}; | ||
return sub; | ||
} | ||
Logger.prototype.setDebug = function setDebug(bool) { | ||
this.debug = bool; | ||
this.subs.forEach(function (sub) { | ||
sub.setDebug(bool); | ||
}); | ||
}; | ||
// createInstance(options = {}) { | ||
// return new Logger(options, callback); | ||
// } | ||
Logger.prototype.log = function log() { | ||
this.forward(arguments, 'log', '', true); | ||
}; | ||
}]); | ||
Logger.prototype.warn = function warn() { | ||
this.forward(arguments, 'warn', '', true); | ||
}; | ||
Logger.prototype.error = function error() { | ||
this.forward(arguments, 'error', ''); | ||
}; | ||
Logger.prototype.deprecate = function deprecate() { | ||
this.forward(arguments, 'warn', 'WARNING DEPRECATED: ', true); | ||
}; | ||
Logger.prototype.forward = function forward(args, lvl, prefix, debugOnly) { | ||
if (debugOnly && !this.debug) return; | ||
if (typeof args[0] === 'string') args[0] = prefix + this.prefix + ' ' + args[0]; | ||
this.logger[lvl](args); | ||
}; | ||
Logger.prototype.create = function create(moduleName) { | ||
var sub = new Logger(this.logger, _extends({ prefix: this.prefix + ':' + moduleName + ':' }, this.options)); | ||
this.subs.push(sub); | ||
return sub; | ||
}; | ||
// createInstance(options = {}) { | ||
// return new Logger(options, callback); | ||
// } | ||
return Logger; | ||
@@ -96,0 +83,0 @@ }(); |
@@ -1,3 +0,1 @@ | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -78,2 +76,16 @@ | ||
function createRules() { | ||
var l, | ||
rules = {}; | ||
sets.forEach(function (set) { | ||
set.lngs.forEach(function (l) { | ||
return rules[l] = { | ||
numbers: set.nr, | ||
plurals: _rulesPluralsTypes[set.fc] | ||
}; | ||
}); | ||
}); | ||
return rules; | ||
} | ||
var PluralResolver = function () { | ||
@@ -85,16 +97,2 @@ function PluralResolver(languageUtils) { | ||
this.rules = function () { | ||
var l, | ||
rules = {}; | ||
sets.forEach(function (set) { | ||
set.lngs.forEach(function (l) { | ||
return rules[l] = { | ||
numbers: set.nr, | ||
plurals: _rulesPluralsTypes[set.fc] | ||
}; | ||
}); | ||
}); | ||
return rules; | ||
}(); | ||
this.languageUtils = languageUtils; | ||
@@ -104,54 +102,50 @@ this.options = options; | ||
this.logger = baseLogger.create('pluralResolver'); | ||
this.rules = createRules(); | ||
} | ||
_createClass(PluralResolver, [{ | ||
key: 'addRule', | ||
value: function addRule(lng, obj) { | ||
this.rules[lng] = obj; | ||
} | ||
}, { | ||
key: 'getRule', | ||
value: function getRule(code) { | ||
return this.rules[this.languageUtils.getLanguagePartFromCode(code)]; | ||
} | ||
}, { | ||
key: 'needsPlural', | ||
value: function needsPlural(code) { | ||
var rule = this.getRule(code); | ||
PluralResolver.prototype.addRule = function addRule(lng, obj) { | ||
this.rules[lng] = obj; | ||
}; | ||
return rule && rule.numbers.length <= 1 ? false : true; | ||
} | ||
}, { | ||
key: 'getSuffix', | ||
value: function getSuffix(code, count) { | ||
var rule = this.getRule(code); | ||
PluralResolver.prototype.getRule = function getRule(code) { | ||
return this.rules[this.languageUtils.getLanguagePartFromCode(code)]; | ||
}; | ||
if (rule) { | ||
if (rule.numbers.length === 1) return ''; // only singular | ||
PluralResolver.prototype.needsPlural = function needsPlural(code) { | ||
var rule = this.getRule(code); | ||
var idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count)); | ||
var suffix = rule.numbers[idx]; | ||
return rule && rule.numbers.length <= 1 ? false : true; | ||
}; | ||
// special treatment for lngs only having singular and plural | ||
if (rule.numbers.length === 2 && rule.numbers[0] === 1) { | ||
if (suffix === 2) { | ||
suffix = 'plural'; | ||
} else if (suffix === 1) { | ||
suffix = ''; | ||
} | ||
} | ||
PluralResolver.prototype.getSuffix = function getSuffix(code, count) { | ||
var rule = this.getRule(code); | ||
// COMPATIBILITY JSON | ||
if (this.options.compatibilityJSON === 'v1') { | ||
if (suffix === 1) return ''; | ||
if (typeof suffix === 'number') return '_plural_' + suffix.toString(); | ||
if (rule) { | ||
if (rule.numbers.length === 1) return ''; // only singular | ||
var idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count)); | ||
var suffix = rule.numbers[idx]; | ||
// special treatment for lngs only having singular and plural | ||
if (rule.numbers.length === 2 && rule.numbers[0] === 1) { | ||
if (suffix === 2) { | ||
suffix = 'plural'; | ||
} else if (suffix === 1) { | ||
suffix = ''; | ||
} | ||
} | ||
return this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString(); | ||
} else { | ||
this.logger.warn('no plural rule found for: ' + code); | ||
return ''; | ||
// COMPATIBILITY JSON | ||
if (this.options.compatibilityJSON === 'v1') { | ||
if (suffix === 1) return ''; | ||
if (typeof suffix === 'number') return '_plural_' + suffix.toString(); | ||
} | ||
return this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString(); | ||
} else { | ||
this.logger.warn('no plural rule found for: ' + code); | ||
return ''; | ||
} | ||
}]); | ||
}; | ||
@@ -158,0 +152,0 @@ return PluralResolver; |
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } | ||
@@ -9,3 +9,3 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } | ||
@@ -24,3 +24,3 @@ import EventEmitter from './EventEmitter'; | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(ResourceStore).call(this)); | ||
var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); | ||
@@ -32,123 +32,111 @@ _this.data = data; | ||
_createClass(ResourceStore, [{ | ||
key: 'addNamespaces', | ||
value: function addNamespaces(ns) { | ||
if (this.options.ns.indexOf(ns) < 0) { | ||
this.options.ns.push(ns); | ||
} | ||
ResourceStore.prototype.addNamespaces = function addNamespaces(ns) { | ||
if (this.options.ns.indexOf(ns) < 0) { | ||
this.options.ns.push(ns); | ||
} | ||
}, { | ||
key: 'removeNamespaces', | ||
value: function removeNamespaces(ns) { | ||
var index = this.options.ns.indexOf(ns); | ||
if (index > -1) { | ||
this.options.ns.splice(index, 1); | ||
} | ||
}; | ||
ResourceStore.prototype.removeNamespaces = function removeNamespaces(ns) { | ||
var index = this.options.ns.indexOf(ns); | ||
if (index > -1) { | ||
this.options.ns.splice(index, 1); | ||
} | ||
}, { | ||
key: 'getResource', | ||
value: function getResource(lng, ns, key) { | ||
var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
}; | ||
var keySeparator = options.keySeparator || this.options.keySeparator; | ||
if (keySeparator === undefined) keySeparator = '.'; | ||
ResourceStore.prototype.getResource = function getResource(lng, ns, key) { | ||
var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
var path = [lng, ns]; | ||
if (key && typeof key !== 'string') path = path.concat(key); | ||
if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key); | ||
var keySeparator = options.keySeparator || this.options.keySeparator; | ||
if (keySeparator === undefined) keySeparator = '.'; | ||
if (lng.indexOf('.') > -1) { | ||
path = lng.split('.'); | ||
} | ||
var path = [lng, ns]; | ||
if (key && typeof key !== 'string') path = path.concat(key); | ||
if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key); | ||
return utils.getPath(this.data, path); | ||
if (lng.indexOf('.') > -1) { | ||
path = lng.split('.'); | ||
} | ||
}, { | ||
key: 'addResource', | ||
value: function addResource(lng, ns, key, value) { | ||
var options = arguments.length <= 4 || arguments[4] === undefined ? { silent: false } : arguments[4]; | ||
var keySeparator = this.options.keySeparator; | ||
if (keySeparator === undefined) keySeparator = '.'; | ||
return utils.getPath(this.data, path); | ||
}; | ||
var path = [lng, ns]; | ||
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key); | ||
ResourceStore.prototype.addResource = function addResource(lng, ns, key, value) { | ||
var options = arguments.length <= 4 || arguments[4] === undefined ? { silent: false } : arguments[4]; | ||
if (lng.indexOf('.') > -1) { | ||
path = lng.split('.'); | ||
value = ns; | ||
ns = path[1]; | ||
} | ||
var keySeparator = this.options.keySeparator; | ||
if (keySeparator === undefined) keySeparator = '.'; | ||
this.addNamespaces(ns); | ||
var path = [lng, ns]; | ||
if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key); | ||
utils.setPath(this.data, path, value); | ||
if (!options.silent) this.emit('added', lng, ns, key, value); | ||
if (lng.indexOf('.') > -1) { | ||
path = lng.split('.'); | ||
value = ns; | ||
ns = path[1]; | ||
} | ||
}, { | ||
key: 'addResources', | ||
value: function addResources(lng, ns, resources) { | ||
for (var m in resources) { | ||
if (typeof resources[m] === 'string') this.addResource(lng, ns, m, resources[m], { silent: true }); | ||
} | ||
this.emit('added', lng, ns, resources); | ||
} | ||
}, { | ||
key: 'addResourceBundle', | ||
value: function addResourceBundle(lng, ns, resources, deep, overwrite) { | ||
var path = [lng, ns]; | ||
if (lng.indexOf('.') > -1) { | ||
path = lng.split('.'); | ||
deep = resources; | ||
resources = ns; | ||
ns = path[1]; | ||
} | ||
this.addNamespaces(ns); | ||
this.addNamespaces(ns); | ||
var pack = utils.getPath(this.data, path) || {}; | ||
utils.setPath(this.data, path, value); | ||
if (deep) { | ||
utils.deepExtend(pack, resources, overwrite); | ||
} else { | ||
pack = _extends({}, pack, resources); | ||
} | ||
if (!options.silent) this.emit('added', lng, ns, key, value); | ||
}; | ||
utils.setPath(this.data, path, pack); | ||
ResourceStore.prototype.addResources = function addResources(lng, ns, resources) { | ||
for (var m in resources) { | ||
if (typeof resources[m] === 'string') this.addResource(lng, ns, m, resources[m], { silent: true }); | ||
} | ||
this.emit('added', lng, ns, resources); | ||
}; | ||
this.emit('added', lng, ns, resources); | ||
ResourceStore.prototype.addResourceBundle = function addResourceBundle(lng, ns, resources, deep, overwrite) { | ||
var path = [lng, ns]; | ||
if (lng.indexOf('.') > -1) { | ||
path = lng.split('.'); | ||
deep = resources; | ||
resources = ns; | ||
ns = path[1]; | ||
} | ||
}, { | ||
key: 'removeResourceBundle', | ||
value: function removeResourceBundle(lng, ns) { | ||
if (this.hasResourceBundle(lng, ns)) { | ||
delete this.data[lng][ns]; | ||
} | ||
this.removeNamespaces(ns); | ||
this.emit('removed', lng, ns); | ||
this.addNamespaces(ns); | ||
var pack = utils.getPath(this.data, path) || {}; | ||
if (deep) { | ||
utils.deepExtend(pack, resources, overwrite); | ||
} else { | ||
pack = _extends({}, pack, resources); | ||
} | ||
}, { | ||
key: 'hasResourceBundle', | ||
value: function hasResourceBundle(lng, ns) { | ||
return this.getResource(lng, ns) !== undefined; | ||
} | ||
}, { | ||
key: 'getResourceBundle', | ||
value: function getResourceBundle(lng, ns) { | ||
if (!ns) ns = this.options.defaultNS; | ||
// TODO: COMPATIBILITY remove extend in v2.1.0 | ||
if (this.options.compatibilityAPI === 'v1') return _extends({}, this.getResource(lng, ns)); | ||
utils.setPath(this.data, path, pack); | ||
return this.getResource(lng, ns); | ||
this.emit('added', lng, ns, resources); | ||
}; | ||
ResourceStore.prototype.removeResourceBundle = function removeResourceBundle(lng, ns) { | ||
if (this.hasResourceBundle(lng, ns)) { | ||
delete this.data[lng][ns]; | ||
} | ||
}, { | ||
key: 'toJSON', | ||
value: function toJSON() { | ||
return this.data; | ||
} | ||
}]); | ||
this.removeNamespaces(ns); | ||
this.emit('removed', lng, ns); | ||
}; | ||
ResourceStore.prototype.hasResourceBundle = function hasResourceBundle(lng, ns) { | ||
return this.getResource(lng, ns) !== undefined; | ||
}; | ||
ResourceStore.prototype.getResourceBundle = function getResourceBundle(lng, ns) { | ||
if (!ns) ns = this.options.defaultNS; | ||
// TODO: COMPATIBILITY remove extend in v2.1.0 | ||
if (this.options.compatibilityAPI === 'v1') return _extends({}, this.getResource(lng, ns)); | ||
return this.getResource(lng, ns); | ||
}; | ||
ResourceStore.prototype.toJSON = function toJSON() { | ||
return this.data; | ||
}; | ||
return ResourceStore; | ||
@@ -155,0 +143,0 @@ }(EventEmitter); |
@@ -5,3 +5,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } | ||
@@ -12,3 +12,3 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } | ||
@@ -29,3 +29,3 @@ import baseLogger from './logger'; | ||
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Translator).call(this)); | ||
var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); | ||
@@ -39,257 +39,247 @@ utils.copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector'], services, _this); | ||
_createClass(Translator, [{ | ||
key: 'changeLanguage', | ||
value: function changeLanguage(lng) { | ||
if (lng) this.language = lng; | ||
} | ||
}, { | ||
key: 'exists', | ||
value: function exists(key) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? { interpolation: {} } : arguments[1]; | ||
Translator.prototype.changeLanguage = function changeLanguage(lng) { | ||
if (lng) this.language = lng; | ||
}; | ||
if (this.options.compatibilityAPI === 'v1') { | ||
options = compat.convertTOptions(options); | ||
} | ||
Translator.prototype.exists = function exists(key) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? { interpolation: {} } : arguments[1]; | ||
return this.resolve(key, options) !== undefined; | ||
if (this.options.compatibilityAPI === 'v1') { | ||
options = compat.convertTOptions(options); | ||
} | ||
}, { | ||
key: 'extractFromKey', | ||
value: function extractFromKey(key, options) { | ||
var nsSeparator = options.nsSeparator || this.options.nsSeparator; | ||
if (nsSeparator === undefined) nsSeparator = ':'; | ||
var namespaces = options.ns || this.options.defaultNS; | ||
if (nsSeparator && key.indexOf(nsSeparator) > -1) { | ||
var parts = key.split(nsSeparator); | ||
namespaces = parts[0]; | ||
key = parts[1]; | ||
} | ||
if (typeof namespaces === 'string') namespaces = [namespaces]; | ||
return this.resolve(key, options) !== undefined; | ||
}; | ||
return { | ||
key: key, | ||
namespaces: namespaces | ||
}; | ||
Translator.prototype.extractFromKey = function extractFromKey(key, options) { | ||
var nsSeparator = options.nsSeparator || this.options.nsSeparator; | ||
if (nsSeparator === undefined) nsSeparator = ':'; | ||
var namespaces = options.ns || this.options.defaultNS; | ||
if (nsSeparator && key.indexOf(nsSeparator) > -1) { | ||
var parts = key.split(nsSeparator); | ||
namespaces = parts[0]; | ||
key = parts[1]; | ||
} | ||
}, { | ||
key: 'translate', | ||
value: function translate(keys) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
if (typeof namespaces === 'string') namespaces = [namespaces]; | ||
if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) !== 'object') { | ||
options = this.options.overloadTranslationOptionHandler(arguments); | ||
} else if (this.options.compatibilityAPI === 'v1') { | ||
options = compat.convertTOptions(options); | ||
} | ||
return { | ||
key: key, | ||
namespaces: namespaces | ||
}; | ||
}; | ||
// non valid keys handling | ||
if (keys === undefined || keys === null || keys === '') return ''; | ||
if (typeof keys === 'number') keys = String(keys); | ||
if (typeof keys === 'string') keys = [keys]; | ||
Translator.prototype.translate = function translate(keys) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
// return key on CIMode | ||
var lng = options.lng || this.language; | ||
if (lng && lng.toLowerCase() === 'cimode') return keys[keys.length - 1]; | ||
if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) !== 'object') { | ||
options = this.options.overloadTranslationOptionHandler(arguments); | ||
} else if (this.options.compatibilityAPI === 'v1') { | ||
options = compat.convertTOptions(options); | ||
} | ||
// separators | ||
var keySeparator = options.keySeparator || this.options.keySeparator || '.'; | ||
// non valid keys handling | ||
if (keys === undefined || keys === null || keys === '') return ''; | ||
if (typeof keys === 'number') keys = String(keys); | ||
if (typeof keys === 'string') keys = [keys]; | ||
// get namespace(s) | ||
// return key on CIMode | ||
var lng = options.lng || this.language; | ||
if (lng && lng.toLowerCase() === 'cimode') return keys[keys.length - 1]; | ||
var _extractFromKey = this.extractFromKey(keys[keys.length - 1], options); | ||
// separators | ||
var keySeparator = options.keySeparator || this.options.keySeparator || '.'; | ||
var key = _extractFromKey.key; | ||
var namespaces = _extractFromKey.namespaces; | ||
// get namespace(s) | ||
var namespace = namespaces[namespaces.length - 1]; | ||
var _extractFromKey = this.extractFromKey(keys[keys.length - 1], options); | ||
// resolve from store | ||
var res = this.resolve(keys, options); | ||
var key = _extractFromKey.key; | ||
var namespaces = _extractFromKey.namespaces; | ||
var resType = Object.prototype.toString.apply(res); | ||
var noObject = ['[object Number]', '[object Function]', '[object RegExp]']; | ||
var joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays; | ||
var namespace = namespaces[namespaces.length - 1]; | ||
// object | ||
if (res && typeof res !== 'string' && noObject.indexOf(resType) < 0 && !(joinArrays && resType === '[object Array]')) { | ||
if (!options.returnObjects && !this.options.returnObjects) { | ||
this.logger.warn('accessing an object - but returnObjects options is not enabled!'); | ||
return this.options.returnedObjectHandler ? this.options.returnedObjectHandler(key, res, options) : 'key \'' + key + ' (' + this.language + ')\' returned an object instead of string.'; | ||
} | ||
// resolve from store | ||
var res = this.resolve(keys, options); | ||
var copy = resType === '[object Array]' ? [] : {}; // apply child translation on a copy | ||
var resType = Object.prototype.toString.apply(res); | ||
var noObject = ['[object Number]', '[object Function]', '[object RegExp]']; | ||
var joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays; | ||
for (var m in res) { | ||
copy[m] = this.translate('' + key + keySeparator + m, _extends({ joinArrays: false, ns: namespaces }, options)); | ||
} | ||
res = copy; | ||
// object | ||
if (res && typeof res !== 'string' && noObject.indexOf(resType) < 0 && !(joinArrays && resType === '[object Array]')) { | ||
if (!options.returnObjects && !this.options.returnObjects) { | ||
this.logger.warn('accessing an object - but returnObjects options is not enabled!'); | ||
return this.options.returnedObjectHandler ? this.options.returnedObjectHandler(key, res, options) : 'key \'' + key + ' (' + this.language + ')\' returned an object instead of string.'; | ||
} | ||
// array special treatment | ||
else if (joinArrays && resType === '[object Array]') { | ||
res = res.join(joinArrays); | ||
if (res) res = this.extendTranslation(res, key, options); | ||
} | ||
// string, empty or null | ||
else { | ||
var usedDefault = false, | ||
usedKey = false; | ||
// fallback value | ||
if (!this.isValidLookup(res) && options.defaultValue) { | ||
usedDefault = true; | ||
res = options.defaultValue; | ||
} | ||
if (!this.isValidLookup(res)) { | ||
usedKey = true; | ||
res = key; | ||
} | ||
var copy = resType === '[object Array]' ? [] : {}; // apply child translation on a copy | ||
// save missing | ||
if (usedKey || usedDefault) { | ||
this.logger.log('missingKey', lng, namespace, key, res); | ||
for (var m in res) { | ||
copy[m] = this.translate('' + key + keySeparator + m, _extends({ joinArrays: false, ns: namespaces }, options)); | ||
} | ||
res = copy; | ||
} | ||
// array special treatment | ||
else if (joinArrays && resType === '[object Array]') { | ||
res = res.join(joinArrays); | ||
if (res) res = this.extendTranslation(res, key, options); | ||
} | ||
// string, empty or null | ||
else { | ||
var usedDefault = false, | ||
usedKey = false; | ||
if (this.options.saveMissing) { | ||
var lngs = []; | ||
if (this.options.saveMissingTo === 'fallback' && this.options.fallbackLng && this.options.fallbackLng[0]) { | ||
for (var i = 0; i < this.options.fallbackLng.length; i++) { | ||
lngs.push(this.options.fallbackLng[i]); | ||
} | ||
} else if (this.options.saveMissingTo === 'all') { | ||
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language); | ||
} else { | ||
//(this.options.saveMissingTo === 'current' || (this.options.saveMissingTo === 'fallback' && this.options.fallbackLng[0] === false) ) { | ||
lngs.push(options.lng || this.language); | ||
} | ||
// fallback value | ||
if (!this.isValidLookup(res) && options.defaultValue) { | ||
usedDefault = true; | ||
res = options.defaultValue; | ||
} | ||
if (!this.isValidLookup(res)) { | ||
usedKey = true; | ||
res = key; | ||
} | ||
if (this.options.missingKeyHandler) { | ||
this.options.missingKeyHandler(lngs, namespace, key, res); | ||
} else if (this.backendConnector && this.backendConnector.saveMissing) { | ||
this.backendConnector.saveMissing(lngs, namespace, key, res); | ||
// save missing | ||
if (usedKey || usedDefault) { | ||
this.logger.log('missingKey', lng, namespace, key, res); | ||
if (this.options.saveMissing) { | ||
var lngs = []; | ||
if (this.options.saveMissingTo === 'fallback' && this.options.fallbackLng && this.options.fallbackLng[0]) { | ||
for (var i = 0; i < this.options.fallbackLng.length; i++) { | ||
lngs.push(this.options.fallbackLng[i]); | ||
} | ||
} else if (this.options.saveMissingTo === 'all') { | ||
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language); | ||
} else { | ||
//(this.options.saveMissingTo === 'current' || (this.options.saveMissingTo === 'fallback' && this.options.fallbackLng[0] === false) ) { | ||
lngs.push(options.lng || this.language); | ||
} | ||
this.emit('missingKey', lngs, namespace, key, res); | ||
if (this.options.missingKeyHandler) { | ||
this.options.missingKeyHandler(lngs, namespace, key, res); | ||
} else if (this.backendConnector && this.backendConnector.saveMissing) { | ||
this.backendConnector.saveMissing(lngs, namespace, key, res); | ||
} | ||
this.emit('missingKey', lngs, namespace, key, res); | ||
} | ||
} | ||
// extend | ||
res = this.extendTranslation(res, key, options); | ||
// extend | ||
res = this.extendTranslation(res, key, options); | ||
// append namespace if still key | ||
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = namespace + ':' + key; | ||
// append namespace if still key | ||
if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = namespace + ':' + key; | ||
// parseMissingKeyHandler | ||
if (usedKey && this.options.parseMissingKeyHandler) res = this.options.parseMissingKeyHandler(res); | ||
} | ||
// parseMissingKeyHandler | ||
if (usedKey && this.options.parseMissingKeyHandler) res = this.options.parseMissingKeyHandler(res); | ||
} | ||
// return | ||
return res; | ||
} | ||
}, { | ||
key: 'extendTranslation', | ||
value: function extendTranslation(res, key, options) { | ||
var _this2 = this; | ||
// return | ||
return res; | ||
}; | ||
if (options.interpolation) this.interpolator.init(options); | ||
Translator.prototype.extendTranslation = function extendTranslation(res, key, options) { | ||
var _this2 = this; | ||
// interpolate | ||
var data = options.replace && typeof options.replace !== 'string' ? options.replace : options; | ||
if (this.options.interpolation.defaultVariables) data = _extends({}, this.options.interpolation.defaultVariables, data); | ||
res = this.interpolator.interpolate(res, data); | ||
if (options.interpolation) this.interpolator.init(options); | ||
// nesting | ||
res = this.interpolator.nest(res, function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
// interpolate | ||
var data = options.replace && typeof options.replace !== 'string' ? options.replace : options; | ||
if (this.options.interpolation.defaultVariables) data = _extends({}, this.options.interpolation.defaultVariables, data); | ||
res = this.interpolator.interpolate(res, data); | ||
return _this2.translate.apply(_this2, args); | ||
}, options); | ||
// nesting | ||
res = this.interpolator.nest(res, function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
if (options.interpolation) this.interpolator.reset(); | ||
return _this2.translate.apply(_this2, args); | ||
}, options); | ||
// post process | ||
var postProcess = options.postProcess || this.options.postProcess; | ||
var postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess; | ||
if (options.interpolation) this.interpolator.reset(); | ||
if (res !== undefined && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) { | ||
res = postProcessor.handle(postProcessorNames, res, key, options, this); | ||
} | ||
// post process | ||
var postProcess = options.postProcess || this.options.postProcess; | ||
var postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess; | ||
return res; | ||
if (res !== undefined && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) { | ||
res = postProcessor.handle(postProcessorNames, res, key, options, this); | ||
} | ||
}, { | ||
key: 'resolve', | ||
value: function resolve(keys) { | ||
var _this3 = this; | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
return res; | ||
}; | ||
var found = void 0; | ||
Translator.prototype.resolve = function resolve(keys) { | ||
var _this3 = this; | ||
if (typeof keys === 'string') keys = [keys]; | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
// forEach possible key | ||
keys.forEach(function (k) { | ||
if (_this3.isValidLookup(found)) return; | ||
var found = void 0; | ||
var _extractFromKey2 = _this3.extractFromKey(k, options); | ||
if (typeof keys === 'string') keys = [keys]; | ||
var key = _extractFromKey2.key; | ||
var namespaces = _extractFromKey2.namespaces; | ||
// forEach possible key | ||
keys.forEach(function (k) { | ||
if (_this3.isValidLookup(found)) return; | ||
if (_this3.options.fallbackNS) namespaces = namespaces.concat(_this3.options.fallbackNS); | ||
var _extractFromKey2 = _this3.extractFromKey(k, options); | ||
var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string'; | ||
var needsContextHandling = options.context !== undefined && typeof options.context === 'string' && options.context !== ''; | ||
var key = _extractFromKey2.key; | ||
var namespaces = _extractFromKey2.namespaces; | ||
var codes = options.lngs ? options.lngs : _this3.languageUtils.toResolveHierarchy(options.lng || _this3.language); | ||
if (_this3.options.fallbackNS) namespaces = namespaces.concat(_this3.options.fallbackNS); | ||
namespaces.forEach(function (ns) { | ||
var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string'; | ||
var needsContextHandling = options.context !== undefined && typeof options.context === 'string' && options.context !== ''; | ||
var codes = options.lngs ? options.lngs : _this3.languageUtils.toResolveHierarchy(options.lng || _this3.language); | ||
namespaces.forEach(function (ns) { | ||
if (_this3.isValidLookup(found)) return; | ||
codes.forEach(function (code) { | ||
if (_this3.isValidLookup(found)) return; | ||
codes.forEach(function (code) { | ||
if (_this3.isValidLookup(found)) return; | ||
var finalKey = key; | ||
var finalKeys = [finalKey]; | ||
var finalKey = key; | ||
var finalKeys = [finalKey]; | ||
var pluralSuffix = void 0; | ||
if (needsPluralHandling) pluralSuffix = _this3.pluralResolver.getSuffix(code, options.count); | ||
var pluralSuffix = void 0; | ||
if (needsPluralHandling) pluralSuffix = _this3.pluralResolver.getSuffix(code, options.count); | ||
// fallback for plural if context not found | ||
if (needsPluralHandling && needsContextHandling) finalKeys.push(finalKey + pluralSuffix); | ||
// fallback for plural if context not found | ||
if (needsPluralHandling && needsContextHandling) finalKeys.push(finalKey + pluralSuffix); | ||
// get key for context if needed | ||
if (needsContextHandling) finalKeys.push(finalKey += '' + _this3.options.contextSeparator + options.context); | ||
// get key for context if needed | ||
if (needsContextHandling) finalKeys.push(finalKey += '' + _this3.options.contextSeparator + options.context); | ||
// get key for plural if needed | ||
if (needsPluralHandling) finalKeys.push(finalKey += pluralSuffix); | ||
// get key for plural if needed | ||
if (needsPluralHandling) finalKeys.push(finalKey += pluralSuffix); | ||
// iterate over finalKeys starting with most specific pluralkey (-> contextkey only) -> singularkey only | ||
var possibleKey = void 0; | ||
while (possibleKey = finalKeys.pop()) { | ||
if (_this3.isValidLookup(found)) continue; | ||
found = _this3.getResource(code, ns, possibleKey, options); | ||
} | ||
}); | ||
// iterate over finalKeys starting with most specific pluralkey (-> contextkey only) -> singularkey only | ||
var possibleKey = void 0; | ||
while (possibleKey = finalKeys.pop()) { | ||
if (_this3.isValidLookup(found)) continue; | ||
found = _this3.getResource(code, ns, possibleKey, options); | ||
} | ||
}); | ||
}); | ||
}); | ||
return found; | ||
} | ||
}, { | ||
key: 'isValidLookup', | ||
value: function isValidLookup(res) { | ||
return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === ''); | ||
} | ||
}, { | ||
key: 'getResource', | ||
value: function getResource(code, ns, key) { | ||
var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
return found; | ||
}; | ||
return this.resourceStore.getResource(code, ns, key, options); | ||
} | ||
}]); | ||
Translator.prototype.isValidLookup = function isValidLookup(res) { | ||
return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === ''); | ||
}; | ||
Translator.prototype.getResource = function getResource(code, ns, key) { | ||
var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
return this.resourceStore.getResource(code, ns, key, options); | ||
}; | ||
return Translator; | ||
@@ -296,0 +286,0 @@ }(EventEmitter); |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define("i18next",t):e.i18next=t()}(this,function(){"use strict";function e(e){return null==e?"":""+e}function t(e,t,n){e.forEach(function(e){t[e]&&(n[e]=t[e])})}function n(e,t,n){function i(e){return e&&e.indexOf("###")>-1?e.replace(/###/g,"."):e}for(var r="string"!=typeof t?[].concat(t):t.split(".");r.length>1;){if(!e)return{};var o=i(r.shift());!e[o]&&n&&(e[o]=new n),e=e[o]}return e?{obj:e,k:i(r.shift())}:{}}function i(e,t,i){var r=n(e,t,Object),o=r.obj,s=r.k;o[s]=i}function r(e,t,i,r){var o=n(e,t,Object),s=o.obj,a=o.k;s[a]=s[a]||[],r&&(s[a]=s[a].concat(i)),r||s[a].push(i)}function o(e,t){var i=n(e,t),r=i.obj,o=i.k;return r?r[o]:void 0}function s(e,t,n){for(var i in t)i in e?"string"==typeof e[i]||e[i]instanceof String||"string"==typeof t[i]||t[i]instanceof String?n&&(e[i]=t[i]):s(e[i],t[i],n):e[i]=t[i];return e}function a(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function l(e){return"string"==typeof e?e.replace(/[&<>"'\/]/g,function(e){return S[e]}):e}function u(e){return e.interpolation={unescapeSuffix:"HTML"},e.interpolation.prefix=e.interpolationPrefix||"__",e.interpolation.suffix=e.interpolationSuffix||"__",e.interpolation.escapeValue=e.escapeInterpolation||!1,e.interpolation.nestingPrefix=e.reusePrefix||"$t(",e.interpolation.nestingSuffix=e.reuseSuffix||")",e}function c(e){return e.resStore&&(e.resources=e.resStore),e.ns&&e.ns.defaultNs?(e.defaultNS=e.ns.defaultNs,e.ns=e.ns.namespaces):e.defaultNS=e.ns||"translation",e.fallbackToDefaultNS&&e.defaultNS&&(e.fallbackNS=e.defaultNS),e.saveMissing=e.sendMissing,e.saveMissingTo=e.sendMissingTo||"current",e.returnNull=!e.fallbackOnNull,e.returnEmptyString=!e.fallbackOnEmpty,e.returnObjects=e.returnObjectTrees,e.joinArrays="\n",e.returnedObjectHandler=e.objectTreeKeyHandler,e.parseMissingKeyHandler=e.parseMissingKey,e.appendNamespaceToMissingKey=!0,e.nsSeparator=e.nsseparator,e.keySeparator=e.keyseparator,"sprintf"===e.shortcutFunction&&(e.overloadTranslationOptionHandler=function(e){for(var t=[],n=1;n<e.length;n++)t.push(e[n]);return{postProcess:"sprintf",sprintf:t}}),e.whitelist=e.lngWhitelist,e.preload=e.preload,"current"===e.load&&(e.load="currentOnly"),"unspecific"===e.load&&(e.load="languageOnly"),e.backend=e.backend||{},e.backend.loadPath=e.resGetPath||"locales/__lng__/__ns__.json",e.backend.addPath=e.resPostPath||"locales/add/__lng__/__ns__",e.backend.allowMultiLoading=e.dynamicLoad,e.cache=e.cache||{},e.cache.prefix="res_",e.cache.expirationTime=6048e5,e.cache.enabled=!!e.useLocalStorage,e=u(e),e.defaultVariables&&(e.interpolation.defaultVariables=e.defaultVariables),e}function f(e){return e=u(e),e.joinArrays="\n",e}function p(e){return(e.interpolationPrefix||e.interpolationSuffix||e.escapeInterpolation)&&(e=u(e)),e.nsSeparator=e.nsseparator,e.keySeparator=e.keyseparator,e.returnObjects=e.returnObjectTrees,e}function h(e){e.lng=function(){return k.deprecate("i18next.lng() can be replaced by i18next.language for detected language or i18next.languages for languages ordered by translation lookup."),e.services.languageUtils.toResolveHierarchy(e.language)[0]},e.preload=function(t,n){k.deprecate("i18next.preload() can be replaced with i18next.loadLanguages()"),e.loadLanguages(t,n)},e.setLng=function(t,n,i){return k.deprecate("i18next.setLng() can be replaced with i18next.changeLanguage() or i18next.getFixedT() to get a translation function with fixed language or namespace."),"function"==typeof n&&(i=n,n={}),n||(n={}),n.fixLng===!0&&i?i(null,e.getFixedT(t)):void e.changeLanguage(t,i)},e.addPostProcessor=function(t,n){k.deprecate("i18next.addPostProcessor() can be replaced by i18next.use({ type: 'postProcessor', name: 'name', process: fc })"),e.use({type:"postProcessor",name:t,process:n})}}function g(e,t){for(var n=e.indexOf(t);-1!==n;)e.splice(n,1),n=e.indexOf(t)}function d(){return{debug:!1,ns:["translation"],defaultNS:["translation"],fallbackLng:["dev"],fallbackNS:!1,whitelist:!1,load:"all",preload:!1,keySeparator:".",nsSeparator:":",pluralSeparator:"_",contextSeparator:"_",saveMissing:!1,saveMissingTo:"fallback",missingKeyHandler:!1,postProcess:!1,returnNull:!0,returnEmptyString:!0,returnObjects:!1,joinArrays:!1,returnedObjectHandler:function(){},parseMissingKeyHandler:!1,appendNamespaceToMissingKey:!1,overloadTranslationOptionHandler:function(e){return{defaultValue:e[1]}},interpolation:{escapeValue:!0,prefix:"{{",suffix:"}}",unescapePrefix:"-",nestingPrefix:"$t(",nestingSuffix:")",defaultVariables:void 0}}}function v(e){return"string"==typeof e.ns&&(e.ns=[e.ns]),"string"==typeof e.fallbackLng&&(e.fallbackLng=[e.fallbackLng]),"string"==typeof e.fallbackNS&&(e.fallbackNS=[e.fallbackNS]),e.whitelist&&e.whitelist.indexOf("cimode")<0&&e.whitelist.push("cimode"),e}var y={};y["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},y.classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},y.createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),y["extends"]=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},y.inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},y.possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},y.slicedToArray=function(){function e(e,t){var n=[],i=!0,r=!1,o=void 0;try{for(var s,a=e[Symbol.iterator]();!(i=(s=a.next()).done)&&(n.push(s.value),!t||n.length!==t);i=!0);}catch(l){r=!0,o=l}finally{try{!i&&a["return"]&&a["return"]()}finally{if(r)throw o}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();var b={type:"logger",log:function(e){this._output("log",e)},warn:function(e){this._output("warn",e)},error:function(e){this._output("error",e)},_output:function(e,t){console&&console[e]&&console[e].apply(console,Array.prototype.slice.call(t))}},m=function(){function e(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];y.classCallCheck(this,e),this.subs=[],this.init(t,n)}return y.createClass(e,[{key:"init",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.prefix=t.prefix||"i18next:",this.logger=e||b,this.options=t,this.debug=t.debug!==!1}},{key:"setDebug",value:function(e){this.debug=e,this.subs.forEach(function(t){t.setDebug(e)})}},{key:"log",value:function(){this.forward(arguments,"log","",!0)}},{key:"warn",value:function(){this.forward(arguments,"warn","",!0)}},{key:"error",value:function(){this.forward(arguments,"error","")}},{key:"deprecate",value:function(){this.forward(arguments,"warn","WARNING DEPRECATED: ",!0)}},{key:"forward",value:function(e,t,n,i){i&&!this.debug||("string"==typeof e[0]&&(e[0]=n+this.prefix+" "+e[0]),this.logger[t](e))}},{key:"create",value:function(t){var n=new e(this.logger,y["extends"]({prefix:this.prefix+":"+t+":"},this.options));return this.subs.push(n),n}}]),e}(),k=new m,x=function(){function e(){y.classCallCheck(this,e),this.observers={}}return y.createClass(e,[{key:"on",value:function(e,t){var n=this;e.split(" ").forEach(function(e){n.observers[e]=n.observers[e]||[],n.observers[e].push(t)})}},{key:"off",value:function(e,t){var n=this;this.observers[e]&&this.observers[e].forEach(function(){if(t){var i=n.observers[e].indexOf(t);i>-1&&n.observers[e].splice(i,1)}else delete n.observers[e]})}},{key:"emit",value:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),i=1;t>i;i++)n[i-1]=arguments[i];this.observers[e]&&this.observers[e].forEach(function(e){e.apply(void 0,n)}),this.observers["*"]&&this.observers["*"].forEach(function(t){var i;t.apply(t,(i=[e]).concat.apply(i,n))})}}]),e}(),S={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},w=function(e){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=arguments.length<=1||void 0===arguments[1]?{ns:["translation"],defaultNS:"translation"}:arguments[1];y.classCallCheck(this,t);var i=y.possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this));return i.data=e,i.options=n,i}return y.inherits(t,e),y.createClass(t,[{key:"addNamespaces",value:function(e){this.options.ns.indexOf(e)<0&&this.options.ns.push(e)}},{key:"removeNamespaces",value:function(e){var t=this.options.ns.indexOf(e);t>-1&&this.options.ns.splice(t,1)}},{key:"getResource",value:function(e,t,n){var i=arguments.length<=3||void 0===arguments[3]?{}:arguments[3],r=i.keySeparator||this.options.keySeparator;void 0===r&&(r=".");var s=[e,t];return n&&"string"!=typeof n&&(s=s.concat(n)),n&&"string"==typeof n&&(s=s.concat(r?n.split(r):n)),e.indexOf(".")>-1&&(s=e.split(".")),o(this.data,s)}},{key:"addResource",value:function(e,t,n,r){var o=arguments.length<=4||void 0===arguments[4]?{silent:!1}:arguments[4],s=this.options.keySeparator;void 0===s&&(s=".");var a=[e,t];n&&(a=a.concat(s?n.split(s):n)),e.indexOf(".")>-1&&(a=e.split("."),r=t,t=a[1]),this.addNamespaces(t),i(this.data,a,r),o.silent||this.emit("added",e,t,n,r)}},{key:"addResources",value:function(e,t,n){for(var i in n)"string"==typeof n[i]&&this.addResource(e,t,i,n[i],{silent:!0});this.emit("added",e,t,n)}},{key:"addResourceBundle",value:function(e,t,n,r,a){var l=[e,t];e.indexOf(".")>-1&&(l=e.split("."),r=n,n=t,t=l[1]),this.addNamespaces(t);var u=o(this.data,l)||{};r?s(u,n,a):u=y["extends"]({},u,n),i(this.data,l,u),this.emit("added",e,t,n)}},{key:"removeResourceBundle",value:function(e,t){this.hasResourceBundle(e,t)&&delete this.data[e][t],this.removeNamespaces(t),this.emit("removed",e,t)}},{key:"hasResourceBundle",value:function(e,t){return void 0!==this.getResource(e,t)}},{key:"getResourceBundle",value:function(e,t){return t||(t=this.options.defaultNS),"v1"===this.options.compatibilityAPI?y["extends"]({},this.getResource(e,t)):this.getResource(e,t)}},{key:"toJSON",value:function(){return this.data}}]),t}(x),C={processors:{},addPostProcessor:function(e){this.processors[e.name]=e},handle:function(e,t,n,i,r){var o=this;return e.forEach(function(e){o.processors[e]&&(t=o.processors[e].process(t,n,i,r))}),t}},O=function(e){function n(e){var i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];y.classCallCheck(this,n);var r=y.possibleConstructorReturn(this,Object.getPrototypeOf(n).call(this));return t(["resourceStore","languageUtils","pluralResolver","interpolator","backendConnector"],e,r),r.options=i,r.logger=k.create("translator"),r}return y.inherits(n,e),y.createClass(n,[{key:"changeLanguage",value:function(e){e&&(this.language=e)}},{key:"exists",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{interpolation:{}}:arguments[1];return"v1"===this.options.compatibilityAPI&&(t=p(t)),void 0!==this.resolve(e,t)}},{key:"extractFromKey",value:function(e,t){var n=t.nsSeparator||this.options.nsSeparator;void 0===n&&(n=":");var i=t.ns||this.options.defaultNS;if(n&&e.indexOf(n)>-1){var r=e.split(n);i=r[0],e=r[1]}return"string"==typeof i&&(i=[i]),{key:e,namespaces:i}}},{key:"translate",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if("object"!==("undefined"==typeof t?"undefined":y["typeof"](t))?t=this.options.overloadTranslationOptionHandler(arguments):"v1"===this.options.compatibilityAPI&&(t=p(t)),void 0===e||null===e||""===e)return"";"number"==typeof e&&(e=String(e)),"string"==typeof e&&(e=[e]);var n=t.lng||this.language;if(n&&"cimode"===n.toLowerCase())return e[e.length-1];var i=t.keySeparator||this.options.keySeparator||".",r=this.extractFromKey(e[e.length-1],t),o=r.key,s=r.namespaces,a=s[s.length-1],l=this.resolve(e,t),u=Object.prototype.toString.apply(l),c=["[object Number]","[object Function]","[object RegExp]"],f=void 0!==t.joinArrays?t.joinArrays:this.options.joinArrays;if(l&&"string"!=typeof l&&c.indexOf(u)<0&&(!f||"[object Array]"!==u)){if(!t.returnObjects&&!this.options.returnObjects)return this.logger.warn("accessing an object - but returnObjects options is not enabled!"),this.options.returnedObjectHandler?this.options.returnedObjectHandler(o,l,t):"key '"+o+" ("+this.language+")' returned an object instead of string.";var h="[object Array]"===u?[]:{};for(var g in l)h[g]=this.translate(""+o+i+g,y["extends"]({joinArrays:!1,ns:s},t));l=h}else if(f&&"[object Array]"===u)l=l.join(f),l&&(l=this.extendTranslation(l,o,t));else{var d=!1,v=!1;if(!this.isValidLookup(l)&&t.defaultValue&&(d=!0,l=t.defaultValue),this.isValidLookup(l)||(v=!0,l=o),(v||d)&&(this.logger.log("missingKey",n,a,o,l),this.options.saveMissing)){var b=[];if("fallback"===this.options.saveMissingTo&&this.options.fallbackLng&&this.options.fallbackLng[0])for(var m=0;m<this.options.fallbackLng.length;m++)b.push(this.options.fallbackLng[m]);else"all"===this.options.saveMissingTo?b=this.languageUtils.toResolveHierarchy(t.lng||this.language):b.push(t.lng||this.language);this.options.missingKeyHandler?this.options.missingKeyHandler(b,a,o,l):this.backendConnector&&this.backendConnector.saveMissing&&this.backendConnector.saveMissing(b,a,o,l),this.emit("missingKey",b,a,o,l)}l=this.extendTranslation(l,o,t),v&&l===o&&this.options.appendNamespaceToMissingKey&&(l=a+":"+o),v&&this.options.parseMissingKeyHandler&&(l=this.options.parseMissingKeyHandler(l))}return l}},{key:"extendTranslation",value:function(e,t,n){var i=this;n.interpolation&&this.interpolator.init(n);var r=n.replace&&"string"!=typeof n.replace?n.replace:n;this.options.interpolation.defaultVariables&&(r=y["extends"]({},this.options.interpolation.defaultVariables,r)),e=this.interpolator.interpolate(e,r),e=this.interpolator.nest(e,function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];return i.translate.apply(i,t)},n),n.interpolation&&this.interpolator.reset();var o=n.postProcess||this.options.postProcess,s="string"==typeof o?[o]:o;return void 0!==e&&s&&s.length&&n.applyPostProcessor!==!1&&(e=C.handle(s,e,t,n,this)),e}},{key:"resolve",value:function(e){var t=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=void 0;return"string"==typeof e&&(e=[e]),e.forEach(function(e){if(!t.isValidLookup(i)){var r=t.extractFromKey(e,n),o=r.key,s=r.namespaces;t.options.fallbackNS&&(s=s.concat(t.options.fallbackNS));var a=void 0!==n.count&&"string"!=typeof n.count,l=void 0!==n.context&&"string"==typeof n.context&&""!==n.context,u=n.lngs?n.lngs:t.languageUtils.toResolveHierarchy(n.lng||t.language);s.forEach(function(e){t.isValidLookup(i)||u.forEach(function(r){if(!t.isValidLookup(i)){var s=o,u=[s],c=void 0;a&&(c=t.pluralResolver.getSuffix(r,n.count)),a&&l&&u.push(s+c),l&&u.push(s+=""+t.options.contextSeparator+n.context),a&&u.push(s+=c);for(var f=void 0;f=u.pop();)t.isValidLookup(i)||(i=t.getResource(r,e,f,n))}})})}}),i}},{key:"isValidLookup",value:function(e){return!(void 0===e||!this.options.returnNull&&null===e||!this.options.returnEmptyString&&""===e)}},{key:"getResource",value:function(e,t,n){var i=arguments.length<=3||void 0===arguments[3]?{}:arguments[3];return this.resourceStore.getResource(e,t,n,i)}}]),n}(x),L=function(){function e(t){y.classCallCheck(this,e),this.options=t,this.whitelist=this.options.whitelist||!1,this.logger=k.create("languageUtils")}return y.createClass(e,[{key:"getLanguagePartFromCode",value:function(e){if(e.indexOf("-")<0)return e;var t=["nb-NO","nn-NO","nb-no","nn-no"],n=e.split("-");return this.formatLanguageCode(t.indexOf(e)>-1?n[1].toLowerCase():n[0])}},{key:"formatLanguageCode",value:function(e){if("string"==typeof e&&e.indexOf("-")>-1){var t=e.split("-"),n=y.slicedToArray(t,2),i=n[0],r=n[1];return this.options.lowerCaseLng?i.toLowerCase()+"-"+r.toLowerCase():i.toLowerCase()+"-"+r.toUpperCase()}return this.options.cleanCode||this.options.lowerCaseLng?e.toLowerCase():e}},{key:"isWhitelisted",value:function(e){return"languageOnly"===this.options.load&&(e=this.getLanguagePartFromCode(e)),!this.whitelist||!this.whitelist.length||this.whitelist.indexOf(e)>-1}},{key:"toResolveHierarchy",value:function(e,t){var n=this;t=t||this.options.fallbackLng||[],"string"==typeof t&&(t=[t]);var i=[],r=function(e){n.isWhitelisted(e)?i.push(e):n.logger.warn("rejecting non-whitelisted language code: "+e)};return"string"==typeof e&&e.indexOf("-")>-1?("languageOnly"!==this.options.load&&r(this.formatLanguageCode(e)),"currentOnly"!==this.options.load&&r(this.getLanguagePartFromCode(e))):"string"==typeof e&&r(this.formatLanguageCode(e)),t.forEach(function(e){i.indexOf(e)<0&&r(n.formatLanguageCode(e))}),i}}]),e}(),N=[{lngs:["ach","ak","am","arn","br","fil","gun","ln","mfe","mg","mi","oc","tg","ti","tr","uz","wa"],nr:[1,2],fc:1},{lngs:["af","an","ast","az","bg","bn","ca","da","de","dev","el","en","eo","es","es_ar","et","eu","fi","fo","fur","fy","gl","gu","ha","he","hi","hu","hy","ia","it","kn","ku","lb","mai","ml","mn","mr","nah","nap","nb","ne","nl","nn","no","nso","pa","pap","pms","ps","pt","pt_br","rm","sco","se","si","so","son","sq","sv","sw","ta","te","tk","ur","yo"],nr:[1,2],fc:2},{lngs:["ay","bo","cgg","fa","id","ja","jbo","ka","kk","km","ko","ky","lo","ms","sah","su","th","tt","ug","vi","wo","zh"],nr:[1],fc:3},{lngs:["be","bs","dz","hr","ru","sr","uk"],nr:[1,2,5],fc:4},{lngs:["ar"],nr:[0,1,2,3,11,100],fc:5},{lngs:["cs","sk"],nr:[1,2,5],fc:6},{lngs:["csb","pl"],nr:[1,2,5],fc:7},{lngs:["cy"],nr:[1,2,3,8],fc:8},{lngs:["fr"],nr:[1,2],fc:9},{lngs:["ga"],nr:[1,2,3,7,11],fc:10},{lngs:["gd"],nr:[1,2,3,20],fc:11},{lngs:["is"],nr:[1,2],fc:12},{lngs:["jv"],nr:[0,1],fc:13},{lngs:["kw"],nr:[1,2,3,4],fc:14},{lngs:["lt"],nr:[1,2,10],fc:15},{lngs:["lv"],nr:[1,2,0],fc:16},{lngs:["mk"],nr:[1,2],fc:17},{lngs:["mnk"],nr:[0,1,2],fc:18},{lngs:["mt"],nr:[1,2,11,20],fc:19},{lngs:["or"],nr:[2,1],fc:2},{lngs:["ro"],nr:[1,2,20],fc:20},{lngs:["sl"],nr:[5,1,2,3],fc:21}],j={1:function(e){return Number(e>1)},2:function(e){return Number(1!=e)},3:function(e){return 0},4:function(e){return Number(e%10==1&&e%100!=11?0:e%10>=2&&4>=e%10&&(10>e%100||e%100>=20)?1:2)},5:function(e){return Number(0===e?0:1==e?1:2==e?2:e%100>=3&&10>=e%100?3:e%100>=11?4:5)},6:function(e){return Number(1==e?0:e>=2&&4>=e?1:2)},7:function(e){return Number(1==e?0:e%10>=2&&4>=e%10&&(10>e%100||e%100>=20)?1:2)},8:function(e){return Number(1==e?0:2==e?1:8!=e&&11!=e?2:3)},9:function(e){return Number(e>=2)},10:function(e){return Number(1==e?0:2==e?1:7>e?2:11>e?3:4)},11:function(e){return Number(1==e||11==e?0:2==e||12==e?1:e>2&&20>e?2:3)},12:function(e){return Number(e%10!=1||e%100==11)},13:function(e){return Number(0!==e)},14:function(e){return Number(1==e?0:2==e?1:3==e?2:3)},15:function(e){return Number(e%10==1&&e%100!=11?0:e%10>=2&&(10>e%100||e%100>=20)?1:2)},16:function(e){return Number(e%10==1&&e%100!=11?0:0!==e?1:2)},17:function(e){return Number(1==e||e%10==1?0:1)},18:function(e){return Number(0==e?0:1==e?1:2)},19:function(e){return Number(1==e?0:0===e||e%100>1&&11>e%100?1:e%100>10&&20>e%100?2:3)},20:function(e){return Number(1==e?0:0===e||e%100>0&&20>e%100?1:2)},21:function(e){return Number(e%100==1?1:e%100==2?2:e%100==3||e%100==4?3:0)}},R=function(){function e(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];y.classCallCheck(this,e),this.rules=function(){var e={};return N.forEach(function(t){t.lngs.forEach(function(n){return e[n]={numbers:t.nr,plurals:j[t.fc]}})}),e}(),this.languageUtils=t,this.options=n,this.logger=k.create("pluralResolver")}return y.createClass(e,[{key:"addRule",value:function(e,t){this.rules[e]=t}},{key:"getRule",value:function(e){return this.rules[this.languageUtils.getLanguagePartFromCode(e)]}},{key:"needsPlural",value:function(e){var t=this.getRule(e);return!(t&&t.numbers.length<=1)}},{key:"getSuffix",value:function(e,t){var n=this.getRule(e);if(n){if(1===n.numbers.length)return"";var i=n.noAbs?n.plurals(t):n.plurals(Math.abs(t)),r=n.numbers[i];if(2===n.numbers.length&&1===n.numbers[0]&&(2===r?r="plural":1===r&&(r="")),"v1"===this.options.compatibilityJSON){if(1===r)return"";if("number"==typeof r)return"_plural_"+r.toString()}return this.options.prepend&&r.toString()?this.options.prepend+r.toString():r.toString()}return this.logger.warn("no plural rule found for: "+e),""}}]),e}(),P=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];y.classCallCheck(this,t),this.logger=k.create("interpolator"),this.init(e,!0)}return y.createClass(t,[{key:"init",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=arguments[1];t&&(this.options=e),e.interpolation||(e.interpolation={escapeValue:!0});var n=e.interpolation;this.escapeValue=n.escapeValue,this.prefix=n.prefix?a(n.prefix):n.prefixEscaped||"{{",this.suffix=n.suffix?a(n.suffix):n.suffixEscaped||"}}",this.unescapePrefix=n.unescapeSuffix?"":n.unescapePrefix||"-",this.unescapeSuffix=this.unescapePrefix?"":n.unescapeSuffix||"",this.nestingPrefix=n.nestingPrefix?a(n.nestingPrefix):n.nestingPrefixEscaped||a("$t("),this.nestingSuffix=n.nestingSuffix?a(n.nestingSuffix):n.nestingSuffixEscaped||a(")");var i=this.prefix+"(.+?)"+this.suffix;this.regexp=new RegExp(i,"g");var r=this.prefix+this.unescapePrefix+"(.+?)"+this.unescapeSuffix+this.suffix;this.regexpUnescape=new RegExp(r,"g");var o=this.nestingPrefix+"(.+?)"+this.nestingSuffix;this.nestingRegexp=new RegExp(o,"g")}},{key:"reset",value:function(){this.options&&this.init(this.options)}},{key:"interpolate",value:function(t,n){function i(e){return e.replace(/\$/g,"$$$$")}for(var r=void 0,s=void 0;r=this.regexpUnescape.exec(t);){var a=o(n,r[1].trim());t=t.replace(r[0],a)}for(;r=this.regexp.exec(t);)s=o(n,r[1].trim()),"string"!=typeof s&&(s=e(s)),s||(this.logger.warn("missed to pass in variable "+r[1]+" for interpolating "+t),s=""),s=i(this.escapeValue?l(s):s),t=t.replace(r[0],s),this.regexp.lastIndex=0;return t}},{key:"nest",value:function(t,n){function i(e){return e.replace(/\$/g,"$$$$")}function r(e){if(e.indexOf(",")<0)return e;var t=e.split(",");e=t.shift();var n=t.join(",");n=this.interpolate(n,u);try{u=JSON.parse(n)}catch(i){this.logger.error("failed parsing options string in nesting for key "+e,i)}return e}var o=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],s=void 0,a=void 0,u=JSON.parse(JSON.stringify(o));for(u.applyPostProcessor=!1;s=this.nestingRegexp.exec(t);)a=n(r.call(this,s[1].trim()),u),"string"!=typeof a&&(a=e(a)),a||(this.logger.warn("missed to pass in variable "+s[1]+" for interpolating "+t),a=""),a=i(this.escapeValue?l(a):a),t=t.replace(s[0],a),this.regexp.lastIndex=0;return t}}]),t}(),E=function(e){function t(e,n,i){var r=arguments.length<=3||void 0===arguments[3]?{}:arguments[3];y.classCallCheck(this,t);var o=y.possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this));return o.backend=e,o.store=n,o.services=i,o.options=r,o.logger=k.create("backendConnector"),o.state={},o.queue=[],o.backend&&o.backend.init&&o.backend.init(i,r.backend,r),o}return y.inherits(t,e),y.createClass(t,[{key:"queueLoad",value:function(e,t,n){var i=this,r=[],o=[],s=[],a=[];return e.forEach(function(e){var n=!0;t.forEach(function(t){var s=e+"|"+t;i.store.hasResourceBundle(e,t)?i.state[s]=2:i.state[s]<0||(1===i.state[s]?o.indexOf(s)<0&&o.push(s):(i.state[s]=1,n=!1,o.indexOf(s)<0&&o.push(s),r.indexOf(s)<0&&r.push(s),a.indexOf(t)<0&&a.push(t)))}),n||s.push(e)}),(r.length||o.length)&&this.queue.push({pending:o,loaded:{},errors:[],callback:n}),{toLoad:r,pending:o,toLoadLanguages:s,toLoadNamespaces:a}}},{key:"loaded",value:function(e,t,n){var i=this,o=e.split("|"),s=y.slicedToArray(o,2),a=s[0],l=s[1];t&&this.emit("failedLoading",a,l,t),n&&this.store.addResourceBundle(a,l,n),this.state[e]=t?-1:2,this.queue.forEach(function(n){r(n.loaded,[a],l),g(n.pending,e),t&&n.errors.push(t),0!==n.pending.length||n.done||(n.errors.length?n.callback(n.errors):n.callback(),i.emit("loaded",n.loaded),n.done=!0)}),this.queue=this.queue.filter(function(e){return!e.done})}},{key:"read",value:function(e,t,n,i,r,o){var s=this;return i||(i=0),r||(r=250),e.length?void this.backend[n](e,t,function(a,l){return a&&l&&5>i?void setTimeout(function(){s.read.call(s,e,t,n,++i,2*r,o)},r):void o(a,l)}):o(null,{})}},{key:"load",value:function(e,t,n){var i=this;if(!this.backend)return this.logger.warn("No backend was added via i18next.use. Will not load resources."),n&&n();var r=y["extends"]({},this.backend.options,this.options.backend);"string"==typeof e&&(e=this.services.languageUtils.toResolveHierarchy(e)),"string"==typeof t&&(t=[t]);var s=this.queueLoad(e,t,n);return s.toLoad.length?void(r.allowMultiLoading&&this.backend.readMulti?this.read(s.toLoadLanguages,s.toLoadNamespaces,"readMulti",null,null,function(e,t){e&&i.logger.warn("loading namespaces "+s.toLoadNamespaces.join(", ")+" for languages "+s.toLoadLanguages.join(", ")+" via multiloading failed",e),!e&&t&&i.logger.log("loaded namespaces "+s.toLoadNamespaces.join(", ")+" for languages "+s.toLoadLanguages.join(", ")+" via multiloading",t),s.toLoad.forEach(function(n){var r=n.split("|"),s=y.slicedToArray(r,2),a=s[0],l=s[1],u=o(t,[a,l]);if(u)i.loaded(n,e,u);else{var c="loading namespace "+l+" for language "+a+" via multiloading failed";i.loaded(n,c),i.logger.error(c)}})}):!function(){var e=function(e){var t=this,n=e.split("|"),i=y.slicedToArray(n,2),r=i[0],o=i[1];this.read(r,o,"read",null,null,function(n,i){n&&t.logger.warn("loading namespace "+o+" for language "+r+" failed",n),!n&&i&&t.logger.log("loaded namespace "+o+" for language "+r,i),t.loaded(e,n,i)})};s.toLoad.forEach(function(t){e.call(i,t)})}()):void(s.pending.length||n())}},{key:"saveMissing",value:function(e,t,n,i){this.backend&&this.backend.create&&this.backend.create(e,t,n,i),this.store.addResource(e[0],t,n,i)}}]),t}(x),_=function(e){function t(e,n,i){var r=arguments.length<=3||void 0===arguments[3]?{}:arguments[3];y.classCallCheck(this,t);var o=y.possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this));return o.cache=e,o.store=n,o.services=i,o.options=r,o.logger=k.create("cacheConnector"),o.cache&&o.cache.init&&o.cache.init(i,r.cache,r),o}return y.inherits(t,e),y.createClass(t,[{key:"load",value:function(e,t,n){var i=this;if(!this.cache)return n&&n();var r=y["extends"]({},this.cache.options,this.options.cache);"string"==typeof e&&(e=this.services.languageUtils.toResolveHierarchy(e)),"string"==typeof t&&(t=[t]),r.enabled?this.cache.load(e,function(t,r){if(t&&i.logger.error("loading languages "+e.join(", ")+" from cache failed",t),r)for(var o in r)for(var s in r[o])if("i18nStamp"!==s){var a=r[o][s];a&&i.store.addResourceBundle(o,s,a)}n&&n()}):n&&n()}},{key:"save",value:function(){this.cache&&this.options.cache&&this.options.cache.enabled&&this.cache.save(this.store.data)}}]),t}(x),T=function(e){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=arguments[1];y.classCallCheck(this,t);var i=y.possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this));return i.options=v(e),i.services={},i.logger=k,i.modules={},n&&!i.isInitialized&&i.init(e,n),i}return y.inherits(t,e),y.createClass(t,[{key:"init",value:function(e,t){function n(e){return e?"function"==typeof e?new e:e:void 0}var i=this;if("function"==typeof e&&(t=e,e={}),e||(e={}),"v1"===e.compatibilityAPI?this.options=y["extends"]({},d(),v(c(e)),{}):"v1"===e.compatibilityJSON?this.options=y["extends"]({},d(),v(f(e)),{}):this.options=y["extends"]({},d(),this.options,v(e)),t||(t=function(){}),!this.options.isClone){this.modules.logger?k.init(n(this.modules.logger),this.options):k.init(null,this.options);var r=new L(this.options);this.store=new w(this.options.resources,this.options);var o=this.services;o.logger=k,o.resourceStore=this.store,o.resourceStore.on("added removed",function(e,t){o.cacheConnector.save()}),o.languageUtils=r,o.pluralResolver=new R(r,{prepend:this.options.pluralSeparator,compatibilityJSON:this.options.compatibilityJSON}),o.interpolator=new P(this.options),o.backendConnector=new E(n(this.modules.backend),o.resourceStore,o,this.options),o.backendConnector.on("*",function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];i.emit.apply(i,[e].concat(n))}),o.backendConnector.on("loaded",function(e){o.cacheConnector.save()}),o.cacheConnector=new _(n(this.modules.cache),o.resourceStore,o,this.options),o.cacheConnector.on("*",function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];i.emit.apply(i,[e].concat(n))}),this.modules.languageDetector&&(o.languageDetector=n(this.modules.languageDetector),o.languageDetector.init(o,this.options.detection,this.options)),this.translator=new O(this.services,this.options),this.translator.on("*",function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];i.emit.apply(i,[e].concat(n))})}var s=["getResource","addResource","addResources","addResourceBundle","removeResourceBundle","hasResourceBundle","getResourceBundle"];return s.forEach(function(e){i[e]=function(){return this.store[e].apply(this.store,arguments)}}),"v1"===this.options.compatibilityAPI&&h(this),this.changeLanguage(this.options.lng,function(e,n){i.emit("initialized",i.options),i.logger.log("initialized",i.options),t(e,n)}),this}},{key:"loadResources",value:function(e){var t=this;if(e||(e=function(){}),this.options.resources)e(null);else{var n=function(){if(t.language&&"cimode"===t.language.toLowerCase())return{v:e()};var n=[],i=function(e){var i=t.services.languageUtils.toResolveHierarchy(e);i.forEach(function(e){n.indexOf(e)<0&&n.push(e)})};i(t.language),t.options.preload&&t.options.preload.forEach(function(e){i(e)}),t.services.cacheConnector.load(n,t.options.ns,function(){t.services.backendConnector.load(n,t.options.ns,e)})}();if("object"===("undefined"==typeof n?"undefined":y["typeof"](n)))return n.v}}},{key:"use",value:function(e){return"backend"===e.type&&(this.modules.backend=e),"cache"===e.type&&(this.modules.cache=e),("logger"===e.type||e.log&&e.warn&&e.warn)&&(this.modules.logger=e),"languageDetector"===e.type&&(this.modules.languageDetector=e),"postProcessor"===e.type&&C.addPostProcessor(e),this}},{key:"changeLanguage",value:function(e,t){var n=this,i=function(i){e&&(n.emit("languageChanged",e),n.logger.log("languageChanged",e)),t&&t(i,function(){for(var e=arguments.length,t=Array(e),i=0;e>i;i++)t[i]=arguments[i];return n.t.apply(n,t)})};!e&&this.services.languageDetector&&(e=this.services.languageDetector.detect()),e&&(this.language=e,this.languages=this.services.languageUtils.toResolveHierarchy(e),this.translator.changeLanguage(e),this.services.languageDetector&&this.services.languageDetector.cacheUserLanguage(e)),this.loadResources(function(e){i(e)})}},{key:"getFixedT",value:function(e,t){var n=this,i=function r(e,t){return t=t||{},t.lng=t.lng||r.lng,t.ns=t.ns||r.ns,n.t(e,t)};return i.lng=e,i.ns=t,i}},{key:"t",value:function(){return this.translator&&this.translator.translate.apply(this.translator,arguments)}},{key:"exists",value:function(){return this.translator&&this.translator.exists.apply(this.translator,arguments)}},{key:"setDefaultNamespace",value:function(e){this.options.defaultNS=e}},{key:"loadNamespaces",value:function(e,t){var n=this;return this.options.ns?("string"==typeof e&&(e=[e]),e.forEach(function(e){n.options.ns.indexOf(e)<0&&n.options.ns.push(e)}),void this.loadResources(t)):t&&t()}},{key:"loadLanguages",value:function(e,t){ | ||
"string"==typeof e&&(e=[e]),this.options.preload=this.options.preload?this.options.preload.concat(e):e,this.loadResources(t)}},{key:"dir",value:function(e){e||(e=this.language);var t=["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","ur","ydd","yds","yih","ji","yi","hbo","men","xmn","fa","jpr","peo","pes","prs","dv","sam"];return t.indexOf(this.services.languageUtils.getLanguagePartFromCode(e))?"ltr":"rtl"}},{key:"createInstance",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=arguments[1];return new t(e,n)}},{key:"cloneInstance",value:function(){var e=this,n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],i=arguments[1],r=new t(y["extends"]({},n,this.options,{isClone:!0}),i),o=["store","translator","services","language"];return o.forEach(function(t){r[t]=e[t]}),r}}]),t}(x),A=new T;return A}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define("i18next",t):e.i18next=t()}(this,function(){"use strict";function e(e){return null==e?"":""+e}function t(e,t,n){e.forEach(function(e){t[e]&&(n[e]=t[e])})}function n(e,t,n){function o(e){return e&&e.indexOf("###")>-1?e.replace(/###/g,"."):e}for(var r="string"!=typeof t?[].concat(t):t.split(".");r.length>1;){if(!e)return{};var i=o(r.shift());!e[i]&&n&&(e[i]=new n),e=e[i]}return e?{obj:e,k:o(r.shift())}:{}}function o(e,t,o){var r=n(e,t,Object),i=r.obj,s=r.k;i[s]=o}function r(e,t,o,r){var i=n(e,t,Object),s=i.obj,a=i.k;s[a]=s[a]||[],r&&(s[a]=s[a].concat(o)),r||s[a].push(o)}function i(e,t){var o=n(e,t),r=o.obj,i=o.k;return r?r[i]:void 0}function s(e,t,n){for(var o in t)o in e?"string"==typeof e[o]||e[o]instanceof String||"string"==typeof t[o]||t[o]instanceof String?n&&(e[o]=t[o]):s(e[o],t[o],n):e[o]=t[o];return e}function a(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function l(e){return"string"==typeof e?e.replace(/[&<>"'\/]/g,function(e){return w[e]}):e}function u(e){return e.interpolation={unescapeSuffix:"HTML"},e.interpolation.prefix=e.interpolationPrefix||"__",e.interpolation.suffix=e.interpolationSuffix||"__",e.interpolation.escapeValue=e.escapeInterpolation||!1,e.interpolation.nestingPrefix=e.reusePrefix||"$t(",e.interpolation.nestingSuffix=e.reuseSuffix||")",e}function c(e){return e.resStore&&(e.resources=e.resStore),e.ns&&e.ns.defaultNs?(e.defaultNS=e.ns.defaultNs,e.ns=e.ns.namespaces):e.defaultNS=e.ns||"translation",e.fallbackToDefaultNS&&e.defaultNS&&(e.fallbackNS=e.defaultNS),e.saveMissing=e.sendMissing,e.saveMissingTo=e.sendMissingTo||"current",e.returnNull=!e.fallbackOnNull,e.returnEmptyString=!e.fallbackOnEmpty,e.returnObjects=e.returnObjectTrees,e.joinArrays="\n",e.returnedObjectHandler=e.objectTreeKeyHandler,e.parseMissingKeyHandler=e.parseMissingKey,e.appendNamespaceToMissingKey=!0,e.nsSeparator=e.nsseparator,e.keySeparator=e.keyseparator,"sprintf"===e.shortcutFunction&&(e.overloadTranslationOptionHandler=function(e){for(var t=[],n=1;n<e.length;n++)t.push(e[n]);return{postProcess:"sprintf",sprintf:t}}),e.whitelist=e.lngWhitelist,e.preload=e.preload,"current"===e.load&&(e.load="currentOnly"),"unspecific"===e.load&&(e.load="languageOnly"),e.backend=e.backend||{},e.backend.loadPath=e.resGetPath||"locales/__lng__/__ns__.json",e.backend.addPath=e.resPostPath||"locales/add/__lng__/__ns__",e.backend.allowMultiLoading=e.dynamicLoad,e.cache=e.cache||{},e.cache.prefix="res_",e.cache.expirationTime=6048e5,e.cache.enabled=!!e.useLocalStorage,e=u(e),e.defaultVariables&&(e.interpolation.defaultVariables=e.defaultVariables),e}function p(e){return e=u(e),e.joinArrays="\n",e}function f(e){return(e.interpolationPrefix||e.interpolationSuffix||e.escapeInterpolation)&&(e=u(e)),e.nsSeparator=e.nsseparator,e.keySeparator=e.keyseparator,e.returnObjects=e.returnObjectTrees,e}function h(e){e.lng=function(){return k.deprecate("i18next.lng() can be replaced by i18next.language for detected language or i18next.languages for languages ordered by translation lookup."),e.services.languageUtils.toResolveHierarchy(e.language)[0]},e.preload=function(t,n){k.deprecate("i18next.preload() can be replaced with i18next.loadLanguages()"),e.loadLanguages(t,n)},e.setLng=function(t,n,o){return k.deprecate("i18next.setLng() can be replaced with i18next.changeLanguage() or i18next.getFixedT() to get a translation function with fixed language or namespace."),"function"==typeof n&&(o=n,n={}),n||(n={}),n.fixLng===!0&&o?o(null,e.getFixedT(t)):void e.changeLanguage(t,o)},e.addPostProcessor=function(t,n){k.deprecate("i18next.addPostProcessor() can be replaced by i18next.use({ type: 'postProcessor', name: 'name', process: fc })"),e.use({type:"postProcessor",name:t,process:n})}}function g(){var e={};return R.forEach(function(t){t.lngs.forEach(function(n){return e[n]={numbers:t.nr,plurals:j[t.fc]}})}),e}function d(e,t){for(var n=e.indexOf(t);-1!==n;)e.splice(n,1),n=e.indexOf(t)}function y(){return{debug:!1,ns:["translation"],defaultNS:["translation"],fallbackLng:["dev"],fallbackNS:!1,whitelist:!1,load:"all",preload:!1,keySeparator:".",nsSeparator:":",pluralSeparator:"_",contextSeparator:"_",saveMissing:!1,saveMissingTo:"fallback",missingKeyHandler:!1,postProcess:!1,returnNull:!0,returnEmptyString:!0,returnObjects:!1,joinArrays:!1,returnedObjectHandler:function(){},parseMissingKeyHandler:!1,appendNamespaceToMissingKey:!1,overloadTranslationOptionHandler:function(e){return{defaultValue:e[1]}},interpolation:{escapeValue:!0,prefix:"{{",suffix:"}}",unescapePrefix:"-",nestingPrefix:"$t(",nestingSuffix:")",defaultVariables:void 0}}}function v(e){return"string"==typeof e.ns&&(e.ns=[e.ns]),"string"==typeof e.fallbackLng&&(e.fallbackLng=[e.fallbackLng]),"string"==typeof e.fallbackNS&&(e.fallbackNS=[e.fallbackNS]),e.whitelist&&e.whitelist.indexOf("cimode")<0&&e.whitelist.push("cimode"),e}var b={};b["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},b.classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},b["extends"]=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},b.inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},b.possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},b.slicedToArray=function(){function e(e,t){var n=[],o=!0,r=!1,i=void 0;try{for(var s,a=e[Symbol.iterator]();!(o=(s=a.next()).done)&&(n.push(s.value),!t||n.length!==t);o=!0);}catch(l){r=!0,i=l}finally{try{!o&&a["return"]&&a["return"]()}finally{if(r)throw i}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();var m={type:"logger",log:function(e){this._output("log",e)},warn:function(e){this._output("warn",e)},error:function(e){this._output("error",e)},_output:function(e,t){console&&console[e]&&console[e].apply(console,Array.prototype.slice.call(t))}},x=function(){function e(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];b.classCallCheck(this,e),this.subs=[],this.init(t,n)}return e.prototype.init=function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.prefix=t.prefix||"i18next:",this.logger=e||m,this.options=t,this.debug=t.debug!==!1},e.prototype.setDebug=function(e){this.debug=e,this.subs.forEach(function(t){t.setDebug(e)})},e.prototype.log=function(){this.forward(arguments,"log","",!0)},e.prototype.warn=function(){this.forward(arguments,"warn","",!0)},e.prototype.error=function(){this.forward(arguments,"error","")},e.prototype.deprecate=function(){this.forward(arguments,"warn","WARNING DEPRECATED: ",!0)},e.prototype.forward=function(e,t,n,o){o&&!this.debug||("string"==typeof e[0]&&(e[0]=n+this.prefix+" "+e[0]),this.logger[t](e))},e.prototype.create=function(t){var n=new e(this.logger,b["extends"]({prefix:this.prefix+":"+t+":"},this.options));return this.subs.push(n),n},e}(),k=new x,S=function(){function e(){b.classCallCheck(this,e),this.observers={}}return e.prototype.on=function(e,t){var n=this;e.split(" ").forEach(function(e){n.observers[e]=n.observers[e]||[],n.observers[e].push(t)})},e.prototype.off=function(e,t){var n=this;this.observers[e]&&this.observers[e].forEach(function(){if(t){var o=n.observers[e].indexOf(t);o>-1&&n.observers[e].splice(o,1)}else delete n.observers[e]})},e.prototype.emit=function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),o=1;t>o;o++)n[o-1]=arguments[o];this.observers[e]&&this.observers[e].forEach(function(e){e.apply(void 0,n)}),this.observers["*"]&&this.observers["*"].forEach(function(t){var o;t.apply(t,(o=[e]).concat.apply(o,n))})},e}(),w={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},L=function(e){function t(){var n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],o=arguments.length<=1||void 0===arguments[1]?{ns:["translation"],defaultNS:"translation"}:arguments[1];b.classCallCheck(this,t);var r=b.possibleConstructorReturn(this,e.call(this));return r.data=n,r.options=o,r}return b.inherits(t,e),t.prototype.addNamespaces=function(e){this.options.ns.indexOf(e)<0&&this.options.ns.push(e)},t.prototype.removeNamespaces=function(e){var t=this.options.ns.indexOf(e);t>-1&&this.options.ns.splice(t,1)},t.prototype.getResource=function(e,t,n){var o=arguments.length<=3||void 0===arguments[3]?{}:arguments[3],r=o.keySeparator||this.options.keySeparator;void 0===r&&(r=".");var s=[e,t];return n&&"string"!=typeof n&&(s=s.concat(n)),n&&"string"==typeof n&&(s=s.concat(r?n.split(r):n)),e.indexOf(".")>-1&&(s=e.split(".")),i(this.data,s)},t.prototype.addResource=function(e,t,n,r){var i=arguments.length<=4||void 0===arguments[4]?{silent:!1}:arguments[4],s=this.options.keySeparator;void 0===s&&(s=".");var a=[e,t];n&&(a=a.concat(s?n.split(s):n)),e.indexOf(".")>-1&&(a=e.split("."),r=t,t=a[1]),this.addNamespaces(t),o(this.data,a,r),i.silent||this.emit("added",e,t,n,r)},t.prototype.addResources=function(e,t,n){for(var o in n)"string"==typeof n[o]&&this.addResource(e,t,o,n[o],{silent:!0});this.emit("added",e,t,n)},t.prototype.addResourceBundle=function(e,t,n,r,a){var l=[e,t];e.indexOf(".")>-1&&(l=e.split("."),r=n,n=t,t=l[1]),this.addNamespaces(t);var u=i(this.data,l)||{};r?s(u,n,a):u=b["extends"]({},u,n),o(this.data,l,u),this.emit("added",e,t,n)},t.prototype.removeResourceBundle=function(e,t){this.hasResourceBundle(e,t)&&delete this.data[e][t],this.removeNamespaces(t),this.emit("removed",e,t)},t.prototype.hasResourceBundle=function(e,t){return void 0!==this.getResource(e,t)},t.prototype.getResourceBundle=function(e,t){return t||(t=this.options.defaultNS),"v1"===this.options.compatibilityAPI?b["extends"]({},this.getResource(e,t)):this.getResource(e,t)},t.prototype.toJSON=function(){return this.data},t}(S),N={processors:{},addPostProcessor:function(e){this.processors[e.name]=e},handle:function(e,t,n,o,r){var i=this;return e.forEach(function(e){i.processors[e]&&(t=i.processors[e].process(t,n,o,r))}),t}},C=function(e){function n(o){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];b.classCallCheck(this,n);var i=b.possibleConstructorReturn(this,e.call(this));return t(["resourceStore","languageUtils","pluralResolver","interpolator","backendConnector"],o,i),i.options=r,i.logger=k.create("translator"),i}return b.inherits(n,e),n.prototype.changeLanguage=function(e){e&&(this.language=e)},n.prototype.exists=function(e){var t=arguments.length<=1||void 0===arguments[1]?{interpolation:{}}:arguments[1];return"v1"===this.options.compatibilityAPI&&(t=f(t)),void 0!==this.resolve(e,t)},n.prototype.extractFromKey=function(e,t){var n=t.nsSeparator||this.options.nsSeparator;void 0===n&&(n=":");var o=t.ns||this.options.defaultNS;if(n&&e.indexOf(n)>-1){var r=e.split(n);o=r[0],e=r[1]}return"string"==typeof o&&(o=[o]),{key:e,namespaces:o}},n.prototype.translate=function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if("object"!==("undefined"==typeof t?"undefined":b["typeof"](t))?t=this.options.overloadTranslationOptionHandler(arguments):"v1"===this.options.compatibilityAPI&&(t=f(t)),void 0===e||null===e||""===e)return"";"number"==typeof e&&(e=String(e)),"string"==typeof e&&(e=[e]);var n=t.lng||this.language;if(n&&"cimode"===n.toLowerCase())return e[e.length-1];var o=t.keySeparator||this.options.keySeparator||".",r=this.extractFromKey(e[e.length-1],t),i=r.key,s=r.namespaces,a=s[s.length-1],l=this.resolve(e,t),u=Object.prototype.toString.apply(l),c=["[object Number]","[object Function]","[object RegExp]"],p=void 0!==t.joinArrays?t.joinArrays:this.options.joinArrays;if(l&&"string"!=typeof l&&c.indexOf(u)<0&&(!p||"[object Array]"!==u)){if(!t.returnObjects&&!this.options.returnObjects)return this.logger.warn("accessing an object - but returnObjects options is not enabled!"),this.options.returnedObjectHandler?this.options.returnedObjectHandler(i,l,t):"key '"+i+" ("+this.language+")' returned an object instead of string.";var h="[object Array]"===u?[]:{};for(var g in l)h[g]=this.translate(""+i+o+g,b["extends"]({joinArrays:!1,ns:s},t));l=h}else if(p&&"[object Array]"===u)l=l.join(p),l&&(l=this.extendTranslation(l,i,t));else{var d=!1,y=!1;if(!this.isValidLookup(l)&&t.defaultValue&&(d=!0,l=t.defaultValue),this.isValidLookup(l)||(y=!0,l=i),(y||d)&&(this.logger.log("missingKey",n,a,i,l),this.options.saveMissing)){var v=[];if("fallback"===this.options.saveMissingTo&&this.options.fallbackLng&&this.options.fallbackLng[0])for(var m=0;m<this.options.fallbackLng.length;m++)v.push(this.options.fallbackLng[m]);else"all"===this.options.saveMissingTo?v=this.languageUtils.toResolveHierarchy(t.lng||this.language):v.push(t.lng||this.language);this.options.missingKeyHandler?this.options.missingKeyHandler(v,a,i,l):this.backendConnector&&this.backendConnector.saveMissing&&this.backendConnector.saveMissing(v,a,i,l),this.emit("missingKey",v,a,i,l)}l=this.extendTranslation(l,i,t),y&&l===i&&this.options.appendNamespaceToMissingKey&&(l=a+":"+i),y&&this.options.parseMissingKeyHandler&&(l=this.options.parseMissingKeyHandler(l))}return l},n.prototype.extendTranslation=function(e,t,n){var o=this;n.interpolation&&this.interpolator.init(n);var r=n.replace&&"string"!=typeof n.replace?n.replace:n;this.options.interpolation.defaultVariables&&(r=b["extends"]({},this.options.interpolation.defaultVariables,r)),e=this.interpolator.interpolate(e,r),e=this.interpolator.nest(e,function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];return o.translate.apply(o,t)},n),n.interpolation&&this.interpolator.reset();var i=n.postProcess||this.options.postProcess,s="string"==typeof i?[i]:i;return void 0!==e&&s&&s.length&&n.applyPostProcessor!==!1&&(e=N.handle(s,e,t,n,this)),e},n.prototype.resolve=function(e){var t=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],o=void 0;return"string"==typeof e&&(e=[e]),e.forEach(function(e){if(!t.isValidLookup(o)){var r=t.extractFromKey(e,n),i=r.key,s=r.namespaces;t.options.fallbackNS&&(s=s.concat(t.options.fallbackNS));var a=void 0!==n.count&&"string"!=typeof n.count,l=void 0!==n.context&&"string"==typeof n.context&&""!==n.context,u=n.lngs?n.lngs:t.languageUtils.toResolveHierarchy(n.lng||t.language);s.forEach(function(e){t.isValidLookup(o)||u.forEach(function(r){if(!t.isValidLookup(o)){var s=i,u=[s],c=void 0;a&&(c=t.pluralResolver.getSuffix(r,n.count)),a&&l&&u.push(s+c),l&&u.push(s+=""+t.options.contextSeparator+n.context),a&&u.push(s+=c);for(var p=void 0;p=u.pop();)t.isValidLookup(o)||(o=t.getResource(r,e,p,n))}})})}}),o},n.prototype.isValidLookup=function(e){return!(void 0===e||!this.options.returnNull&&null===e||!this.options.returnEmptyString&&""===e)},n.prototype.getResource=function(e,t,n){var o=arguments.length<=3||void 0===arguments[3]?{}:arguments[3];return this.resourceStore.getResource(e,t,n,o)},n}(S),O=function(){function e(t){b.classCallCheck(this,e),this.options=t,this.whitelist=this.options.whitelist||!1,this.logger=k.create("languageUtils")}return e.prototype.getLanguagePartFromCode=function(e){if(e.indexOf("-")<0)return e;var t=["nb-NO","nn-NO","nb-no","nn-no"],n=e.split("-");return this.formatLanguageCode(t.indexOf(e)>-1?n[1].toLowerCase():n[0])},e.prototype.formatLanguageCode=function(e){if("string"==typeof e&&e.indexOf("-")>-1){var t=e.split("-"),n=b.slicedToArray(t,2),o=n[0],r=n[1];return this.options.lowerCaseLng?o.toLowerCase()+"-"+r.toLowerCase():o.toLowerCase()+"-"+r.toUpperCase()}return this.options.cleanCode||this.options.lowerCaseLng?e.toLowerCase():e},e.prototype.isWhitelisted=function(e){return"languageOnly"===this.options.load&&(e=this.getLanguagePartFromCode(e)),!this.whitelist||!this.whitelist.length||this.whitelist.indexOf(e)>-1},e.prototype.toResolveHierarchy=function(e,t){var n=this;t=t||this.options.fallbackLng||[],"string"==typeof t&&(t=[t]);var o=[],r=function(e){n.isWhitelisted(e)?o.push(e):n.logger.warn("rejecting non-whitelisted language code: "+e)};return"string"==typeof e&&e.indexOf("-")>-1?("languageOnly"!==this.options.load&&r(this.formatLanguageCode(e)),"currentOnly"!==this.options.load&&r(this.getLanguagePartFromCode(e))):"string"==typeof e&&r(this.formatLanguageCode(e)),t.forEach(function(e){o.indexOf(e)<0&&r(n.formatLanguageCode(e))}),o},e}(),R=[{lngs:["ach","ak","am","arn","br","fil","gun","ln","mfe","mg","mi","oc","tg","ti","tr","uz","wa"],nr:[1,2],fc:1},{lngs:["af","an","ast","az","bg","bn","ca","da","de","dev","el","en","eo","es","es_ar","et","eu","fi","fo","fur","fy","gl","gu","ha","he","hi","hu","hy","ia","it","kn","ku","lb","mai","ml","mn","mr","nah","nap","nb","ne","nl","nn","no","nso","pa","pap","pms","ps","pt","pt_br","rm","sco","se","si","so","son","sq","sv","sw","ta","te","tk","ur","yo"],nr:[1,2],fc:2},{lngs:["ay","bo","cgg","fa","id","ja","jbo","ka","kk","km","ko","ky","lo","ms","sah","su","th","tt","ug","vi","wo","zh"],nr:[1],fc:3},{lngs:["be","bs","dz","hr","ru","sr","uk"],nr:[1,2,5],fc:4},{lngs:["ar"],nr:[0,1,2,3,11,100],fc:5},{lngs:["cs","sk"],nr:[1,2,5],fc:6},{lngs:["csb","pl"],nr:[1,2,5],fc:7},{lngs:["cy"],nr:[1,2,3,8],fc:8},{lngs:["fr"],nr:[1,2],fc:9},{lngs:["ga"],nr:[1,2,3,7,11],fc:10},{lngs:["gd"],nr:[1,2,3,20],fc:11},{lngs:["is"],nr:[1,2],fc:12},{lngs:["jv"],nr:[0,1],fc:13},{lngs:["kw"],nr:[1,2,3,4],fc:14},{lngs:["lt"],nr:[1,2,10],fc:15},{lngs:["lv"],nr:[1,2,0],fc:16},{lngs:["mk"],nr:[1,2],fc:17},{lngs:["mnk"],nr:[0,1,2],fc:18},{lngs:["mt"],nr:[1,2,11,20],fc:19},{lngs:["or"],nr:[2,1],fc:2},{lngs:["ro"],nr:[1,2,20],fc:20},{lngs:["sl"],nr:[5,1,2,3],fc:21}],j={1:function(e){return Number(e>1)},2:function(e){return Number(1!=e)},3:function(e){return 0},4:function(e){return Number(e%10==1&&e%100!=11?0:e%10>=2&&4>=e%10&&(10>e%100||e%100>=20)?1:2)},5:function(e){return Number(0===e?0:1==e?1:2==e?2:e%100>=3&&10>=e%100?3:e%100>=11?4:5)},6:function(e){return Number(1==e?0:e>=2&&4>=e?1:2)},7:function(e){return Number(1==e?0:e%10>=2&&4>=e%10&&(10>e%100||e%100>=20)?1:2)},8:function(e){return Number(1==e?0:2==e?1:8!=e&&11!=e?2:3)},9:function(e){return Number(e>=2)},10:function(e){return Number(1==e?0:2==e?1:7>e?2:11>e?3:4)},11:function(e){return Number(1==e||11==e?0:2==e||12==e?1:e>2&&20>e?2:3)},12:function(e){return Number(e%10!=1||e%100==11)},13:function(e){return Number(0!==e)},14:function(e){return Number(1==e?0:2==e?1:3==e?2:3)},15:function(e){return Number(e%10==1&&e%100!=11?0:e%10>=2&&(10>e%100||e%100>=20)?1:2)},16:function(e){return Number(e%10==1&&e%100!=11?0:0!==e?1:2)},17:function(e){return Number(1==e||e%10==1?0:1)},18:function(e){return Number(0==e?0:1==e?1:2)},19:function(e){return Number(1==e?0:0===e||e%100>1&&11>e%100?1:e%100>10&&20>e%100?2:3)},20:function(e){return Number(1==e?0:0===e||e%100>0&&20>e%100?1:2)},21:function(e){return Number(e%100==1?1:e%100==2?2:e%100==3||e%100==4?3:0)}},P=function(){function e(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];b.classCallCheck(this,e),this.languageUtils=t,this.options=n,this.logger=k.create("pluralResolver"),this.rules=g()}return e.prototype.addRule=function(e,t){this.rules[e]=t},e.prototype.getRule=function(e){return this.rules[this.languageUtils.getLanguagePartFromCode(e)]},e.prototype.needsPlural=function(e){var t=this.getRule(e);return!(t&&t.numbers.length<=1)},e.prototype.getSuffix=function(e,t){var n=this.getRule(e);if(n){if(1===n.numbers.length)return"";var o=n.noAbs?n.plurals(t):n.plurals(Math.abs(t)),r=n.numbers[o];if(2===n.numbers.length&&1===n.numbers[0]&&(2===r?r="plural":1===r&&(r="")),"v1"===this.options.compatibilityJSON){if(1===r)return"";if("number"==typeof r)return"_plural_"+r.toString()}return this.options.prepend&&r.toString()?this.options.prepend+r.toString():r.toString()}return this.logger.warn("no plural rule found for: "+e),""},e}(),E=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];b.classCallCheck(this,t),this.logger=k.create("interpolator"),this.init(e,!0)}return t.prototype.init=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=arguments[1];t&&(this.options=e),e.interpolation||(e.interpolation={escapeValue:!0});var n=e.interpolation;this.escapeValue=n.escapeValue,this.prefix=n.prefix?a(n.prefix):n.prefixEscaped||"{{",this.suffix=n.suffix?a(n.suffix):n.suffixEscaped||"}}",this.unescapePrefix=n.unescapeSuffix?"":n.unescapePrefix||"-",this.unescapeSuffix=this.unescapePrefix?"":n.unescapeSuffix||"",this.nestingPrefix=n.nestingPrefix?a(n.nestingPrefix):n.nestingPrefixEscaped||a("$t("),this.nestingSuffix=n.nestingSuffix?a(n.nestingSuffix):n.nestingSuffixEscaped||a(")");var o=this.prefix+"(.+?)"+this.suffix;this.regexp=new RegExp(o,"g");var r=this.prefix+this.unescapePrefix+"(.+?)"+this.unescapeSuffix+this.suffix;this.regexpUnescape=new RegExp(r,"g");var i=this.nestingPrefix+"(.+?)"+this.nestingSuffix;this.nestingRegexp=new RegExp(i,"g")},t.prototype.reset=function(){this.options&&this.init(this.options)},t.prototype.interpolate=function(t,n){function o(e){return e.replace(/\$/g,"$$$$")}for(var r=void 0,s=void 0;r=this.regexpUnescape.exec(t);){var a=i(n,r[1].trim());t=t.replace(r[0],a)}for(;r=this.regexp.exec(t);)s=i(n,r[1].trim()),"string"!=typeof s&&(s=e(s)),s||(this.logger.warn("missed to pass in variable "+r[1]+" for interpolating "+t),s=""),s=o(this.escapeValue?l(s):s),t=t.replace(r[0],s),this.regexp.lastIndex=0;return t},t.prototype.nest=function(t,n){function o(e){return e.replace(/\$/g,"$$$$")}function r(e){if(e.indexOf(",")<0)return e;var t=e.split(",");e=t.shift();var n=t.join(",");n=this.interpolate(n,u);try{u=JSON.parse(n)}catch(o){this.logger.error("failed parsing options string in nesting for key "+e,o)}return e}var i=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],s=void 0,a=void 0,u=JSON.parse(JSON.stringify(i));for(u.applyPostProcessor=!1;s=this.nestingRegexp.exec(t);)a=n(r.call(this,s[1].trim()),u),"string"!=typeof a&&(a=e(a)),a||(this.logger.warn("missed to pass in variable "+s[1]+" for interpolating "+t),a=""),a=o(this.escapeValue?l(a):a),t=t.replace(s[0],a),this.regexp.lastIndex=0;return t},t}(),_=function(e){function t(n,o,r){var i=arguments.length<=3||void 0===arguments[3]?{}:arguments[3];b.classCallCheck(this,t);var s=b.possibleConstructorReturn(this,e.call(this));return s.backend=n,s.store=o,s.services=r,s.options=i,s.logger=k.create("backendConnector"),s.state={},s.queue=[],s.backend&&s.backend.init&&s.backend.init(r,i.backend,i),s}return b.inherits(t,e),t.prototype.queueLoad=function(e,t,n){var o=this,r=[],i=[],s=[],a=[];return e.forEach(function(e){var n=!0;t.forEach(function(t){var s=e+"|"+t;o.store.hasResourceBundle(e,t)?o.state[s]=2:o.state[s]<0||(1===o.state[s]?i.indexOf(s)<0&&i.push(s):(o.state[s]=1,n=!1,i.indexOf(s)<0&&i.push(s),r.indexOf(s)<0&&r.push(s),a.indexOf(t)<0&&a.push(t)))}),n||s.push(e)}),(r.length||i.length)&&this.queue.push({pending:i,loaded:{},errors:[],callback:n}),{toLoad:r,pending:i,toLoadLanguages:s,toLoadNamespaces:a}},t.prototype.loaded=function(e,t,n){var o=this,i=e.split("|"),s=b.slicedToArray(i,2),a=s[0],l=s[1];t&&this.emit("failedLoading",a,l,t),n&&this.store.addResourceBundle(a,l,n),this.state[e]=t?-1:2,this.queue.forEach(function(n){r(n.loaded,[a],l),d(n.pending,e),t&&n.errors.push(t),0!==n.pending.length||n.done||(n.errors.length?n.callback(n.errors):n.callback(),o.emit("loaded",n.loaded),n.done=!0)}),this.queue=this.queue.filter(function(e){return!e.done})},t.prototype.read=function(e,t,n,o,r,i){var s=this;return o||(o=0),r||(r=250),e.length?void this.backend[n](e,t,function(a,l){return a&&l&&5>o?void setTimeout(function(){s.read.call(s,e,t,n,++o,2*r,i)},r):void i(a,l)}):i(null,{})},t.prototype.load=function(e,t,n){var o=this;if(!this.backend)return this.logger.warn("No backend was added via i18next.use. Will not load resources."),n&&n();var r=b["extends"]({},this.backend.options,this.options.backend);"string"==typeof e&&(e=this.services.languageUtils.toResolveHierarchy(e)),"string"==typeof t&&(t=[t]);var s=this.queueLoad(e,t,n);return s.toLoad.length?void(r.allowMultiLoading&&this.backend.readMulti?this.read(s.toLoadLanguages,s.toLoadNamespaces,"readMulti",null,null,function(e,t){e&&o.logger.warn("loading namespaces "+s.toLoadNamespaces.join(", ")+" for languages "+s.toLoadLanguages.join(", ")+" via multiloading failed",e),!e&&t&&o.logger.log("loaded namespaces "+s.toLoadNamespaces.join(", ")+" for languages "+s.toLoadLanguages.join(", ")+" via multiloading",t),s.toLoad.forEach(function(n){var r=n.split("|"),s=b.slicedToArray(r,2),a=s[0],l=s[1],u=i(t,[a,l]);if(u)o.loaded(n,e,u);else{var c="loading namespace "+l+" for language "+a+" via multiloading failed";o.loaded(n,c),o.logger.error(c)}})}):!function(){var e=function(e){var t=this,n=e.split("|"),o=b.slicedToArray(n,2),r=o[0],i=o[1];this.read(r,i,"read",null,null,function(n,o){n&&t.logger.warn("loading namespace "+i+" for language "+r+" failed",n),!n&&o&&t.logger.log("loaded namespace "+i+" for language "+r,o),t.loaded(e,n,o)})};s.toLoad.forEach(function(t){e.call(o,t)})}()):void(s.pending.length||n())},t.prototype.saveMissing=function(e,t,n,o){this.backend&&this.backend.create&&this.backend.create(e,t,n,o),this.store.addResource(e[0],t,n,o)},t}(S),T=function(e){function t(n,o,r){var i=arguments.length<=3||void 0===arguments[3]?{}:arguments[3];b.classCallCheck(this,t);var s=b.possibleConstructorReturn(this,e.call(this));return s.cache=n,s.store=o,s.services=r,s.options=i,s.logger=k.create("cacheConnector"),s.cache&&s.cache.init&&s.cache.init(r,i.cache,i),s}return b.inherits(t,e),t.prototype.load=function(e,t,n){var o=this;if(!this.cache)return n&&n();var r=b["extends"]({},this.cache.options,this.options.cache);"string"==typeof e&&(e=this.services.languageUtils.toResolveHierarchy(e)),"string"==typeof t&&(t=[t]),r.enabled?this.cache.load(e,function(t,r){if(t&&o.logger.error("loading languages "+e.join(", ")+" from cache failed",t),r)for(var i in r)for(var s in r[i])if("i18nStamp"!==s){var a=r[i][s];a&&o.store.addResourceBundle(i,s,a)}n&&n()}):n&&n()},t.prototype.save=function(){this.cache&&this.options.cache&&this.options.cache.enabled&&this.cache.save(this.store.data)},t}(S),A=function(e){function t(){var n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],o=arguments[1];b.classCallCheck(this,t);var r=b.possibleConstructorReturn(this,e.call(this));return r.options=v(n),r.services={},r.logger=k,r.modules={},o&&!r.isInitialized&&r.init(n,o),r}return b.inherits(t,e),t.prototype.init=function(e,t){function n(e){return e?"function"==typeof e?new e:e:void 0}var o=this;if("function"==typeof e&&(t=e,e={}),e||(e={}),"v1"===e.compatibilityAPI?this.options=b["extends"]({},y(),v(c(e)),{}):"v1"===e.compatibilityJSON?this.options=b["extends"]({},y(),v(p(e)),{}):this.options=b["extends"]({},y(),this.options,v(e)),t||(t=function(){}),!this.options.isClone){this.modules.logger?k.init(n(this.modules.logger),this.options):k.init(null,this.options);var r=new O(this.options);this.store=new L(this.options.resources,this.options);var i=this.services;i.logger=k,i.resourceStore=this.store,i.resourceStore.on("added removed",function(e,t){i.cacheConnector.save()}),i.languageUtils=r,i.pluralResolver=new P(r,{prepend:this.options.pluralSeparator,compatibilityJSON:this.options.compatibilityJSON}),i.interpolator=new E(this.options),i.backendConnector=new _(n(this.modules.backend),i.resourceStore,i,this.options),i.backendConnector.on("*",function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];o.emit.apply(o,[e].concat(n))}),i.backendConnector.on("loaded",function(e){i.cacheConnector.save()}),i.cacheConnector=new T(n(this.modules.cache),i.resourceStore,i,this.options),i.cacheConnector.on("*",function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];o.emit.apply(o,[e].concat(n))}),this.modules.languageDetector&&(i.languageDetector=n(this.modules.languageDetector),i.languageDetector.init(i,this.options.detection,this.options)),this.translator=new C(this.services,this.options),this.translator.on("*",function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];o.emit.apply(o,[e].concat(n))})}var s=["getResource","addResource","addResources","addResourceBundle","removeResourceBundle","hasResourceBundle","getResourceBundle"];return s.forEach(function(e){o[e]=function(){return this.store[e].apply(this.store,arguments)}}),"v1"===this.options.compatibilityAPI&&h(this),this.changeLanguage(this.options.lng,function(e,n){o.emit("initialized",o.options),o.logger.log("initialized",o.options),t(e,n)}),this},t.prototype.loadResources=function(e){var t=this;if(e||(e=function(){}),this.options.resources)e(null);else{var n=function(){if(t.language&&"cimode"===t.language.toLowerCase())return{v:e()};var n=[],o=function(e){var o=t.services.languageUtils.toResolveHierarchy(e);o.forEach(function(e){n.indexOf(e)<0&&n.push(e)})};o(t.language),t.options.preload&&t.options.preload.forEach(function(e){o(e)}),t.services.cacheConnector.load(n,t.options.ns,function(){t.services.backendConnector.load(n,t.options.ns,e)})}();if("object"===("undefined"==typeof n?"undefined":b["typeof"](n)))return n.v}},t.prototype.use=function(e){return"backend"===e.type&&(this.modules.backend=e),"cache"===e.type&&(this.modules.cache=e),("logger"===e.type||e.log&&e.warn&&e.warn)&&(this.modules.logger=e),"languageDetector"===e.type&&(this.modules.languageDetector=e),"postProcessor"===e.type&&N.addPostProcessor(e),this},t.prototype.changeLanguage=function(e,t){var n=this,o=function(o){e&&(n.emit("languageChanged",e),n.logger.log("languageChanged",e)),t&&t(o,function(){for(var e=arguments.length,t=Array(e),o=0;e>o;o++)t[o]=arguments[o];return n.t.apply(n,t)})};!e&&this.services.languageDetector&&(e=this.services.languageDetector.detect()),e&&(this.language=e,this.languages=this.services.languageUtils.toResolveHierarchy(e),this.translator.changeLanguage(e),this.services.languageDetector&&this.services.languageDetector.cacheUserLanguage(e)),this.loadResources(function(e){o(e)})},t.prototype.getFixedT=function(e,t){var n=this,o=function r(e,t){return t=t||{},t.lng=t.lng||r.lng,t.ns=t.ns||r.ns,n.t(e,t)};return o.lng=e,o.ns=t,o},t.prototype.t=function(){return this.translator&&this.translator.translate.apply(this.translator,arguments)},t.prototype.exists=function(){return this.translator&&this.translator.exists.apply(this.translator,arguments)},t.prototype.setDefaultNamespace=function(e){this.options.defaultNS=e},t.prototype.loadNamespaces=function(e,t){var n=this;return this.options.ns?("string"==typeof e&&(e=[e]),e.forEach(function(e){n.options.ns.indexOf(e)<0&&n.options.ns.push(e)}),void this.loadResources(t)):t&&t()},t.prototype.loadLanguages=function(e,t){"string"==typeof e&&(e=[e]),this.options.preload=this.options.preload?this.options.preload.concat(e):e,this.loadResources(t)},t.prototype.dir=function(e){e||(e=this.language);var t=["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","ur","ydd","yds","yih","ji","yi","hbo","men","xmn","fa","jpr","peo","pes","prs","dv","sam"];return t.indexOf(this.services.languageUtils.getLanguagePartFromCode(e))?"ltr":"rtl"},t.prototype.createInstance=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=arguments[1]; | ||
return new t(e,n)},t.prototype.cloneInstance=function(){var e=this,n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],o=arguments[1],r=new t(b["extends"]({},n,this.options,{isClone:!0}),o),i=["store","translator","services","language"];return i.forEach(function(t){r[t]=e[t]}),r},t}(S),M=new A;return M}); |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define("i18next",t):e.i18next=t()}(this,function(){"use strict";function e(e){return null==e?"":""+e}function t(e,t,n){e.forEach(function(e){t[e]&&(n[e]=t[e])})}function n(e,t,n){function i(e){return e&&e.indexOf("###")>-1?e.replace(/###/g,"."):e}for(var r="string"!=typeof t?[].concat(t):t.split(".");r.length>1;){if(!e)return{};var o=i(r.shift());!e[o]&&n&&(e[o]=new n),e=e[o]}return e?{obj:e,k:i(r.shift())}:{}}function i(e,t,i){var r=n(e,t,Object),o=r.obj,s=r.k;o[s]=i}function r(e,t,i,r){var o=n(e,t,Object),s=o.obj,a=o.k;s[a]=s[a]||[],r&&(s[a]=s[a].concat(i)),r||s[a].push(i)}function o(e,t){var i=n(e,t),r=i.obj,o=i.k;return r?r[o]:void 0}function s(e,t,n){for(var i in t)i in e?"string"==typeof e[i]||e[i]instanceof String||"string"==typeof t[i]||t[i]instanceof String?n&&(e[i]=t[i]):s(e[i],t[i],n):e[i]=t[i];return e}function a(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function l(e){return"string"==typeof e?e.replace(/[&<>"'\/]/g,function(e){return S[e]}):e}function u(e){return e.interpolation={unescapeSuffix:"HTML"},e.interpolation.prefix=e.interpolationPrefix||"__",e.interpolation.suffix=e.interpolationSuffix||"__",e.interpolation.escapeValue=e.escapeInterpolation||!1,e.interpolation.nestingPrefix=e.reusePrefix||"$t(",e.interpolation.nestingSuffix=e.reuseSuffix||")",e}function c(e){return e.resStore&&(e.resources=e.resStore),e.ns&&e.ns.defaultNs?(e.defaultNS=e.ns.defaultNs,e.ns=e.ns.namespaces):e.defaultNS=e.ns||"translation",e.fallbackToDefaultNS&&e.defaultNS&&(e.fallbackNS=e.defaultNS),e.saveMissing=e.sendMissing,e.saveMissingTo=e.sendMissingTo||"current",e.returnNull=!e.fallbackOnNull,e.returnEmptyString=!e.fallbackOnEmpty,e.returnObjects=e.returnObjectTrees,e.joinArrays="\n",e.returnedObjectHandler=e.objectTreeKeyHandler,e.parseMissingKeyHandler=e.parseMissingKey,e.appendNamespaceToMissingKey=!0,e.nsSeparator=e.nsseparator,e.keySeparator=e.keyseparator,"sprintf"===e.shortcutFunction&&(e.overloadTranslationOptionHandler=function(e){for(var t=[],n=1;n<e.length;n++)t.push(e[n]);return{postProcess:"sprintf",sprintf:t}}),e.whitelist=e.lngWhitelist,e.preload=e.preload,"current"===e.load&&(e.load="currentOnly"),"unspecific"===e.load&&(e.load="languageOnly"),e.backend=e.backend||{},e.backend.loadPath=e.resGetPath||"locales/__lng__/__ns__.json",e.backend.addPath=e.resPostPath||"locales/add/__lng__/__ns__",e.backend.allowMultiLoading=e.dynamicLoad,e.cache=e.cache||{},e.cache.prefix="res_",e.cache.expirationTime=6048e5,e.cache.enabled=!!e.useLocalStorage,e=u(e),e.defaultVariables&&(e.interpolation.defaultVariables=e.defaultVariables),e}function f(e){return e=u(e),e.joinArrays="\n",e}function p(e){return(e.interpolationPrefix||e.interpolationSuffix||e.escapeInterpolation)&&(e=u(e)),e.nsSeparator=e.nsseparator,e.keySeparator=e.keyseparator,e.returnObjects=e.returnObjectTrees,e}function h(e){e.lng=function(){return k.deprecate("i18next.lng() can be replaced by i18next.language for detected language or i18next.languages for languages ordered by translation lookup."),e.services.languageUtils.toResolveHierarchy(e.language)[0]},e.preload=function(t,n){k.deprecate("i18next.preload() can be replaced with i18next.loadLanguages()"),e.loadLanguages(t,n)},e.setLng=function(t,n,i){return k.deprecate("i18next.setLng() can be replaced with i18next.changeLanguage() or i18next.getFixedT() to get a translation function with fixed language or namespace."),"function"==typeof n&&(i=n,n={}),n||(n={}),n.fixLng===!0&&i?i(null,e.getFixedT(t)):void e.changeLanguage(t,i)},e.addPostProcessor=function(t,n){k.deprecate("i18next.addPostProcessor() can be replaced by i18next.use({ type: 'postProcessor', name: 'name', process: fc })"),e.use({type:"postProcessor",name:t,process:n})}}function g(e,t){for(var n=e.indexOf(t);-1!==n;)e.splice(n,1),n=e.indexOf(t)}function d(){return{debug:!1,ns:["translation"],defaultNS:["translation"],fallbackLng:["dev"],fallbackNS:!1,whitelist:!1,load:"all",preload:!1,keySeparator:".",nsSeparator:":",pluralSeparator:"_",contextSeparator:"_",saveMissing:!1,saveMissingTo:"fallback",missingKeyHandler:!1,postProcess:!1,returnNull:!0,returnEmptyString:!0,returnObjects:!1,joinArrays:!1,returnedObjectHandler:function(){},parseMissingKeyHandler:!1,appendNamespaceToMissingKey:!1,overloadTranslationOptionHandler:function(e){return{defaultValue:e[1]}},interpolation:{escapeValue:!0,prefix:"{{",suffix:"}}",unescapePrefix:"-",nestingPrefix:"$t(",nestingSuffix:")",defaultVariables:void 0}}}function v(e){return"string"==typeof e.ns&&(e.ns=[e.ns]),"string"==typeof e.fallbackLng&&(e.fallbackLng=[e.fallbackLng]),"string"==typeof e.fallbackNS&&(e.fallbackNS=[e.fallbackNS]),e.whitelist&&e.whitelist.indexOf("cimode")<0&&e.whitelist.push("cimode"),e}var y={};y["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},y.classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},y.createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),y["extends"]=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},y.inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},y.possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},y.slicedToArray=function(){function e(e,t){var n=[],i=!0,r=!1,o=void 0;try{for(var s,a=e[Symbol.iterator]();!(i=(s=a.next()).done)&&(n.push(s.value),!t||n.length!==t);i=!0);}catch(l){r=!0,o=l}finally{try{!i&&a["return"]&&a["return"]()}finally{if(r)throw o}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();var b={type:"logger",log:function(e){this._output("log",e)},warn:function(e){this._output("warn",e)},error:function(e){this._output("error",e)},_output:function(e,t){console&&console[e]&&console[e].apply(console,Array.prototype.slice.call(t))}},m=function(){function e(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];y.classCallCheck(this,e),this.subs=[],this.init(t,n)}return y.createClass(e,[{key:"init",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.prefix=t.prefix||"i18next:",this.logger=e||b,this.options=t,this.debug=t.debug!==!1}},{key:"setDebug",value:function(e){this.debug=e,this.subs.forEach(function(t){t.setDebug(e)})}},{key:"log",value:function(){this.forward(arguments,"log","",!0)}},{key:"warn",value:function(){this.forward(arguments,"warn","",!0)}},{key:"error",value:function(){this.forward(arguments,"error","")}},{key:"deprecate",value:function(){this.forward(arguments,"warn","WARNING DEPRECATED: ",!0)}},{key:"forward",value:function(e,t,n,i){i&&!this.debug||("string"==typeof e[0]&&(e[0]=n+this.prefix+" "+e[0]),this.logger[t](e))}},{key:"create",value:function(t){var n=new e(this.logger,y["extends"]({prefix:this.prefix+":"+t+":"},this.options));return this.subs.push(n),n}}]),e}(),k=new m,x=function(){function e(){y.classCallCheck(this,e),this.observers={}}return y.createClass(e,[{key:"on",value:function(e,t){var n=this;e.split(" ").forEach(function(e){n.observers[e]=n.observers[e]||[],n.observers[e].push(t)})}},{key:"off",value:function(e,t){var n=this;this.observers[e]&&this.observers[e].forEach(function(){if(t){var i=n.observers[e].indexOf(t);i>-1&&n.observers[e].splice(i,1)}else delete n.observers[e]})}},{key:"emit",value:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),i=1;t>i;i++)n[i-1]=arguments[i];this.observers[e]&&this.observers[e].forEach(function(e){e.apply(void 0,n)}),this.observers["*"]&&this.observers["*"].forEach(function(t){var i;t.apply(t,(i=[e]).concat.apply(i,n))})}}]),e}(),S={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},w=function(e){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=arguments.length<=1||void 0===arguments[1]?{ns:["translation"],defaultNS:"translation"}:arguments[1];y.classCallCheck(this,t);var i=y.possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this));return i.data=e,i.options=n,i}return y.inherits(t,e),y.createClass(t,[{key:"addNamespaces",value:function(e){this.options.ns.indexOf(e)<0&&this.options.ns.push(e)}},{key:"removeNamespaces",value:function(e){var t=this.options.ns.indexOf(e);t>-1&&this.options.ns.splice(t,1)}},{key:"getResource",value:function(e,t,n){var i=arguments.length<=3||void 0===arguments[3]?{}:arguments[3],r=i.keySeparator||this.options.keySeparator;void 0===r&&(r=".");var s=[e,t];return n&&"string"!=typeof n&&(s=s.concat(n)),n&&"string"==typeof n&&(s=s.concat(r?n.split(r):n)),e.indexOf(".")>-1&&(s=e.split(".")),o(this.data,s)}},{key:"addResource",value:function(e,t,n,r){var o=arguments.length<=4||void 0===arguments[4]?{silent:!1}:arguments[4],s=this.options.keySeparator;void 0===s&&(s=".");var a=[e,t];n&&(a=a.concat(s?n.split(s):n)),e.indexOf(".")>-1&&(a=e.split("."),r=t,t=a[1]),this.addNamespaces(t),i(this.data,a,r),o.silent||this.emit("added",e,t,n,r)}},{key:"addResources",value:function(e,t,n){for(var i in n)"string"==typeof n[i]&&this.addResource(e,t,i,n[i],{silent:!0});this.emit("added",e,t,n)}},{key:"addResourceBundle",value:function(e,t,n,r,a){var l=[e,t];e.indexOf(".")>-1&&(l=e.split("."),r=n,n=t,t=l[1]),this.addNamespaces(t);var u=o(this.data,l)||{};r?s(u,n,a):u=y["extends"]({},u,n),i(this.data,l,u),this.emit("added",e,t,n)}},{key:"removeResourceBundle",value:function(e,t){this.hasResourceBundle(e,t)&&delete this.data[e][t],this.removeNamespaces(t),this.emit("removed",e,t)}},{key:"hasResourceBundle",value:function(e,t){return void 0!==this.getResource(e,t)}},{key:"getResourceBundle",value:function(e,t){return t||(t=this.options.defaultNS),"v1"===this.options.compatibilityAPI?y["extends"]({},this.getResource(e,t)):this.getResource(e,t)}},{key:"toJSON",value:function(){return this.data}}]),t}(x),C={processors:{},addPostProcessor:function(e){this.processors[e.name]=e},handle:function(e,t,n,i,r){var o=this;return e.forEach(function(e){o.processors[e]&&(t=o.processors[e].process(t,n,i,r))}),t}},O=function(e){function n(e){var i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];y.classCallCheck(this,n);var r=y.possibleConstructorReturn(this,Object.getPrototypeOf(n).call(this));return t(["resourceStore","languageUtils","pluralResolver","interpolator","backendConnector"],e,r),r.options=i,r.logger=k.create("translator"),r}return y.inherits(n,e),y.createClass(n,[{key:"changeLanguage",value:function(e){e&&(this.language=e)}},{key:"exists",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{interpolation:{}}:arguments[1];return"v1"===this.options.compatibilityAPI&&(t=p(t)),void 0!==this.resolve(e,t)}},{key:"extractFromKey",value:function(e,t){var n=t.nsSeparator||this.options.nsSeparator;void 0===n&&(n=":");var i=t.ns||this.options.defaultNS;if(n&&e.indexOf(n)>-1){var r=e.split(n);i=r[0],e=r[1]}return"string"==typeof i&&(i=[i]),{key:e,namespaces:i}}},{key:"translate",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if("object"!==("undefined"==typeof t?"undefined":y["typeof"](t))?t=this.options.overloadTranslationOptionHandler(arguments):"v1"===this.options.compatibilityAPI&&(t=p(t)),void 0===e||null===e||""===e)return"";"number"==typeof e&&(e=String(e)),"string"==typeof e&&(e=[e]);var n=t.lng||this.language;if(n&&"cimode"===n.toLowerCase())return e[e.length-1];var i=t.keySeparator||this.options.keySeparator||".",r=this.extractFromKey(e[e.length-1],t),o=r.key,s=r.namespaces,a=s[s.length-1],l=this.resolve(e,t),u=Object.prototype.toString.apply(l),c=["[object Number]","[object Function]","[object RegExp]"],f=void 0!==t.joinArrays?t.joinArrays:this.options.joinArrays;if(l&&"string"!=typeof l&&c.indexOf(u)<0&&(!f||"[object Array]"!==u)){if(!t.returnObjects&&!this.options.returnObjects)return this.logger.warn("accessing an object - but returnObjects options is not enabled!"),this.options.returnedObjectHandler?this.options.returnedObjectHandler(o,l,t):"key '"+o+" ("+this.language+")' returned an object instead of string.";var h="[object Array]"===u?[]:{};for(var g in l)h[g]=this.translate(""+o+i+g,y["extends"]({joinArrays:!1,ns:s},t));l=h}else if(f&&"[object Array]"===u)l=l.join(f),l&&(l=this.extendTranslation(l,o,t));else{var d=!1,v=!1;if(!this.isValidLookup(l)&&t.defaultValue&&(d=!0,l=t.defaultValue),this.isValidLookup(l)||(v=!0,l=o),(v||d)&&(this.logger.log("missingKey",n,a,o,l),this.options.saveMissing)){var b=[];if("fallback"===this.options.saveMissingTo&&this.options.fallbackLng&&this.options.fallbackLng[0])for(var m=0;m<this.options.fallbackLng.length;m++)b.push(this.options.fallbackLng[m]);else"all"===this.options.saveMissingTo?b=this.languageUtils.toResolveHierarchy(t.lng||this.language):b.push(t.lng||this.language);this.options.missingKeyHandler?this.options.missingKeyHandler(b,a,o,l):this.backendConnector&&this.backendConnector.saveMissing&&this.backendConnector.saveMissing(b,a,o,l),this.emit("missingKey",b,a,o,l)}l=this.extendTranslation(l,o,t),v&&l===o&&this.options.appendNamespaceToMissingKey&&(l=a+":"+o),v&&this.options.parseMissingKeyHandler&&(l=this.options.parseMissingKeyHandler(l))}return l}},{key:"extendTranslation",value:function(e,t,n){var i=this;n.interpolation&&this.interpolator.init(n);var r=n.replace&&"string"!=typeof n.replace?n.replace:n;this.options.interpolation.defaultVariables&&(r=y["extends"]({},this.options.interpolation.defaultVariables,r)),e=this.interpolator.interpolate(e,r),e=this.interpolator.nest(e,function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];return i.translate.apply(i,t)},n),n.interpolation&&this.interpolator.reset();var o=n.postProcess||this.options.postProcess,s="string"==typeof o?[o]:o;return void 0!==e&&s&&s.length&&n.applyPostProcessor!==!1&&(e=C.handle(s,e,t,n,this)),e}},{key:"resolve",value:function(e){var t=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=void 0;return"string"==typeof e&&(e=[e]),e.forEach(function(e){if(!t.isValidLookup(i)){var r=t.extractFromKey(e,n),o=r.key,s=r.namespaces;t.options.fallbackNS&&(s=s.concat(t.options.fallbackNS));var a=void 0!==n.count&&"string"!=typeof n.count,l=void 0!==n.context&&"string"==typeof n.context&&""!==n.context,u=n.lngs?n.lngs:t.languageUtils.toResolveHierarchy(n.lng||t.language);s.forEach(function(e){t.isValidLookup(i)||u.forEach(function(r){if(!t.isValidLookup(i)){var s=o,u=[s],c=void 0;a&&(c=t.pluralResolver.getSuffix(r,n.count)),a&&l&&u.push(s+c),l&&u.push(s+=""+t.options.contextSeparator+n.context),a&&u.push(s+=c);for(var f=void 0;f=u.pop();)t.isValidLookup(i)||(i=t.getResource(r,e,f,n))}})})}}),i}},{key:"isValidLookup",value:function(e){return!(void 0===e||!this.options.returnNull&&null===e||!this.options.returnEmptyString&&""===e)}},{key:"getResource",value:function(e,t,n){var i=arguments.length<=3||void 0===arguments[3]?{}:arguments[3];return this.resourceStore.getResource(e,t,n,i)}}]),n}(x),L=function(){function e(t){y.classCallCheck(this,e),this.options=t,this.whitelist=this.options.whitelist||!1,this.logger=k.create("languageUtils")}return y.createClass(e,[{key:"getLanguagePartFromCode",value:function(e){if(e.indexOf("-")<0)return e;var t=["nb-NO","nn-NO","nb-no","nn-no"],n=e.split("-");return this.formatLanguageCode(t.indexOf(e)>-1?n[1].toLowerCase():n[0])}},{key:"formatLanguageCode",value:function(e){if("string"==typeof e&&e.indexOf("-")>-1){var t=e.split("-"),n=y.slicedToArray(t,2),i=n[0],r=n[1];return this.options.lowerCaseLng?i.toLowerCase()+"-"+r.toLowerCase():i.toLowerCase()+"-"+r.toUpperCase()}return this.options.cleanCode||this.options.lowerCaseLng?e.toLowerCase():e}},{key:"isWhitelisted",value:function(e){return"languageOnly"===this.options.load&&(e=this.getLanguagePartFromCode(e)),!this.whitelist||!this.whitelist.length||this.whitelist.indexOf(e)>-1}},{key:"toResolveHierarchy",value:function(e,t){var n=this;t=t||this.options.fallbackLng||[],"string"==typeof t&&(t=[t]);var i=[],r=function(e){n.isWhitelisted(e)?i.push(e):n.logger.warn("rejecting non-whitelisted language code: "+e)};return"string"==typeof e&&e.indexOf("-")>-1?("languageOnly"!==this.options.load&&r(this.formatLanguageCode(e)),"currentOnly"!==this.options.load&&r(this.getLanguagePartFromCode(e))):"string"==typeof e&&r(this.formatLanguageCode(e)),t.forEach(function(e){i.indexOf(e)<0&&r(n.formatLanguageCode(e))}),i}}]),e}(),N=[{lngs:["ach","ak","am","arn","br","fil","gun","ln","mfe","mg","mi","oc","tg","ti","tr","uz","wa"],nr:[1,2],fc:1},{lngs:["af","an","ast","az","bg","bn","ca","da","de","dev","el","en","eo","es","es_ar","et","eu","fi","fo","fur","fy","gl","gu","ha","he","hi","hu","hy","ia","it","kn","ku","lb","mai","ml","mn","mr","nah","nap","nb","ne","nl","nn","no","nso","pa","pap","pms","ps","pt","pt_br","rm","sco","se","si","so","son","sq","sv","sw","ta","te","tk","ur","yo"],nr:[1,2],fc:2},{lngs:["ay","bo","cgg","fa","id","ja","jbo","ka","kk","km","ko","ky","lo","ms","sah","su","th","tt","ug","vi","wo","zh"],nr:[1],fc:3},{lngs:["be","bs","dz","hr","ru","sr","uk"],nr:[1,2,5],fc:4},{lngs:["ar"],nr:[0,1,2,3,11,100],fc:5},{lngs:["cs","sk"],nr:[1,2,5],fc:6},{lngs:["csb","pl"],nr:[1,2,5],fc:7},{lngs:["cy"],nr:[1,2,3,8],fc:8},{lngs:["fr"],nr:[1,2],fc:9},{lngs:["ga"],nr:[1,2,3,7,11],fc:10},{lngs:["gd"],nr:[1,2,3,20],fc:11},{lngs:["is"],nr:[1,2],fc:12},{lngs:["jv"],nr:[0,1],fc:13},{lngs:["kw"],nr:[1,2,3,4],fc:14},{lngs:["lt"],nr:[1,2,10],fc:15},{lngs:["lv"],nr:[1,2,0],fc:16},{lngs:["mk"],nr:[1,2],fc:17},{lngs:["mnk"],nr:[0,1,2],fc:18},{lngs:["mt"],nr:[1,2,11,20],fc:19},{lngs:["or"],nr:[2,1],fc:2},{lngs:["ro"],nr:[1,2,20],fc:20},{lngs:["sl"],nr:[5,1,2,3],fc:21}],j={1:function(e){return Number(e>1)},2:function(e){return Number(1!=e)},3:function(e){return 0},4:function(e){return Number(e%10==1&&e%100!=11?0:e%10>=2&&4>=e%10&&(10>e%100||e%100>=20)?1:2)},5:function(e){return Number(0===e?0:1==e?1:2==e?2:e%100>=3&&10>=e%100?3:e%100>=11?4:5)},6:function(e){return Number(1==e?0:e>=2&&4>=e?1:2)},7:function(e){return Number(1==e?0:e%10>=2&&4>=e%10&&(10>e%100||e%100>=20)?1:2)},8:function(e){return Number(1==e?0:2==e?1:8!=e&&11!=e?2:3)},9:function(e){return Number(e>=2)},10:function(e){return Number(1==e?0:2==e?1:7>e?2:11>e?3:4)},11:function(e){return Number(1==e||11==e?0:2==e||12==e?1:e>2&&20>e?2:3)},12:function(e){return Number(e%10!=1||e%100==11)},13:function(e){return Number(0!==e)},14:function(e){return Number(1==e?0:2==e?1:3==e?2:3)},15:function(e){return Number(e%10==1&&e%100!=11?0:e%10>=2&&(10>e%100||e%100>=20)?1:2)},16:function(e){return Number(e%10==1&&e%100!=11?0:0!==e?1:2)},17:function(e){return Number(1==e||e%10==1?0:1)},18:function(e){return Number(0==e?0:1==e?1:2)},19:function(e){return Number(1==e?0:0===e||e%100>1&&11>e%100?1:e%100>10&&20>e%100?2:3)},20:function(e){return Number(1==e?0:0===e||e%100>0&&20>e%100?1:2)},21:function(e){return Number(e%100==1?1:e%100==2?2:e%100==3||e%100==4?3:0)}},R=function(){function e(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];y.classCallCheck(this,e),this.rules=function(){var e={};return N.forEach(function(t){t.lngs.forEach(function(n){return e[n]={numbers:t.nr,plurals:j[t.fc]}})}),e}(),this.languageUtils=t,this.options=n,this.logger=k.create("pluralResolver")}return y.createClass(e,[{key:"addRule",value:function(e,t){this.rules[e]=t}},{key:"getRule",value:function(e){return this.rules[this.languageUtils.getLanguagePartFromCode(e)]}},{key:"needsPlural",value:function(e){var t=this.getRule(e);return!(t&&t.numbers.length<=1)}},{key:"getSuffix",value:function(e,t){var n=this.getRule(e);if(n){if(1===n.numbers.length)return"";var i=n.noAbs?n.plurals(t):n.plurals(Math.abs(t)),r=n.numbers[i];if(2===n.numbers.length&&1===n.numbers[0]&&(2===r?r="plural":1===r&&(r="")),"v1"===this.options.compatibilityJSON){if(1===r)return"";if("number"==typeof r)return"_plural_"+r.toString()}return this.options.prepend&&r.toString()?this.options.prepend+r.toString():r.toString()}return this.logger.warn("no plural rule found for: "+e),""}}]),e}(),P=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];y.classCallCheck(this,t),this.logger=k.create("interpolator"),this.init(e,!0)}return y.createClass(t,[{key:"init",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=arguments[1];t&&(this.options=e),e.interpolation||(e.interpolation={escapeValue:!0});var n=e.interpolation;this.escapeValue=n.escapeValue,this.prefix=n.prefix?a(n.prefix):n.prefixEscaped||"{{",this.suffix=n.suffix?a(n.suffix):n.suffixEscaped||"}}",this.unescapePrefix=n.unescapeSuffix?"":n.unescapePrefix||"-",this.unescapeSuffix=this.unescapePrefix?"":n.unescapeSuffix||"",this.nestingPrefix=n.nestingPrefix?a(n.nestingPrefix):n.nestingPrefixEscaped||a("$t("),this.nestingSuffix=n.nestingSuffix?a(n.nestingSuffix):n.nestingSuffixEscaped||a(")");var i=this.prefix+"(.+?)"+this.suffix;this.regexp=new RegExp(i,"g");var r=this.prefix+this.unescapePrefix+"(.+?)"+this.unescapeSuffix+this.suffix;this.regexpUnescape=new RegExp(r,"g");var o=this.nestingPrefix+"(.+?)"+this.nestingSuffix;this.nestingRegexp=new RegExp(o,"g")}},{key:"reset",value:function(){this.options&&this.init(this.options)}},{key:"interpolate",value:function(t,n){function i(e){return e.replace(/\$/g,"$$$$")}for(var r=void 0,s=void 0;r=this.regexpUnescape.exec(t);){var a=o(n,r[1].trim());t=t.replace(r[0],a)}for(;r=this.regexp.exec(t);)s=o(n,r[1].trim()),"string"!=typeof s&&(s=e(s)),s||(this.logger.warn("missed to pass in variable "+r[1]+" for interpolating "+t),s=""),s=i(this.escapeValue?l(s):s),t=t.replace(r[0],s),this.regexp.lastIndex=0;return t}},{key:"nest",value:function(t,n){function i(e){return e.replace(/\$/g,"$$$$")}function r(e){if(e.indexOf(",")<0)return e;var t=e.split(",");e=t.shift();var n=t.join(",");n=this.interpolate(n,u);try{u=JSON.parse(n)}catch(i){this.logger.error("failed parsing options string in nesting for key "+e,i)}return e}var o=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],s=void 0,a=void 0,u=JSON.parse(JSON.stringify(o));for(u.applyPostProcessor=!1;s=this.nestingRegexp.exec(t);)a=n(r.call(this,s[1].trim()),u),"string"!=typeof a&&(a=e(a)),a||(this.logger.warn("missed to pass in variable "+s[1]+" for interpolating "+t),a=""),a=i(this.escapeValue?l(a):a),t=t.replace(s[0],a),this.regexp.lastIndex=0;return t}}]),t}(),E=function(e){function t(e,n,i){var r=arguments.length<=3||void 0===arguments[3]?{}:arguments[3];y.classCallCheck(this,t);var o=y.possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this));return o.backend=e,o.store=n,o.services=i,o.options=r,o.logger=k.create("backendConnector"),o.state={},o.queue=[],o.backend&&o.backend.init&&o.backend.init(i,r.backend,r),o}return y.inherits(t,e),y.createClass(t,[{key:"queueLoad",value:function(e,t,n){var i=this,r=[],o=[],s=[],a=[];return e.forEach(function(e){var n=!0;t.forEach(function(t){var s=e+"|"+t;i.store.hasResourceBundle(e,t)?i.state[s]=2:i.state[s]<0||(1===i.state[s]?o.indexOf(s)<0&&o.push(s):(i.state[s]=1,n=!1,o.indexOf(s)<0&&o.push(s),r.indexOf(s)<0&&r.push(s),a.indexOf(t)<0&&a.push(t)))}),n||s.push(e)}),(r.length||o.length)&&this.queue.push({pending:o,loaded:{},errors:[],callback:n}),{toLoad:r,pending:o,toLoadLanguages:s,toLoadNamespaces:a}}},{key:"loaded",value:function(e,t,n){var i=this,o=e.split("|"),s=y.slicedToArray(o,2),a=s[0],l=s[1];t&&this.emit("failedLoading",a,l,t),n&&this.store.addResourceBundle(a,l,n),this.state[e]=t?-1:2,this.queue.forEach(function(n){r(n.loaded,[a],l),g(n.pending,e),t&&n.errors.push(t),0!==n.pending.length||n.done||(n.errors.length?n.callback(n.errors):n.callback(),i.emit("loaded",n.loaded),n.done=!0)}),this.queue=this.queue.filter(function(e){return!e.done})}},{key:"read",value:function(e,t,n,i,r,o){var s=this;return i||(i=0),r||(r=250),e.length?void this.backend[n](e,t,function(a,l){return a&&l&&5>i?void setTimeout(function(){s.read.call(s,e,t,n,++i,2*r,o)},r):void o(a,l)}):o(null,{})}},{key:"load",value:function(e,t,n){var i=this;if(!this.backend)return this.logger.warn("No backend was added via i18next.use. Will not load resources."),n&&n();var r=y["extends"]({},this.backend.options,this.options.backend);"string"==typeof e&&(e=this.services.languageUtils.toResolveHierarchy(e)),"string"==typeof t&&(t=[t]);var s=this.queueLoad(e,t,n);return s.toLoad.length?void(r.allowMultiLoading&&this.backend.readMulti?this.read(s.toLoadLanguages,s.toLoadNamespaces,"readMulti",null,null,function(e,t){e&&i.logger.warn("loading namespaces "+s.toLoadNamespaces.join(", ")+" for languages "+s.toLoadLanguages.join(", ")+" via multiloading failed",e),!e&&t&&i.logger.log("loaded namespaces "+s.toLoadNamespaces.join(", ")+" for languages "+s.toLoadLanguages.join(", ")+" via multiloading",t),s.toLoad.forEach(function(n){var r=n.split("|"),s=y.slicedToArray(r,2),a=s[0],l=s[1],u=o(t,[a,l]);if(u)i.loaded(n,e,u);else{var c="loading namespace "+l+" for language "+a+" via multiloading failed";i.loaded(n,c),i.logger.error(c)}})}):!function(){var e=function(e){var t=this,n=e.split("|"),i=y.slicedToArray(n,2),r=i[0],o=i[1];this.read(r,o,"read",null,null,function(n,i){n&&t.logger.warn("loading namespace "+o+" for language "+r+" failed",n),!n&&i&&t.logger.log("loaded namespace "+o+" for language "+r,i),t.loaded(e,n,i)})};s.toLoad.forEach(function(t){e.call(i,t)})}()):void(s.pending.length||n())}},{key:"saveMissing",value:function(e,t,n,i){this.backend&&this.backend.create&&this.backend.create(e,t,n,i),this.store.addResource(e[0],t,n,i)}}]),t}(x),_=function(e){function t(e,n,i){var r=arguments.length<=3||void 0===arguments[3]?{}:arguments[3];y.classCallCheck(this,t);var o=y.possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this));return o.cache=e,o.store=n,o.services=i,o.options=r,o.logger=k.create("cacheConnector"),o.cache&&o.cache.init&&o.cache.init(i,r.cache,r),o}return y.inherits(t,e),y.createClass(t,[{key:"load",value:function(e,t,n){var i=this;if(!this.cache)return n&&n();var r=y["extends"]({},this.cache.options,this.options.cache);"string"==typeof e&&(e=this.services.languageUtils.toResolveHierarchy(e)),"string"==typeof t&&(t=[t]),r.enabled?this.cache.load(e,function(t,r){if(t&&i.logger.error("loading languages "+e.join(", ")+" from cache failed",t),r)for(var o in r)for(var s in r[o])if("i18nStamp"!==s){var a=r[o][s];a&&i.store.addResourceBundle(o,s,a)}n&&n()}):n&&n()}},{key:"save",value:function(){this.cache&&this.options.cache&&this.options.cache.enabled&&this.cache.save(this.store.data)}}]),t}(x),T=function(e){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=arguments[1];y.classCallCheck(this,t);var i=y.possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this));return i.options=v(e),i.services={},i.logger=k,i.modules={},n&&!i.isInitialized&&i.init(e,n),i}return y.inherits(t,e),y.createClass(t,[{key:"init",value:function(e,t){function n(e){return e?"function"==typeof e?new e:e:void 0}var i=this;if("function"==typeof e&&(t=e,e={}),e||(e={}),"v1"===e.compatibilityAPI?this.options=y["extends"]({},d(),v(c(e)),{}):"v1"===e.compatibilityJSON?this.options=y["extends"]({},d(),v(f(e)),{}):this.options=y["extends"]({},d(),this.options,v(e)),t||(t=function(){}),!this.options.isClone){this.modules.logger?k.init(n(this.modules.logger),this.options):k.init(null,this.options);var r=new L(this.options);this.store=new w(this.options.resources,this.options);var o=this.services;o.logger=k,o.resourceStore=this.store,o.resourceStore.on("added removed",function(e,t){o.cacheConnector.save()}),o.languageUtils=r,o.pluralResolver=new R(r,{prepend:this.options.pluralSeparator,compatibilityJSON:this.options.compatibilityJSON}),o.interpolator=new P(this.options),o.backendConnector=new E(n(this.modules.backend),o.resourceStore,o,this.options),o.backendConnector.on("*",function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];i.emit.apply(i,[e].concat(n))}),o.backendConnector.on("loaded",function(e){o.cacheConnector.save()}),o.cacheConnector=new _(n(this.modules.cache),o.resourceStore,o,this.options),o.cacheConnector.on("*",function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];i.emit.apply(i,[e].concat(n))}),this.modules.languageDetector&&(o.languageDetector=n(this.modules.languageDetector),o.languageDetector.init(o,this.options.detection,this.options)),this.translator=new O(this.services,this.options),this.translator.on("*",function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];i.emit.apply(i,[e].concat(n))})}var s=["getResource","addResource","addResources","addResourceBundle","removeResourceBundle","hasResourceBundle","getResourceBundle"];return s.forEach(function(e){i[e]=function(){return this.store[e].apply(this.store,arguments)}}),"v1"===this.options.compatibilityAPI&&h(this),this.changeLanguage(this.options.lng,function(e,n){i.emit("initialized",i.options),i.logger.log("initialized",i.options),t(e,n)}),this}},{key:"loadResources",value:function(e){var t=this;if(e||(e=function(){}),this.options.resources)e(null);else{var n=function(){if(t.language&&"cimode"===t.language.toLowerCase())return{v:e()};var n=[],i=function(e){var i=t.services.languageUtils.toResolveHierarchy(e);i.forEach(function(e){n.indexOf(e)<0&&n.push(e)})};i(t.language),t.options.preload&&t.options.preload.forEach(function(e){i(e)}),t.services.cacheConnector.load(n,t.options.ns,function(){t.services.backendConnector.load(n,t.options.ns,e)})}();if("object"===("undefined"==typeof n?"undefined":y["typeof"](n)))return n.v}}},{key:"use",value:function(e){return"backend"===e.type&&(this.modules.backend=e),"cache"===e.type&&(this.modules.cache=e),("logger"===e.type||e.log&&e.warn&&e.warn)&&(this.modules.logger=e),"languageDetector"===e.type&&(this.modules.languageDetector=e),"postProcessor"===e.type&&C.addPostProcessor(e),this}},{key:"changeLanguage",value:function(e,t){var n=this,i=function(i){e&&(n.emit("languageChanged",e),n.logger.log("languageChanged",e)),t&&t(i,function(){for(var e=arguments.length,t=Array(e),i=0;e>i;i++)t[i]=arguments[i];return n.t.apply(n,t)})};!e&&this.services.languageDetector&&(e=this.services.languageDetector.detect()),e&&(this.language=e,this.languages=this.services.languageUtils.toResolveHierarchy(e),this.translator.changeLanguage(e),this.services.languageDetector&&this.services.languageDetector.cacheUserLanguage(e)),this.loadResources(function(e){i(e)})}},{key:"getFixedT",value:function(e,t){var n=this,i=function r(e,t){return t=t||{},t.lng=t.lng||r.lng,t.ns=t.ns||r.ns,n.t(e,t)};return i.lng=e,i.ns=t,i}},{key:"t",value:function(){return this.translator&&this.translator.translate.apply(this.translator,arguments)}},{key:"exists",value:function(){return this.translator&&this.translator.exists.apply(this.translator,arguments)}},{key:"setDefaultNamespace",value:function(e){this.options.defaultNS=e}},{key:"loadNamespaces",value:function(e,t){var n=this;return this.options.ns?("string"==typeof e&&(e=[e]),e.forEach(function(e){n.options.ns.indexOf(e)<0&&n.options.ns.push(e)}),void this.loadResources(t)):t&&t()}},{key:"loadLanguages",value:function(e,t){ | ||
"string"==typeof e&&(e=[e]),this.options.preload=this.options.preload?this.options.preload.concat(e):e,this.loadResources(t)}},{key:"dir",value:function(e){e||(e=this.language);var t=["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","ur","ydd","yds","yih","ji","yi","hbo","men","xmn","fa","jpr","peo","pes","prs","dv","sam"];return t.indexOf(this.services.languageUtils.getLanguagePartFromCode(e))?"ltr":"rtl"}},{key:"createInstance",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=arguments[1];return new t(e,n)}},{key:"cloneInstance",value:function(){var e=this,n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],i=arguments[1],r=new t(y["extends"]({},n,this.options,{isClone:!0}),i),o=["store","translator","services","language"];return o.forEach(function(t){r[t]=e[t]}),r}}]),t}(x),A=new T;return A}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define("i18next",t):e.i18next=t()}(this,function(){"use strict";function e(e){return null==e?"":""+e}function t(e,t,n){e.forEach(function(e){t[e]&&(n[e]=t[e])})}function n(e,t,n){function o(e){return e&&e.indexOf("###")>-1?e.replace(/###/g,"."):e}for(var r="string"!=typeof t?[].concat(t):t.split(".");r.length>1;){if(!e)return{};var i=o(r.shift());!e[i]&&n&&(e[i]=new n),e=e[i]}return e?{obj:e,k:o(r.shift())}:{}}function o(e,t,o){var r=n(e,t,Object),i=r.obj,s=r.k;i[s]=o}function r(e,t,o,r){var i=n(e,t,Object),s=i.obj,a=i.k;s[a]=s[a]||[],r&&(s[a]=s[a].concat(o)),r||s[a].push(o)}function i(e,t){var o=n(e,t),r=o.obj,i=o.k;return r?r[i]:void 0}function s(e,t,n){for(var o in t)o in e?"string"==typeof e[o]||e[o]instanceof String||"string"==typeof t[o]||t[o]instanceof String?n&&(e[o]=t[o]):s(e[o],t[o],n):e[o]=t[o];return e}function a(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function l(e){return"string"==typeof e?e.replace(/[&<>"'\/]/g,function(e){return w[e]}):e}function u(e){return e.interpolation={unescapeSuffix:"HTML"},e.interpolation.prefix=e.interpolationPrefix||"__",e.interpolation.suffix=e.interpolationSuffix||"__",e.interpolation.escapeValue=e.escapeInterpolation||!1,e.interpolation.nestingPrefix=e.reusePrefix||"$t(",e.interpolation.nestingSuffix=e.reuseSuffix||")",e}function c(e){return e.resStore&&(e.resources=e.resStore),e.ns&&e.ns.defaultNs?(e.defaultNS=e.ns.defaultNs,e.ns=e.ns.namespaces):e.defaultNS=e.ns||"translation",e.fallbackToDefaultNS&&e.defaultNS&&(e.fallbackNS=e.defaultNS),e.saveMissing=e.sendMissing,e.saveMissingTo=e.sendMissingTo||"current",e.returnNull=!e.fallbackOnNull,e.returnEmptyString=!e.fallbackOnEmpty,e.returnObjects=e.returnObjectTrees,e.joinArrays="\n",e.returnedObjectHandler=e.objectTreeKeyHandler,e.parseMissingKeyHandler=e.parseMissingKey,e.appendNamespaceToMissingKey=!0,e.nsSeparator=e.nsseparator,e.keySeparator=e.keyseparator,"sprintf"===e.shortcutFunction&&(e.overloadTranslationOptionHandler=function(e){for(var t=[],n=1;n<e.length;n++)t.push(e[n]);return{postProcess:"sprintf",sprintf:t}}),e.whitelist=e.lngWhitelist,e.preload=e.preload,"current"===e.load&&(e.load="currentOnly"),"unspecific"===e.load&&(e.load="languageOnly"),e.backend=e.backend||{},e.backend.loadPath=e.resGetPath||"locales/__lng__/__ns__.json",e.backend.addPath=e.resPostPath||"locales/add/__lng__/__ns__",e.backend.allowMultiLoading=e.dynamicLoad,e.cache=e.cache||{},e.cache.prefix="res_",e.cache.expirationTime=6048e5,e.cache.enabled=!!e.useLocalStorage,e=u(e),e.defaultVariables&&(e.interpolation.defaultVariables=e.defaultVariables),e}function p(e){return e=u(e),e.joinArrays="\n",e}function f(e){return(e.interpolationPrefix||e.interpolationSuffix||e.escapeInterpolation)&&(e=u(e)),e.nsSeparator=e.nsseparator,e.keySeparator=e.keyseparator,e.returnObjects=e.returnObjectTrees,e}function h(e){e.lng=function(){return k.deprecate("i18next.lng() can be replaced by i18next.language for detected language or i18next.languages for languages ordered by translation lookup."),e.services.languageUtils.toResolveHierarchy(e.language)[0]},e.preload=function(t,n){k.deprecate("i18next.preload() can be replaced with i18next.loadLanguages()"),e.loadLanguages(t,n)},e.setLng=function(t,n,o){return k.deprecate("i18next.setLng() can be replaced with i18next.changeLanguage() or i18next.getFixedT() to get a translation function with fixed language or namespace."),"function"==typeof n&&(o=n,n={}),n||(n={}),n.fixLng===!0&&o?o(null,e.getFixedT(t)):void e.changeLanguage(t,o)},e.addPostProcessor=function(t,n){k.deprecate("i18next.addPostProcessor() can be replaced by i18next.use({ type: 'postProcessor', name: 'name', process: fc })"),e.use({type:"postProcessor",name:t,process:n})}}function g(){var e={};return R.forEach(function(t){t.lngs.forEach(function(n){return e[n]={numbers:t.nr,plurals:j[t.fc]}})}),e}function d(e,t){for(var n=e.indexOf(t);-1!==n;)e.splice(n,1),n=e.indexOf(t)}function y(){return{debug:!1,ns:["translation"],defaultNS:["translation"],fallbackLng:["dev"],fallbackNS:!1,whitelist:!1,load:"all",preload:!1,keySeparator:".",nsSeparator:":",pluralSeparator:"_",contextSeparator:"_",saveMissing:!1,saveMissingTo:"fallback",missingKeyHandler:!1,postProcess:!1,returnNull:!0,returnEmptyString:!0,returnObjects:!1,joinArrays:!1,returnedObjectHandler:function(){},parseMissingKeyHandler:!1,appendNamespaceToMissingKey:!1,overloadTranslationOptionHandler:function(e){return{defaultValue:e[1]}},interpolation:{escapeValue:!0,prefix:"{{",suffix:"}}",unescapePrefix:"-",nestingPrefix:"$t(",nestingSuffix:")",defaultVariables:void 0}}}function v(e){return"string"==typeof e.ns&&(e.ns=[e.ns]),"string"==typeof e.fallbackLng&&(e.fallbackLng=[e.fallbackLng]),"string"==typeof e.fallbackNS&&(e.fallbackNS=[e.fallbackNS]),e.whitelist&&e.whitelist.indexOf("cimode")<0&&e.whitelist.push("cimode"),e}var b={};b["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},b.classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},b["extends"]=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},b.inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},b.possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},b.slicedToArray=function(){function e(e,t){var n=[],o=!0,r=!1,i=void 0;try{for(var s,a=e[Symbol.iterator]();!(o=(s=a.next()).done)&&(n.push(s.value),!t||n.length!==t);o=!0);}catch(l){r=!0,i=l}finally{try{!o&&a["return"]&&a["return"]()}finally{if(r)throw i}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();var m={type:"logger",log:function(e){this._output("log",e)},warn:function(e){this._output("warn",e)},error:function(e){this._output("error",e)},_output:function(e,t){console&&console[e]&&console[e].apply(console,Array.prototype.slice.call(t))}},x=function(){function e(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];b.classCallCheck(this,e),this.subs=[],this.init(t,n)}return e.prototype.init=function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.prefix=t.prefix||"i18next:",this.logger=e||m,this.options=t,this.debug=t.debug!==!1},e.prototype.setDebug=function(e){this.debug=e,this.subs.forEach(function(t){t.setDebug(e)})},e.prototype.log=function(){this.forward(arguments,"log","",!0)},e.prototype.warn=function(){this.forward(arguments,"warn","",!0)},e.prototype.error=function(){this.forward(arguments,"error","")},e.prototype.deprecate=function(){this.forward(arguments,"warn","WARNING DEPRECATED: ",!0)},e.prototype.forward=function(e,t,n,o){o&&!this.debug||("string"==typeof e[0]&&(e[0]=n+this.prefix+" "+e[0]),this.logger[t](e))},e.prototype.create=function(t){var n=new e(this.logger,b["extends"]({prefix:this.prefix+":"+t+":"},this.options));return this.subs.push(n),n},e}(),k=new x,S=function(){function e(){b.classCallCheck(this,e),this.observers={}}return e.prototype.on=function(e,t){var n=this;e.split(" ").forEach(function(e){n.observers[e]=n.observers[e]||[],n.observers[e].push(t)})},e.prototype.off=function(e,t){var n=this;this.observers[e]&&this.observers[e].forEach(function(){if(t){var o=n.observers[e].indexOf(t);o>-1&&n.observers[e].splice(o,1)}else delete n.observers[e]})},e.prototype.emit=function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),o=1;t>o;o++)n[o-1]=arguments[o];this.observers[e]&&this.observers[e].forEach(function(e){e.apply(void 0,n)}),this.observers["*"]&&this.observers["*"].forEach(function(t){var o;t.apply(t,(o=[e]).concat.apply(o,n))})},e}(),w={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},L=function(e){function t(){var n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],o=arguments.length<=1||void 0===arguments[1]?{ns:["translation"],defaultNS:"translation"}:arguments[1];b.classCallCheck(this,t);var r=b.possibleConstructorReturn(this,e.call(this));return r.data=n,r.options=o,r}return b.inherits(t,e),t.prototype.addNamespaces=function(e){this.options.ns.indexOf(e)<0&&this.options.ns.push(e)},t.prototype.removeNamespaces=function(e){var t=this.options.ns.indexOf(e);t>-1&&this.options.ns.splice(t,1)},t.prototype.getResource=function(e,t,n){var o=arguments.length<=3||void 0===arguments[3]?{}:arguments[3],r=o.keySeparator||this.options.keySeparator;void 0===r&&(r=".");var s=[e,t];return n&&"string"!=typeof n&&(s=s.concat(n)),n&&"string"==typeof n&&(s=s.concat(r?n.split(r):n)),e.indexOf(".")>-1&&(s=e.split(".")),i(this.data,s)},t.prototype.addResource=function(e,t,n,r){var i=arguments.length<=4||void 0===arguments[4]?{silent:!1}:arguments[4],s=this.options.keySeparator;void 0===s&&(s=".");var a=[e,t];n&&(a=a.concat(s?n.split(s):n)),e.indexOf(".")>-1&&(a=e.split("."),r=t,t=a[1]),this.addNamespaces(t),o(this.data,a,r),i.silent||this.emit("added",e,t,n,r)},t.prototype.addResources=function(e,t,n){for(var o in n)"string"==typeof n[o]&&this.addResource(e,t,o,n[o],{silent:!0});this.emit("added",e,t,n)},t.prototype.addResourceBundle=function(e,t,n,r,a){var l=[e,t];e.indexOf(".")>-1&&(l=e.split("."),r=n,n=t,t=l[1]),this.addNamespaces(t);var u=i(this.data,l)||{};r?s(u,n,a):u=b["extends"]({},u,n),o(this.data,l,u),this.emit("added",e,t,n)},t.prototype.removeResourceBundle=function(e,t){this.hasResourceBundle(e,t)&&delete this.data[e][t],this.removeNamespaces(t),this.emit("removed",e,t)},t.prototype.hasResourceBundle=function(e,t){return void 0!==this.getResource(e,t)},t.prototype.getResourceBundle=function(e,t){return t||(t=this.options.defaultNS),"v1"===this.options.compatibilityAPI?b["extends"]({},this.getResource(e,t)):this.getResource(e,t)},t.prototype.toJSON=function(){return this.data},t}(S),N={processors:{},addPostProcessor:function(e){this.processors[e.name]=e},handle:function(e,t,n,o,r){var i=this;return e.forEach(function(e){i.processors[e]&&(t=i.processors[e].process(t,n,o,r))}),t}},C=function(e){function n(o){var r=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];b.classCallCheck(this,n);var i=b.possibleConstructorReturn(this,e.call(this));return t(["resourceStore","languageUtils","pluralResolver","interpolator","backendConnector"],o,i),i.options=r,i.logger=k.create("translator"),i}return b.inherits(n,e),n.prototype.changeLanguage=function(e){e&&(this.language=e)},n.prototype.exists=function(e){var t=arguments.length<=1||void 0===arguments[1]?{interpolation:{}}:arguments[1];return"v1"===this.options.compatibilityAPI&&(t=f(t)),void 0!==this.resolve(e,t)},n.prototype.extractFromKey=function(e,t){var n=t.nsSeparator||this.options.nsSeparator;void 0===n&&(n=":");var o=t.ns||this.options.defaultNS;if(n&&e.indexOf(n)>-1){var r=e.split(n);o=r[0],e=r[1]}return"string"==typeof o&&(o=[o]),{key:e,namespaces:o}},n.prototype.translate=function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if("object"!==("undefined"==typeof t?"undefined":b["typeof"](t))?t=this.options.overloadTranslationOptionHandler(arguments):"v1"===this.options.compatibilityAPI&&(t=f(t)),void 0===e||null===e||""===e)return"";"number"==typeof e&&(e=String(e)),"string"==typeof e&&(e=[e]);var n=t.lng||this.language;if(n&&"cimode"===n.toLowerCase())return e[e.length-1];var o=t.keySeparator||this.options.keySeparator||".",r=this.extractFromKey(e[e.length-1],t),i=r.key,s=r.namespaces,a=s[s.length-1],l=this.resolve(e,t),u=Object.prototype.toString.apply(l),c=["[object Number]","[object Function]","[object RegExp]"],p=void 0!==t.joinArrays?t.joinArrays:this.options.joinArrays;if(l&&"string"!=typeof l&&c.indexOf(u)<0&&(!p||"[object Array]"!==u)){if(!t.returnObjects&&!this.options.returnObjects)return this.logger.warn("accessing an object - but returnObjects options is not enabled!"),this.options.returnedObjectHandler?this.options.returnedObjectHandler(i,l,t):"key '"+i+" ("+this.language+")' returned an object instead of string.";var h="[object Array]"===u?[]:{};for(var g in l)h[g]=this.translate(""+i+o+g,b["extends"]({joinArrays:!1,ns:s},t));l=h}else if(p&&"[object Array]"===u)l=l.join(p),l&&(l=this.extendTranslation(l,i,t));else{var d=!1,y=!1;if(!this.isValidLookup(l)&&t.defaultValue&&(d=!0,l=t.defaultValue),this.isValidLookup(l)||(y=!0,l=i),(y||d)&&(this.logger.log("missingKey",n,a,i,l),this.options.saveMissing)){var v=[];if("fallback"===this.options.saveMissingTo&&this.options.fallbackLng&&this.options.fallbackLng[0])for(var m=0;m<this.options.fallbackLng.length;m++)v.push(this.options.fallbackLng[m]);else"all"===this.options.saveMissingTo?v=this.languageUtils.toResolveHierarchy(t.lng||this.language):v.push(t.lng||this.language);this.options.missingKeyHandler?this.options.missingKeyHandler(v,a,i,l):this.backendConnector&&this.backendConnector.saveMissing&&this.backendConnector.saveMissing(v,a,i,l),this.emit("missingKey",v,a,i,l)}l=this.extendTranslation(l,i,t),y&&l===i&&this.options.appendNamespaceToMissingKey&&(l=a+":"+i),y&&this.options.parseMissingKeyHandler&&(l=this.options.parseMissingKeyHandler(l))}return l},n.prototype.extendTranslation=function(e,t,n){var o=this;n.interpolation&&this.interpolator.init(n);var r=n.replace&&"string"!=typeof n.replace?n.replace:n;this.options.interpolation.defaultVariables&&(r=b["extends"]({},this.options.interpolation.defaultVariables,r)),e=this.interpolator.interpolate(e,r),e=this.interpolator.nest(e,function(){for(var e=arguments.length,t=Array(e),n=0;e>n;n++)t[n]=arguments[n];return o.translate.apply(o,t)},n),n.interpolation&&this.interpolator.reset();var i=n.postProcess||this.options.postProcess,s="string"==typeof i?[i]:i;return void 0!==e&&s&&s.length&&n.applyPostProcessor!==!1&&(e=N.handle(s,e,t,n,this)),e},n.prototype.resolve=function(e){var t=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],o=void 0;return"string"==typeof e&&(e=[e]),e.forEach(function(e){if(!t.isValidLookup(o)){var r=t.extractFromKey(e,n),i=r.key,s=r.namespaces;t.options.fallbackNS&&(s=s.concat(t.options.fallbackNS));var a=void 0!==n.count&&"string"!=typeof n.count,l=void 0!==n.context&&"string"==typeof n.context&&""!==n.context,u=n.lngs?n.lngs:t.languageUtils.toResolveHierarchy(n.lng||t.language);s.forEach(function(e){t.isValidLookup(o)||u.forEach(function(r){if(!t.isValidLookup(o)){var s=i,u=[s],c=void 0;a&&(c=t.pluralResolver.getSuffix(r,n.count)),a&&l&&u.push(s+c),l&&u.push(s+=""+t.options.contextSeparator+n.context),a&&u.push(s+=c);for(var p=void 0;p=u.pop();)t.isValidLookup(o)||(o=t.getResource(r,e,p,n))}})})}}),o},n.prototype.isValidLookup=function(e){return!(void 0===e||!this.options.returnNull&&null===e||!this.options.returnEmptyString&&""===e)},n.prototype.getResource=function(e,t,n){var o=arguments.length<=3||void 0===arguments[3]?{}:arguments[3];return this.resourceStore.getResource(e,t,n,o)},n}(S),O=function(){function e(t){b.classCallCheck(this,e),this.options=t,this.whitelist=this.options.whitelist||!1,this.logger=k.create("languageUtils")}return e.prototype.getLanguagePartFromCode=function(e){if(e.indexOf("-")<0)return e;var t=["nb-NO","nn-NO","nb-no","nn-no"],n=e.split("-");return this.formatLanguageCode(t.indexOf(e)>-1?n[1].toLowerCase():n[0])},e.prototype.formatLanguageCode=function(e){if("string"==typeof e&&e.indexOf("-")>-1){var t=e.split("-"),n=b.slicedToArray(t,2),o=n[0],r=n[1];return this.options.lowerCaseLng?o.toLowerCase()+"-"+r.toLowerCase():o.toLowerCase()+"-"+r.toUpperCase()}return this.options.cleanCode||this.options.lowerCaseLng?e.toLowerCase():e},e.prototype.isWhitelisted=function(e){return"languageOnly"===this.options.load&&(e=this.getLanguagePartFromCode(e)),!this.whitelist||!this.whitelist.length||this.whitelist.indexOf(e)>-1},e.prototype.toResolveHierarchy=function(e,t){var n=this;t=t||this.options.fallbackLng||[],"string"==typeof t&&(t=[t]);var o=[],r=function(e){n.isWhitelisted(e)?o.push(e):n.logger.warn("rejecting non-whitelisted language code: "+e)};return"string"==typeof e&&e.indexOf("-")>-1?("languageOnly"!==this.options.load&&r(this.formatLanguageCode(e)),"currentOnly"!==this.options.load&&r(this.getLanguagePartFromCode(e))):"string"==typeof e&&r(this.formatLanguageCode(e)),t.forEach(function(e){o.indexOf(e)<0&&r(n.formatLanguageCode(e))}),o},e}(),R=[{lngs:["ach","ak","am","arn","br","fil","gun","ln","mfe","mg","mi","oc","tg","ti","tr","uz","wa"],nr:[1,2],fc:1},{lngs:["af","an","ast","az","bg","bn","ca","da","de","dev","el","en","eo","es","es_ar","et","eu","fi","fo","fur","fy","gl","gu","ha","he","hi","hu","hy","ia","it","kn","ku","lb","mai","ml","mn","mr","nah","nap","nb","ne","nl","nn","no","nso","pa","pap","pms","ps","pt","pt_br","rm","sco","se","si","so","son","sq","sv","sw","ta","te","tk","ur","yo"],nr:[1,2],fc:2},{lngs:["ay","bo","cgg","fa","id","ja","jbo","ka","kk","km","ko","ky","lo","ms","sah","su","th","tt","ug","vi","wo","zh"],nr:[1],fc:3},{lngs:["be","bs","dz","hr","ru","sr","uk"],nr:[1,2,5],fc:4},{lngs:["ar"],nr:[0,1,2,3,11,100],fc:5},{lngs:["cs","sk"],nr:[1,2,5],fc:6},{lngs:["csb","pl"],nr:[1,2,5],fc:7},{lngs:["cy"],nr:[1,2,3,8],fc:8},{lngs:["fr"],nr:[1,2],fc:9},{lngs:["ga"],nr:[1,2,3,7,11],fc:10},{lngs:["gd"],nr:[1,2,3,20],fc:11},{lngs:["is"],nr:[1,2],fc:12},{lngs:["jv"],nr:[0,1],fc:13},{lngs:["kw"],nr:[1,2,3,4],fc:14},{lngs:["lt"],nr:[1,2,10],fc:15},{lngs:["lv"],nr:[1,2,0],fc:16},{lngs:["mk"],nr:[1,2],fc:17},{lngs:["mnk"],nr:[0,1,2],fc:18},{lngs:["mt"],nr:[1,2,11,20],fc:19},{lngs:["or"],nr:[2,1],fc:2},{lngs:["ro"],nr:[1,2,20],fc:20},{lngs:["sl"],nr:[5,1,2,3],fc:21}],j={1:function(e){return Number(e>1)},2:function(e){return Number(1!=e)},3:function(e){return 0},4:function(e){return Number(e%10==1&&e%100!=11?0:e%10>=2&&4>=e%10&&(10>e%100||e%100>=20)?1:2)},5:function(e){return Number(0===e?0:1==e?1:2==e?2:e%100>=3&&10>=e%100?3:e%100>=11?4:5)},6:function(e){return Number(1==e?0:e>=2&&4>=e?1:2)},7:function(e){return Number(1==e?0:e%10>=2&&4>=e%10&&(10>e%100||e%100>=20)?1:2)},8:function(e){return Number(1==e?0:2==e?1:8!=e&&11!=e?2:3)},9:function(e){return Number(e>=2)},10:function(e){return Number(1==e?0:2==e?1:7>e?2:11>e?3:4)},11:function(e){return Number(1==e||11==e?0:2==e||12==e?1:e>2&&20>e?2:3)},12:function(e){return Number(e%10!=1||e%100==11)},13:function(e){return Number(0!==e)},14:function(e){return Number(1==e?0:2==e?1:3==e?2:3)},15:function(e){return Number(e%10==1&&e%100!=11?0:e%10>=2&&(10>e%100||e%100>=20)?1:2)},16:function(e){return Number(e%10==1&&e%100!=11?0:0!==e?1:2)},17:function(e){return Number(1==e||e%10==1?0:1)},18:function(e){return Number(0==e?0:1==e?1:2)},19:function(e){return Number(1==e?0:0===e||e%100>1&&11>e%100?1:e%100>10&&20>e%100?2:3)},20:function(e){return Number(1==e?0:0===e||e%100>0&&20>e%100?1:2)},21:function(e){return Number(e%100==1?1:e%100==2?2:e%100==3||e%100==4?3:0)}},P=function(){function e(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];b.classCallCheck(this,e),this.languageUtils=t,this.options=n,this.logger=k.create("pluralResolver"),this.rules=g()}return e.prototype.addRule=function(e,t){this.rules[e]=t},e.prototype.getRule=function(e){return this.rules[this.languageUtils.getLanguagePartFromCode(e)]},e.prototype.needsPlural=function(e){var t=this.getRule(e);return!(t&&t.numbers.length<=1)},e.prototype.getSuffix=function(e,t){var n=this.getRule(e);if(n){if(1===n.numbers.length)return"";var o=n.noAbs?n.plurals(t):n.plurals(Math.abs(t)),r=n.numbers[o];if(2===n.numbers.length&&1===n.numbers[0]&&(2===r?r="plural":1===r&&(r="")),"v1"===this.options.compatibilityJSON){if(1===r)return"";if("number"==typeof r)return"_plural_"+r.toString()}return this.options.prepend&&r.toString()?this.options.prepend+r.toString():r.toString()}return this.logger.warn("no plural rule found for: "+e),""},e}(),E=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];b.classCallCheck(this,t),this.logger=k.create("interpolator"),this.init(e,!0)}return t.prototype.init=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=arguments[1];t&&(this.options=e),e.interpolation||(e.interpolation={escapeValue:!0});var n=e.interpolation;this.escapeValue=n.escapeValue,this.prefix=n.prefix?a(n.prefix):n.prefixEscaped||"{{",this.suffix=n.suffix?a(n.suffix):n.suffixEscaped||"}}",this.unescapePrefix=n.unescapeSuffix?"":n.unescapePrefix||"-",this.unescapeSuffix=this.unescapePrefix?"":n.unescapeSuffix||"",this.nestingPrefix=n.nestingPrefix?a(n.nestingPrefix):n.nestingPrefixEscaped||a("$t("),this.nestingSuffix=n.nestingSuffix?a(n.nestingSuffix):n.nestingSuffixEscaped||a(")");var o=this.prefix+"(.+?)"+this.suffix;this.regexp=new RegExp(o,"g");var r=this.prefix+this.unescapePrefix+"(.+?)"+this.unescapeSuffix+this.suffix;this.regexpUnescape=new RegExp(r,"g");var i=this.nestingPrefix+"(.+?)"+this.nestingSuffix;this.nestingRegexp=new RegExp(i,"g")},t.prototype.reset=function(){this.options&&this.init(this.options)},t.prototype.interpolate=function(t,n){function o(e){return e.replace(/\$/g,"$$$$")}for(var r=void 0,s=void 0;r=this.regexpUnescape.exec(t);){var a=i(n,r[1].trim());t=t.replace(r[0],a)}for(;r=this.regexp.exec(t);)s=i(n,r[1].trim()),"string"!=typeof s&&(s=e(s)),s||(this.logger.warn("missed to pass in variable "+r[1]+" for interpolating "+t),s=""),s=o(this.escapeValue?l(s):s),t=t.replace(r[0],s),this.regexp.lastIndex=0;return t},t.prototype.nest=function(t,n){function o(e){return e.replace(/\$/g,"$$$$")}function r(e){if(e.indexOf(",")<0)return e;var t=e.split(",");e=t.shift();var n=t.join(",");n=this.interpolate(n,u);try{u=JSON.parse(n)}catch(o){this.logger.error("failed parsing options string in nesting for key "+e,o)}return e}var i=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],s=void 0,a=void 0,u=JSON.parse(JSON.stringify(i));for(u.applyPostProcessor=!1;s=this.nestingRegexp.exec(t);)a=n(r.call(this,s[1].trim()),u),"string"!=typeof a&&(a=e(a)),a||(this.logger.warn("missed to pass in variable "+s[1]+" for interpolating "+t),a=""),a=o(this.escapeValue?l(a):a),t=t.replace(s[0],a),this.regexp.lastIndex=0;return t},t}(),_=function(e){function t(n,o,r){var i=arguments.length<=3||void 0===arguments[3]?{}:arguments[3];b.classCallCheck(this,t);var s=b.possibleConstructorReturn(this,e.call(this));return s.backend=n,s.store=o,s.services=r,s.options=i,s.logger=k.create("backendConnector"),s.state={},s.queue=[],s.backend&&s.backend.init&&s.backend.init(r,i.backend,i),s}return b.inherits(t,e),t.prototype.queueLoad=function(e,t,n){var o=this,r=[],i=[],s=[],a=[];return e.forEach(function(e){var n=!0;t.forEach(function(t){var s=e+"|"+t;o.store.hasResourceBundle(e,t)?o.state[s]=2:o.state[s]<0||(1===o.state[s]?i.indexOf(s)<0&&i.push(s):(o.state[s]=1,n=!1,i.indexOf(s)<0&&i.push(s),r.indexOf(s)<0&&r.push(s),a.indexOf(t)<0&&a.push(t)))}),n||s.push(e)}),(r.length||i.length)&&this.queue.push({pending:i,loaded:{},errors:[],callback:n}),{toLoad:r,pending:i,toLoadLanguages:s,toLoadNamespaces:a}},t.prototype.loaded=function(e,t,n){var o=this,i=e.split("|"),s=b.slicedToArray(i,2),a=s[0],l=s[1];t&&this.emit("failedLoading",a,l,t),n&&this.store.addResourceBundle(a,l,n),this.state[e]=t?-1:2,this.queue.forEach(function(n){r(n.loaded,[a],l),d(n.pending,e),t&&n.errors.push(t),0!==n.pending.length||n.done||(n.errors.length?n.callback(n.errors):n.callback(),o.emit("loaded",n.loaded),n.done=!0)}),this.queue=this.queue.filter(function(e){return!e.done})},t.prototype.read=function(e,t,n,o,r,i){var s=this;return o||(o=0),r||(r=250),e.length?void this.backend[n](e,t,function(a,l){return a&&l&&5>o?void setTimeout(function(){s.read.call(s,e,t,n,++o,2*r,i)},r):void i(a,l)}):i(null,{})},t.prototype.load=function(e,t,n){var o=this;if(!this.backend)return this.logger.warn("No backend was added via i18next.use. Will not load resources."),n&&n();var r=b["extends"]({},this.backend.options,this.options.backend);"string"==typeof e&&(e=this.services.languageUtils.toResolveHierarchy(e)),"string"==typeof t&&(t=[t]);var s=this.queueLoad(e,t,n);return s.toLoad.length?void(r.allowMultiLoading&&this.backend.readMulti?this.read(s.toLoadLanguages,s.toLoadNamespaces,"readMulti",null,null,function(e,t){e&&o.logger.warn("loading namespaces "+s.toLoadNamespaces.join(", ")+" for languages "+s.toLoadLanguages.join(", ")+" via multiloading failed",e),!e&&t&&o.logger.log("loaded namespaces "+s.toLoadNamespaces.join(", ")+" for languages "+s.toLoadLanguages.join(", ")+" via multiloading",t),s.toLoad.forEach(function(n){var r=n.split("|"),s=b.slicedToArray(r,2),a=s[0],l=s[1],u=i(t,[a,l]);if(u)o.loaded(n,e,u);else{var c="loading namespace "+l+" for language "+a+" via multiloading failed";o.loaded(n,c),o.logger.error(c)}})}):!function(){var e=function(e){var t=this,n=e.split("|"),o=b.slicedToArray(n,2),r=o[0],i=o[1];this.read(r,i,"read",null,null,function(n,o){n&&t.logger.warn("loading namespace "+i+" for language "+r+" failed",n),!n&&o&&t.logger.log("loaded namespace "+i+" for language "+r,o),t.loaded(e,n,o)})};s.toLoad.forEach(function(t){e.call(o,t)})}()):void(s.pending.length||n())},t.prototype.saveMissing=function(e,t,n,o){this.backend&&this.backend.create&&this.backend.create(e,t,n,o),this.store.addResource(e[0],t,n,o)},t}(S),T=function(e){function t(n,o,r){var i=arguments.length<=3||void 0===arguments[3]?{}:arguments[3];b.classCallCheck(this,t);var s=b.possibleConstructorReturn(this,e.call(this));return s.cache=n,s.store=o,s.services=r,s.options=i,s.logger=k.create("cacheConnector"),s.cache&&s.cache.init&&s.cache.init(r,i.cache,i),s}return b.inherits(t,e),t.prototype.load=function(e,t,n){var o=this;if(!this.cache)return n&&n();var r=b["extends"]({},this.cache.options,this.options.cache);"string"==typeof e&&(e=this.services.languageUtils.toResolveHierarchy(e)),"string"==typeof t&&(t=[t]),r.enabled?this.cache.load(e,function(t,r){if(t&&o.logger.error("loading languages "+e.join(", ")+" from cache failed",t),r)for(var i in r)for(var s in r[i])if("i18nStamp"!==s){var a=r[i][s];a&&o.store.addResourceBundle(i,s,a)}n&&n()}):n&&n()},t.prototype.save=function(){this.cache&&this.options.cache&&this.options.cache.enabled&&this.cache.save(this.store.data)},t}(S),A=function(e){function t(){var n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],o=arguments[1];b.classCallCheck(this,t);var r=b.possibleConstructorReturn(this,e.call(this));return r.options=v(n),r.services={},r.logger=k,r.modules={},o&&!r.isInitialized&&r.init(n,o),r}return b.inherits(t,e),t.prototype.init=function(e,t){function n(e){return e?"function"==typeof e?new e:e:void 0}var o=this;if("function"==typeof e&&(t=e,e={}),e||(e={}),"v1"===e.compatibilityAPI?this.options=b["extends"]({},y(),v(c(e)),{}):"v1"===e.compatibilityJSON?this.options=b["extends"]({},y(),v(p(e)),{}):this.options=b["extends"]({},y(),this.options,v(e)),t||(t=function(){}),!this.options.isClone){this.modules.logger?k.init(n(this.modules.logger),this.options):k.init(null,this.options);var r=new O(this.options);this.store=new L(this.options.resources,this.options);var i=this.services;i.logger=k,i.resourceStore=this.store,i.resourceStore.on("added removed",function(e,t){i.cacheConnector.save()}),i.languageUtils=r,i.pluralResolver=new P(r,{prepend:this.options.pluralSeparator,compatibilityJSON:this.options.compatibilityJSON}),i.interpolator=new E(this.options),i.backendConnector=new _(n(this.modules.backend),i.resourceStore,i,this.options),i.backendConnector.on("*",function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];o.emit.apply(o,[e].concat(n))}),i.backendConnector.on("loaded",function(e){i.cacheConnector.save()}),i.cacheConnector=new T(n(this.modules.cache),i.resourceStore,i,this.options),i.cacheConnector.on("*",function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];o.emit.apply(o,[e].concat(n))}),this.modules.languageDetector&&(i.languageDetector=n(this.modules.languageDetector),i.languageDetector.init(i,this.options.detection,this.options)),this.translator=new C(this.services,this.options),this.translator.on("*",function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];o.emit.apply(o,[e].concat(n))})}var s=["getResource","addResource","addResources","addResourceBundle","removeResourceBundle","hasResourceBundle","getResourceBundle"];return s.forEach(function(e){o[e]=function(){return this.store[e].apply(this.store,arguments)}}),"v1"===this.options.compatibilityAPI&&h(this),this.changeLanguage(this.options.lng,function(e,n){o.emit("initialized",o.options),o.logger.log("initialized",o.options),t(e,n)}),this},t.prototype.loadResources=function(e){var t=this;if(e||(e=function(){}),this.options.resources)e(null);else{var n=function(){if(t.language&&"cimode"===t.language.toLowerCase())return{v:e()};var n=[],o=function(e){var o=t.services.languageUtils.toResolveHierarchy(e);o.forEach(function(e){n.indexOf(e)<0&&n.push(e)})};o(t.language),t.options.preload&&t.options.preload.forEach(function(e){o(e)}),t.services.cacheConnector.load(n,t.options.ns,function(){t.services.backendConnector.load(n,t.options.ns,e)})}();if("object"===("undefined"==typeof n?"undefined":b["typeof"](n)))return n.v}},t.prototype.use=function(e){return"backend"===e.type&&(this.modules.backend=e),"cache"===e.type&&(this.modules.cache=e),("logger"===e.type||e.log&&e.warn&&e.warn)&&(this.modules.logger=e),"languageDetector"===e.type&&(this.modules.languageDetector=e),"postProcessor"===e.type&&N.addPostProcessor(e),this},t.prototype.changeLanguage=function(e,t){var n=this,o=function(o){e&&(n.emit("languageChanged",e),n.logger.log("languageChanged",e)),t&&t(o,function(){for(var e=arguments.length,t=Array(e),o=0;e>o;o++)t[o]=arguments[o];return n.t.apply(n,t)})};!e&&this.services.languageDetector&&(e=this.services.languageDetector.detect()),e&&(this.language=e,this.languages=this.services.languageUtils.toResolveHierarchy(e),this.translator.changeLanguage(e),this.services.languageDetector&&this.services.languageDetector.cacheUserLanguage(e)),this.loadResources(function(e){o(e)})},t.prototype.getFixedT=function(e,t){var n=this,o=function r(e,t){return t=t||{},t.lng=t.lng||r.lng,t.ns=t.ns||r.ns,n.t(e,t)};return o.lng=e,o.ns=t,o},t.prototype.t=function(){return this.translator&&this.translator.translate.apply(this.translator,arguments)},t.prototype.exists=function(){return this.translator&&this.translator.exists.apply(this.translator,arguments)},t.prototype.setDefaultNamespace=function(e){this.options.defaultNS=e},t.prototype.loadNamespaces=function(e,t){var n=this;return this.options.ns?("string"==typeof e&&(e=[e]),e.forEach(function(e){n.options.ns.indexOf(e)<0&&n.options.ns.push(e)}),void this.loadResources(t)):t&&t()},t.prototype.loadLanguages=function(e,t){"string"==typeof e&&(e=[e]),this.options.preload=this.options.preload?this.options.preload.concat(e):e,this.loadResources(t)},t.prototype.dir=function(e){e||(e=this.language);var t=["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","ur","ydd","yds","yih","ji","yi","hbo","men","xmn","fa","jpr","peo","pes","prs","dv","sam"];return t.indexOf(this.services.languageUtils.getLanguagePartFromCode(e))?"ltr":"rtl"},t.prototype.createInstance=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=arguments[1]; | ||
return new t(e,n)},t.prototype.cloneInstance=function(){var e=this,n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],o=arguments[1],r=new t(b["extends"]({},n,this.options,{isClone:!0}),o),i=["store","translator","services","language"];return i.forEach(function(t){r[t]=e[t]}),r},t}(S),M=new A;return M}); |
{ | ||
"name": "i18next", | ||
"version": "2.3.3", | ||
"version": "2.3.4", | ||
"description": "i18next internationalization framework", | ||
@@ -28,2 +28,4 @@ "main": "./index.js", | ||
"babel-eslint": "6.0.0-beta.5", | ||
"babel-plugin-transform-es2015-classes": "^6.6.5", | ||
"babel-plugin-transform-proto-to-assign": "^6.6.5", | ||
"babel-preset-es2015": "6.6.0", | ||
@@ -30,0 +32,0 @@ "babel-preset-es2015-native-modules": "^6.6.0", |
@@ -12,2 +12,3 @@ import babel from 'rollup-plugin-babel'; | ||
presets: ['es2015-rollup', 'stage-0'], | ||
plugins: [['transform-es2015-classes', { loose: true }], 'transform-proto-to-assign'], | ||
babelrc: false | ||
@@ -14,0 +15,0 @@ }; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46
375673
44
6289