-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
i18next-locize-backend.min.js
1 lines (1 loc) · 3.79 KB
/
i18next-locize-backend.min.js
1
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define("i18next-locize-backend",t):e.i18next-locize-backend=t()}(this,function(){"use strict";function e(e,t,n){var i;return function(){var o=this,r=arguments,a=function(){i=null,n||e.apply(o,r)},s=n&&!i;clearTimeout(i),i=setTimeout(a,t),s&&e.apply(o,r)}}function t(e,t,n){function i(e){return e&&e.indexOf("###")>-1?e.replace(/###/g,"."):e}for(var o="string"!=typeof t?[].concat(t):t.split(".");o.length>1;){if(!e)return{};var r=i(o.shift());!e[r]&&n&&(e[r]=new n),e=e[r]}return e?{obj:e,k:i(o.shift())}:{}}function n(e,n,i){var o=t(e,n,Object),r=o.obj,a=o.k;r[a]=i}function i(e,n,i,o){var r=t(e,n,Object),a=r.obj,s=r.k;a[s]=a[s]||[],o&&(a[s]=a[s].concat(i)),o||a[s].push(i)}function o(e,n){var i=t(e,n),o=i.obj,r=i.k;return o?o[r]:void 0}function r(e,t,n,i,o){try{var r=new(XMLHttpRequest||ActiveXObject)("MSXML2.XMLHTTP.3.0");r.open(i?"POST":"GET",e,1),t.crossDomain||r.setRequestHeader("X-Requested-With","XMLHttpRequest"),t.authorize&&t.apiKey&&r.setRequestHeader("Authorization",t.apiKey),r.setRequestHeader("Content-type","application/json"),r.onreadystatechange=function(){r.readyState>3&&n&&n(r.responseText,r)},r.send(JSON.stringify(i))}catch(a){window.console&&console.log(a)}}function a(){return{loadPath:"/locales/{{lng}}/{{ns}}.json",addPath:"locales/add/{{lng}}/{{ns}}",referenceLng:"en",crossDomain:!0,version:"latest"}}var s={};s.classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},s.createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),s["extends"]=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e};var c=function(){function t(e){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];s.classCallCheck(this,t),this.init(e,n),this.type="backend"}return s.createClass(t,[{key:"init",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.services=t,this.options=s["extends"]({},a(),this.options,n),this.queuedWrites={},this.debouncedWrite=e(this.write,1e4)}},{key:"read",value:function(e,t,n){var i=this.services.interpolator.interpolate(this.options.loadPath,{lng:e,ns:t,projectId:this.options.projectId,version:this.options.version});this.loadUrl(i,n)}},{key:"loadUrl",value:function(e,t){r(e,this.options,function(n,i){var o=i.status.toString();if(0===o.indexOf("5"))return t("failed loading "+e,!0);if(0===o.indexOf("4"))return t("failed loading "+e,!1);var r=void 0,a=void 0;try{r=JSON.parse(n)}catch(s){a="failed parsing "+e+" to json"}return a?t(a,!1):void t(null,r)})}},{key:"create",value:function(e,t,n,i,o){var r=this;o||(o=function(){}),"string"==typeof e&&(e=[e]),e.forEach(function(e){e===r.options.referenceLng&&r.queue.call(r,r.options.referenceLng,t,n,i,o)})}},{key:"write",value:function(e,t){var i=this,a=o(this.queuedWrites,["locks",e,t]);if(!a){var c=this.services.interpolator.interpolate(this.options.addPath,{lng:e,ns:t,projectId:this.options.projectId,version:this.options.version}),u=o(this.queuedWrites,[e,t]);n(this.queuedWrites,[e,t],[]),u.length&&!function(){n(i.queuedWrites,["locks",e,t],!0);var o={};u.forEach(function(e){o[e.key]=e.fallbackValue||""}),r(c,s["extends"]({authorize:!0},i.options),function(o,r){n(i.queuedWrites,["locks",e,t],!1),u.forEach(function(e){e.callback&&e.callback()}),i.debouncedWrite(e,t)},o)}()}}},{key:"queue",value:function(e,t,n,o,r){i(this.queuedWrites,[e,t],{key:n,fallbackValue:o||"",callback:r}),this.debouncedWrite(e,t)}}]),t}();return c.type="backend",c});