From 3324041669c243b63f68a489f5d7edb480576565 Mon Sep 17 00:00:00 2001 From: Ruben Vermeersch Date: Thu, 9 Mar 2017 07:45:14 +0100 Subject: [PATCH] Rebuild --- dist/pofile.js | 40 +++++++++++++++++++++++++++++++++++++--- dist/pofile.min.js | 2 +- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/dist/pofile.js b/dist/pofile.js index 0a16aef..2117c5b 100644 --- a/dist/pofile.js +++ b/dist/pofile.js @@ -117,7 +117,9 @@ PO.parse = function (data) { } }); - var item = new PO.Item(); + var parsedPluralForms = PO.parsePluralForms(po.headers['Plural-Forms']); + var nplurals = parsedPluralForms.nplurals; + var item = new PO.Item({ nplurals: nplurals }); var context = null; var plural = 0; var obsoleteCount = 0; @@ -131,7 +133,7 @@ PO.parse = function (data) { obsoleteCount = 0; noCommentLineCount = 0; po.items.push(item); - item = new PO.Item(); + item = new PO.Item({ nplurals: nplurals }); } } @@ -237,7 +239,26 @@ PO.parse = function (data) { return po; }; -PO.Item = function () { +PO.parsePluralForms = function (pluralFormsString) { + var results = (pluralFormsString || '') + .split(';') + .reduce(function (acc, keyValueString) { + var trimmedString = keyValueString.trim(); + var equalsIndex = trimmedString.indexOf('='); + var key = trimmedString.substring(0, equalsIndex).trim(); + var value = trimmedString.substring(equalsIndex + 1).trim(); + acc[key] = value; + return acc; + }, {}); + return { + nplurals: results.nplurals, + plural: results.plural + }; +}; + +PO.Item = function (options) { + var nplurals = options && options.nplurals; + this.msgid = ''; this.msgctxt = null; this.references = []; @@ -247,6 +268,8 @@ PO.Item = function () { this.extractedComments = []; this.flags = {}; this.obsolete = false; + var npluralsNumber = Number(nplurals); + this.nplurals = (isNaN(npluralsNumber)) ? 2 : npluralsNumber; }; PO.Item.prototype.toString = function () { @@ -319,10 +342,21 @@ PO.Item.prototype.toString = function () { ['msgctxt', 'msgid', 'msgid_plural', 'msgstr'].forEach(function (keyword) { var text = self[keyword]; if (text != null) { + var hasTranslation = false; + if (Array.isArray(text)) { + hasTranslation = text.some(function (text) { + return text; + }); + } + if (Array.isArray(text) && text.length > 1) { text.forEach(function (t, i) { lines = lines.concat(mkObsolete + _process(keyword, t, i)); }); + } else if (self.msgid_plural && keyword === 'msgstr' && !hasTranslation) { + for (var pluralIndex = 0; pluralIndex < self.nplurals; pluralIndex++) { + lines = lines.concat(mkObsolete + _process(keyword, '', pluralIndex)); + } } else { var index = (self.msgid_plural && Array.isArray(text)) ? 0 : diff --git a/dist/pofile.min.js b/dist/pofile.min.js index 1e457d6..117a278 100644 --- a/dist/pofile.min.js +++ b/dist/pofile.min.js @@ -1 +1 @@ -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;g0&&(m>=n&&(j.obsolete=!0),m=0,n=0,e.items.push(j),j=new f.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"\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":""},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 f.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;r0&&(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},f.Item=function(){this.msgid="",this.msgctxt=null,this.references=[],this.msgid_plural=null,this.msgstr=[],this.comments=[],this.extractedComments=[],this.flags={},this.obsolete=!1},f.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"\t":return"\\t";case"\v":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};this.comments.forEach(function(b){a.push("# "+b)}),this.extractedComments.forEach(function(b){a.push("#. "+b)}),this.references.forEach(function(b){a.push("#: "+b)});var e=Object.keys(this.flags).filter(function(a){return!!this.flags[a]},this);e.length>0&&a.push("#, "+e.join(","));var f=this.obsolete?"#~ ":"";return["msgctxt","msgid","msgid_plural","msgstr"].forEach(function(c){var e=b[c];if(null!=e)if(Array.isArray(e)&&e.length>1)e.forEach(function(b,e){a=a.concat(f+d(c,b,e))});else{var g=b.msgid_plural&&Array.isArray(e)?0:void 0;e=Array.isArray(e)?e.join():e;for(var h=d(c,e,g),i=1;i0&&(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":""},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=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;t0&&(p++,"msgstr"===m?l.msgstr[n]+=c(q):"msgid"===m?l.msgid+=c(q):"msgid_plural"===m&&(l.msgid_plural+=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{nplurals:b.nplurals,plural:b.plural}},f.Item=function(a){var b=a&&a.nplurals;this.msgid="",this.msgctxt=null,this.references=[],this.msgid_plural=null,this.msgstr=[],this.comments=[],this.extractedComments=[],this.flags={},this.obsolete=!1;var c=Number(b);this.nplurals=isNaN(c)?2:c},f.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"\t":return"\\t";case"\v":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};this.comments.forEach(function(b){a.push("# "+b)}),this.extractedComments.forEach(function(b){a.push("#. "+b)}),this.references.forEach(function(b){a.push("#: "+b)});var e=Object.keys(this.flags).filter(function(a){return!!this.flags[a]},this);e.length>0&&a.push("#, "+e.join(","));var f=this.obsolete?"#~ ":"";return["msgctxt","msgid","msgid_plural","msgstr"].forEach(function(c){var e=b[c];if(null!=e){var g=!1;if(Array.isArray(e)&&(g=e.some(function(a){return a})),Array.isArray(e)&&e.length>1)e.forEach(function(b,e){a=a.concat(f+d(c,b,e))});else if(b.msgid_plural&&"msgstr"===c&&!g)for(var h=0;h