forked from i18next/i18next-http-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi18nextHttpBackend.min.js
1 lines (1 loc) · 7.79 KB
/
i18nextHttpBackend.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).i18nextHttpBackend=e()}(function(){return function r(a,s,u){function f(t,e){if(!s[t]){if(!a[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(l)return l(t,!0);var o=new Error("Cannot find module '"+t+"'");throw o.code="MODULE_NOT_FOUND",o}var i=s[t]={exports:{}};a[t][0].call(i.exports,function(e){return f(a[t][1][e]||e)},i,i.exports,r,a,s,u)}return s[t].exports}for(var l="function"==typeof require&&require,e=0;e<u.length;e++)f(u[e]);return f}({1:[function(o,i,r){(function(e){var t,n;"function"==typeof fetch&&(void 0!==e&&e.fetch?t=e.fetch:"undefined"!=typeof window&&window.fetch&&(t=window.fetch)),void 0===o||"undefined"!=typeof window&&void 0!==window.document||((n=t||o("node-fetch")).default&&(n=n.default),r.default=n,i.exports=r.default)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"node-fetch":5}],2:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var o,a=e("./utils.js"),i=(o=e("./request.js"))&&o.__esModule?o:{default:o};function r(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function s(){return{loadPath:"/locales/{{lng}}/{{ns}}.json",addPath:"/locales/add/{{lng}}/{{ns}}",allowMultiLoading:!1,parse:function(e){return JSON.parse(e)},stringify:JSON.stringify,parsePayload:function(e,t,n){return r=n||"",(i=t)in(o={})?Object.defineProperty(o,i,{value:r,enumerable:!0,configurable:!0,writable:!0}):o[i]=r,o;var o,i,r},request:i.default,reloadInterval:!1,customHeaders:{},queryStringParams:{},crossDomain:!1,withCredentials:!1,overrideMimeType:!1,requestOptions:{mode:"cors",credentials:"same-origin",cache:"default"}}}var u=function(){function o(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),this.services=e,this.options=t,this.allOptions=n,this.type="backend",this.init(e,t,n)}var e,t,n;return e=o,(t=[{key:"init",value:function(e,t,n){var o=this,i=1<arguments.length&&void 0!==t?t:{},r=2<arguments.length&&void 0!==n?n:{};this.services=e,this.options=(0,a.defaults)(i,this.options||{},s()),this.allOptions=r,this.options.reloadInterval&&setInterval(function(){return o.reload()},this.options.reloadInterval)}},{key:"readMulti",value:function(e,t,n){var o=this.options.loadPath;"function"==typeof this.options.loadPath&&(o=this.options.loadPath(e,t));var i=this.services.interpolator.interpolate(o,{lng:e.join("+"),ns:t.join("+")});this.loadUrl(i,n,e,t)}},{key:"read",value:function(e,t,n){var o=this.options.loadPath;"function"==typeof this.options.loadPath&&(o=this.options.loadPath([e],[t]));var i=this.services.interpolator.interpolate(o,{lng:e,ns:t});this.loadUrl(i,n,e,t)}},{key:"loadUrl",value:function(i,r,a,s){var u=this;this.options.request(this.options,i,void 0,function(e,t){if(t&&500<=t.status&&t.status<600)return r("failed loading "+i,!0);if(t&&400<=t.status&&t.status<500)return r("failed loading "+i,!1);if(e)return r(e,!1);var n,o;try{n=u.options.parse(t.data,a,s)}catch(e){o="failed parsing "+i+" to json"}if(o)return r(o,!1);r(null,n)})}},{key:"create",value:function(e,n,t,o){var i,r=this;this.options.addPath&&("string"==typeof e&&(e=[e]),i=this.options.parsePayload(n,t,o),e.forEach(function(e){var t=r.services.interpolator.interpolate(r.options.addPath,{lng:e,ns:n});r.options.request(r.options,t,i,function(e,t){})}))}},{key:"reload",value:function(){var t,e,n=this,o=this.services,i=o.backendConnector,r=o.languageUtils,a=o.logger,s=i.language;s&&"cimode"===s.toLowerCase()||(t=[],(e=function(e){r.toResolveHierarchy(e).forEach(function(e){t.indexOf(e)<0&&t.push(e)})})(s),this.allOptions.preload&&this.allOptions.preload.forEach(e),t.forEach(function(o){n.allOptions.ns.forEach(function(n){i.read(o,n,"read",null,null,function(e,t){e&&a.warn("loading namespace ".concat(n," for language ").concat(o," failed"),e),!e&&t&&a.log("loaded namespace ".concat(n," for language ").concat(o),t),i.loaded("".concat(o,"|").concat(n),e,t)})})}))}}])&&r(e.prototype,t),n&&r(e,n),o}();u.type="backend",n.default=u,t.exports=n.default},{"./request.js":3,"./utils.js":4}],3:[function(o,i,d){(function(e){"use strict";Object.defineProperty(d,"__esModule",{value:!0}),d.default=void 0;var r,s,u,a=o("./utils.js"),t=function(e){if(e&&e.__esModule)return e;if(null===e||"object"!==l(e)&&"function"!=typeof e)return{default:e};var t=f();if(t&&t.has(e))return t.get(e);var n={},o=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var i in e){var r;Object.prototype.hasOwnProperty.call(e,i)&&((r=o?Object.getOwnPropertyDescriptor(e,i):null)&&(r.get||r.set)?Object.defineProperty(n,i,r):n[i]=e[i])}n.default=e,t&&t.set(e,n);return n}(o("./getFetch.js"));function f(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return f=function(){return e},e}function l(e){return(l="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"==typeof fetch&&(void 0!==e&&e.fetch?r=e.fetch:"undefined"!=typeof window&&window.fetch&&(r=window.fetch)),"function"==typeof XMLHttpRequest&&(void 0!==e&&e.XMLHttpRequest?s=e.XMLHttpRequest:"undefined"!=typeof window&&window.XMLHttpRequest&&(s=window.XMLHttpRequest)),"function"==typeof ActiveXObject&&(void 0!==e&&e.ActiveXObject?u=e.ActiveXObject:"undefined"!=typeof window&&window.ActiveXObject&&(u=window.ActiveXObject)),r||!t||s||u||(r=t.default||t),"function"!=typeof r&&(r=void 0);function c(e,t){if(t&&"object"===l(t)){var n="";for(var o in t)n+="&"+encodeURIComponent(o)+"="+encodeURIComponent(t[o]);if(!n)return e;e=e+(-1!==e.indexOf("?")?"&":"?")+n.slice(1)}return e}function n(e,t,n,o){return"function"==typeof n&&(o=n,n=void 0),o=o||function(){},r?function(e,t,n,o){e.queryStringParams&&(t=c(t,e.queryStringParams));var i=(0,a.defaults)({},e.customHeaders);n&&(i["Content-Type"]="application/json"),r(t,(0,a.defaults)({method:n?"POST":"GET",body:n?e.stringify(n):void 0,headers:i},"function"==typeof e.requestOptions?e.requestOptions(n):e.requestOptions)).then(function(t){if(!t.ok)return o(t.statusText||"Error",{status:t.status});t.text().then(function(e){o(null,{status:t.status,data:e})}).catch(o)}).catch(o)}(e,t,n,o):"function"==typeof XMLHttpRequest||"function"==typeof ActiveXObject?function(e,t,n,o){n&&"object"===l(n)&&(n=c("",n).slice(1)),e.queryStringParams&&(t=c(t,e.queryStringParams));try{var i=s?new s:new u("MSXML2.XMLHTTP.3.0");i.open(n?"POST":"GET",t,1),e.crossDomain||i.setRequestHeader("X-Requested-With","XMLHttpRequest"),i.withCredentials=!!e.withCredentials,n&&i.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),i.overrideMimeType&&i.overrideMimeType("application/json");var r=e.customHeaders;if(r="function"==typeof r?r():r)for(var a in r)i.setRequestHeader(a,r[a]);i.onreadystatechange=function(){3<i.readyState&&o(400<=i.status?i.statusText:null,{status:i.status,data:i.responseText})},i.send(n)}catch(e){console&&console.log(e)}}(e,t,n,o):void 0}d.default=n,i.exports=d.default}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./getFetch.js":1,"./utils.js":4}],4:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.defaults=function(n){return i.call(r.call(arguments,1),function(e){if(e)for(var t in e)void 0===n[t]&&(n[t]=e[t])}),n};var o=[],i=o.forEach,r=o.slice},{}],5:[function(e,t,n){},{}]},{},[2])(2)});