[Pkg-javascript-commits] [node-po2json] 02/04: Imported Upstream version 0.4.4

Mathias Behrle mbehrle at moszumanska.debian.org
Wed Aug 31 18:37:05 UTC 2016


This is an automated email from the git hooks/post-receive script.

mbehrle pushed a commit to branch master
in repository node-po2json.

commit 0a4768f02f28c3defc23b73c23286e730f641e71
Author: Mathias Behrle <mathiasb at m9s.biz>
Date:   Wed Aug 31 20:26:57 2016 +0200

    Imported Upstream version 0.4.4
---
 .travis.yml                     |  1 +
 README.md                       |  5 +++++
 bower.json                      |  2 +-
 lib/parse.js                    | 14 +++++++++++---
 package.json                    |  9 ++++++++-
 test/fixtures/en-no-header.json |  6 ++++++
 test/fixtures/en-no-header.po   |  4 ++++
 test/fixtures/ja.json           | 16 ++++++++++++++++
 test/fixtures/ja.po             | 22 ++++++++++++++++++++++
 test/po2json_test.js            | 28 ++++++++++++++++++++++++++++
 10 files changed, 102 insertions(+), 5 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index cda2e6c..2cf583e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,6 @@
 language: node_js
 node_js:
+  - 6
   - 5
   - 4
   - 0.12
