-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlanguages.min.js
1 lines (1 loc) · 9.04 KB
/
languages.min.js
1
var Languages=function(t){function r(n){if(e[n])return e[n].exports;var a=e[n]={exports:{},id:n,loaded:!1};return t[n].call(a.exports,a,a.exports,r),a.loaded=!0,a.exports}var e={};return r.m=t,r.c=e,r.p="",r(0)}([function(t,r,e){"use strict";var n=e(1),a=function(){var t=new n;return t.instance=function(){return t=new n},String.prototype.t=function(){for(var r,e=arguments.length,n=Array(e),a=0;a<e;a++)n[a]=arguments[a];return(r=t).translate.apply(r,[this].concat(n))},"undefined"!=typeof Handlebars&&t.load.Handlebars(Handlebars),"undefined"!=typeof angular&&t.load.Angular(angular),"undefined"!=typeof Vue&&Vue.use(t.load.Vue),t}();t.exports=a},function(t,r,e){"use strict";function n(t){if(Array.isArray(t)){for(var r=0,e=Array(t.length);r<t.length;r++)e[r]=t[r];return e}return Array.from(t)}function a(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}var i=function(){function t(t,r){var e=[],n=!0,a=!1,i=void 0;try{for(var o,u=t[Symbol.iterator]();!(n=(o=u.next()).done)&&(e.push(o.value),!r||e.length!==r);n=!0);}catch(t){a=!0,i=t}finally{try{!n&&u.return&&u.return()}finally{if(a)throw i}}return e}return function(r,e){if(Array.isArray(r))return r;if(Symbol.iterator in Object(r))return t(r,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),o=function(){function t(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(r,e,n){return e&&t(r.prototype,e),n&&t(r,n),r}}(),u=void 0,l=!1;"undefined"!=typeof r&&"undefined"==typeof window&&(u=e(2),l=!0),t.exports=function(){function t(){a(this,t),this.current="en",this.data={},this.options={},this._path=null,this._cache={},this._list=[]}return o(t,[{key:"set",value:function(t,r){return this.init(t,this._path,r),this}},{key:"add",value:function(t,r,e,n){this.init(t,r,n,{namespace:e})}},{key:"packages",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=[],n=r.namespace||"self";this._cache[n]||(this._cache[n]={});for(var a in t)this._cache[n][a]=t[a],e.push(a);return this.init(e,!1,!1,r)}},{key:"default",value:function(t){this.current=t}},{key:"all",value:function(t,r){var e=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=function(a){var i=[],o=/\.json$/,u=!0,l=!1,c=void 0;try{for(var f,s=a[Symbol.iterator]();!(u=(f=s.next()).done);u=!0){var v=f.value;o.test(v)&&i.push(v.replace(o,""))}}catch(t){l=!0,c=t}finally{try{!u&&s.return&&s.return()}finally{if(l)throw c}}e.init(i,t,r,n)};r?u.readdir(t,function(t,r){if(t)throw t;a(r)}):a(u.readdirSync(t))}},{key:"init",value:function(t,r,e){var n=this,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=void 0,l=void 0,c=a.namespace||"self";"function"==typeof r&&(e=r,r=!1),this._path=r,t instanceof Array||(t=[t]),this._list=t;var f=function(t){return t+="_"+t.toUpperCase()},s=f(this.getUserLanguage().replace(/\-.+/,""));this._list.indexOf(s)==-1?this.current=this._list[0]:this.current=s,r&&(o=r+this.current+".json");var v=function(t,a,o){var u=void 0;a||(a=n.current),r?(t=t.toString("utf8"),u=JSON.parse(t)):u=t,n._cache[c]||(n._cache[c]={});var l=u,f=i(l,2),s=f[0],v=f[1];n.data[a]={},n.options[a]={},n.data[a][c]=n._initMultiple(s),n.options[a][c]=v,n._cache[c][a]=t,e&&!o&&e.call(self)};if(this._cache[c]&&this._cache[c][this.current]){for(var h in this._cache[c])v(this._cache[c][h],h);return this}if(u){if(e)!function(){var t=0,a=!0,i=!1,o=void 0;try{for(var l,c=function(){var a=l.value;u.readFile(r+a+".json",function(r,i){if(r)throw r;v(i,a,!0),t++,e&&t==n._list.length&&e.call(n)})},f=n._list[Symbol.iterator]();!(a=(l=f.next()).done);a=!0)c()}catch(t){i=!0,o=t}finally{try{!a&&f.return&&f.return()}finally{if(i)throw o}}}();else{var p=!0,d=!1,y=void 0;try{for(var g,m=this._list[Symbol.iterator]();!(p=(g=m.next()).done);p=!0){var b=g.value;v(u.readFileSync(r+b+".json"),b,!0)}}catch(t){d=!0,y=t}finally{try{!p&&m.return&&m.return()}finally{if(d)throw y}}}return this}try{l=new XMLHttpRequest}catch(t){l=!1}return l.onreadystatechange=function(){4==l.readyState&&200==l.status&&v(l.responseText)},l.open("GET",o,!0),l.send(),this}},{key:"getUserLanguage",value:function(){var t=this._list[0];return l?t:navigator.language||navigator.userLanguage||t}},{key:"_initMultiple",value:function(t){function r(t,r,e,n){var a={},i=n?n[t]:r[t],o=e.split(" "),u=function(n){var i=e.replace(t,n);r[e].text?a[i]={text:r[e].text,replacePattern:r[e].replacePattern.map(function(r){return t==r?n:r})}:a[i]={text:r[e],replacePattern:o.map(function(r){return t==r?n:r})}};for(var l in i)u(l);return a}function e(t,r){for(var e in r)t[e]=r[e];return t}var n=void 0,a=void 0,i={},o={},u=JSON.parse(JSON.stringify(t));for(var l in u){var c=/^\$[^ ]+$/.test(l),f=/\[(.+)\]/,s=/\$[^ ]+/g;if(f.test(l)){n=f.exec(l)[1].split(",");var v=!0,h=!1,p=void 0;try{for(var d,y=n[Symbol.iterator]();!(v=(d=y.next()).done);v=!0){var g=d.value;t[l.replace(f,g)]=t[l]}}catch(t){h=!0,p=t}finally{try{!v&&y.return&&y.return()}finally{if(h)throw p}}}if(s.test(l)&&!c)if(i={},o={},a=l.match(s),i=r(a[0],t,l),a.length>1)for(var m in i)o=r(a[1],i,m,t),e(t,o);else e(t,i);if(c){if(t[l]instanceof Array){for(var b={},_=l.replace(/^\$/,""),x=0;x<t[l].length;x++)b[_+"_"+x]=t[l][x];t[l]=b}for(var k in t[l])t[k]=t[l][k]}}return t}},{key:"get",value:function(t,r,e){return e=e||this.current,r=r||"self",this.data[e]&&this.data[e][r]?this.replaceWorlds(this.data[e][r][t],t,r):""}},{key:"capitalizeFirstLetter",value:function(t){return t.charAt(0).toUpperCase()+t.slice(1)}},{key:"replaceWorlds",value:function(t,r,e){var n=this,a={};return t?(t.text&&(a=t,t=t.text),t.replace(/\{([0-9]+)\}/g,function(t,i){var o=a.replacePattern||r.split(" ");return n.get(o[i-1],e)})):t}},{key:"getGroup",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"self",e=this.data[this.current][r]["$"+t],n=[];for(var a in e)n.push(a);return n}},{key:"render",value:function(t){var r=this,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=e.patternStart,i=void 0===a?"{{":a,o=e.patternEnd,u=void 0===o?"}}":o,l=e.pipe,c=void 0===l?"|":l,f=e.fnStart,s=void 0===f?"":f,v=e.fnEnd,h=void 0===v?"":v,p=e.paramsSeparator,d=void 0===p?":":p,y=arguments[2],g=function(t){return t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")};i=g(i),u=g(u),c=g(c),s=g(s),h=g(h);var m=g(d),b=new RegExp(i+"([^"+u+"]+)"+c+"[ ]*t("+m+"?"+s+"([^"+u+"]+)"+h+")?"+u,"g");return t=t.replace(b,function(t,e,a,i,o,u){return e=e.replace(/["']/g,""),e=e.trim(),i?(i=i.split(d),i=i.map(function(t){return t=t.trim(),t>=0||t<=0?t=+t:"true"==t?t="true"===t:"false"==t&&(t="false"===t),t})):i=[],y&&(i=[y].concat(n(i))),r.translate.apply(r,[e].concat(n(i)))})}},{key:"getPlurial",value:function(t,r,e,n){if(e=e||"self",n=n||this.current,t=Math.abs(t),!/^[0-9]+$/.test(t))return!1;var a=this.options[n][e].plurial[r];return a||(a=["s"]),t>2&&a[t-1]?a[t-1]:t>1?a[0]:a[1]||""}},{key:"format",value:function(t,r,e){for(var n=arguments.length,a=Array(n>3?n-3:0),i=3;i<n;i++)a[i-3]=arguments[i];var o=this,u=-1,l=void 0,c=void 0,f=t.match(/%[sdp]/g);if(!f)return t;var s=!0,v=!1,h=void 0;try{for(var p,d=f[Symbol.iterator]();!(s=(p=d.next()).done);s=!0){var y=p.value;if(u++,"%d"==y)l=a[u];else if("%p"==y)break}}catch(t){v=!0,h=t}finally{try{!s&&d.return&&d.return()}finally{if(v)throw h}}return u=-1,t.replace(/%[sdp]([0-9]+)?/g,function(t,n){return u++,c="undefined"!=typeof a[u]?a[u]:t,/^%p/.test(t)&&(void 0==l&&(l=c),"number"!=typeof l&&(l=0),c=o.getPlurial(l,t.replace("%",""),r,e)),c})}},{key:"translate",value:function(t){function r(){n.shift(),l=n[0]}for(var e=arguments.length,n=Array(e>1?e-1:0),a=1;a<e;a++)n[a-1]=arguments[a];var i,o,u;if(null===t||"undefined"==typeof t)return"";var l=n[0];if(this._list.indexOf(n[0])!=-1&&(u=l,r()),"boolean"==typeof l){var c=t.match(/\((.*?)\)/);c?(i=c[1].split("|"),o=l?t.replace(c[0],i[0].trim()):t.replace(c[0],i[1].trim())):(i=t.split("|"),o=l?i[0]:i[1]),r()}else o=t;var f=o.split("+"),s="",v=!0,h=!1,p=void 0;try{for(var d,y=f[Symbol.iterator]();!(v=(d=y.next()).done);v=!0){var g=d.value,m=void 0,b=void 0;(m=/(.+)\.(.+)/.exec(g))&&(b=m[1],g=m[2]);var _=this.get(g.trim(),b,u);_&&(s+=this.format.apply(this,[_,b,u].concat(n))),s+=" "}}catch(t){h=!0,p=t}finally{try{!v&&y.return&&y.return()}finally{if(h)throw p}}return this.capitalizeFirstLetter(s.trim())}},{key:"load",get:function(){var r=this;return{Handlebars:function(t){return t.registerHelper("t",function(t,r){var e=r.hash.nb,n=r.hash.if;return void 0===e?t.t():void 0===n?t.t(+e):t.t(n,+e)}),t},Pug:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return t.translate=function(t){return r.render(t)},t},Angular:function(e){e.module("Languages",[]).provider("Languages",function(){this.init=r.init.bind(t),this.$get=function(){return r}}).filter("t",function(){return function(t){for(var r=arguments.length,e=Array(r>1?r-1:0),n=1;n<r;n++)e[n-1]=arguments[n];return t.t.apply(t,e)}})},get Vue(){return{install:function(t,e){t.Languages=r,t.filter("t",function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),a=1;a<e;a++)n[a-1]=arguments[a];return r.translate.apply(r,[t].concat(n))})}}}}}}]),t}()},function(t,r){}]);