Handle extracted comments
This commit is contained in:
20
lib/po.js
20
lib/po.js
@@ -120,9 +120,13 @@ PO.parse = function (data) {
|
||||
item.flags[flags[i]] = true;
|
||||
}
|
||||
}
|
||||
else if (line.match(/^#/)) { // Comment
|
||||
else if (line.match(/^#\s+/)) { // Translator comment
|
||||
finish();
|
||||
item.comments.push(trim(line.replace(/^#/, '')));
|
||||
item.comments.push(trim(line.replace(/^#\s+/, '')));
|
||||
}
|
||||
else if (line.match(/^#\./)) { // Extracted comment
|
||||
finish();
|
||||
item.extractedComments.push(trim(line.replace(/^#\./, '')));
|
||||
}
|
||||
else if (line.match(/^msgid_plural/)) { // Plural form
|
||||
item.msgid_plural = extract(line);
|
||||
@@ -168,7 +172,8 @@ PO.Item = function () {
|
||||
this.references = [];
|
||||
this.msgid_plural = null;
|
||||
this.msgstr = [];
|
||||
this.comments = [];
|
||||
this.comments = []; // translator comments
|
||||
this.extractedComments = [];
|
||||
this.flags = {};
|
||||
};
|
||||
|
||||
@@ -192,12 +197,21 @@ PO.Item.prototype.toString = function () {
|
||||
return lines;
|
||||
};
|
||||
|
||||
// https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html
|
||||
// says order is translator-comments, extracted-comments, references, flags
|
||||
|
||||
if (this.comments.length > 0) {
|
||||
this.comments.forEach(function (c) {
|
||||
lines.push('# ' + c);
|
||||
});
|
||||
}
|
||||
|
||||
if (this.extractedComments.length > 0) {
|
||||
this.extractedComments.forEach(function (c) {
|
||||
lines.push('#. ' + c);
|
||||
});
|
||||
}
|
||||
|
||||
if (this.references.length > 0) {
|
||||
this.references.forEach(function (ref) {
|
||||
lines.push('#: ' + ref);
|
||||
|
||||
Reference in New Issue
Block a user