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