Skip to content

Commit

Permalink
fix ja-JP pluralization for jed-1.x #57
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeedwards committed Oct 10, 2016
1 parent 4520fb0 commit f95dd09
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ module.exports = function(buffer, options) {
if (!fuzzy || options.fuzzy) {
if (options.format === 'mf') {
result[translationKey] = t.msgstr[0];
} else if (options.format === 'jed1.x') {
result[translationKey] = [ t.msgid_plural ? t.msgid_plural : null ].concat(t.msgstr);
} else {
if(pluralForms == 'nplurals=1; plural=0;') {
msgstr = t.msgid_plural ? [t.msgstr] : t.msgstr
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/ja-jed1.x.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"domain":"messages","locale_data":{"messages":{"":{"domain":"messages","plural_forms":"nplurals=1; plural=0;","lang":"ja"},"♂ Male":["男性"],"partner application":["パートナーアプリ"],"result":["検索結果"],"For %s person starting at %s":["For %1$s people starting at %2$s"]}}}
3 changes: 2 additions & 1 deletion test/fixtures/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
},
"♂ Male": [ null, "男性" ],
"partner application": [ "partner applications", [ "パートナーアプリ" ] ],
"result": [ "results", [ "検索結果" ] ]
"result": [ "results", [ "検索結果" ] ],
"For %s person starting at %s": [ "For %s people starting at %s", ["For %1$s people starting at %2$s"] ]
}
5 changes: 5 additions & 0 deletions test/fixtures/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ msgstr[0] "パートナーアプリ"
msgid "result"
msgid_plural "results"
msgstr[0] "検索結果"

msgid "For %s person starting at %s"
msgid_plural "For %s people starting at %s"
msgstr[0] "For %1$s people starting at %2$s"

14 changes: 14 additions & 0 deletions test/po2json_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ module.exports["parse with Plural-Forms == nplurals=1; plural=0;"] = {
}
}

module.exports["parse with Plural-Forms == nplurals=1; plural=0; and with Jed1.x format"] = {
setUp: function(callback){
this.po = fs.readFileSync(__dirname + "/fixtures/ja.po");
this.json = JSON.parse(fs.readFileSync(__dirname + "/fixtures/ja-jed1.x.json", "utf-8"));
callback();
},

parse: function(test){
var parsed = po2json.parse(this.po, { format: 'jed1.x' });
test.deepEqual(parsed, this.json);
test.done();
}
}

module.exports["parse with no headers"] ={
setUp: function(callback){
this.po = fs.readFileSync(__dirname + "/fixtures/en-no-header.po");
Expand Down

0 comments on commit f95dd09

Please sign in to comment.