-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathi18nextMultiloadBackendAdapter.min.js
1 lines (1 loc) · 4.8 KB
/
i18nextMultiloadBackendAdapter.min.js
1
!function(e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).i18nextMultiloadBackendAdapter=e()}(function(){return function i(r,o,a){function u(n,e){if(!o[n]){if(!r[n]){var t="function"==typeof require&&require;if(!e&&t)return t(n,!0);if(c)return c(n,!0);throw(e=new Error("Cannot find module '"+n+"'")).code="MODULE_NOT_FOUND",e}t=o[n]={exports:{}},r[n][0].call(t.exports,function(e){return u(r[n][1][e]||e)},t,t.exports,i,r,o,a)}return o[n].exports}for(var c="function"==typeof require&&require,e=0;e<a.length;e++)u(a[e]);return u}({1:[function(e,n,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i=function(e,n){if(!n&&e&&e.__esModule)return e;if(null===e||"object"!=u(e)&&"function"!=typeof e)return{default:e};n=a(n);if(n&&n.has(e))return n.get(e);var t,i={__proto__:null},r=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(t in e){var o;"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&((o=r?Object.getOwnPropertyDescriptor(e,t):null)&&(o.get||o.set)?Object.defineProperty(i,t,o):i[t]=e[t])}return i.default=e,n&&n.set(e,i),i}(e("./utils.js"));function a(e){var n,t;return"function"!=typeof WeakMap?null:(n=new WeakMap,t=new WeakMap,(a=function(e){return e?t:n})(e))}function u(e){return(u="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 r(e,n){for(var t=0;t<n.length;t++){var i=n[t];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,function(e){e=function(e,n){if("object"!==u(e)||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0===t)return("string"===n?String:Number)(e);t=t.call(e,n||"default");if("object"!==u(t))return t;throw new TypeError("@@toPrimitive must return a primitive value.")}(e,"string");return"symbol"===u(e)?e:String(e)}(i.key),i)}}e=l,(c=[{key:"init",value:function(e){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},t=2<arguments.length?arguments[2]:void 0;if(this.services=e,this.options=i.defaults(n,this.options||{},{debounceInterval:50}),this.debouncedLoad=i.debounce(this.load,this.options.debounceInterval),this.options.backend&&(this.backend=this.backend||i.createClassOnDemand(this.options.backend),this.backend.init(e,this.options.backendOption,t)),this.backend&&!this.backend.readMulti)throw new Error("The wrapped backend does not support the readMulti function.")}},{key:"read",value:function(e,n,t){this.pending.push({language:e,namespace:n,callback:t}),this.debouncedLoad()}},{key:"load",value:function(){if(this.backend&&this.pending.length){var e=this.pending,n=(this.pending=[],e.reduce(function(e,n){return e.languages.indexOf(n.language)<0&&e.languages.push(n.language),e.namespaces.indexOf(n.namespace)<0&&e.namespaces.push(n.namespace),e},{languages:[],namespaces:[]})),t=function(n,t){if(n)return e.forEach(function(e){return e.callback(n,t)});e.forEach(function(e){var n=t[e.language]&&t[e.language][e.namespace];e.callback(null,n||{})})},i=this.backend.readMulti.bind(this.backend);if(2===i.length)try{var r=i(n.languages,n.namespaces);r&&"function"==typeof r.then?r.then(function(e){return t(null,e)}).catch(t):t(null,r)}catch(e){t(e)}else i(n.languages,n.namespaces,t)}}},{key:"create",value:function(e,n,t,i){var r=4<arguments.length&&void 0!==arguments[4]?arguments[4]:function(){},o=5<arguments.length&&void 0!==arguments[5]?arguments[5]:{};if(this.backend&&this.backend.create){var a=this.backend.create.bind(this.backend);if(a.length<6)try{var u=5===a.length?a(e,n,t,i,o):a(e,n,t,i);u&&"function"==typeof u.then?u.then(function(e){return r(null,e)}).catch(r):r(null,u)}catch(e){r(e)}else a(e,n,t,i,r,o)}}}])&&r(e.prototype,c),o&&r(e,o),Object.defineProperty(e,"prototype",{writable:!1});var o,c=l;function l(e){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},t=this,i=l;if(!(t instanceof i))throw new TypeError("Cannot call a class as a function");this.type="backend",this.pending=[],this.init(e,n)}c.type="backend";t.default=c;n.exports=t.default},{"./utils.js":2}],2:[function(e,n,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.createClassOnDemand=function(e){return e?"function"==typeof e?new e:e:null},t.debounce=function(i,r,o){var a;return function(){var e=this,n=arguments,t=o&&!a;clearTimeout(a),a=setTimeout(function(){a=null,o||i.apply(e,n)},r),t&&i.apply(e,n)}},t.defaults=function(t){return i.call(r.call(arguments,1),function(e){if(e)for(var n in e)void 0===t[n]&&(t[n]=e[n])}),t},t.extend=function(t){return i.call(r.call(arguments,1),function(e){if(e)for(var n in e)t[n]=e[n]}),t};var t=[],i=t.forEach,r=t.slice},{}]},{},[1])(1)});