pofile/dist/pofile.min.js

1 line
5.1 KiB
JavaScript
Raw Permalink Normal View History

2015-08-20 16:12:56 +03:00
require=function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({pofile:[function(a,b,c){b.exports=a("W8CkM0")},{}],W8CkM0:[function(a,b,c){function d(a){return a.replace(/^\s+|\s+$/g,"")}var e=a("fs"),f=a("lodash.isarray"),g=function(){this.comments=[],this.extractedComments=[],this.headers={},this.items=[]};g.prototype.save=function(a,b){e.writeFile(a,this.toString(),b)},g.prototype.toString=function(){var a=[];this.comments&&this.comments.forEach(function(b){a.push("# "+b)}),this.extractedComments&&this.extractedComments.forEach(function(b){a.push("#. "+b)}),a.push('msgid ""'),a.push('msgstr ""');var b=Object.keys(this.headers),c=this;return b.forEach(function(b){a.push('"'+b+": "+c.headers[b]+'\\n"')}),a.push(""),this.items.forEach(function(b){a.push(b.toString()),a.push("")}),a.join("\n")},g.load=function(a,b){e.readFile(a,"utf-8",function(a,c){if(a)return b(a);var d=g.parse(c);b(null,d)})},g.parse=function(a){function b(){j.msgid.length>0&&(m>=n&&(j.obsolete=!0),m=0,n=0,e.items.push(j),j=new g.Item)}function c(a){return a=d(a),a=a.replace(/^[^"]*"|"$/g,""),a=a.replace(/\\([abtnvfr'"\\?]|([0-7]{3})|x([0-9a-fA-F]{2}))/g,function(a,b,c,d){if(c)return String.fromCharCode(parseInt(c,8));if(d)return String.fromCharCode(parseInt(d,16));switch(b){case"a":return"";case"b":return"\b";case"t":return" ";case"n":return"\n";case"v":return" ";case"f":return"\f";case"r":return"\r";default:return b}})}a=a.replace(/\r\n/g,"\n");var e=new g,f=a.split(/\n\n/),h=f.shift(),i=f.join("\n").split(/\n/);e.headers={"Project-Id-Version":"","Report-Msgid-Bugs-To":"","POT-Creation-Date":"","PO-Revision-Date":"","Last-Translator":"",Language:"","Language-Team":"","Content-Type":"","Content-Transfer-Encoding":"","Plural-Forms":""},h.split(/\n/).reduce(function(a,b){return a.merge&&(b=a.pop().slice(0,-1)+b.slice(1),delete a.merge),/^".*"$/.test(b)&&!/^".*\\n"$/.test(b)&&(a.merge=!0),a.push(b),a},[]).forEach(function(a){if(a.match(/^#\./))e.extractedComments.push(a.replace(/^#\.\s*/,""));else if(a.match(/^#/))e.comments.push(a.replace(/^#\s*/,""));else if(a.match(/^"/)){a=a.trim().replace(/^"/,"").replace(/\\n"$/,"");var b=a.split(/:/),c=b.shift().trim(),d=b.join(":").trim();e.headers[c]=d}});for(var j=new g.Item,k=null,l=0,m=0,n=0;i.length>0;){var o=d(i.shift()),p=!1;if(o.match(/^#\~/)&&(o=d(o.substring(2)),p=!0),o.match(/^#:/))b(),j.references.push(d(o.replace(/^#:/,"")));else if(o.match(/^#,/)){b();for(var q=d(o.replace(/^#,/,"")).split(","),r=0;r<q.length;r++)j.flags[q[r]]=!0}else if(o.match(/^#($|\s+)/))b(),j.comments.push(d(o.replace(/^#($|\s+)/,"")));else if(o.match(/^#\./))b(),j.extractedComments.push(d(o.replace(/^#\./,"")));else if(o.match(/^msgid_plural/))j.msgid_plural=c(o),k="msgid_plural",n++;else if(o.match(/^msgid/))b(),j.msgid=c(o),k="msgid",n++;else if(o.match(/^msgstr/)){var s=o.match(/^msgstr\[(\d+)\]/);l=s&&s[1]?parseInt(s[1]):0,j.msgstr[l]=c(o),k="msgstr",n++}else o.match(/^msgctxt/)?(b(),j.msgctxt=c(o),n++):o.length>0&&(n++,"msgstr"===k?j.msgstr[l]+=c(o):"msgid"===k?j.msgid+=c(o):"msgid_plural"===k&&(j.msgid_plural+=c(o)));p&&m++}return b(),e},g.Item=function(){this.msgid="",this.msgctxt=null,this.references=[],this.msgid_plural=null,this.msgstr=[],this.comments=[],this.extractedComments=[],this.flags={},this.obsolete=!1},g.Item.prototype.toString=function(){var a=[],b=this,c=function(a){return a=a.replace(/[\x07\b\t\v\f\r"\\]/g,function(a){switch(a){case"":return"\\a";case"\b":return"\\b";case" ":return"\\t";case" ":return"\\v";case"\f":return"\\f";case"\r":return"\\r";default:return"\\"+a}})},d=function(a,b,d){var e=[],f=b.split(/\n/),g="undefined"!=typeof d?"["+d+"]":"";return f.length>1?(e.push(a+g+' ""'),f.forEach(function(a){e.push('"'+c(a)+'"')})):e.push(a+g+' "'+c(b)+'"'),e}