Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/pocompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -88,7 +89,7 @@ Compiler.prototype._drawComments = function (comments) {
prefix: '#, '
}, {
key: 'previous',
prefix: '#| '
prefix: obsolete ? '#~| ' : '#| '
}];

types.forEach(type => {
Expand Down Expand Up @@ -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);
}

Expand Down
7 changes: 7 additions & 0 deletions lib/poparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/obsolete.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/obsolete.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading