i18nextChainedBackend.js

A i18next module

Dit script moet niet direct worden geïnstalleerd - het is een bibliotheek voor andere scripts om op te nemen met de meta-richtlijn // @require https://update.greasyfork.org/scripts/484742/1311040/i18nextChainedBackendjs.js

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).i18nextChainedBackend=n()}(this,(function(){"use strict";function e(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function t(e){var t=function(e,t){if("object"!==n(e)||null===e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var i=o.call(e,t||"default");if("object"!==n(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"===n(t)?t:String(t)}function o(e,n){for(var o=0;o<n.length;o++){var i=n[o];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,t(i.key),i)}}var i=[],r=i.forEach,a=i.slice;function c(e){return r.call(a.call(arguments,1),(function(n){if(n)for(var t in n)void 0===e[t]&&(e[t]=n[t])})),e}function s(e){return e?"function"==typeof e?new e:e:null}function l(e,n,t,o){var i=e.read.bind(e);if(2!==i.length)i(n,t,o);else try{var r=i(n,t);r&&"function"==typeof r.then?r.then((function(e){return o(null,e)})).catch(o):o(null,r)}catch(e){o(e)}}var f=function(){function n(t){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};e(this,n),this.backends=[],this.type="backend",this.allOptions=i,this.init(t,o)}var t,i,r;return t=n,(i=[{key:"init",value:function(e){var n=this,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.services=e,this.options=c(t,this.options||{},{handleEmptyResourcesAsFailed:!0,cacheHitMode:"none"}),this.allOptions=o,this.options.backends&&this.options.backends.forEach((function(t,i){n.backends[i]=n.backends[i]||s(t),n.backends[i].init(e,n.options.backendOptions&&n.options.backendOptions[i]||{},o)})),this.services&&this.options.reloadInterval&&setInterval((function(){return n.reload()}),this.options.reloadInterval)}},{key:"read",value:function(e,n,t){var o=this,i=this.backends.length,r=function t(i,r){if(!(i<0)){var a=o.backends[i];a.save?(a.save(e,n,r),t(i-1,r)):t(i-1,r)}};!function a(c){if(c>=i)return t(new Error("non of the backend loaded data",!0));var s=c===i-1,f=o.options.handleEmptyResourcesAsFailed&&!s?0:-1,u=o.backends[c];u.read?l(u,e,n,(function(i,s,d){if(!i&&s&&Object.keys(s).length>f){if(t(null,s,c),r(c-1,s),u.save&&o.options.cacheHitMode&&["refresh","refreshAndUpdateStore"].indexOf(o.options.cacheHitMode)>-1){if(d&&o.options.refreshExpirationTime&&d+o.options.refreshExpirationTime>Date.now())return;var h=o.backends[c+1];h&&h.read&&l(h,e,n,(function(t,i){t||i&&(Object.keys(i).length<=f||(r(c,i),"refreshAndUpdateStore"===o.options.cacheHitMode&&o.services&&o.services.resourceStore&&o.services.resourceStore.addResourceBundle(e,n,i)))}))}}else a(c+1)})):a(c+1)}(0)}},{key:"create",value:function(e,n,t,o){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:function(){},r=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};this.backends.forEach((function(a){if(a.create){var c=a.create.bind(a);if(c.length<6)try{var s;(s=5===c.length?c(e,n,t,o,r):c(e,n,t,o))&&"function"==typeof s.then?s.then((function(e){return i(null,e)})).catch(i):i(null,s)}catch(e){i(e)}else c(e,n,t,o,i,r)}}))}},{key:"reload",value:function(){var e=this,n=this.services,t=n.backendConnector,o=n.languageUtils,i=n.logger,r=t.language;if(!r||"cimode"!==r.toLowerCase()){var a=[],c=function(e){o.toResolveHierarchy(e).forEach((function(e){a.indexOf(e)<0&&a.push(e)}))};c(r),this.allOptions.preload&&this.allOptions.preload.forEach((function(e){return c(e)})),a.forEach((function(n){e.allOptions.ns.forEach((function(e){t.read(n,e,"read",null,null,(function(o,r){o&&i.warn("loading namespace ".concat(e," for language ").concat(n," failed"),o),!o&&r&&i.log("loaded namespace ".concat(e," for language ").concat(n),r),t.loaded("".concat(n,"|").concat(e),o,r)}))}))}))}}}])&&o(t.prototype,i),r&&o(t,r),Object.defineProperty(t,"prototype",{writable:!1}),n}();return f.type="backend",f}));