5 Commits

Author SHA1 Message Date
Ruben Vermeersch
fbe773c636 Release v1.0.1 2015-09-21 09:35:02 +02:00
Ruben Vermeersch
7ceda82794 Merge pull request #17 from rubenv/fix_issue16
fix issue #16
2015-09-21 09:34:41 +02:00
Julian Bäume
d1be0f51b0 fix issue #16
add a blank line in the comments of the headers of the big.po file. This
breaks parsing the headers. msgcat of gettext tools just ignores empty
lines until a header is found and treats everything above as header
comment.

The change to the library itself fixes the tests again, after the blank
linke broke 3.
2015-09-21 09:13:43 +02:00
Ruben Vermeersch
869f763d80 Release v1.0.0 2015-08-20 15:13:21 +02:00
Ruben Vermeersch
b9394176b1 Handle extracted comments in headers 2015-08-20 15:12:56 +02:00
9 changed files with 41 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "pofile",
"version": "0.3.0",
"version": "1.0.1",
"authors": [
"Ruben Vermeersch <ruben@rocketeer.be>"
],

20
dist/pofile.js vendored
View File

@@ -8,6 +8,7 @@ function trim(string) {
var PO = function () {
this.comments = [];
this.extractedComments = [];
this.headers = {};
this.items = [];
};
@@ -24,6 +25,11 @@ PO.prototype.toString = function () {
lines.push('# ' + comment);
});
}
if (this.extractedComments) {
this.extractedComments.forEach(function (comment) {
lines.push('#. ' + comment);
});
}
lines.push('msgid ""');
lines.push('msgstr ""');
@@ -59,7 +65,12 @@ PO.parse = function (data) {
data = data.replace(/\r\n/g, '\n');
var po = new PO();
var sections = data.split(/\n\n/);
var headers = sections.shift();
var headers = [sections.shift()];
//everything until the first 'msgid ""' is considered header
while (headers[headers.length - 1].indexOf('msgid ""') < 0) {
headers.push(sections.shift());
}
headers = headers.join('\n');
var lines = sections.join('\n').split(/\n/);
po.headers = {
@@ -87,10 +98,11 @@ PO.parse = function (data) {
acc.push(line);
return acc;
}, []).forEach(function (header) {
if (header.match(/^#/)) {
if (header.match(/^#\./)) {
po.extractedComments.push(header.replace(/^#\.\s*/, ''));
} else if (header.match(/^#/)) {
po.comments.push(header.replace(/^#\s*/, ''));
}
if (header.match(/^"/)) {
} else if (header.match(/^"/)) {
header = header.trim().replace(/^"/, '').replace(/\\n"$/, '');
var p = header.split(/:/);
var name = p.shift().trim();

2
dist/pofile.min.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -7,6 +7,7 @@ function trim(string) {
var PO = function () {
this.comments = [];
this.extractedComments = [];
this.headers = {};
this.items = [];
};
@@ -23,6 +24,11 @@ PO.prototype.toString = function () {
lines.push('# ' + comment);
});
}
if (this.extractedComments) {
this.extractedComments.forEach(function (comment) {
lines.push('#. ' + comment);
});
}
lines.push('msgid ""');
lines.push('msgstr ""');
@@ -58,7 +64,12 @@ PO.parse = function (data) {
data = data.replace(/\r\n/g, '\n');
var po = new PO();
var sections = data.split(/\n\n/);
var headers = sections.shift();
var headers = [sections.shift()];
//everything until the first 'msgid ""' is considered header
while (headers[headers.length - 1].indexOf('msgid ""') < 0) {
headers.push(sections.shift());
}
headers = headers.join('\n');
var lines = sections.join('\n').split(/\n/);
po.headers = {
@@ -86,10 +97,11 @@ PO.parse = function (data) {
acc.push(line);
return acc;
}, []).forEach(function (header) {
if (header.match(/^#/)) {
if (header.match(/^#\./)) {
po.extractedComments.push(header.replace(/^#\.\s*/, ''));
} else if (header.match(/^#/)) {
po.comments.push(header.replace(/^#\s*/, ''));
}
if (header.match(/^"/)) {
} else if (header.match(/^"/)) {
header = header.trim().replace(/^"/, '').replace(/\\n"$/, '');
var p = header.split(/:/);
var name = p.shift().trim();

View File

@@ -1,7 +1,7 @@
{
"name": "pofile",
"description": "Parse and serialize Gettext PO files.",
"version": "0.3.0",
"version": "1.0.1",
"author": {
"name": "Ruben Vermeersch",
"email": "ruben@savanne.be",

View File

@@ -1,4 +1,5 @@
# French translation of Link (6.x-2.9)
# Copyright (c) 2011 by the French translation team
#
msgid ""

View File

@@ -1,6 +1,7 @@
# French translation of Link (6.x-2.9)
# Copyright (c) 2011 by the French translation team
#
#. extracted from test
msgid ""
msgstr ""
"Project-Id-Version: Link (6.x-2.9)\n"

View File

@@ -61,6 +61,9 @@ describe('Parse', function () {
assert.notEqual(po, null);
assert.equal(po.items.length, 2);
assert.equal(po.extractedComments.length, 1);
assert.equal(po.extractedComments[0], 'extracted from test');
var item = po.items[0];
assert.equal(item.msgid, 'Title, as plain text');
assert.equal(item.msgstr, 'Attribut title, en tant que texte brut');

View File

@@ -74,6 +74,7 @@ describe('Write', function () {
var input = fs.readFileSync(__dirname + '/fixtures/comment.po', 'utf8');
var po = PO.parse(input);
var str = po.toString();
assertHasLine(str, '#. extracted from test');
assertHasLine(str, '#. Extracted comment');
});