-
Notifications
You must be signed in to change notification settings - Fork 1
/
translate.me.min.js
1 lines (1 loc) · 4.73 KB
/
translate.me.min.js
1
define("lib/public/ajax-translations-handler.amd",["jquery","underscore"],function(e,t){var n=function(e){e&&e.intelligentMasterCreation&&this.enableIntelligentMasterCreation()};return n.prototype.get=function(t){if("function"!=typeof t)throw new TypeError("The argument done, must be function.");e.ajax({url:"/translate.me/api/json/translations",method:"get",data:{select:["-_id","key","namespace","translations.locale","translations.value"]},success:function(e){t(e)},error:function(e,t,n){console.log("Could not retrieve translation. This is the JQuery response:",{jqXHR:e,textStatus:t,errorThrown:n})}})},n.prototype.createMaster=function(t,n,a){var r={namespace:t,key:n};e.ajax({url:"/translate.me/api/json/translations",method:"post",data:r,success:function(e){a(null,{namespace:e.namespace,key:e.key})},error:function(t,n,o){a(e.extend(new Error("Could not save translation"),{translation:r,jquery:{jqXHR:t,textStatus:n,errorThrown:o}})),console.log("Could not save translation: ",r,{jqXHR:t,textStatus:n,errorThrown:o})}})},n.prototype.enableIntelligentMasterCreation=function(){var e,n=this,a=100,r={},o=null;this._createMaster=this.createMaster,this.createMaster=function(s,i,l){s&&i&&(null===o||(new Date).valueOf()-o.valueOf()<=a)?(r[s+":"+i]||(r[s+":"+i]={namespace:s,key:i,callbacks:[]}),r[s+":"+i].callbacks.push(l),clearTimeout(e),e=setTimeout(n.createMaster,a)):(t.each(t.values(r),function(e){n._createMaster(e.namespace,e.key,function(){var n=arguments;t.each(e.callbacks,function(e){e.call(n)})})}),r={}),o=new Date}},n}),function(e,t){"object"==typeof exports?module.exports=t():"function"==typeof define&&define.amd?define("lib/handlebars-helpers.umd",t):e.handlebarsHelpers=t()}(this,function(){return{createNamespaceBlockHelper:function(){return function(e){var t=e.hash.name||"";return e.fn(this,{data:{namespace:t}})}},createTranslationBlockHelper:function(e){return function(t){var n,a=t.hash.key;if(!a)throw"Invalid translation statement! Argument 'key' is missing!";return n=t.hash&&void 0!==t.hash.namespace?t.hash.namespace:t.data&&void 0!==t.data.namespace?t.data.namespace:"",e.translate(a,n,this)}}}}),function(e,t){"object"==typeof exports?module.exports=t():"function"==typeof define&&define.amd?define("lib/property-path-utility.umd.js",t):e.propertiesPathUtility=t()}(this,function(){function e(t,n,a){var a=a?a:0,r=n[a];return t&&n&&r?e(t[r],n,++a):t}function t(t,n){var a,r,o=/\{\{(.+?)\}\}/g,s=t,i=0;if("string"!=typeof t)throw new TypeError("The argument str is not a string.");if("object"!=typeof n)throw new TypeError('Could not replace properties in: "'+t+'". The passed object is not of type object.');if(t.length>1)for(;a=o.exec(t);)(r=e(n,a[1].split(".")))&&(r=new String(r),s=s.substring(0,o.lastIndex-a[0].length+i)+r+s.substring(o.lastIndex+i),i=-1*(a[0].length-r.length));return s}return{replace:t}}),function(e,t){"object"==typeof exports?module.exports=t(require("./property-path-utility.umd.js")):"function"==typeof define&&define.amd?define("lib/translator.umd",["./property-path-utility.umd.js"],t):e.translator=t(e.propertiesPathUtility)}(this,function(e){var t=function(t,n){var a={elements:{},get:function(e,t,n){return this.elements[e]&&this.elements[e][t]?this.elements[e][t][n]:void 0},build:function(e){var t=this;e.forEach(function(e){e.translations&&e.translations.forEach(function(n){t.elements[e.namespace]||(t.elements[e.namespace]={}),t.elements[e.namespace][e.key]||(t.elements[e.namespace][e.key]={}),t.elements[e.namespace][e.key][n.locale]=n.value})})}};t.get(function(e){a.build(e)}),this.translate=function(t,r,o,s){var i,l,c={};if(c.namespace="",c.locale=n,"string"==typeof t?c.key=t:"object"==typeof t&&(c=t),"string"==typeof r?c.namespace=r:"object"==typeof r&&(c.context=r),"string"==typeof o?c.locale=o:"object"==typeof o&&(c.context=o),s){if("object"!=typeof s)throw new TypeError('The passed context: "'+s+'" is not an object.');c.context=s}if(!c.key)throw"A key is required!";if(void 0===c.namespace)throw"A namespace is required!";if(!c.locale)throw"A locale is required!";return l=a.get(c.namespace,c.key,c.locale),l||(l=a.get(c.namespace,c.key,n)),i=l,i||(i=c.key),c.context&&(i=e.replace(i,c.context)),i},this.getNamespace=function(e){var t,r={};if(void 0===e||"string"!=typeof e)throw new TypeError("The passed namespace is not a string.");for(t in a.elements[e])r[t]=a.elements[e][t][n];return r},this.isReady=function(){return Object.keys(a.elements).length>0},this.setPreferredLocale=function(e){if("string"!=typeof e)throw new TypeError("The passed argument locale is not a string.");if(e.length<=0)throw new Error("The passed locale is empty.");n=e}};return t}),define("translate.me",["lib/public/ajax-translations-handler.amd","lib/handlebars-helpers.umd","lib/translator.umd"],function(e,t,n){return{AjaxTranslationHandler:e,Helpers:t,Translator:n}});