From 8b90d64b5c5dbeb1b9e683570374519918c9d2d1 Mon Sep 17 00:00:00 2001 From: Kisaragi Hiu Date: Wed, 1 Jul 2026 05:45:54 +0900 Subject: [PATCH 1/3] Parse obsolete previous comments (#~|) \#~| is common and often generated by msgmerge. --- lib/poparser.js | 7 +++++++ 1 file changed, 7 insertions(+) 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, From d74b42bb433da76eb499bc9127a30890f08ecd67 Mon Sep 17 00:00:00 2001 From: Kisaragi Hiu Date: Wed, 1 Jul 2026 05:26:45 +0900 Subject: [PATCH 2/3] Add obsolete with previous msgid test case --- test/fixtures/obsolete.json | 11 +++++++++++ test/fixtures/obsolete.po | 6 ++++++ 2 files changed, 17 insertions(+) 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" From 14256c4e71534cd63342cf1b5a9c9f6f7d55bb08 Mon Sep 17 00:00:00 2001 From: Kisaragi Hiu Date: Wed, 1 Jul 2026 06:12:18 +0900 Subject: [PATCH 3/3] Emit previous translation of an obsolete entry --- lib/pocompiler.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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); }