Gettext=function(h){this.domain="messages";this.locale_data=undefined;var e=["domain","locale_data"];if(this.isValidObject(h)){for(var g in h){for(var f=0;f<e.length;f++){if(g==e[f]){if(this.isValidObject(h[g])){this[g]=h[g]}}}}}this.try_load_lang();return this};Gettext.context_glue="\004";Gettext._locale_data={};Gettext.prototype.try_load_lang=function(){if(typeof(this.locale_data)!="undefined"){var g=this.locale_data;this.locale_data=undefined;this.parse_locale_data(g);if(typeof(Gettext._locale_data[this.domain])=="undefined"){throw new Error("Error: Gettext 'locale_data' does not contain the domain '"+this.domain+"'")}}var e=this.get_lang_refs();if(typeof(e)=="object"&&e.length>0){for(var f=0;f<e.length;f++){var h=e[f];if(h.type=="application/json"){if(!this.try_load_lang_json(h.href)){throw new Error("Error: Gettext 'try_load_lang_json' failed. Unable to exec xmlhttprequest for link ["+h.href+"]")}}else{if(h.type=="application/x-po"){if(!this.try_load_lang_po(h.href)){throw new Error("Error: Gettext 'try_load_lang_po' failed. Unable to exec xmlhttprequest for link ["+h.href+"]")}}else{throw new Error("TODO: link type ["+h.type+"] found, and support is planned, but not implemented at this time.")}}}}};Gettext.prototype.parse_locale_data=function(u){if(typeof(Gettext._locale_data)=="undefined"){Gettext._locale_data={}}for(var v in u){if((!u.hasOwnProperty(v))||(!this.isValidObject(u[v]))){continue}var y=false;for(var z in u[v]){y=true;break}if(!y){continue}var t=u[v];if(v==""){v="messages"}if(!this.isValidObject(Gettext._locale_data[v])){Gettext._locale_data[v]={}}if(!this.isValidObject(Gettext._locale_data[v].head)){Gettext._locale_data[v].head={}}if(!this.isValidObject(Gettext._locale_data[v].msgs)){Gettext._locale_data[v].msgs={}}for(var h in t){if(h==""){var r=t[h];for(var o in r){var s=o.toLowerCase();Gettext._locale_data[v].head[s]=r[o]}}else{Gettext._locale_data[v].msgs[h]=t[h]}}}for(var v in Gettext._locale_data){if(this.isValidObject(Gettext._locale_data[v].head["plural-forms"])&&typeof(Gettext._locale_data[v].head.plural_func)=="undefined"){var p=Gettext._locale_data[v].head["plural-forms"];var w=new RegExp("^(\\s*nplurals\\s*=\\s*[0-9]+\\s*;\\s*plural\\s*=\\s*(?:\\s|[-\\?\\|&=!<>+*/%:;a-zA-Z0-9_()])+)","m");if(w.test(p)){var q=Gettext._locale_data[v].head["plural-forms"];if(!/;\s*$/.test(q)){q=q.concat(";")}var x="var plural; var nplurals; "+q+' return { "nplural" : nplurals, "plural" : (plural === true ? 1 : plural ? plural : 0) };';Gettext._locale_data[v].head.plural_func=new Function("n",x)}else{throw new Error("Syntax error in language file. Plural-Forms header is invalid ["+p+"]")}}else{if(typeof(Gettext._locale_data[v].head.plural_func)=="undefined"){Gettext._locale_data[v].head.plural_func=function(b){var a=(b!=1)?1:0;return{nplural:2,plural:a}}}}}return};Gettext.prototype.try_load_lang_po=function(f){var i=this.sjax(f);if(!i){return}var j=this.uri_basename(f);var g=this.parse_po(i);var h={};if(g){if(!g[""]){g[""]={}}if(!g[""]["domain"]){g[""]["domain"]=j}j=g[""]["domain"];h[j]=g;this.parse_locale_data(h)}return 1};Gettext.prototype.uri_basename=function(d){var f;if(f=d.match(/^(.*\/)?(.*)/)){var e;if(e=f[2].match(/^(.*)\..+$/)){return e[1]}else{return f[2]}}else{return""}};Gettext.prototype.parse_po=function(u){var F={};var z={};var B="";var D=[];var J=u.split("\n");for(var x=0;x<J.length;x++){J[x]=J[x].replace(/(\n|\r)+$/,"");var E;if(/^$/.test(J[x])){if(typeof(z.msgid)!="undefined"){var v=(typeof(z.msgctxt)!="undefined"&&z.msgctxt.length)?z.msgctxt+Gettext.context_glue+z.msgid:z.msgid;var y=(typeof(z.msgid_plural)!="undefined"&&z.msgid_plural.length)?z.msgid_plural:null;var H=[];for(var A in z){var E;if(E=A.match(/^msgstr_(\d+)/)){H[parseInt(E[1])]=z[A]}}H.unshift(y);if(H.length>1){F[v]=H}z={};B=""}}else{if(/^#/.test(J[x])){continue}else{if(E=J[x].match(/^msgctxt\s+(.*)/)){B="msgctxt";z[B]=this.parse_po_dequote(E[1])}else{if(E=J[x].match(/^msgid\s+(.*)/)){B="msgid";z[B]=this.parse_po_dequote(E[1])}else{if(E=J[x].match(/^msgid_plural\s+(.*)/)){B="msgid_plural";z[B]=this.parse_po_dequote(E[1])}else{if(E=J[x].match(/^msgstr\s+(.*)/)){B="msgstr_0";z[B]=this.parse_po_dequote(E[1])}else{if(E=J[x].match(/^msgstr\[0\]\s+(.*)/)){B="msgstr_0";z[B]=this.parse_po_dequote(E[1])}else{if(E=J[x].match(/^msgstr\[(\d+)\]\s+(.*)/)){B="msgstr_"+E[1];z[B]=this.parse_po_dequote(E[2])}else{if(/^"/.test(J[x])){z[B]+=this.parse_po_dequote(J[x])}else{D.push("Strange line ["+x+"] : "+J[x])}}}}}}}}}}if(typeof(z.msgid)!="undefined"){var v=(typeof(z.msgctxt)!="undefined"&&z.msgctxt.length)?z.msgctxt+Gettext.context_glue+z.msgid:z.msgid;var y=(typeof(z.msgid_plural)!="undefined"&&z.msgid_plural.length)?z.msgid_plural:null;var H=[];for(var A in z){var E;if(E=A.match(/^msgstr_(\d+)/)){H[parseInt(E[1])]=z[A]}}H.unshift(y);if(H.length>1){F[v]=H}z={};B=""}if(F[""]&&F[""][1]){var I={};var w=F[""][1].split(/\\n/);for(var x=0;x<w.length;x++){if(!w.length){continue}var G=w[x].indexOf(":",0);if(G!=-1){var t=w[x].substring(0,G);var i=w[x].substring(G+1);var C=t.toLowerCase();if(I[C]&&I[C].length){D.push("SKIPPING DUPLICATE HEADER LINE: "+w[x])}else{if(/#-#-#-#-#/.test(C)){D.push("SKIPPING ERROR MARKER IN HEADER: "+w[x])}else{i=i.replace(/^\s+/,"");I[C]=i}}}else{D.push("PROBLEM LINE IN HEADER: "+w[x]);I[w[x]]=""}}F[""]=I}else{F[""]={}}return F};Gettext.prototype.parse_po_dequote=function(c){var d;if(d=c.match(/^"(.*)"/)){c=d[1]}c=c.replace(/\\"/,"");return c};Gettext.prototype.try_load_lang_json=function(e){var d=this.sjax(e);if(!d){return}var f=this.JSON(d);this.parse_locale_data(f);return 1};Gettext.prototype.get_lang_refs=function(){var f=new Array();var e=document.getElementsByTagName("link");for(var d=0;d<e.length;d++){if(e[d].rel=="gettext"&&e[d].href){if(typeof(e[d].type)=="undefined"||e[d].type==""){if(/\.json$/i.test(e[d].href)){e[d].type="application/json"}else{if(/\.js$/i.test(e[d].href)){e[d].type="application/json"}else{if(/\.po$/i.test(e[d].href)){e[d].type="application/x-po"}else{if(/\.mo$/i.test(e[d].href)){e[d].type="application/x-mo"}else{throw new Error("LINK tag with rel=gettext found, but the type and extension are unrecognized.")}}}}}e[d].type=e[d].type.toLowerCase();if(e[d].type=="application/json"){e[d].type="application/json"}else{if(e[d].type=="text/javascript"){e[d].type="application/json"}else{if(e[d].type=="application/x-po"){e[d].type="application/x-po"}else{if(e[d].type=="application/x-mo"){e[d].type="application/x-mo"}else{throw new Error("LINK tag with rel=gettext found, but the type attribute ["+e[d].type+"] is unrecognized.")}}}}f.push(e[d])}}return f};Gettext.prototype.textdomain=function(b){if(b&&b.length){this.domain=b}return this.domain};Gettext.prototype.gettext=function(j){var h;var g;var i;var f;return this.dcnpgettext(null,h,j,g,i,f)};Gettext.prototype.dgettext=function(k,l){var i;var h;var j;var g;return this.dcnpgettext(k,i,l,h,j,g)};Gettext.prototype.dcgettext=function(k,l,g){var i;var h;var j;return this.dcnpgettext(k,i,l,h,j,g)};Gettext.prototype.ngettext=function(j,g,h){var i;var f;return this.dcnpgettext(null,i,j,g,h,f)};Gettext.prototype.dngettext=function(k,l,h,i){var j;var g;return this.dcnpgettext(k,j,l,h,i,g)};Gettext.prototype.dcngettext=function(k,l,h,i,g){var j;return this.dcnpgettext(k,j,l,h,i,g,g)};Gettext.prototype.pgettext=function(h,j){var g;var i;var f;return this.dcnpgettext(null,h,j,g,i,f)};Gettext.prototype.dpgettext=function(k,i,l){var h;var j;var g;return this.dcnpgettext(k,i,l,h,j,g)};Gettext.prototype.dcpgettext=function(k,i,l,g){var h;var j;return this.dcnpgettext(k,i,l,h,j,g)};Gettext.prototype.npgettext=function(h,j,g,i){var f;return this.dcnpgettext(null,h,j,g,i,f)};Gettext.prototype.dnpgettext=function(k,i,l,h,j){var g;return this.dcnpgettext(k,i,l,h,j,g)};Gettext.prototype.dcnpgettext=function(i,L,j,B,G,E){if(!this.isValidObject(j)){return""}var J=this.isValidObject(B);var z=this.isValidObject(L)?L+Gettext.context_glue+j:j;var P=this.isValidObject(i)?i:this.isValidObject(this.domain)?this.domain:"messages";var n="LC_MESSAGES";var E=5;var F=new Array();if(typeof(Gettext._locale_data)!="undefined"&&this.isValidObject(Gettext._locale_data[P])){F.push(Gettext._locale_data[P])}else{if(typeof(Gettext._locale_data)!="undefined"){for(var p in Gettext._locale_data){F.push(Gettext._locale_data[p])}}}var O=[];var K=false;var H;if(F.length){for(var A=0;A<F.length;A++){var C=F[A];if(this.isValidObject(C.msgs[z])){for(var D=0;D<C.msgs[z].length;D++){O[D]=C.msgs[z][D]}O.shift();H=C;K=true;if(O.length>0&&O[0].length!=0){break}}}}if(O.length==0||O[0].length==0){O=[j,B]}var M=O[0];if(J){var I;if(K&&this.isValidObject(H.head.plural_func)){var N=H.head.plural_func(G);if(!N.plural){N.plural=0}if(!N.nplural){N.nplural=0}if(N.nplural<=N.plural){N.plural=0}I=N.plural}else{I=(G!=1)?1:0}if(this.isValidObject(O[I])){M=O[I]}}return M};Gettext.strargs=function(j,n){if(null==n||"undefined"==typeof(n)){n=[]}else{if(n.constructor!=Array){n=[n]}}var k="";while(true){var m=j.indexOf("%");var i;if(m==-1){k+=j;break}k+=j.substr(0,m);if(j.substr(m,2)=="%%"){k+="%";j=j.substr((m+2))}else{if(i=j.substr(m).match(/^%(\d+)/)){var l=parseInt(i[1]);var h=i[1].length;if(l>0&&n[l-1]!=null&&typeof(n[l-1])!="undefined"){k+=n[l-1]}j=j.substr((m+1+h))}else{k+="%";j=j.substr((m+1))}}}return k};Gettext.prototype.strargs=function(c,d){return Gettext.strargs(c,d)};Gettext.prototype.isArray=function(b){return this.isValidObject(b)&&b.constructor==Array};Gettext.prototype.isValidObject=function(b){if(null==b){return false}else{if("undefined"==typeof(b)){return false}else{return true}}};Gettext.prototype.sjax=function(i){var j;if(window.XMLHttpRequest){j=new XMLHttpRequest()}else{if(navigator.userAgent.toLowerCase().indexOf("msie 5")!=-1){j=new ActiveXObject("Microsoft.XMLHTTP")}else{j=new ActiveXObject("Msxml2.XMLHTTP")}}if(!j){throw new Error("Your browser doesn't do Ajax. Unable to support external language files.")}j.open("GET",i,false);try{j.send(null)}catch(h){return}var g=j.status;if(g==200||g==0){return j.responseText}else{var e=j.statusText+" (Error "+j.status+")";if(j.responseText.length){e+="\n"+j.responseText}alert(e);return}};Gettext.prototype.JSON=function(data){return eval("("+data+")")};
