forked from i18next/i18next-xhr-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi18nextXHRBackend.min.js
1 lines (1 loc) · 2.92 KB
/
i18nextXHRBackend.min.js
1
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.i18nextXHRBackend=n()}(this,function(){"use strict";function t(t){return i.call(a.call(arguments,1),function(n){if(n)for(var e in n)void 0===t[e]&&(t[e]=n[e])}),t}function n(t,n,e,o,i){if(o&&"object"===("undefined"==typeof o?"undefined":r(o))){var a="",s=encodeURIComponent;for(var l in o)a+="&"+s(l)+"="+s(o[l]);o=a.slice(1)+(i?"":"&_t="+new Date)}try{var c=new(XMLHttpRequest||ActiveXObject)("MSXML2.XMLHTTP.3.0");c.open(o?"POST":"GET",t,1),n.crossDomain||c.setRequestHeader("X-Requested-With","XMLHttpRequest"),c.withCredentials=!!n.withCredentials,o&&c.setRequestHeader("Content-type","application/x-www-form-urlencoded"),c.onreadystatechange=function(){c.readyState>3&&e&&e(c.responseText,c)},c.send(o)}catch(t){window.console&&console.log(t)}}function e(){return{loadPath:"/locales/{{lng}}/{{ns}}.json",addPath:"locales/add/{{lng}}/{{ns}}",allowMultiLoading:!1,parse:JSON.parse,crossDomain:!1,ajax:n}}var o=[],i=o.forEach,a=o.slice,r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},s=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")},l=function(){function t(t,n){for(var e=0;e<n.length;e++){var o=n[e];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(n,e,o){return e&&t(n.prototype,e),o&&t(n,o),n}}(),c=function(){function n(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];s(this,n),this.init(t,e),this.type="backend"}return l(n,[{key:"init",value:function(n){var o=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.services=n,this.options=t(o,this.options||{},e())}},{key:"readMulti",value:function(t,n,e){var o=this.options.loadPath;"function"==typeof this.options.loadPath&&(o=this.options.loadPath(t,n));var i=this.services.interpolator.interpolate(o,{lng:t.join("+"),ns:n.join("+")});this.loadUrl(i,e)}},{key:"read",value:function(t,n,e){var o=this.options.loadPath;"function"==typeof this.options.loadPath&&(o=this.options.loadPath([t],[n]));var i=this.services.interpolator.interpolate(o,{lng:t,ns:n});this.loadUrl(i,e)}},{key:"loadUrl",value:function(t,n){var e=this;this.options.ajax(t,this.options,function(o,i){if(i.status>=500&&i.status<600)return n("failed loading "+t,!0);if(i.status>=400&&i.status<500)return n("failed loading "+t,!1);var a=void 0,r=void 0;try{a=e.options.parse(o,t)}catch(n){r="failed parsing "+t+" to json"}return r?n(r,!1):void n(null,a)})}},{key:"create",value:function(t,n,e,o){var i=this;"string"==typeof t&&(t=[t]);var a={};a[e]=o||"",t.forEach(function(t){var e=i.services.interpolator.interpolate(i.options.addPath,{lng:t,ns:n});i.options.ajax(e,i.options,function(t,n){},a)})}}]),n}();return c.type="backend",c});