Skip to content

Commit 4520fb0

Browse files
authored
Merge pull request #56 from pettyalex/master
Fix parsing of .po files with no headers
2 parents 77f5dcd + 13be2c9 commit 4520fb0

File tree

5 files changed

+33
-3
lines changed

5 files changed

+33
-3
lines changed

lib/parse.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = function(buffer, options) {
3232

3333
Object.keys(contexts).forEach(function (context) {
3434
var translations = parsed.translations[context];
35-
var pluralForms = parsed.headers['plural-forms'];
35+
var pluralForms = parsed.headers ? parsed.headers['plural-forms'] : '';
3636

3737
Object.keys(translations).forEach(function (key, i) {
3838
var t = translations[key],
@@ -66,7 +66,9 @@ module.exports = function(buffer, options) {
6666
});
6767

6868
// Attach headers (overwrites any empty translation keys that may have somehow gotten in)
69-
result[''] = parsed.headers;
69+
if (parsed.headers) {
70+
result[''] = parsed.headers;
71+
}
7072

7173
if (options.format === 'mf') {
7274
delete result[''];

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "po2json",
33
"description": "Convert PO files to JSON",
4-
"version": "0.4.3",
4+
"version": "0.4.4",
55
"homepage": "https://github.com/mikeedwards/po2json",
66
"author": {
77
"name": "Joshua I. Miller",
@@ -33,6 +33,10 @@
3333
},
3434
{
3535
"name": "rafalt-iRonin"
36+
},
37+
{
38+
"name": "Alex Petty",
39+
"email": "[email protected]"
3640
}
3741
],
3842
"repository": {

test/fixtures/en-no-header.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"Hello World": [
3+
null,
4+
"Hello World"
5+
]
6+
}

test/fixtures/en-no-header.po

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Very minimal .po
2+
3+
msgid "Hello World"
4+
msgstr "Hello World"

test/po2json_test.js

+14
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,17 @@ module.exports["parse with Plural-Forms == nplurals=1; plural=0;"] = {
128128
test.done();
129129
}
130130
}
131+
132+
module.exports["parse with no headers"] ={
133+
setUp: function(callback){
134+
this.po = fs.readFileSync(__dirname + "/fixtures/en-no-header.po");
135+
this.json = JSON.parse(fs.readFileSync(__dirname + "/fixtures/en-no-header.json", "utf-8"));
136+
callback();
137+
},
138+
139+
parse: function(test){
140+
var parsed = po2json.parse(this.po);
141+
test.deepEqual(parsed, this.json);
142+
test.done();
143+
}
144+
}

0 commit comments

Comments
 (0)