Handle extracted comments

This commit is contained in:
Gabe Gorelick
2014-03-02 13:11:37 -05:00
parent ada76116b0
commit ac85ba0b9c
4 changed files with 40 additions and 7 deletions

View File

@@ -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);