header order

This commit is contained in:
Martin Bachtík
2018-05-23 18:25:55 +02:00
committed by Martin Bachtik
parent ad71dba6ad
commit 8bd7810703
4 changed files with 62 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ var PO = function () {
this.comments = [];
this.extractedComments = [];
this.headers = {};
this.headerOrder = [];
this.items = [];
};
@@ -32,9 +33,24 @@ PO.prototype.toString = function () {
lines.push('msgid ""');
lines.push('msgstr ""');
var keys = Object.keys(this.headers);
var self = this;
var headerOrder = [];
this.headerOrder.forEach(function (key) {
if (key in self.headers) {
headerOrder.push(key);
}
});
var keys = Object.keys(this.headers);
keys.forEach(function (key) {
if (headerOrder.indexOf(key) === -1) {
headerOrder.push(key);
}
});
headerOrder.forEach(function (key) {
lines.push('"' + key + ': ' + self.headers[key] + '\\n"');
});
@@ -88,6 +104,7 @@ PO.parse = function (data) {
'Content-Transfer-Encoding': '',
'Plural-Forms': '',
};
po.headerOrder = [];
headers.split(/\n/).reduce(function (acc, line) {
if (acc.merge) {
@@ -111,6 +128,7 @@ PO.parse = function (data) {
var name = p.shift().trim();
var value = p.join(':').trim();
po.headers[name] = value;
po.headerOrder.push(name);
}
});