1234567891011121314 |
- (function(q){function u(j,h,f){this.bindFunction=function(f,a){return function(){return f.apply(a,[a])}};this.stateChange=function(){4===this.request.readyState&&this.callbackFunction(this.request.responseText)};this.getRequest=function(){return window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):window.XMLHttpRequest?new XMLHttpRequest:!1};this.postBody=f||"";this.callbackFunction=h;this.url=j;if(this.request=this.getRequest())h=this.request,h.onreadystatechange=this.bindFunction(this.stateChange,
- this),""!==this.postBody?(h.open("POST",j,!0),h.setRequestHeader("X-Requested-With","XMLHttpRequest"),h.setRequestHeader("Content-type","application/x-www-form-urlencoded"),h.setRequestHeader("Connection","close")):h.open("GET",j,!0),h.send(this.postBody)}var r,t=function(j){return Object.prototype.toString.call(j).slice(8,-1).toLowerCase()},m=function(){m.cache.hasOwnProperty(arguments[0])||(m.cache[arguments[0]]=m.parse(arguments[0]));return m.format.call(null,m.cache[arguments[0]],arguments)};
- m.format=function(j,h){var f=1,k=j.length,a="",p=[],c,b,d,g;for(c=0;c<k;c++)if(a=t(j[c]),"string"===a)p.push(j[c]);else if("array"===a){d=j[c];if(d[2]){a=h[f];for(b=0;b<d[2].length;b++){if(!a.hasOwnProperty(d[2][b]))throw r('[sprintf] property "%s" does not exist',d[2][b]);a=a[d[2][b]]}}else a=d[1]?h[d[1]]:h[f++];if(/[^s]/.test(d[8])&&"number"!=t(a))throw r("[sprintf] expecting number but found %s",t(a));switch(d[8]){case "b":a=a.toString(2);break;case "c":a=String.fromCharCode(a);break;case "d":a>>=
- 0;break;case "e":a=d[7]?a.toExponential(d[7]):a.toExponential();break;case "f":a=d[7]?parseFloat(a).toFixed(d[7]):parseFloat(a);break;case "o":a=a.toString(8);break;case "s":a=(a=String(a))&&d[7]?a.substring(0,d[7]):a;break;case "u":a=Math.abs(a);break;case "x":a=a.toString(16);break;case "X":a=a.toString(16).toUpperCase()}a=/[def]/.test(d[8])&&d[3]&&0<=a?"+"+a:a;b=d[4]?"0"===d[4]?"0":d[4].charAt(1):" ";g=d[6]-String(a).length;if(d[6]){for(var e=[];0<g;e[--g]=b);b=e.join("")}else b="";p.push(d[5]?
- a+b:b+a)}return p.join("")};m.cache={};m.parse=function(j){for(var h=[],f=[],k=0;j;){if(null!==(h=/^[^\x25]+/.exec(j)))f.push(h[0]);else if(null!==(h=/^\x25{2}/.exec(j)))f.push("%");else if(null!==(h=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(j))){if(h[2]){var k=k|1,a=[],p=h[2],c=[];if(null!==(c=/^([a-z_][a-z_\d]*)/i.exec(p)))for(a.push(c[1]);""!==(p=p.substring(c[0].length));)if(null!==(c=/^\.([a-z_][a-z_\d]*)/i.exec(p)))a.push(c[1]);else if(null!==
- (c=/^\[(\d+)\]/.exec(p)))a.push(c[1]);else throw"[sprintf] huh?";else throw"[sprintf] huh?";h[2]=a}else k|=2;if(3===k)throw"[sprintf] mixing positional and named placeholders is not (yet) supported";f.push(h)}else throw"[sprintf] huh?";j=j.substring(h[0].length)}return f};r=m;q.Pomo=new function(){this.VERSION="0.1.0";this.domain="messages";this.unescapeStrings=this.returnStrings=!1;var j=function(a){var c;a.constructor!=String()&&(c=a);a.replace&&(c=a.replace(/[\"]/g,'\\"').replace(/[\\]/g,"\\").replace(/[\/]/g,
- "/").replace(/[\b]/g,"\\b").replace(/[\f]/g,"\\f").replace(/[\n]/g,"\\n").replace(/[\r]/g,"\\r").replace(/[\t]/g,"\\t"));return c},h=function(a){var c;a.replace&&(c=a.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\f","\f").replace("\\b","\b").replace("\\r","\r"));return c},f=this;q.String.prototype.trim||(q.String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});f.storage={};f.Parser={};f.Parser.Object=function(a){var c=1,b;for(b in a)this[b]=a[b];this.setCount=
- function(a){c=a>>0};this.toString=function(){var a;this.isPlural?a=this.translation:(a=f.storage.calculatePluralIndex(c),a=this.plural_forms[a]);return a}};f.Parser.po={parse:function(a,c){var b=function(a){a=a.split("\n");for(var b=0,c=a.length;b<c;b++)if(0===a[b].indexOf('"Plural-Forms: nplurals')){var d=a[b].substring(14).slice(0,-1);f.storage.calculatePluralIndex=function(){eval(h(d));"undefined"===typeof plural&&(plural=0);return plural}}},d={},g,e,s="undefined"===typeof c?"messages":c,n=[],
- k=0;a=a.replace(/\r\n|\r/g,"\n");d[s]={};n=a.split(/\n\n/);e=n.shift();for((g=b(e))?f.storage.header_info=b(g):n.unshift(e);g=n.shift();){b={};g=g?g.split(/\n/):[];for(e="";e=g.shift();){e=e.trim();var l=g.slice(0,-1)[0],m=e.substring(0,12).split(" ")[0].trim();l&&l.substring(0,12).split(" ")[0].trim();switch(m){case "msgctxt":b.context=e.substring(9).slice(0,-1);break;case "msgid_plural":b.isPlural=!0;b.plural_id=e.substring(14).slice(0,-1);break;case "msgid":if(0===e.indexOf('msgid ""')){if(e=l.trim(),
- 0===e.indexOf('"')){for(l=[];e=g.shift();)if(e=e.trim(),0===e.indexOf('"'))l.push(e.substring(1).slice(0,-1));else{g.unshift(e);break}b.id=l.join("")}}else b.id=e.substr(7).slice(0,-1);continue;case "msgstr":if(0===e.indexOf('msgstr ""')){for(l=[];e=g.shift();)if(e=e.trim(),0===e.indexOf('"'))l.push(e.substr(1).slice(0,-1));else{g.unshift(e);break}b.translation=l.join("")}else b.translation=e.substr(8).slice(0,-1);break;case "#:":case "#.":case "#":continue;case "#,":break;default:if(e&&e.match(/msgstr\[[0-9]\]/)){for(l=
- [];e&&e.match(/msgstr\[[0-9]\]/);)l.push(e.substring(10).slice(0,-1)),e=g.shift();b.plural_forms=l;b.translation=l[0]}}}b.id&&b.translation&&(b=new f.Parser.Object(b),d[s][b.id]?d[s][j(b.id)].push(b):d[s][j(b.id)]=[b]);k++}return d},generate:function(){throw"Feature unimplemented";}};var k=function(a,c,b){this.waiting=!0;switch(c){case "po":a=f.Parser.po.parse(a,b);break;default:case "mo":throw"Unimplemented format";}this.waiting=!1;f.storage.contents=a},a=function(a,c,b){f.waiting=!0;return u(a,
- function(a){f.waiting=!1;return k(a,c,b)})};this.noConflict=function(){q.__Pomo=q.Pomo;delete q.Pomo;return q.__Pomo};this.load=function(h,c){c=!c?{}:c;var b=c.format?c.format:!1,d=c.translation_domain?c.translation_domain:"messages";switch(c.mode?c.mode:!1){case "literal":k(h,b,d);break;case "link":var g=document.getElementById(h);g&&(g.type&&"text/x-gettext-translation"===g.type)&&a(g.href,b,d);break;case "ajax":a(h,b,d);break;default:throw"specify a "+b+" files acquisition mode";}var e={ready:function(a){f.waiting?
- window.setTimeout(function(){e.ready(a)},20):a.apply(f,[])}};return e};this.getText=function(a,c){c=!c?{}:c;var b=c.variables?c.variables:[],d=c.context?c.context:!1,g=c.domain?c.domain:"messages",e=c.count?c.count:!1,k=j(a);!g&&!f.domain?g="messages":f.domain&&(g=f.domain);if(f.storage.contents[g]&&f.storage.contents[g][k]){var n=f.storage.contents[g][k];if(d)for(var m=0,l=f.storage.contents[g][k].length;m<l&&!(n.context&&n.context===d);m++);f.storage.contents[g][k].unshift&&(n=f.storage.contents[g][k][0]);
- d=n;e&&n.setCount(e);e=n.constructor===String();f.returnStrings&&(d=n.toString());b&&(b.unshift(e?d:d.translation),b=r.apply(null,b),e?d=b:d.translation=b);e&&f.unescapeStrings?d=h(d):f.unescapeStrings&&!e&&(d.translation=h(d.translation));return d}throw"Unknown id "+msgid;};this.getMap=function(){return f.storage.contents}}})(window,document);
|