mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-08 07:10:56 +03:00
WebClient WIP: add support for localizations
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
2297
static/vendor/i18next/i18next.js
vendored
Normal file
2297
static/vendor/i18next/i18next.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
420
static/vendor/i18next/i18nextBrowserLanguageDetector.js
vendored
Normal file
420
static/vendor/i18next/i18nextBrowserLanguageDetector.js
vendored
Normal file
@@ -0,0 +1,420 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.i18nextBrowserLanguageDetector = factory());
|
||||
})(this, (function () { 'use strict';
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
function _typeof(o) {
|
||||
"@babel/helpers - typeof";
|
||||
|
||||
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
||||
return typeof o;
|
||||
} : function (o) {
|
||||
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
||||
}, _typeof(o);
|
||||
}
|
||||
|
||||
function _toPrimitive(input, hint) {
|
||||
if (_typeof(input) !== "object" || input === null) return input;
|
||||
var prim = input[Symbol.toPrimitive];
|
||||
if (prim !== undefined) {
|
||||
var res = prim.call(input, hint || "default");
|
||||
if (_typeof(res) !== "object") return res;
|
||||
throw new TypeError("@@toPrimitive must return a primitive value.");
|
||||
}
|
||||
return (hint === "string" ? String : Number)(input);
|
||||
}
|
||||
|
||||
function _toPropertyKey(arg) {
|
||||
var key = _toPrimitive(arg, "string");
|
||||
return _typeof(key) === "symbol" ? key : String(key);
|
||||
}
|
||||
|
||||
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, _toPropertyKey(descriptor.key), descriptor);
|
||||
}
|
||||
}
|
||||
function _createClass(Constructor, protoProps, staticProps) {
|
||||
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) _defineProperties(Constructor, staticProps);
|
||||
Object.defineProperty(Constructor, "prototype", {
|
||||
writable: false
|
||||
});
|
||||
return Constructor;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-control-regex
|
||||
var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
||||
var serializeCookie = function serializeCookie(name, val, options) {
|
||||
var opt = options || {};
|
||||
opt.path = opt.path || '/';
|
||||
var value = encodeURIComponent(val);
|
||||
var str = "".concat(name, "=").concat(value);
|
||||
if (opt.maxAge > 0) {
|
||||
var maxAge = opt.maxAge - 0;
|
||||
if (Number.isNaN(maxAge)) throw new Error('maxAge should be a Number');
|
||||
str += "; Max-Age=".concat(Math.floor(maxAge));
|
||||
}
|
||||
if (opt.domain) {
|
||||
if (!fieldContentRegExp.test(opt.domain)) {
|
||||
throw new TypeError('option domain is invalid');
|
||||
}
|
||||
str += "; Domain=".concat(opt.domain);
|
||||
}
|
||||
if (opt.path) {
|
||||
if (!fieldContentRegExp.test(opt.path)) {
|
||||
throw new TypeError('option path is invalid');
|
||||
}
|
||||
str += "; Path=".concat(opt.path);
|
||||
}
|
||||
if (opt.expires) {
|
||||
if (typeof opt.expires.toUTCString !== 'function') {
|
||||
throw new TypeError('option expires is invalid');
|
||||
}
|
||||
str += "; Expires=".concat(opt.expires.toUTCString());
|
||||
}
|
||||
if (opt.httpOnly) str += '; HttpOnly';
|
||||
if (opt.secure) str += '; Secure';
|
||||
if (opt.sameSite) {
|
||||
var sameSite = typeof opt.sameSite === 'string' ? opt.sameSite.toLowerCase() : opt.sameSite;
|
||||
switch (sameSite) {
|
||||
case true:
|
||||
str += '; SameSite=Strict';
|
||||
break;
|
||||
case 'lax':
|
||||
str += '; SameSite=Lax';
|
||||
break;
|
||||
case 'strict':
|
||||
str += '; SameSite=Strict';
|
||||
break;
|
||||
case 'none':
|
||||
str += '; SameSite=None';
|
||||
break;
|
||||
default:
|
||||
throw new TypeError('option sameSite is invalid');
|
||||
}
|
||||
}
|
||||
return str;
|
||||
};
|
||||
var cookie = {
|
||||
create: function create(name, value, minutes, domain) {
|
||||
var cookieOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
||||
path: '/',
|
||||
sameSite: 'strict'
|
||||
};
|
||||
if (minutes) {
|
||||
cookieOptions.expires = new Date();
|
||||
cookieOptions.expires.setTime(cookieOptions.expires.getTime() + minutes * 60 * 1000);
|
||||
}
|
||||
if (domain) cookieOptions.domain = domain;
|
||||
document.cookie = serializeCookie(name, encodeURIComponent(value), cookieOptions);
|
||||
},
|
||||
read: function read(name) {
|
||||
var nameEQ = "".concat(name, "=");
|
||||
var ca = document.cookie.split(';');
|
||||
for (var i = 0; i < ca.length; i++) {
|
||||
var c = ca[i];
|
||||
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
|
||||
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
remove: function remove(name) {
|
||||
this.create(name, '', -1);
|
||||
}
|
||||
};
|
||||
var cookie$1 = {
|
||||
name: 'cookie',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
if (options.lookupCookie && typeof document !== 'undefined') {
|
||||
var c = cookie.read(options.lookupCookie);
|
||||
if (c) found = c;
|
||||
}
|
||||
return found;
|
||||
},
|
||||
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
||||
if (options.lookupCookie && typeof document !== 'undefined') {
|
||||
cookie.create(options.lookupCookie, lng, options.cookieMinutes, options.cookieDomain, options.cookieOptions);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var querystring = {
|
||||
name: 'querystring',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
if (typeof window !== 'undefined') {
|
||||
var search = window.location.search;
|
||||
if (!window.location.search && window.location.hash && window.location.hash.indexOf('?') > -1) {
|
||||
search = window.location.hash.substring(window.location.hash.indexOf('?'));
|
||||
}
|
||||
var query = search.substring(1);
|
||||
var params = query.split('&');
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
var pos = params[i].indexOf('=');
|
||||
if (pos > 0) {
|
||||
var key = params[i].substring(0, pos);
|
||||
if (key === options.lookupQuerystring) {
|
||||
found = params[i].substring(pos + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
var hasLocalStorageSupport = null;
|
||||
var localStorageAvailable = function localStorageAvailable() {
|
||||
if (hasLocalStorageSupport !== null) return hasLocalStorageSupport;
|
||||
try {
|
||||
hasLocalStorageSupport = window !== 'undefined' && window.localStorage !== null;
|
||||
var testKey = 'i18next.translate.boo';
|
||||
window.localStorage.setItem(testKey, 'foo');
|
||||
window.localStorage.removeItem(testKey);
|
||||
} catch (e) {
|
||||
hasLocalStorageSupport = false;
|
||||
}
|
||||
return hasLocalStorageSupport;
|
||||
};
|
||||
var localStorage = {
|
||||
name: 'localStorage',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
if (options.lookupLocalStorage && localStorageAvailable()) {
|
||||
var lng = window.localStorage.getItem(options.lookupLocalStorage);
|
||||
if (lng) found = lng;
|
||||
}
|
||||
return found;
|
||||
},
|
||||
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
||||
if (options.lookupLocalStorage && localStorageAvailable()) {
|
||||
window.localStorage.setItem(options.lookupLocalStorage, lng);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var hasSessionStorageSupport = null;
|
||||
var sessionStorageAvailable = function sessionStorageAvailable() {
|
||||
if (hasSessionStorageSupport !== null) return hasSessionStorageSupport;
|
||||
try {
|
||||
hasSessionStorageSupport = window !== 'undefined' && window.sessionStorage !== null;
|
||||
var testKey = 'i18next.translate.boo';
|
||||
window.sessionStorage.setItem(testKey, 'foo');
|
||||
window.sessionStorage.removeItem(testKey);
|
||||
} catch (e) {
|
||||
hasSessionStorageSupport = false;
|
||||
}
|
||||
return hasSessionStorageSupport;
|
||||
};
|
||||
var sessionStorage = {
|
||||
name: 'sessionStorage',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
if (options.lookupSessionStorage && sessionStorageAvailable()) {
|
||||
var lng = window.sessionStorage.getItem(options.lookupSessionStorage);
|
||||
if (lng) found = lng;
|
||||
}
|
||||
return found;
|
||||
},
|
||||
cacheUserLanguage: function cacheUserLanguage(lng, options) {
|
||||
if (options.lookupSessionStorage && sessionStorageAvailable()) {
|
||||
window.sessionStorage.setItem(options.lookupSessionStorage, lng);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var navigator$1 = {
|
||||
name: 'navigator',
|
||||
lookup: function lookup(options) {
|
||||
var found = [];
|
||||
if (typeof navigator !== 'undefined') {
|
||||
if (navigator.languages) {
|
||||
// chrome only; not an array, so can't use .push.apply instead of iterating
|
||||
for (var i = 0; i < navigator.languages.length; i++) {
|
||||
found.push(navigator.languages[i]);
|
||||
}
|
||||
}
|
||||
if (navigator.userLanguage) {
|
||||
found.push(navigator.userLanguage);
|
||||
}
|
||||
if (navigator.language) {
|
||||
found.push(navigator.language);
|
||||
}
|
||||
}
|
||||
return found.length > 0 ? found : undefined;
|
||||
}
|
||||
};
|
||||
|
||||
var htmlTag = {
|
||||
name: 'htmlTag',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
var htmlTag = options.htmlTag || (typeof document !== 'undefined' ? document.documentElement : null);
|
||||
if (htmlTag && typeof htmlTag.getAttribute === 'function') {
|
||||
found = htmlTag.getAttribute('lang');
|
||||
}
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
var path = {
|
||||
name: 'path',
|
||||
lookup: function lookup(options) {
|
||||
var found;
|
||||
if (typeof window !== 'undefined') {
|
||||
var language = window.location.pathname.match(/\/([a-zA-Z-]*)/g);
|
||||
if (language instanceof Array) {
|
||||
if (typeof options.lookupFromPathIndex === 'number') {
|
||||
if (typeof language[options.lookupFromPathIndex] !== 'string') {
|
||||
return undefined;
|
||||
}
|
||||
found = language[options.lookupFromPathIndex].replace('/', '');
|
||||
} else {
|
||||
found = language[0].replace('/', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
var subdomain = {
|
||||
name: 'subdomain',
|
||||
lookup: function lookup(options) {
|
||||
// If given get the subdomain index else 1
|
||||
var lookupFromSubdomainIndex = typeof options.lookupFromSubdomainIndex === 'number' ? options.lookupFromSubdomainIndex + 1 : 1;
|
||||
// get all matches if window.location. is existing
|
||||
// first item of match is the match itself and the second is the first group macht which sould be the first subdomain match
|
||||
// is the hostname no public domain get the or option of localhost
|
||||
var language = typeof window !== 'undefined' && window.location && window.location.hostname && window.location.hostname.match(/^(\w{2,5})\.(([a-z0-9-]{1,63}\.[a-z]{2,6})|localhost)/i);
|
||||
|
||||
// if there is no match (null) return undefined
|
||||
if (!language) return undefined;
|
||||
// return the given group match
|
||||
return language[lookupFromSubdomainIndex];
|
||||
}
|
||||
};
|
||||
|
||||
function getDefaults() {
|
||||
return {
|
||||
order: ['querystring', 'cookie', 'localStorage', 'sessionStorage', 'navigator', 'htmlTag'],
|
||||
lookupQuerystring: 'lng',
|
||||
lookupCookie: 'i18next',
|
||||
lookupLocalStorage: 'i18nextLng',
|
||||
lookupSessionStorage: 'i18nextLng',
|
||||
// cache user language
|
||||
caches: ['localStorage'],
|
||||
excludeCacheFor: ['cimode'],
|
||||
// cookieMinutes: 10,
|
||||
// cookieDomain: 'myDomain'
|
||||
|
||||
convertDetectedLanguage: function convertDetectedLanguage(l) {
|
||||
return l;
|
||||
}
|
||||
};
|
||||
}
|
||||
var Browser = /*#__PURE__*/function () {
|
||||
function Browser(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
_classCallCheck(this, Browser);
|
||||
this.type = 'languageDetector';
|
||||
this.detectors = {};
|
||||
this.init(services, options);
|
||||
}
|
||||
_createClass(Browser, [{
|
||||
key: "init",
|
||||
value: function init(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var i18nOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
this.services = services || {
|
||||
languageUtils: {}
|
||||
}; // this way the language detector can be used without i18next
|
||||
this.options = defaults(options, this.options || {}, getDefaults());
|
||||
if (typeof this.options.convertDetectedLanguage === 'string' && this.options.convertDetectedLanguage.indexOf('15897') > -1) {
|
||||
this.options.convertDetectedLanguage = function (l) {
|
||||
return l.replace('-', '_');
|
||||
};
|
||||
}
|
||||
|
||||
// backwards compatibility
|
||||
if (this.options.lookupFromUrlIndex) this.options.lookupFromPathIndex = this.options.lookupFromUrlIndex;
|
||||
this.i18nOptions = i18nOptions;
|
||||
this.addDetector(cookie$1);
|
||||
this.addDetector(querystring);
|
||||
this.addDetector(localStorage);
|
||||
this.addDetector(sessionStorage);
|
||||
this.addDetector(navigator$1);
|
||||
this.addDetector(htmlTag);
|
||||
this.addDetector(path);
|
||||
this.addDetector(subdomain);
|
||||
}
|
||||
}, {
|
||||
key: "addDetector",
|
||||
value: function addDetector(detector) {
|
||||
this.detectors[detector.name] = detector;
|
||||
}
|
||||
}, {
|
||||
key: "detect",
|
||||
value: function detect(detectionOrder) {
|
||||
var _this = this;
|
||||
if (!detectionOrder) detectionOrder = this.options.order;
|
||||
var detected = [];
|
||||
detectionOrder.forEach(function (detectorName) {
|
||||
if (_this.detectors[detectorName]) {
|
||||
var lookup = _this.detectors[detectorName].lookup(_this.options);
|
||||
if (lookup && typeof lookup === 'string') lookup = [lookup];
|
||||
if (lookup) detected = detected.concat(lookup);
|
||||
}
|
||||
});
|
||||
detected = detected.map(function (d) {
|
||||
return _this.options.convertDetectedLanguage(d);
|
||||
});
|
||||
if (this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0
|
||||
return detected.length > 0 ? detected[0] : null; // a little backward compatibility
|
||||
}
|
||||
}, {
|
||||
key: "cacheUserLanguage",
|
||||
value: function cacheUserLanguage(lng, caches) {
|
||||
var _this2 = this;
|
||||
if (!caches) caches = this.options.caches;
|
||||
if (!caches) return;
|
||||
if (this.options.excludeCacheFor && this.options.excludeCacheFor.indexOf(lng) > -1) return;
|
||||
caches.forEach(function (cacheName) {
|
||||
if (_this2.detectors[cacheName]) _this2.detectors[cacheName].cacheUserLanguage(lng, _this2.options);
|
||||
});
|
||||
}
|
||||
}]);
|
||||
return Browser;
|
||||
}();
|
||||
Browser.type = 'languageDetector';
|
||||
|
||||
return Browser;
|
||||
|
||||
}));
|
||||
266
static/vendor/i18next/i18nextChainedBackend.js
vendored
Normal file
266
static/vendor/i18next/i18nextChainedBackend.js
vendored
Normal file
@@ -0,0 +1,266 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.i18nextChainedBackend = factory());
|
||||
})(this, (function () { 'use strict';
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
function _typeof(o) {
|
||||
"@babel/helpers - typeof";
|
||||
|
||||
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
||||
return typeof o;
|
||||
} : function (o) {
|
||||
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
||||
}, _typeof(o);
|
||||
}
|
||||
|
||||
function _toPrimitive(input, hint) {
|
||||
if (_typeof(input) !== "object" || input === null) return input;
|
||||
var prim = input[Symbol.toPrimitive];
|
||||
if (prim !== undefined) {
|
||||
var res = prim.call(input, hint || "default");
|
||||
if (_typeof(res) !== "object") return res;
|
||||
throw new TypeError("@@toPrimitive must return a primitive value.");
|
||||
}
|
||||
return (hint === "string" ? String : Number)(input);
|
||||
}
|
||||
|
||||
function _toPropertyKey(arg) {
|
||||
var key = _toPrimitive(arg, "string");
|
||||
return _typeof(key) === "symbol" ? key : String(key);
|
||||
}
|
||||
|
||||
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, _toPropertyKey(descriptor.key), descriptor);
|
||||
}
|
||||
}
|
||||
function _createClass(Constructor, protoProps, staticProps) {
|
||||
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) _defineProperties(Constructor, staticProps);
|
||||
Object.defineProperty(Constructor, "prototype", {
|
||||
writable: false
|
||||
});
|
||||
return Constructor;
|
||||
}
|
||||
|
||||
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 createClassOnDemand(ClassOrObject) {
|
||||
if (!ClassOrObject) return null;
|
||||
if (typeof ClassOrObject === 'function') return new ClassOrObject();
|
||||
return ClassOrObject;
|
||||
}
|
||||
|
||||
function getDefaults() {
|
||||
return {
|
||||
handleEmptyResourcesAsFailed: true,
|
||||
cacheHitMode: 'none'
|
||||
// reloadInterval: typeof window !== 'undefined' ? false : 60 * 60 * 1000
|
||||
// refreshExpirationTime: 60 * 60 * 1000
|
||||
};
|
||||
}
|
||||
|
||||
function handleCorrectReadFunction(backend, language, namespace, resolver) {
|
||||
var fc = backend.read.bind(backend);
|
||||
if (fc.length === 2) {
|
||||
// no callback
|
||||
try {
|
||||
var r = fc(language, namespace);
|
||||
if (r && typeof r.then === 'function') {
|
||||
// promise
|
||||
r.then(function (data) {
|
||||
return resolver(null, data);
|
||||
})["catch"](resolver);
|
||||
} else {
|
||||
// sync
|
||||
resolver(null, r);
|
||||
}
|
||||
} catch (err) {
|
||||
resolver(err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// normal with callback
|
||||
fc(language, namespace, resolver);
|
||||
}
|
||||
var Backend = /*#__PURE__*/function () {
|
||||
function Backend(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var i18nextOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
_classCallCheck(this, Backend);
|
||||
this.backends = [];
|
||||
this.type = 'backend';
|
||||
this.allOptions = i18nextOptions;
|
||||
this.init(services, options);
|
||||
}
|
||||
_createClass(Backend, [{
|
||||
key: "init",
|
||||
value: function init(services) {
|
||||
var _this = this;
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var i18nextOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
this.services = services;
|
||||
this.options = defaults(options, this.options || {}, getDefaults());
|
||||
this.allOptions = i18nextOptions;
|
||||
this.options.backends && this.options.backends.forEach(function (b, i) {
|
||||
_this.backends[i] = _this.backends[i] || createClassOnDemand(b);
|
||||
_this.backends[i].init(services, _this.options.backendOptions && _this.options.backendOptions[i] || {}, i18nextOptions);
|
||||
});
|
||||
if (this.services && this.options.reloadInterval) {
|
||||
setInterval(function () {
|
||||
return _this.reload();
|
||||
}, this.options.reloadInterval);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "read",
|
||||
value: function read(language, namespace, callback) {
|
||||
var _this2 = this;
|
||||
var bLen = this.backends.length;
|
||||
var loadPosition = function loadPosition(pos) {
|
||||
if (pos >= bLen) return callback(new Error('non of the backend loaded data', true)); // failed pass retry flag
|
||||
var isLastBackend = pos === bLen - 1;
|
||||
var lengthCheckAmount = _this2.options.handleEmptyResourcesAsFailed && !isLastBackend ? 0 : -1;
|
||||
var backend = _this2.backends[pos];
|
||||
if (backend.read) {
|
||||
handleCorrectReadFunction(backend, language, namespace, function (err, data, savedAt) {
|
||||
if (!err && data && Object.keys(data).length > lengthCheckAmount) {
|
||||
callback(null, data, pos);
|
||||
savePosition(pos - 1, data); // save one in front
|
||||
if (backend.save && _this2.options.cacheHitMode && ['refresh', 'refreshAndUpdateStore'].indexOf(_this2.options.cacheHitMode) > -1) {
|
||||
if (savedAt && _this2.options.refreshExpirationTime && savedAt + _this2.options.refreshExpirationTime > Date.now()) return;
|
||||
var nextBackend = _this2.backends[pos + 1];
|
||||
if (nextBackend && nextBackend.read) {
|
||||
handleCorrectReadFunction(nextBackend, language, namespace, function (err, data) {
|
||||
if (err) return;
|
||||
if (!data) return;
|
||||
if (Object.keys(data).length <= lengthCheckAmount) return;
|
||||
savePosition(pos, data);
|
||||
if (_this2.options.cacheHitMode !== 'refreshAndUpdateStore') return;
|
||||
if (_this2.services && _this2.services.resourceStore) {
|
||||
_this2.services.resourceStore.addResourceBundle(language, namespace, data);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
loadPosition(pos + 1); // try load from next
|
||||
}
|
||||
});
|
||||
} else {
|
||||
loadPosition(pos + 1); // try load from next
|
||||
}
|
||||
};
|
||||
|
||||
var savePosition = function savePosition(pos, data) {
|
||||
if (pos < 0) return;
|
||||
var backend = _this2.backends[pos];
|
||||
if (backend.save) {
|
||||
backend.save(language, namespace, data);
|
||||
savePosition(pos - 1, data);
|
||||
} else {
|
||||
savePosition(pos - 1, data);
|
||||
}
|
||||
};
|
||||
loadPosition(0);
|
||||
}
|
||||
}, {
|
||||
key: "create",
|
||||
value: function create(languages, namespace, key, fallbackValue) {
|
||||
var clb = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : function () {};
|
||||
var opts = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
||||
this.backends.forEach(function (b) {
|
||||
if (!b.create) return;
|
||||
var fc = b.create.bind(b);
|
||||
if (fc.length < 6) {
|
||||
// no callback
|
||||
try {
|
||||
var r;
|
||||
if (fc.length === 5) {
|
||||
// future callback-less api for i18next-locize-backend
|
||||
r = fc(languages, namespace, key, fallbackValue, opts);
|
||||
} else {
|
||||
r = fc(languages, namespace, key, fallbackValue);
|
||||
}
|
||||
if (r && typeof r.then === 'function') {
|
||||
// promise
|
||||
r.then(function (data) {
|
||||
return clb(null, data);
|
||||
})["catch"](clb);
|
||||
} else {
|
||||
// sync
|
||||
clb(null, r);
|
||||
}
|
||||
} catch (err) {
|
||||
clb(err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// normal with callback
|
||||
fc(languages, namespace, key, fallbackValue, clb /* unused callback */, opts);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "reload",
|
||||
value: function reload() {
|
||||
var _this3 = this;
|
||||
var _this$services = this.services,
|
||||
backendConnector = _this$services.backendConnector,
|
||||
languageUtils = _this$services.languageUtils,
|
||||
logger = _this$services.logger;
|
||||
var currentLanguage = backendConnector.language;
|
||||
if (currentLanguage && currentLanguage.toLowerCase() === 'cimode') return; // avoid loading resources for cimode
|
||||
|
||||
var toLoad = [];
|
||||
var append = function append(lng) {
|
||||
var lngs = languageUtils.toResolveHierarchy(lng);
|
||||
lngs.forEach(function (l) {
|
||||
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
||||
});
|
||||
};
|
||||
append(currentLanguage);
|
||||
if (this.allOptions.preload) this.allOptions.preload.forEach(function (l) {
|
||||
return append(l);
|
||||
});
|
||||
toLoad.forEach(function (lng) {
|
||||
_this3.allOptions.ns.forEach(function (ns) {
|
||||
backendConnector.read(lng, ns, 'read', null, null, function (err, data) {
|
||||
if (err) logger.warn("loading namespace ".concat(ns, " for language ").concat(lng, " failed"), err);
|
||||
if (!err && data) logger.log("loaded namespace ".concat(ns, " for language ").concat(lng), data);
|
||||
backendConnector.loaded("".concat(lng, "|").concat(ns), err, data);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}]);
|
||||
return Backend;
|
||||
}();
|
||||
Backend.type = 'backend';
|
||||
|
||||
return Backend;
|
||||
|
||||
}));
|
||||
414
static/vendor/i18next/i18nextHttpBackend.js
vendored
Normal file
414
static/vendor/i18next/i18nextHttpBackend.js
vendored
Normal file
@@ -0,0 +1,414 @@
|
||||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.i18nextHttpBackend = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
|
||||
(function (global){(function (){
|
||||
var fetchApi
|
||||
if (typeof fetch === 'function') {
|
||||
if (typeof global !== 'undefined' && global.fetch) {
|
||||
fetchApi = global.fetch
|
||||
} else if (typeof window !== 'undefined' && window.fetch) {
|
||||
fetchApi = window.fetch
|
||||
} else {
|
||||
fetchApi = fetch
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof require !== 'undefined' && (typeof window === 'undefined' || typeof window.document === 'undefined')) {
|
||||
var f = fetchApi || require('cross-fetch')
|
||||
if (f.default) f = f.default
|
||||
exports.default = f
|
||||
module.exports = exports.default
|
||||
}
|
||||
|
||||
}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||||
},{"cross-fetch":5}],2:[function(require,module,exports){
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _utils = require("./utils.js");
|
||||
var _request = _interopRequireDefault(require("./request.js"));
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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, _toPropertyKey(descriptor.key), descriptor); } }
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
||||
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
||||
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
||||
var getDefaults = function getDefaults() {
|
||||
return {
|
||||
loadPath: '/locales/{{lng}}/{{ns}}.json',
|
||||
addPath: '/locales/add/{{lng}}/{{ns}}',
|
||||
parse: function parse(data) {
|
||||
return JSON.parse(data);
|
||||
},
|
||||
stringify: JSON.stringify,
|
||||
parsePayload: function parsePayload(namespace, key, fallbackValue) {
|
||||
return _defineProperty({}, key, fallbackValue || '');
|
||||
},
|
||||
parseLoadPayload: function parseLoadPayload(languages, namespaces) {
|
||||
return undefined;
|
||||
},
|
||||
request: _request.default,
|
||||
reloadInterval: typeof window !== 'undefined' ? false : 60 * 60 * 1000,
|
||||
customHeaders: {},
|
||||
queryStringParams: {},
|
||||
crossDomain: false,
|
||||
withCredentials: false,
|
||||
overrideMimeType: false,
|
||||
requestOptions: {
|
||||
mode: 'cors',
|
||||
credentials: 'same-origin',
|
||||
cache: 'default'
|
||||
}
|
||||
};
|
||||
};
|
||||
var Backend = function () {
|
||||
function Backend(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var allOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
_classCallCheck(this, Backend);
|
||||
this.services = services;
|
||||
this.options = options;
|
||||
this.allOptions = allOptions;
|
||||
this.type = 'backend';
|
||||
this.init(services, options, allOptions);
|
||||
}
|
||||
_createClass(Backend, [{
|
||||
key: "init",
|
||||
value: function init(services) {
|
||||
var _this = this;
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
var allOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
this.services = services;
|
||||
this.options = (0, _utils.defaults)(options, this.options || {}, getDefaults());
|
||||
this.allOptions = allOptions;
|
||||
if (this.services && this.options.reloadInterval) {
|
||||
setInterval(function () {
|
||||
return _this.reload();
|
||||
}, this.options.reloadInterval);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "readMulti",
|
||||
value: function readMulti(languages, namespaces, callback) {
|
||||
this._readAny(languages, languages, namespaces, namespaces, callback);
|
||||
}
|
||||
}, {
|
||||
key: "read",
|
||||
value: function read(language, namespace, callback) {
|
||||
this._readAny([language], language, [namespace], namespace, callback);
|
||||
}
|
||||
}, {
|
||||
key: "_readAny",
|
||||
value: function _readAny(languages, loadUrlLanguages, namespaces, loadUrlNamespaces, callback) {
|
||||
var _this2 = this;
|
||||
var loadPath = this.options.loadPath;
|
||||
if (typeof this.options.loadPath === 'function') {
|
||||
loadPath = this.options.loadPath(languages, namespaces);
|
||||
}
|
||||
loadPath = (0, _utils.makePromise)(loadPath);
|
||||
loadPath.then(function (resolvedLoadPath) {
|
||||
if (!resolvedLoadPath) return callback(null, {});
|
||||
var url = _this2.services.interpolator.interpolate(resolvedLoadPath, {
|
||||
lng: languages.join('+'),
|
||||
ns: namespaces.join('+')
|
||||
});
|
||||
_this2.loadUrl(url, callback, loadUrlLanguages, loadUrlNamespaces);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "loadUrl",
|
||||
value: function loadUrl(url, callback, languages, namespaces) {
|
||||
var _this3 = this;
|
||||
var lng = typeof languages === 'string' ? [languages] : languages;
|
||||
var ns = typeof namespaces === 'string' ? [namespaces] : namespaces;
|
||||
var payload = this.options.parseLoadPayload(lng, ns);
|
||||
this.options.request(this.options, url, payload, function (err, res) {
|
||||
if (res && (res.status >= 500 && res.status < 600 || !res.status)) return callback('failed loading ' + url + '; status code: ' + res.status, true);
|
||||
if (res && res.status >= 400 && res.status < 500) return callback('failed loading ' + url + '; status code: ' + res.status, false);
|
||||
if (!res && err && err.message && err.message.indexOf('Failed to fetch') > -1) return callback('failed loading ' + url + ': ' + err.message, true);
|
||||
if (err) return callback(err, false);
|
||||
var ret, parseErr;
|
||||
try {
|
||||
if (typeof res.data === 'string') {
|
||||
ret = _this3.options.parse(res.data, languages, namespaces);
|
||||
} else {
|
||||
ret = res.data;
|
||||
}
|
||||
} catch (e) {
|
||||
parseErr = 'failed parsing ' + url + ' to json';
|
||||
}
|
||||
if (parseErr) return callback(parseErr, false);
|
||||
callback(null, ret);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "create",
|
||||
value: function create(languages, namespace, key, fallbackValue, callback) {
|
||||
var _this4 = this;
|
||||
if (!this.options.addPath) return;
|
||||
if (typeof languages === 'string') languages = [languages];
|
||||
var payload = this.options.parsePayload(namespace, key, fallbackValue);
|
||||
var finished = 0;
|
||||
var dataArray = [];
|
||||
var resArray = [];
|
||||
languages.forEach(function (lng) {
|
||||
var addPath = _this4.options.addPath;
|
||||
if (typeof _this4.options.addPath === 'function') {
|
||||
addPath = _this4.options.addPath(lng, namespace);
|
||||
}
|
||||
var url = _this4.services.interpolator.interpolate(addPath, {
|
||||
lng: lng,
|
||||
ns: namespace
|
||||
});
|
||||
_this4.options.request(_this4.options, url, payload, function (data, res) {
|
||||
finished += 1;
|
||||
dataArray.push(data);
|
||||
resArray.push(res);
|
||||
if (finished === languages.length) {
|
||||
if (typeof callback === 'function') callback(dataArray, resArray);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "reload",
|
||||
value: function reload() {
|
||||
var _this5 = this;
|
||||
var _this$services = this.services,
|
||||
backendConnector = _this$services.backendConnector,
|
||||
languageUtils = _this$services.languageUtils,
|
||||
logger = _this$services.logger;
|
||||
var currentLanguage = backendConnector.language;
|
||||
if (currentLanguage && currentLanguage.toLowerCase() === 'cimode') return;
|
||||
var toLoad = [];
|
||||
var append = function append(lng) {
|
||||
var lngs = languageUtils.toResolveHierarchy(lng);
|
||||
lngs.forEach(function (l) {
|
||||
if (toLoad.indexOf(l) < 0) toLoad.push(l);
|
||||
});
|
||||
};
|
||||
append(currentLanguage);
|
||||
if (this.allOptions.preload) this.allOptions.preload.forEach(function (l) {
|
||||
return append(l);
|
||||
});
|
||||
toLoad.forEach(function (lng) {
|
||||
_this5.allOptions.ns.forEach(function (ns) {
|
||||
backendConnector.read(lng, ns, 'read', null, null, function (err, data) {
|
||||
if (err) logger.warn("loading namespace ".concat(ns, " for language ").concat(lng, " failed"), err);
|
||||
if (!err && data) logger.log("loaded namespace ".concat(ns, " for language ").concat(lng), data);
|
||||
backendConnector.loaded("".concat(lng, "|").concat(ns), err, data);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}]);
|
||||
return Backend;
|
||||
}();
|
||||
Backend.type = 'backend';
|
||||
var _default = exports.default = Backend;
|
||||
module.exports = exports.default;
|
||||
},{"./request.js":3,"./utils.js":4}],3:[function(require,module,exports){
|
||||
(function (global){(function (){
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _utils = require("./utils.js");
|
||||
var fetchNode = _interopRequireWildcard(require("./getFetch.js"));
|
||||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
||||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
||||
var fetchApi;
|
||||
if (typeof fetch === 'function') {
|
||||
if (typeof global !== 'undefined' && global.fetch) {
|
||||
fetchApi = global.fetch;
|
||||
} else if (typeof window !== 'undefined' && window.fetch) {
|
||||
fetchApi = window.fetch;
|
||||
} else {
|
||||
fetchApi = fetch;
|
||||
}
|
||||
}
|
||||
var XmlHttpRequestApi;
|
||||
if ((0, _utils.hasXMLHttpRequest)()) {
|
||||
if (typeof global !== 'undefined' && global.XMLHttpRequest) {
|
||||
XmlHttpRequestApi = global.XMLHttpRequest;
|
||||
} else if (typeof window !== 'undefined' && window.XMLHttpRequest) {
|
||||
XmlHttpRequestApi = window.XMLHttpRequest;
|
||||
}
|
||||
}
|
||||
var ActiveXObjectApi;
|
||||
if (typeof ActiveXObject === 'function') {
|
||||
if (typeof global !== 'undefined' && global.ActiveXObject) {
|
||||
ActiveXObjectApi = global.ActiveXObject;
|
||||
} else if (typeof window !== 'undefined' && window.ActiveXObject) {
|
||||
ActiveXObjectApi = window.ActiveXObject;
|
||||
}
|
||||
}
|
||||
if (!fetchApi && fetchNode && !XmlHttpRequestApi && !ActiveXObjectApi) fetchApi = fetchNode.default || fetchNode;
|
||||
if (typeof fetchApi !== 'function') fetchApi = undefined;
|
||||
var addQueryString = function addQueryString(url, params) {
|
||||
if (params && _typeof(params) === 'object') {
|
||||
var queryString = '';
|
||||
for (var paramName in params) {
|
||||
queryString += '&' + encodeURIComponent(paramName) + '=' + encodeURIComponent(params[paramName]);
|
||||
}
|
||||
if (!queryString) return url;
|
||||
url = url + (url.indexOf('?') !== -1 ? '&' : '?') + queryString.slice(1);
|
||||
}
|
||||
return url;
|
||||
};
|
||||
var fetchIt = function fetchIt(url, fetchOptions, callback) {
|
||||
var resolver = function resolver(response) {
|
||||
if (!response.ok) return callback(response.statusText || 'Error', {
|
||||
status: response.status
|
||||
});
|
||||
response.text().then(function (data) {
|
||||
callback(null, {
|
||||
status: response.status,
|
||||
data: data
|
||||
});
|
||||
}).catch(callback);
|
||||
};
|
||||
if (typeof fetch === 'function') {
|
||||
fetch(url, fetchOptions).then(resolver).catch(callback);
|
||||
} else {
|
||||
fetchApi(url, fetchOptions).then(resolver).catch(callback);
|
||||
}
|
||||
};
|
||||
var omitFetchOptions = false;
|
||||
var requestWithFetch = function requestWithFetch(options, url, payload, callback) {
|
||||
if (options.queryStringParams) {
|
||||
url = addQueryString(url, options.queryStringParams);
|
||||
}
|
||||
var headers = (0, _utils.defaults)({}, typeof options.customHeaders === 'function' ? options.customHeaders() : options.customHeaders);
|
||||
if (typeof window === 'undefined' && typeof global !== 'undefined' && typeof global.process !== 'undefined' && global.process.versions && global.process.versions.node) {
|
||||
headers['User-Agent'] = "i18next-http-backend (node/".concat(global.process.version, "; ").concat(global.process.platform, " ").concat(global.process.arch, ")");
|
||||
}
|
||||
if (payload) headers['Content-Type'] = 'application/json';
|
||||
var reqOptions = typeof options.requestOptions === 'function' ? options.requestOptions(payload) : options.requestOptions;
|
||||
var fetchOptions = (0, _utils.defaults)({
|
||||
method: payload ? 'POST' : 'GET',
|
||||
body: payload ? options.stringify(payload) : undefined,
|
||||
headers: headers
|
||||
}, omitFetchOptions ? {} : reqOptions);
|
||||
try {
|
||||
fetchIt(url, fetchOptions, callback);
|
||||
} catch (e) {
|
||||
if (!reqOptions || Object.keys(reqOptions).length === 0 || !e.message || e.message.indexOf('not implemented') < 0) {
|
||||
return callback(e);
|
||||
}
|
||||
try {
|
||||
Object.keys(reqOptions).forEach(function (opt) {
|
||||
delete fetchOptions[opt];
|
||||
});
|
||||
fetchIt(url, fetchOptions, callback);
|
||||
omitFetchOptions = true;
|
||||
} catch (err) {
|
||||
callback(err);
|
||||
}
|
||||
}
|
||||
};
|
||||
var requestWithXmlHttpRequest = function requestWithXmlHttpRequest(options, url, payload, callback) {
|
||||
if (payload && _typeof(payload) === 'object') {
|
||||
payload = addQueryString('', payload).slice(1);
|
||||
}
|
||||
if (options.queryStringParams) {
|
||||
url = addQueryString(url, options.queryStringParams);
|
||||
}
|
||||
try {
|
||||
var x;
|
||||
if (XmlHttpRequestApi) {
|
||||
x = new XmlHttpRequestApi();
|
||||
} else {
|
||||
x = new ActiveXObjectApi('MSXML2.XMLHTTP.3.0');
|
||||
}
|
||||
x.open(payload ? 'POST' : 'GET', url, 1);
|
||||
if (!options.crossDomain) {
|
||||
x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
}
|
||||
x.withCredentials = !!options.withCredentials;
|
||||
if (payload) {
|
||||
x.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
}
|
||||
if (x.overrideMimeType) {
|
||||
x.overrideMimeType('application/json');
|
||||
}
|
||||
var h = options.customHeaders;
|
||||
h = typeof h === 'function' ? h() : h;
|
||||
if (h) {
|
||||
for (var i in h) {
|
||||
x.setRequestHeader(i, h[i]);
|
||||
}
|
||||
}
|
||||
x.onreadystatechange = function () {
|
||||
x.readyState > 3 && callback(x.status >= 400 ? x.statusText : null, {
|
||||
status: x.status,
|
||||
data: x.responseText
|
||||
});
|
||||
};
|
||||
x.send(payload);
|
||||
} catch (e) {
|
||||
console && console.log(e);
|
||||
}
|
||||
};
|
||||
var request = function request(options, url, payload, callback) {
|
||||
if (typeof payload === 'function') {
|
||||
callback = payload;
|
||||
payload = undefined;
|
||||
}
|
||||
callback = callback || function () {};
|
||||
if (fetchApi && url.indexOf('file:') !== 0) {
|
||||
return requestWithFetch(options, url, payload, callback);
|
||||
}
|
||||
if ((0, _utils.hasXMLHttpRequest)() || typeof ActiveXObject === 'function') {
|
||||
return requestWithXmlHttpRequest(options, url, payload, callback);
|
||||
}
|
||||
callback(new Error('No fetch and no xhr implementation found!'));
|
||||
};
|
||||
var _default = exports.default = request;
|
||||
module.exports = exports.default;
|
||||
}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||||
},{"./getFetch.js":1,"./utils.js":4}],4:[function(require,module,exports){
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.defaults = defaults;
|
||||
exports.hasXMLHttpRequest = hasXMLHttpRequest;
|
||||
exports.makePromise = makePromise;
|
||||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
||||
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 hasXMLHttpRequest() {
|
||||
return typeof XMLHttpRequest === 'function' || (typeof XMLHttpRequest === "undefined" ? "undefined" : _typeof(XMLHttpRequest)) === 'object';
|
||||
}
|
||||
function isPromise(maybePromise) {
|
||||
return !!maybePromise && typeof maybePromise.then === 'function';
|
||||
}
|
||||
function makePromise(maybePromise) {
|
||||
if (isPromise(maybePromise)) {
|
||||
return maybePromise;
|
||||
}
|
||||
return Promise.resolve(maybePromise);
|
||||
}
|
||||
},{}],5:[function(require,module,exports){
|
||||
|
||||
},{}]},{},[2])(2)
|
||||
});
|
||||
190
static/vendor/i18next/i18nextLocalStorageBackend.js
vendored
Normal file
190
static/vendor/i18next/i18nextLocalStorageBackend.js
vendored
Normal file
@@ -0,0 +1,190 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.i18nextLocalStorageBackend = factory());
|
||||
})(this, (function () { 'use strict';
|
||||
|
||||
function _typeof(o) {
|
||||
"@babel/helpers - typeof";
|
||||
|
||||
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
||||
return typeof o;
|
||||
} : function (o) {
|
||||
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
||||
}, _typeof(o);
|
||||
}
|
||||
|
||||
function _toPrimitive(input, hint) {
|
||||
if (_typeof(input) !== "object" || input === null) return input;
|
||||
var prim = input[Symbol.toPrimitive];
|
||||
if (prim !== undefined) {
|
||||
var res = prim.call(input, hint || "default");
|
||||
if (_typeof(res) !== "object") return res;
|
||||
throw new TypeError("@@toPrimitive must return a primitive value.");
|
||||
}
|
||||
return (hint === "string" ? String : Number)(input);
|
||||
}
|
||||
|
||||
function _toPropertyKey(arg) {
|
||||
var key = _toPrimitive(arg, "string");
|
||||
return _typeof(key) === "symbol" ? key : String(key);
|
||||
}
|
||||
|
||||
function _defineProperty(obj, key, value) {
|
||||
key = _toPropertyKey(key);
|
||||
if (key in obj) {
|
||||
Object.defineProperty(obj, key, {
|
||||
value: value,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
} else {
|
||||
obj[key] = value;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a 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, _toPropertyKey(descriptor.key), descriptor);
|
||||
}
|
||||
}
|
||||
function _createClass(Constructor, protoProps, staticProps) {
|
||||
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) _defineProperties(Constructor, staticProps);
|
||||
Object.defineProperty(Constructor, "prototype", {
|
||||
writable: false
|
||||
});
|
||||
return Constructor;
|
||||
}
|
||||
|
||||
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
||||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
||||
/* eslint-disable max-classes-per-file */
|
||||
var Storage = /*#__PURE__*/function () {
|
||||
function Storage(options) {
|
||||
_classCallCheck(this, Storage);
|
||||
this.store = options.store;
|
||||
}
|
||||
_createClass(Storage, [{
|
||||
key: "setItem",
|
||||
value: function setItem(key, value) {
|
||||
if (this.store) {
|
||||
try {
|
||||
this.store.setItem(key, value);
|
||||
} catch (e) {
|
||||
// f.log('failed to set value for key "' + key + '" to localStorage.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "getItem",
|
||||
value: function getItem(key, value) {
|
||||
if (this.store) {
|
||||
try {
|
||||
return this.store.getItem(key, value);
|
||||
} catch (e) {
|
||||
// f.log('failed to get value for key "' + key + '" from localStorage.');
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}]);
|
||||
return Storage;
|
||||
}();
|
||||
function getDefaults() {
|
||||
var store = null;
|
||||
try {
|
||||
store = window.localStorage;
|
||||
} catch (e) {
|
||||
if (typeof window !== 'undefined') {
|
||||
console.log('Failed to load local storage.', e);
|
||||
}
|
||||
}
|
||||
return {
|
||||
prefix: 'i18next_res_',
|
||||
expirationTime: 7 * 24 * 60 * 60 * 1000,
|
||||
defaultVersion: undefined,
|
||||
versions: {},
|
||||
store: store
|
||||
};
|
||||
}
|
||||
var Cache = /*#__PURE__*/function () {
|
||||
function Cache(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
_classCallCheck(this, Cache);
|
||||
this.init(services, options);
|
||||
this.type = 'backend';
|
||||
}
|
||||
_createClass(Cache, [{
|
||||
key: "init",
|
||||
value: function init(services) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
this.services = services;
|
||||
this.options = _objectSpread(_objectSpread(_objectSpread({}, getDefaults()), this.options), options);
|
||||
this.storage = new Storage(this.options);
|
||||
}
|
||||
}, {
|
||||
key: "read",
|
||||
value: function read(language, namespace, callback) {
|
||||
var nowMS = Date.now();
|
||||
if (!this.storage.store) {
|
||||
return callback(null, null);
|
||||
}
|
||||
var local = this.storage.getItem("".concat(this.options.prefix).concat(language, "-").concat(namespace));
|
||||
if (local) {
|
||||
local = JSON.parse(local);
|
||||
var version = this.getVersion(language);
|
||||
if (
|
||||
// expiration field is mandatory, and should not be expired
|
||||
local.i18nStamp && local.i18nStamp + this.options.expirationTime > nowMS &&
|
||||
// there should be no language version set, or if it is, it should match the one in translation
|
||||
version === local.i18nVersion) {
|
||||
var i18nStamp = local.i18nStamp;
|
||||
delete local.i18nVersion;
|
||||
delete local.i18nStamp;
|
||||
return callback(null, local, i18nStamp);
|
||||
}
|
||||
}
|
||||
return callback(null, null);
|
||||
}
|
||||
}, {
|
||||
key: "save",
|
||||
value: function save(language, namespace, data) {
|
||||
if (this.storage.store) {
|
||||
data.i18nStamp = Date.now();
|
||||
|
||||
// language version (if set)
|
||||
var version = this.getVersion(language);
|
||||
if (version) {
|
||||
data.i18nVersion = version;
|
||||
}
|
||||
|
||||
// save
|
||||
this.storage.setItem("".concat(this.options.prefix).concat(language, "-").concat(namespace), JSON.stringify(data));
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "getVersion",
|
||||
value: function getVersion(language) {
|
||||
return this.options.versions[language] || this.options.defaultVersion;
|
||||
}
|
||||
}]);
|
||||
return Cache;
|
||||
}();
|
||||
Cache.type = 'backend';
|
||||
|
||||
return Cache;
|
||||
|
||||
}));
|
||||
128
static/vendor/i18next/jquery-i18next.js
vendored
Normal file
128
static/vendor/i18next/jquery-i18next.js
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global.jqueryI18next = factory());
|
||||
}(this, (function () { 'use strict';
|
||||
|
||||
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 defaults = {
|
||||
tName: 't',
|
||||
i18nName: 'i18n',
|
||||
handleName: 'localize',
|
||||
selectorAttr: 'data-i18n',
|
||||
targetAttr: 'i18n-target',
|
||||
optionsAttr: 'i18n-options',
|
||||
useOptionsAttr: false,
|
||||
parseDefaultValueFromContent: true
|
||||
};
|
||||
|
||||
function init(i18next, $) {
|
||||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
|
||||
|
||||
options = _extends({}, defaults, options);
|
||||
|
||||
function parse(ele, key, opts) {
|
||||
if (key.length === 0) return;
|
||||
|
||||
var attr = 'text';
|
||||
|
||||
if (key.indexOf('[') === 0) {
|
||||
var parts = key.split(']');
|
||||
key = parts[1];
|
||||
attr = parts[0].substr(1, parts[0].length - 1);
|
||||
}
|
||||
|
||||
if (key.indexOf(';') === key.length - 1) {
|
||||
key = key.substr(0, key.length - 2);
|
||||
}
|
||||
|
||||
function extendDefault(o, val) {
|
||||
if (!options.parseDefaultValueFromContent) return o;
|
||||
return _extends({}, o, { defaultValue: val });
|
||||
}
|
||||
|
||||
if (attr === 'html') {
|
||||
ele.html(i18next.t(key, extendDefault(opts, ele.html())));
|
||||
} else if (attr === 'text') {
|
||||
ele.text(i18next.t(key, extendDefault(opts, ele.text())));
|
||||
} else if (attr === 'prepend') {
|
||||
ele.prepend(i18next.t(key, extendDefault(opts, ele.html())));
|
||||
} else if (attr === 'append') {
|
||||
ele.append(i18next.t(key, extendDefault(opts, ele.html())));
|
||||
} else if (attr.indexOf('data-') === 0) {
|
||||
var dataAttr = attr.substr('data-'.length);
|
||||
var translated = i18next.t(key, extendDefault(opts, ele.data(dataAttr)));
|
||||
|
||||
// we change into the data cache
|
||||
ele.data(dataAttr, translated);
|
||||
// we change into the dom
|
||||
ele.attr(attr, translated);
|
||||
} else {
|
||||
ele.attr(attr, i18next.t(key, extendDefault(opts, ele.attr(attr))));
|
||||
}
|
||||
}
|
||||
|
||||
function localize(ele, opts) {
|
||||
var key = ele.attr(options.selectorAttr);
|
||||
if (!key && typeof key !== 'undefined' && key !== false) key = ele.text() || ele.val();
|
||||
if (!key) return;
|
||||
|
||||
var target = ele,
|
||||
targetSelector = ele.data(options.targetAttr);
|
||||
|
||||
if (targetSelector) target = ele.find(targetSelector) || ele;
|
||||
|
||||
if (!opts && options.useOptionsAttr === true) opts = ele.data(options.optionsAttr);
|
||||
|
||||
opts = opts || {};
|
||||
|
||||
if (key.indexOf(';') >= 0) {
|
||||
var keys = key.split(';');
|
||||
|
||||
$.each(keys, function (m, k) {
|
||||
// .trim(): Trim the comma-separated parameters on the data-i18n attribute.
|
||||
if (k !== '') parse(target, k.trim(), opts);
|
||||
});
|
||||
} else {
|
||||
parse(target, key, opts);
|
||||
}
|
||||
|
||||
if (options.useOptionsAttr === true) {
|
||||
var clone = {};
|
||||
clone = _extends({ clone: clone }, opts);
|
||||
|
||||
delete clone.lng;
|
||||
ele.data(options.optionsAttr, clone);
|
||||
}
|
||||
}
|
||||
|
||||
function handle(opts) {
|
||||
return this.each(function () {
|
||||
// localize element itself
|
||||
localize($(this), opts);
|
||||
|
||||
// localize children
|
||||
var elements = $(this).find('[' + options.selectorAttr + ']');
|
||||
elements.each(function () {
|
||||
localize($(this), opts);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// $.t $.i18n shortcut
|
||||
$[options.tName] = i18next.t.bind(i18next);
|
||||
$[options.i18nName] = i18next;
|
||||
|
||||
// selector function $(mySelector).localize(opts);
|
||||
$.fn[options.handleName] = handle;
|
||||
}
|
||||
|
||||
var index = {
|
||||
init: init
|
||||
};
|
||||
|
||||
return index;
|
||||
|
||||
})));
|
||||
Reference in New Issue
Block a user