diff --git a/lib/pocompiler.js b/lib/pocompiler.js index c7140d7..d0803ac 100644 --- a/lib/pocompiler.js +++ b/lib/pocompiler.js @@ -70,9 +70,10 @@ function Compiler (table = {}, options = {}) { * in the form of {translator:'', reference: '', extracted: '', flag: '', previous:''} * * @param {Object} comments A comments object + * @param {boolean} [obsolete] This comments object is for an obsolete block * @return {String} A comment string for the PO file */ -Compiler.prototype._drawComments = function (comments) { +Compiler.prototype._drawComments = function (comments, obsolete = false) { const lines = []; const types = [{ key: 'translator', @@ -88,7 +89,7 @@ Compiler.prototype._drawComments = function (comments) { prefix: '#, ' }, { key: 'previous', - prefix: '#| ' + prefix: obsolete ? '#~| ' : '#| ' }]; types.forEach(type => { @@ -121,7 +122,7 @@ Compiler.prototype._drawBlock = function (block, override = {}, obsolete = false let comments = override.comments || block.comments; // add comments - if (comments && (comments = this._drawComments(comments))) { + if (comments && (comments = this._drawComments(comments, obsolete))) { response.push(comments); } diff --git a/lib/poparser.js b/lib/poparser.js index f64d3db..9966b9b 100644 --- a/lib/poparser.js +++ b/lib/poparser.js @@ -161,6 +161,13 @@ Parser.prototype._lexer = function (chunk) { }; this._lex.push(this._node); this._state = this.states.comments; + } else if (chr === '|') { + this._node = { + type: this.types.comments, + value: chr + }; + this._lex.push(this._node); + this._state = this.states.comments; } else if (!chr.match(this.symbols.whitespace)) { this._node = { type: this.types.key, diff --git a/test/fixtures/obsolete.json b/test/fixtures/obsolete.json index ef6c4c2..067eee5 100644 --- a/test/fixtures/obsolete.json +++ b/test/fixtures/obsolete.json @@ -38,6 +38,17 @@ "One", "Two" ] + }, + "Obsolete message with previous translation": { + "msgid": "Obsolete message with previous translation", + "comments": { + "flag": "fuzzy", + "previous": "msgid \"Obsolete message with previous tr\"", + "translator": "Obsolete message with previous" + }, + "msgstr": [ + "Translation" + ] } }, "Obsolete context": { diff --git a/test/fixtures/obsolete.po b/test/fixtures/obsolete.po index da826ed..a1c4bdd 100644 --- a/test/fixtures/obsolete.po +++ b/test/fixtures/obsolete.po @@ -16,6 +16,12 @@ msgstr "Test msgstr" #~ msgstr[0] "One" #~ msgstr[1] "Two" +# Obsolete message with previous +#, fuzzy +#~| msgid "Obsolete message with previous tr" +#~ msgid "Obsolete message with previous translation" +#~ msgstr "Translation" + # Obsolete message with context #, fuzzy #~ msgctxt "Obsolete context"