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