use standard URLSearchParams insead of custom functions
This commit is contained in:
77
node_modules/i18next-xhr-backend/dist/commonjs/ajax.js
generated
vendored
Normal file
77
node_modules/i18next-xhr-backend/dist/commonjs/ajax.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
function addQueryString(url, params) {
|
||||
if (params && (typeof params === 'undefined' ? 'undefined' : _typeof(params)) === 'object') {
|
||||
var queryString = '',
|
||||
e = encodeURIComponent;
|
||||
|
||||
// Must encode data
|
||||
for (var paramName in params) {
|
||||
queryString += '&' + e(paramName) + '=' + e(params[paramName]);
|
||||
}
|
||||
|
||||
if (!queryString) {
|
||||
return url;
|
||||
}
|
||||
|
||||
url = url + (url.indexOf('?') !== -1 ? '&' : '?') + queryString.slice(1);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
// https://gist.github.com/Xeoncross/7663273
|
||||
function ajax(url, options, callback, data, cache) {
|
||||
|
||||
if (data && (typeof data === 'undefined' ? 'undefined' : _typeof(data)) === 'object') {
|
||||
if (!cache) {
|
||||
data['_t'] = new Date();
|
||||
}
|
||||
// URL encoded form data must be in querystring format
|
||||
data = addQueryString('', data).slice(1);
|
||||
}
|
||||
|
||||
if (options.queryStringParams) {
|
||||
url = addQueryString(url, options.queryStringParams);
|
||||
}
|
||||
|
||||
try {
|
||||
var x;
|
||||
if (XMLHttpRequest) {
|
||||
x = new XMLHttpRequest();
|
||||
} else {
|
||||
x = new ActiveXObject('MSXML2.XMLHTTP.3.0');
|
||||
}
|
||||
x.open(data ? 'POST' : 'GET', url, 1);
|
||||
if (!options.crossDomain) {
|
||||
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
}
|
||||
x.withCredentials = !!options.withCredentials;
|
||||
if (data) {
|
||||
x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
}
|
||||
if (x.overrideMimeType) {
|
||||
x.overrideMimeType("application/json");
|
||||
}
|
||||
var h = options.customHeaders;
|
||||
if (h) {
|
||||
for (var i in h) {
|
||||
x.setRequestHeader(i, h[i]);
|
||||
}
|
||||
}
|
||||
x.onreadystatechange = function () {
|
||||
x.readyState > 3 && callback && callback(x.responseText, x);
|
||||
};
|
||||
x.send(data);
|
||||
} catch (e) {
|
||||
console && console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
exports.default = ajax;
|
123
node_modules/i18next-xhr-backend/dist/commonjs/index.js
generated
vendored
Normal file
123
node_modules/i18next-xhr-backend/dist/commonjs/index.js
generated
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
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.js');
|
||||
|
||||
var utils = _interopRequireWildcard(_utils);
|
||||
|
||||
var _ajax = require('./ajax.js');
|
||||
|
||||
var _ajax2 = _interopRequireDefault(_ajax);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function getDefaults() {
|
||||
return {
|
||||
loadPath: '/locales/{{lng}}/{{ns}}.json',
|
||||
addPath: '/locales/add/{{lng}}/{{ns}}',
|
||||
allowMultiLoading: false,
|
||||
parse: JSON.parse,
|
||||
crossDomain: false,
|
||||
ajax: _ajax2.default
|
||||
};
|
||||
}
|
||||
|
||||
var Backend = function () {
|
||||
function Backend(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
_classCallCheck(this, Backend);
|
||||
|
||||
this.init(services, options);
|
||||
|
||||
this.type = 'backend';
|
||||
}
|
||||
|
||||
_createClass(Backend, [{
|
||||
key: 'init',
|
||||
value: function init(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
this.services = services;
|
||||
this.options = utils.defaults(options, this.options || {}, getDefaults());
|
||||
}
|
||||
}, {
|
||||
key: 'readMulti',
|
||||
value: function readMulti(languages, namespaces, callback) {
|
||||
var loadPath = this.options.loadPath;
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath(languages, namespaces);
|
||||
}
|
||||
|
||||
var url = this.services.interpolator.interpolate(loadPath, { lng: languages.join('+'), ns: namespaces.join('+') });
|
||||
|
||||
this.loadUrl(url, callback);
|
||||
}
|
||||
}, {
|
||||
key: 'read',
|
||||
value: function read(language, namespace, callback) {
|
||||
var loadPath = this.options.loadPath;
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath([language], [namespace]);
|
||||
}
|
||||
|
||||
var url = this.services.interpolator.interpolate(loadPath, { lng: language, ns: namespace });
|
||||
|
||||
this.loadUrl(url, callback);
|
||||
}
|
||||
}, {
|
||||
key: 'loadUrl',
|
||||
value: function loadUrl(url, callback) {
|
||||
var _this = this;
|
||||
|
||||
this.options.ajax(url, this.options, function (data, xhr) {
|
||||
if (xhr.status >= 500 && xhr.status < 600) return callback('failed loading ' + url, true /* retry */);
|
||||
if (xhr.status >= 400 && xhr.status < 500) return callback('failed loading ' + url, false /* no retry */);
|
||||
|
||||
var ret = void 0,
|
||||
err = void 0;
|
||||
try {
|
||||
ret = _this.options.parse(data, url);
|
||||
} catch (e) {
|
||||
err = 'failed parsing ' + url + ' to json';
|
||||
}
|
||||
if (err) return callback(err, false);
|
||||
callback(null, ret);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'create',
|
||||
value: function create(languages, namespace, key, fallbackValue) {
|
||||
var _this2 = this;
|
||||
|
||||
if (typeof languages === 'string') languages = [languages];
|
||||
|
||||
var payload = {};
|
||||
payload[key] = fallbackValue || '';
|
||||
|
||||
languages.forEach(function (lng) {
|
||||
var url = _this2.services.interpolator.interpolate(_this2.options.addPath, { lng: lng, ns: namespace });
|
||||
|
||||
_this2.options.ajax(url, _this2.options, function (data, xhr) {
|
||||
//const statusCode = xhr.status.toString();
|
||||
// TODO: if statusCode === 4xx do log
|
||||
}, payload);
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return Backend;
|
||||
}();
|
||||
|
||||
Backend.type = 'backend';
|
||||
|
||||
exports.default = Backend;
|
32
node_modules/i18next-xhr-backend/dist/commonjs/utils.js
generated
vendored
Normal file
32
node_modules/i18next-xhr-backend/dist/commonjs/utils.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.defaults = defaults;
|
||||
exports.extend = extend;
|
||||
var arr = [];
|
||||
var each = arr.forEach;
|
||||
var slice = arr.slice;
|
||||
|
||||
function defaults(obj) {
|
||||
each.call(slice.call(arguments, 1), function (source) {
|
||||
if (source) {
|
||||
for (var prop in source) {
|
||||
if (obj[prop] === undefined) obj[prop] = source[prop];
|
||||
}
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
|
||||
function extend(obj) {
|
||||
each.call(slice.call(arguments, 1), function (source) {
|
||||
if (source) {
|
||||
for (var prop in source) {
|
||||
obj[prop] = source[prop];
|
||||
}
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
71
node_modules/i18next-xhr-backend/dist/es/ajax.js
generated
vendored
Normal file
71
node_modules/i18next-xhr-backend/dist/es/ajax.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
function addQueryString(url, params) {
|
||||
if (params && (typeof params === 'undefined' ? 'undefined' : _typeof(params)) === 'object') {
|
||||
var queryString = '',
|
||||
e = encodeURIComponent;
|
||||
|
||||
// Must encode data
|
||||
for (var paramName in params) {
|
||||
queryString += '&' + e(paramName) + '=' + e(params[paramName]);
|
||||
}
|
||||
|
||||
if (!queryString) {
|
||||
return url;
|
||||
}
|
||||
|
||||
url = url + (url.indexOf('?') !== -1 ? '&' : '?') + queryString.slice(1);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
// https://gist.github.com/Xeoncross/7663273
|
||||
function ajax(url, options, callback, data, cache) {
|
||||
|
||||
if (data && (typeof data === 'undefined' ? 'undefined' : _typeof(data)) === 'object') {
|
||||
if (!cache) {
|
||||
data['_t'] = new Date();
|
||||
}
|
||||
// URL encoded form data must be in querystring format
|
||||
data = addQueryString('', data).slice(1);
|
||||
}
|
||||
|
||||
if (options.queryStringParams) {
|
||||
url = addQueryString(url, options.queryStringParams);
|
||||
}
|
||||
|
||||
try {
|
||||
var x;
|
||||
if (XMLHttpRequest) {
|
||||
x = new XMLHttpRequest();
|
||||
} else {
|
||||
x = new ActiveXObject('MSXML2.XMLHTTP.3.0');
|
||||
}
|
||||
x.open(data ? 'POST' : 'GET', url, 1);
|
||||
if (!options.crossDomain) {
|
||||
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
}
|
||||
x.withCredentials = !!options.withCredentials;
|
||||
if (data) {
|
||||
x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
}
|
||||
if (x.overrideMimeType) {
|
||||
x.overrideMimeType("application/json");
|
||||
}
|
||||
var h = options.customHeaders;
|
||||
if (h) {
|
||||
for (var i in h) {
|
||||
x.setRequestHeader(i, h[i]);
|
||||
}
|
||||
}
|
||||
x.onreadystatechange = function () {
|
||||
x.readyState > 3 && callback && callback(x.responseText, x);
|
||||
};
|
||||
x.send(data);
|
||||
} catch (e) {
|
||||
console && console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
export default ajax;
|
108
node_modules/i18next-xhr-backend/dist/es/index.js
generated
vendored
Normal file
108
node_modules/i18next-xhr-backend/dist/es/index.js
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
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"); } }
|
||||
|
||||
import * as utils from './utils.js';
|
||||
import ajax from './ajax.js';
|
||||
|
||||
function getDefaults() {
|
||||
return {
|
||||
loadPath: '/locales/{{lng}}/{{ns}}.json',
|
||||
addPath: '/locales/add/{{lng}}/{{ns}}',
|
||||
allowMultiLoading: false,
|
||||
parse: JSON.parse,
|
||||
crossDomain: false,
|
||||
ajax: ajax
|
||||
};
|
||||
}
|
||||
|
||||
var Backend = function () {
|
||||
function Backend(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
_classCallCheck(this, Backend);
|
||||
|
||||
this.init(services, options);
|
||||
|
||||
this.type = 'backend';
|
||||
}
|
||||
|
||||
_createClass(Backend, [{
|
||||
key: 'init',
|
||||
value: function init(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
this.services = services;
|
||||
this.options = utils.defaults(options, this.options || {}, getDefaults());
|
||||
}
|
||||
}, {
|
||||
key: 'readMulti',
|
||||
value: function readMulti(languages, namespaces, callback) {
|
||||
var loadPath = this.options.loadPath;
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath(languages, namespaces);
|
||||
}
|
||||
|
||||
var url = this.services.interpolator.interpolate(loadPath, { lng: languages.join('+'), ns: namespaces.join('+') });
|
||||
|
||||
this.loadUrl(url, callback);
|
||||
}
|
||||
}, {
|
||||
key: 'read',
|
||||
value: function read(language, namespace, callback) {
|
||||
var loadPath = this.options.loadPath;
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath([language], [namespace]);
|
||||
}
|
||||
|
||||
var url = this.services.interpolator.interpolate(loadPath, { lng: language, ns: namespace });
|
||||
|
||||
this.loadUrl(url, callback);
|
||||
}
|
||||
}, {
|
||||
key: 'loadUrl',
|
||||
value: function loadUrl(url, callback) {
|
||||
var _this = this;
|
||||
|
||||
this.options.ajax(url, this.options, function (data, xhr) {
|
||||
if (xhr.status >= 500 && xhr.status < 600) return callback('failed loading ' + url, true /* retry */);
|
||||
if (xhr.status >= 400 && xhr.status < 500) return callback('failed loading ' + url, false /* no retry */);
|
||||
|
||||
var ret = void 0,
|
||||
err = void 0;
|
||||
try {
|
||||
ret = _this.options.parse(data, url);
|
||||
} catch (e) {
|
||||
err = 'failed parsing ' + url + ' to json';
|
||||
}
|
||||
if (err) return callback(err, false);
|
||||
callback(null, ret);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'create',
|
||||
value: function create(languages, namespace, key, fallbackValue) {
|
||||
var _this2 = this;
|
||||
|
||||
if (typeof languages === 'string') languages = [languages];
|
||||
|
||||
var payload = {};
|
||||
payload[key] = fallbackValue || '';
|
||||
|
||||
languages.forEach(function (lng) {
|
||||
var url = _this2.services.interpolator.interpolate(_this2.options.addPath, { lng: lng, ns: namespace });
|
||||
|
||||
_this2.options.ajax(url, _this2.options, function (data, xhr) {
|
||||
//const statusCode = xhr.status.toString();
|
||||
// TODO: if statusCode === 4xx do log
|
||||
}, payload);
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return Backend;
|
||||
}();
|
||||
|
||||
Backend.type = 'backend';
|
||||
|
||||
export default Backend;
|
25
node_modules/i18next-xhr-backend/dist/es/utils.js
generated
vendored
Normal file
25
node_modules/i18next-xhr-backend/dist/es/utils.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
var arr = [];
|
||||
var each = arr.forEach;
|
||||
var slice = arr.slice;
|
||||
|
||||
export function defaults(obj) {
|
||||
each.call(slice.call(arguments, 1), function (source) {
|
||||
if (source) {
|
||||
for (var prop in source) {
|
||||
if (obj[prop] === undefined) obj[prop] = source[prop];
|
||||
}
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
|
||||
export function extend(obj) {
|
||||
each.call(slice.call(arguments, 1), function (source) {
|
||||
if (source) {
|
||||
for (var prop in source) {
|
||||
obj[prop] = source[prop];
|
||||
}
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
198
node_modules/i18next-xhr-backend/dist/umd/i18nextXHRBackend.js
generated
vendored
Normal file
198
node_modules/i18next-xhr-backend/dist/umd/i18nextXHRBackend.js
generated
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global.i18nextXHRBackend = factory());
|
||||
}(this, (function () { 'use strict';
|
||||
|
||||
var arr = [];
|
||||
var each = arr.forEach;
|
||||
var slice = arr.slice;
|
||||
|
||||
function defaults(obj) {
|
||||
each.call(slice.call(arguments, 1), function (source) {
|
||||
if (source) {
|
||||
for (var prop in source) {
|
||||
if (obj[prop] === undefined) obj[prop] = source[prop];
|
||||
}
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
function addQueryString(url, params) {
|
||||
if (params && (typeof params === 'undefined' ? 'undefined' : _typeof(params)) === 'object') {
|
||||
var queryString = '',
|
||||
e = encodeURIComponent;
|
||||
|
||||
// Must encode data
|
||||
for (var paramName in params) {
|
||||
queryString += '&' + e(paramName) + '=' + e(params[paramName]);
|
||||
}
|
||||
|
||||
if (!queryString) {
|
||||
return url;
|
||||
}
|
||||
|
||||
url = url + (url.indexOf('?') !== -1 ? '&' : '?') + queryString.slice(1);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
// https://gist.github.com/Xeoncross/7663273
|
||||
function ajax(url, options, callback, data, cache) {
|
||||
|
||||
if (data && (typeof data === 'undefined' ? 'undefined' : _typeof(data)) === 'object') {
|
||||
if (!cache) {
|
||||
data['_t'] = new Date();
|
||||
}
|
||||
// URL encoded form data must be in querystring format
|
||||
data = addQueryString('', data).slice(1);
|
||||
}
|
||||
|
||||
if (options.queryStringParams) {
|
||||
url = addQueryString(url, options.queryStringParams);
|
||||
}
|
||||
|
||||
try {
|
||||
var x;
|
||||
if (XMLHttpRequest) {
|
||||
x = new XMLHttpRequest();
|
||||
} else {
|
||||
x = new ActiveXObject('MSXML2.XMLHTTP.3.0');
|
||||
}
|
||||
x.open(data ? 'POST' : 'GET', url, 1);
|
||||
if (!options.crossDomain) {
|
||||
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
}
|
||||
x.withCredentials = !!options.withCredentials;
|
||||
if (data) {
|
||||
x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
}
|
||||
if (x.overrideMimeType) {
|
||||
x.overrideMimeType("application/json");
|
||||
}
|
||||
var h = options.customHeaders;
|
||||
if (h) {
|
||||
for (var i in h) {
|
||||
x.setRequestHeader(i, h[i]);
|
||||
}
|
||||
}
|
||||
x.onreadystatechange = function () {
|
||||
x.readyState > 3 && callback && callback(x.responseText, x);
|
||||
};
|
||||
x.send(data);
|
||||
} catch (e) {
|
||||
console && console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
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"); } }
|
||||
|
||||
function getDefaults() {
|
||||
return {
|
||||
loadPath: '/locales/{{lng}}/{{ns}}.json',
|
||||
addPath: '/locales/add/{{lng}}/{{ns}}',
|
||||
allowMultiLoading: false,
|
||||
parse: JSON.parse,
|
||||
crossDomain: false,
|
||||
ajax: ajax
|
||||
};
|
||||
}
|
||||
|
||||
var Backend = function () {
|
||||
function Backend(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
_classCallCheck(this, Backend);
|
||||
|
||||
this.init(services, options);
|
||||
|
||||
this.type = 'backend';
|
||||
}
|
||||
|
||||
_createClass(Backend, [{
|
||||
key: 'init',
|
||||
value: function init(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
this.services = services;
|
||||
this.options = defaults(options, this.options || {}, getDefaults());
|
||||
}
|
||||
}, {
|
||||
key: 'readMulti',
|
||||
value: function readMulti(languages, namespaces, callback) {
|
||||
var loadPath = this.options.loadPath;
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath(languages, namespaces);
|
||||
}
|
||||
|
||||
var url = this.services.interpolator.interpolate(loadPath, { lng: languages.join('+'), ns: namespaces.join('+') });
|
||||
|
||||
this.loadUrl(url, callback);
|
||||
}
|
||||
}, {
|
||||
key: 'read',
|
||||
value: function read(language, namespace, callback) {
|
||||
var loadPath = this.options.loadPath;
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath([language], [namespace]);
|
||||
}
|
||||
|
||||
var url = this.services.interpolator.interpolate(loadPath, { lng: language, ns: namespace });
|
||||
|
||||
this.loadUrl(url, callback);
|
||||
}
|
||||
}, {
|
||||
key: 'loadUrl',
|
||||
value: function loadUrl(url, callback) {
|
||||
var _this = this;
|
||||
|
||||
this.options.ajax(url, this.options, function (data, xhr) {
|
||||
if (xhr.status >= 500 && xhr.status < 600) return callback('failed loading ' + url, true /* retry */);
|
||||
if (xhr.status >= 400 && xhr.status < 500) return callback('failed loading ' + url, false /* no retry */);
|
||||
|
||||
var ret = void 0,
|
||||
err = void 0;
|
||||
try {
|
||||
ret = _this.options.parse(data, url);
|
||||
} catch (e) {
|
||||
err = 'failed parsing ' + url + ' to json';
|
||||
}
|
||||
if (err) return callback(err, false);
|
||||
callback(null, ret);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'create',
|
||||
value: function create(languages, namespace, key, fallbackValue) {
|
||||
var _this2 = this;
|
||||
|
||||
if (typeof languages === 'string') languages = [languages];
|
||||
|
||||
var payload = {};
|
||||
payload[key] = fallbackValue || '';
|
||||
|
||||
languages.forEach(function (lng) {
|
||||
var url = _this2.services.interpolator.interpolate(_this2.options.addPath, { lng: lng, ns: namespace });
|
||||
|
||||
_this2.options.ajax(url, _this2.options, function (data, xhr) {
|
||||
//const statusCode = xhr.status.toString();
|
||||
// TODO: if statusCode === 4xx do log
|
||||
}, payload);
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return Backend;
|
||||
}();
|
||||
|
||||
Backend.type = 'backend';
|
||||
|
||||
return Backend;
|
||||
|
||||
})));
|
1
node_modules/i18next-xhr-backend/dist/umd/i18nextXHRBackend.min.js
generated
vendored
Normal file
1
node_modules/i18next-xhr-backend/dist/umd/i18nextXHRBackend.min.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.i18nextXHRBackend=e()}(this,function(){"use strict";function t(t){return r.call(s.call(arguments,1),function(e){if(e)for(var n in e)void 0===t[n]&&(t[n]=e[n])}),t}function e(t,e){if(e&&"object"===(void 0===e?"undefined":l(e))){var n="",o=encodeURIComponent;for(var i in e)n+="&"+o(i)+"="+o(e[i]);if(!n)return t;t=t+(-1!==t.indexOf("?")?"&":"?")+n.slice(1)}return t}function n(t,n,o,i,a){i&&"object"===(void 0===i?"undefined":l(i))&&(a||(i._t=new Date),i=e("",i).slice(1)),n.queryStringParams&&(t=e(t,n.queryStringParams));try{var r;r=XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("MSXML2.XMLHTTP.3.0"),r.open(i?"POST":"GET",t,1),n.crossDomain||r.setRequestHeader("X-Requested-With","XMLHttpRequest"),r.withCredentials=!!n.withCredentials,i&&r.setRequestHeader("Content-type","application/x-www-form-urlencoded"),r.overrideMimeType&&r.overrideMimeType("application/json");var s=n.customHeaders;if(s)for(var u in s)r.setRequestHeader(u,s[u]);r.onreadystatechange=function(){r.readyState>3&&o&&o(r.responseText,r)},r.send(i)}catch(t){console&&console.log(t)}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(){return{loadPath:"/locales/{{lng}}/{{ns}}.json",addPath:"/locales/add/{{lng}}/{{ns}}",allowMultiLoading:!1,parse:JSON.parse,crossDomain:!1,ajax:n}}var a=[],r=a.forEach,s=a.slice,l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),c=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};o(this,e),this.init(t,n),this.type="backend"}return u(e,[{key:"init",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.services=e,this.options=t(n,this.options||{},i())}},{key:"readMulti",value:function(t,e,n){var o=this.options.loadPath;"function"==typeof this.options.loadPath&&(o=this.options.loadPath(t,e));var i=this.services.interpolator.interpolate(o,{lng:t.join("+"),ns:e.join("+")});this.loadUrl(i,n)}},{key:"read",value:function(t,e,n){var o=this.options.loadPath;"function"==typeof this.options.loadPath&&(o=this.options.loadPath([t],[e]));var i=this.services.interpolator.interpolate(o,{lng:t,ns:e});this.loadUrl(i,n)}},{key:"loadUrl",value:function(t,e){var n=this;this.options.ajax(t,this.options,function(o,i){if(i.status>=500&&i.status<600)return e("failed loading "+t,!0);if(i.status>=400&&i.status<500)return e("failed loading "+t,!1);var a=void 0,r=void 0;try{a=n.options.parse(o,t)}catch(e){r="failed parsing "+t+" to json"}if(r)return e(r,!1);e(null,a)})}},{key:"create",value:function(t,e,n,o){var i=this;"string"==typeof t&&(t=[t]);var a={};a[n]=o||"",t.forEach(function(t){var n=i.services.interpolator.interpolate(i.options.addPath,{lng:t,ns:e});i.options.ajax(n,i.options,function(t,e){},a)})}}]),e}();return c.type="backend",c});
|
Reference in New Issue
Block a user