diff --git a/README.md b/README.md
index 0a1bf9f..434b747 100644
--- a/README.md
+++ b/README.md
@@ -115,6 +115,11 @@ po2json.parseFile('messages.po', { format: 'jed' }, function (err, jsonData) {
 });
 ```
 
+### Running tests
+```
+npm test
+```
+
 ## Contributing
 In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt](https://github.com/gruntjs/grunt).
 
diff --git a/bower.json b/bower.json
index d4e250b..8fa9a66 100644
--- a/bower.json
+++ b/bower.json
@@ -17,5 +17,5 @@
     "gettext",
     "po"
   ],
-  "license": "GPL"
+  "license": "LGPL"
 }
diff --git a/lib/parse.js b/lib/parse.js
index e48ec58..06139b2 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -32,6 +32,7 @@ module.exports = function(buffer, options) {
 
   Object.keys(contexts).forEach(function (context) {
     var translations = parsed.translations[context];
+    var pluralForms = parsed.headers ? parsed.headers['plural-forms'] : '';
 
     Object.keys(translations).forEach(function (key, i) {
       var t = translations[key],
@@ -42,7 +43,12 @@ module.exports = function(buffer, options) {
         if (options.format === 'mf') {
           result[translationKey] = t.msgstr[0];
         } else {
-          result[translationKey] = [ t.msgid_plural ? t.msgid_plural : null ].concat(t.msgstr);
+          if(pluralForms == 'nplurals=1; plural=0;') {
+            msgstr = t.msgid_plural ? [t.msgstr] : t.msgstr
+            result[translationKey] = [ t.msgid_plural ? t.msgid_plural : null ].concat(msgstr);
+          } else {
+            result[translationKey] = [ t.msgid_plural ? t.msgid_plural : null ].concat(t.msgstr);
+          }
         }
       }
 
@@ -60,7 +66,9 @@ module.exports = function(buffer, options) {
   });
 
   // Attach headers (overwrites any empty translation keys that may have somehow gotten in)
-  result[''] = parsed.headers;
+  if (parsed.headers) {
+    result[''] = parsed.headers;
+  }
 
   if (options.format === 'mf') {
     delete result[''];
@@ -73,7 +81,7 @@ module.exports = function(buffer, options) {
       locale_data: {}
     };
     if (options.format === 'jed1.x'){
-      for (key in result) {
+      for (var key in result) {
         if (result.hasOwnProperty(key) && key !== ''){
           for (var i = 2; i < result[key].length; i++){
             if ('' === result[key][i]){
diff --git a/package.json b/package.json
index 835ee2b..3645a5d 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "name": "po2json",
   "description": "Convert PO files to JSON",
-  "version": "0.4.2",
+  "version": "0.4.4",
   "homepage": "https://github.com/mikeedwards/po2json",
   "author": {
     "name": "Joshua I. Miller",
@@ -30,6 +30,13 @@
     },
     {
       "name": "Szigetvári Áron"
+    },
+    {
+      "name": "rafalt-iRonin"
+    },
+    {
+      "name": "Alex Petty",
+      "email": "pettyalex at gmail.com"
     }
   ],
   "repository": {
diff --git a/test/fixtures/en-no-header.json b/test/fixtures/en-no-header.json
new file mode 100644
index 0000000..f933eb8
--- /dev/null
+++ b/test/fixtures/en-no-header.json
@@ -0,0 +1,6 @@
+{
+   "Hello World": [
+      null,
+      "Hello World"
+   ]
+}
\ No newline at end of file
diff --git a/test/fixtures/en-no-header.po b/test/fixtures/en-no-header.po
new file mode 100644
index 0000000..7b57ae1
--- /dev/null
+++ b/test/fixtures/en-no-header.po
@@ -0,0 +1,4 @@
+# Very minimal .po
+
+msgid "Hello World"
+msgstr "Hello World"
diff --git a/test/fixtures/ja.json b/test/fixtures/ja.json
new file mode 100644
index 0000000..35f2cdc
--- /dev/null
+++ b/test/fixtures/ja.json
@@ -0,0 +1,16 @@
+{
+   "": {
+     "project-id-version": "VERSION",
+     "po-revision-date": "2016-08-08 14:08+0000",
+     "last-translator": "FULL NAME <EMAIL at ADDRESS>",
+     "language-team": "LANGUAGE TEAM <EMAIL at ADDRESS>",
+     "language": "ja",
+     "mime-version": "1.0",
+     "content-type": "text/plain; charset=UTF-8",
+     "content-transfer-encoding": "8bit",
+     "plural-forms": "nplurals=1; plural=0;"
+   },
+   "♂ Male": [ null, "男性" ],
+   "partner application": [ "partner applications", [ "パートナーアプリ" ] ],
+   "result": [ "results", [ "検索結果" ] ]
+}
diff --git a/test/fixtures/ja.po b/test/fixtures/ja.po
new file mode 100755
index 0000000..3310fa9
--- /dev/null
+++ b/test/fixtures/ja.po
@@ -0,0 +1,22 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: VERSION\n"
+"PO-Revision-Date: 2016-08-08 14:08+0000\n"
+"Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
+"Language-Team: LANGUAGE TEAM <EMAIL at ADDRESS>\n"
+"Language: ja\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=1; plural=0;\n"
+
+msgid "♂ Male"
+msgstr "男性"
+
+msgid "partner application"
+msgid_plural "partner applications"
+msgstr[0] "パートナーアプリ"
+
+msgid "result"
+msgid_plural "results"
+msgstr[0] "検索結果"
diff --git a/test/po2json_test.js b/test/po2json_test.js
index 337ed4f..1838527 100644
--- a/test/po2json_test.js
+++ b/test/po2json_test.js
@@ -114,3 +114,31 @@ module.exports["parseFileSync"] = {
     test.done();
   }
 }
+
+module.exports["parse with Plural-Forms == nplurals=1; plural=0;"] = {
+  setUp: function(callback){
+    this.po = fs.readFileSync(__dirname + "/fixtures/ja.po");
+    this.json = JSON.parse(fs.readFileSync(__dirname + "/fixtures/ja.json", "utf-8"));
+    callback();
+  },
+
+  parse: function(test){
+    var parsed = po2json.parse(this.po);
+    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");
+    this.json = JSON.parse(fs.readFileSync(__dirname + "/fixtures/en-no-header.json", "utf-8"));
+    callback();
+  },
+
+  parse: function(test){
+    var parsed = po2json.parse(this.po);
+    test.deepEqual(parsed, this.json);
+    test.done();
+  }
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-po2json.git



More information about the Pkg-javascript-commits mailing list