pofile/dist/pofile.min.js

1 line
5.7 KiB
JavaScript
Raw Permalink Normal View History

2018-05-25 12:34:26 +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);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.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}({1:[function(a,b,c){},{}],pofile:[function(a,b,c){function d(a){return a.replace(/^\s+|\s+$/g,"")}var e=a("fs"),f=function(){this.comments=[],this.extractedComments=[],this.headers={},this.headerOrder=[],this.items=[]};f.prototype.save=function(a,b){e.writeFile(a,this.toString(),b)},f.prototype.toString=function(){var a=[];this.comments&&this.comments.forEach(function(b){a.push(("# "+b).trim())}),this.extractedComments&&this.extractedComments.forEach(function(b){a.push(("#. "+b).trim())}),a.push('msgid ""'),a.push('msgstr ""');var b=this,c=[];this.headerOrder.forEach(function(a){a in b.headers&&c.push(a)});var d=Object.keys(this.headers);return d.forEach(function(a){c.indexOf(a)===-1&&c.push(a)}),c.forEach(function(c){a.push('"'+c+": "+b.headers[c]+'\\n"')}),a.push(""),this.items.forEach(function(b){a.push(b.toString()),a.push("")}),a.join("\n")},f.load=function(a,b){e.readFile(a,"utf-8",function(a,c){if(a)return b(a);var d=f.parse(c);b(null,d)})},f.parse=function(a){function b(){l.msgid.length>0&&(o>=p&&(l.obsolete=!0),o=0,p=0,e.items.push(l),l=new f.Item({nplurals:k}))}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"\t";case"n":return"\n";case"v":return"\v";case"f":return"\f";case"r":return"\r";default:return b}})}a=a.replace(/\r\n/g,"\n");for(var e=new f,g=a.split(/\n\n/),h=[];g[0]&&(0===h.length||h[h.length-1].indexOf('msgid ""')<0);)g[0].match(/msgid "[^"]/)?h.push('msgid ""'):h.push(g.shift());h=h.join("\n");var i=g.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":""},e.headerOrder=[],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,e.headerOrder.push(c)}});for(var j=f.parsePluralForms(e.headers["Plural-Forms"]),k=j.nplurals,l=new f.Item({nplurals:k}),m=null,n=0,o=0,p=0;i.length>0;){var q=d(i.shift()),r=!1;if(q.match(/^#\~/)&&(q=d(q.substring(2)),r=!0),q.match(/^#:/))b(),l.references.push(d(q.replace(/^#:/,"")));else if(q.match(/^#,/)){b();for(var s=d(q.replace(/^#,/,"")).split(","),t=0;t<s.length;t++)l.flags[s[t]]=!0}else if(q.match(/^#($|\s+)/))b(),l.comments.push(d(q.replace(/^#($|\s+)/,"")));else if(q.match(/^#\./))b(),l.extractedComments.push(d(q.replace(/^#\./,"")));else if(q.match(/^msgid_plural/))l.msgid_plural=c(q),m="msgid_plural",p++;else if(q.match(/^msgid/))b(),l.msgid=c(q),m="msgid",p++;else if(q.match(/^msgstr/)){var u=q.match(/^msgstr\[(\d+)\]/);n=u&&u[1]?parseInt(u[1]):0,l.msgstr[n]=c(q),m="msgstr",p++}else q.match(/^msgctxt/)?(b(),l.msgctxt=c(q),m="msgctxt",p++):q.length>0&&(p++,"msgstr"===m?l.msgstr[n]+=c(q):"msgid"===m?l.msgid+=c(q):"msgid_plural"===m?l.msgid_plural+=c(q):"msgctxt"===m&&(l.msgctxt+=c(q)));r&&o++}return b(),e},f.parsePluralForms=function(a){var b=(a||"").split(";").reduce(function(a,b){var c=b.trim(),d=c.indexOf("="),e=c.substring(0,d).trim(),f=c.substring(d+1).trim();return a[e]=f,a},{});return{np