add support for po files without headers
basically fix all the examples.
This commit is contained in:
parent
ba9a2db453
commit
71bb04f046
11
lib/po.js
11
lib/po.js
@ -64,10 +64,15 @@ PO.parse = function (data) {
|
|||||||
data = data.replace(/\r\n/g, '\n');
|
data = data.replace(/\r\n/g, '\n');
|
||||||
var po = new PO();
|
var po = new PO();
|
||||||
var sections = data.split(/\n\n/);
|
var sections = data.split(/\n\n/);
|
||||||
var headers = [sections.shift()];
|
var headers = [];
|
||||||
//everything until the first 'msgid ""' is considered header
|
//everything until the first 'msgid ""' is considered header
|
||||||
while (headers[headers.length - 1].indexOf('msgid ""') < 0) {
|
while (sections[0] && (headers.length === 0 || headers[headers.length - 1].indexOf('msgid ""') < 0)) {
|
||||||
headers.push(sections.shift());
|
if (sections[0].match(/msgid "[^"]/)) {
|
||||||
|
//found first real string, adding a dummy header item
|
||||||
|
headers.push('msgid ""');
|
||||||
|
} else {
|
||||||
|
headers.push(sections.shift());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
headers = headers.join('\n');
|
headers = headers.join('\n');
|
||||||
var lines = sections.join('\n').split(/\n/);
|
var lines = sections.join('\n').split(/\n/);
|
||||||
|
Loading…
Reference in New Issue
Block a user