[Pkg-javascript-commits] [node-po2json] 01/02: Imported Upstream version 0.4.2

Mathias Behrle mbehrle at moszumanska.debian.org
Sat Jul 23 15:35:04 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 41b6e738eb4427eb29d18cf2a813455651ca29e5
Author: Mathias Behrle <mathiasb at m9s.biz>
Date:   Fri Jul 1 13:18:20 2016 +0200

    Imported Upstream version 0.4.2
---
 .gitignore                                 |   2 +
 .npmignore                                 |   1 +
 .travis.yml                                |   7 +
 AUTHORS                                    |  10 ++
 History.md                                 |  95 +++++++++++++
 LICENSE                                    |  28 ++++
 README.md                                  | 206 +++++++++++++++++++++++++++++
 bin/po2json                                |  53 ++++++++
 bower.json                                 |  21 +++
 index.js                                   |   5 +
 lib/parse.js                               |  98 ++++++++++++++
 lib/parseFile.js                           |  28 ++++
 lib/parseFileSync.js                       |  15 +++
 package.json                               |  72 ++++++++++
 test/fixtures/en-empty.json                |  40 ++++++
 test/fixtures/en-empty.po                  |  45 +++++++
 test/fixtures/en-mf-fallback-to-msgid.json |   9 ++
 test/fixtures/pl-jed.json                  |  40 ++++++
 test/fixtures/pl-jed1.x.json               |  34 +++++
 test/fixtures/pl-mf.json                   |   7 +
 test/fixtures/pl-mf.po                     |  44 ++++++
 test/fixtures/pl.json                      |  43 ++++++
 test/fixtures/pl.po                        |  58 ++++++++
 test/po2json_test.js                       | 116 ++++++++++++++++
 24 files changed, 1077 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5171c54
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+node_modules
+npm-debug.log
\ No newline at end of file
diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..2ccbe46
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1 @@
+/node_modules/
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..cda2e6c
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,7 @@
+language: node_js
+node_js:
+  - 5
+  - 4
+  - 0.12
+  - 0.11
+  - 0.10
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..c0ce749
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,10 @@
+# Authors ordered by first contribution.
+
+Illimar Tambek <illimar at sliptree.com>
+Mike Edwards <michael.edwards at huffingtonpost.com>
+gilles <gilles.devaux at gmail.com>
+Asbjørn Sloth Tønnesen <ast at veridu.com>
+Zach Carter <zack.carter at gmail.com>
+Dan MacTough <danmactough at gmail.com>
+Evan Moses
+Dima Kurguzov
diff --git a/History.md b/History.md
new file mode 100644
index 0000000..0f64edd
--- /dev/null
+++ b/History.md
@@ -0,0 +1,95 @@
+0.4.1 / 2016-04-13
+==================
+ * Updated documentation for Jed > 1.1.0
+ * Use msgid_plural when there is no translation
+
+0.4.1 / 2015-03-01
+==================
+ * Updated Jed-format code and test to deal with the new plural form
+
+0.4.0 / 2015-03-01
+==================
+ * Added Jed > 1.1.0 compatible format (Evan Moses)
+
+0.3.0 / 2014-07-16
+==================
+ * Added command line flags for fuzzy, pretty, format, and domain (Szigetvári Áron)
+ * Deals with fallback-to-msgid for fuzzy entries without the fuzzy flag (Szigetvári Áron)
+
+0.2.4 / 2014-07-15
+==================
+
+ * Fixed fuzzy flag (mahata)
+
+0.2.3 / 2014-01-26
+==================
+
+ * Raised minimum node version requirement to 0.8
+ * Raised lodash version to ~2.4.1
+ * Clean up documentations
+
+0.2.0 / 2013-11-08
+==================
+
+**NB! This release is NOT backwards-compatible!** It has the following **braking changes**:
+
+ * `po2json.parse_po` has been replaced with `po2json.parse`
+ * `po2json.parse` has been replaced with `po2json.parseFile`
+ * `po2json.parseSync` has been replaced with `po2json.parseFileSync`
+
+Other changes in this release:
+
+  * The library has been competely rewritten, it now uses the [gettext-parser](https://github.com/andris9/gettext-parser) module to parse PO files. (Illimar Tambek)
+  * Tests have been completely rewritten (Illimar Tambek)
+  * Fixed issue with double-escaping quotes (Illimar Tambek)
+  * Option to skip/include fuzzy translations (Illimar Tambek)
+
+
+0.0.7 / 2012-10-26
+==================
+
+  * Fixed linting bugs and added a better fr.po fixture (Mike Edwards)
+  * Add tests for po2json.parse and po2json.parseSync (Dan MacTough)
+  * updated README.md with version history (Mike Edwards)
+  * updated history (Mike Edwards)
+
+0.0.6 / 2012-10-22
+==================
+
+  * Add AUTHORS to identify contributors (Dan MacTough)
+  * Update README with revision history and basic examples (Dan MacTough)
+
+0.0.5 / 2012-10-19
+==================
+
+  * cut out fake README example from grunt boilerplate (Mike Edwards)
+  * fixed README.md markdown (Mike Edwards)
+  * fixes tests (Mike Edwards)
+  * added first test for parse_po (Mike Edwards)
+  * Added boilerplate using grunt init (Mike Edwards)
+  * Changed exports.parse to use node's convetional error-first callback style. Added exports.parseSync for synchronous parsing. (Dan MacTough)
+
+0.0.4 / 2012-09-18
+==================
+
+  * Properly escape linebreaks (Zach Carter)
+  * Update package.json (Mike Edwards)
+  * package.json: define main module (Asbjørn Sloth Tønnesen)
+
+0.0.2 / 2012-07-03
+==================
+
+  * fix package, fix pretty print return, remove debug logs (gilles)
+  * upped version (Mike Edwards)
+
+0.0.1 / 2012-06-06
+==================
+
+  * Added build status to README (Mike Edwards)
+  * Removed built=ints from the dependencies (Mike Edwards)
+  * Added a .travis file for continuous integration (Mike Edwards)
+  * Added usage note to README.md (Mike Edwards)
+  * First working script! (Mike Edwards)
+  * Added new git repo (Mike Edwards)
+  * initial commit (Mike Edwards)
+  * Initial commit (Mike Edwards)
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..59a64e7
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,28 @@
+Pure Javascript implementation of Uniforum message translation.
+Copyright (C) 2008 Joshua I. Miller <unrtst at cpan.org>, all rights reserved
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU Library General Public License as published
+by the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+USA.
+
+PO parser from http://jsgettext.berlios.de/lib/Gettext.js
+adapted for Node.js and modified to be more like po2json.pl
+- Zach Carter <zcarter at cse.usf.edu>
+
+Further adapted to be used inside a node.js environment instead of the command line. Import with a require statement:
+var po2json = require('po2json.js')
+po2json.parse('filename', function(result) {
+   on parse complete callaback, result is the json string.
+});
+- Daniel Roberts <danielrobertsdesign at gmail.com>
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..0a1bf9f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,206 @@
+# po2json
+
+[![Build Status](https://secure.travis-ci.org/mikeedwards/po2json.png?branch=master)](http://travis-ci.org/mikeedwards/po2json)
+[![Dependency Status](https://david-dm.org/mikeedwards/po2json.png?theme=shields.io)](https://david-dm.org/mikeedwards/po2json)
+[![devDependency Status](https://david-dm.org/mikeedwards/po2json/dev-status.png?theme=shields.io)](https://david-dm.org/mikeedwards/po2json#info=devDependencies)
+
+[![NPM](https://nodei.co/npm/po2json.png)](https://nodei.co/npm/po2json/)
+
+Convert PO files to Javascript objects or JSON strings. The result is Jed-compatible.
+
+## Getting Started
+Install the module with: `npm install po2json`
+
+### As a library
+```
+var po2json = require('po2json');
+```
+
+### As an executable
+```
+po2json translation.po translation.json
+```
+
+## Documentation
+
+### Methods
+
+po2json has 3 methods, all of which take exactly the same options. The main function is `parse` which actually does the parsing to JSON. The 2 others - `parseFile` and `parseFileSync` are convenience functions to directly read PO data from a file and convert it to JSON.
+
+Parse a PO buffer to JSON
+
+* `po2json.parse(buf[, options])`
+	* `buf` - a _po_ file as a Buffer or an unicode string.
+	* `options` - an optional object with the following possible parameters:
+		* `fuzzy` Whether to include fuzzy translation in JSON or not. Should be either `true` or `false`. Defaults to `false`.
+		* `stringify` If `true`, returns a JSON string. Otherwise returns a plain Javascript object. Defaults to `false`.
+		* `pretty` If `true`, the resulting JSON string will be pretty-printed. Has no effect when `stringify` is `false`. Defaults to `false`
+		* `format` Defaults to `raw`.
+			* `raw` produces a "raw" JSON output
+			* `jed` produces an output that is 100% compatible with Jed < 1.1.0
+			* `jed1.x` produces an output that is 100% compatible with Jed >= 1.1.0
+			* `mf` produces simple key:value output.
+		* `domain` - the domain the messages will be wrapped inside. Only has effect if `format: 'jed'`.
+
+Parse a PO file to JSON
+
+* `po2json.parseFile(fileName[,options], cb)`
+	* `fileName` - path to the po file
+	* `options` - same as for `po2json.parse`
+	* `cb` - a function that receives 2 arguments: `err` and `jsonData`
+
+Parse a PO file to JSON (synchronous)
+
+* `po2json.parseFileSync(fileName[, options])`
+	* `fileName` - path to the po file
+	* `options` - same as for `po2json.parse`
+
+#### fallback-to-msgid
+If `fallback-to-msgid` is set, for those entries that would be omitted
+(fuzzy entries without the fuzzy flag) and for those that are empty,
+the msgid will be used as translation in the json file.
+If the entry is plural, msgid_plural will be used for msgstr[1].
+This means that this option makes sense only for those languages
+that have nplurals=2.
+
+### Command Line Arguments
+
+po2json in command-line parametrization support added to allow override
+default options.
+
+* --pretty, -p: same as pretty = true in function options
+* --fuzzy, -F:  same as fuzzy = true in function options
+* --format, -f: Output format (raw, jed, jed1.x, or mf)
+* --domain, -d: same as domain in function options
+
+Note: `'format': 'mf'` means the json format used by messageFormatter in github.com/SlexAxton/messageformat.js
+This system does any pluralization within the string, so only msgstr[0] is used with these format, in a simple "key": "value" form.
+
+## Examples
+
+### Basic usage with PO data as a buffer/string
+```
+var po2json = require('po2json'),
+    fs = require('fs');
+fs.readFile('messages.po', function (err, buffer) {
+  var jsonData = po2json.parse(buffer);
+  // do something interesting ...
+});
+```
+
+### Parse a PO file directly - Asynchronous Usage
+```
+var po2json = require('po2json');
+po2json.parseFile('messages.po', function (err, jsonData) {
+    // do something interesting ...
+});
+```
+
+### Parse a PO file directly - Synchronous Usage
+```
+var po2json = require('po2json');
+var jsonData = '';
+try {
+    jsonData = po2json.parseFileSync('messages.po');
+    // do something interesting ...
+} catch (e) {}
+```
+
+### Parse a PO file to Jed format
+```
+var po2json = require('po2json'),
+    Jed = require('jed');
+po2json.parseFile('messages.po', { format: 'jed' }, function (err, jsonData) {
+    var i18n = new Jed( jsonData );
+});
+```
+
+## 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).
+
+## Release History
+### 0.4.2 / 2015-04-13
+ * Updated documentation for Jed > 1.1.0
+ * Use msgid_plural when there is no translation
+
+### 0.4.1 / 2015-03-01
+ * Updated Jed-format code and test to deal with the new plural form
+
+### 0.4.0 / 2015-03-01
+ * Added Jed > 1.1.0 compatible format (Evan Moses)
+
+### 0.3.0 / 2014-07-16
+ * Added command line flags for fuzzy, pretty, format, and domain (Szigetvári Áron)
+ * Deals with fallback-to-msgid for fuzzy entries without the fuzzy flag (Szigetvári Áron)
+
+### 0.2.4 / 2014-07-15
+
+ * Fixed fuzzy flag (mahata)
+
+### 0.2.3 / 2014-01-26
+
+ * Raised minimum node version requirement to 0.8
+ * Raised lodash version to ~2.4.1
+ * Clean up documentations
+
+### 0.2.0 / 2013-11-08
+
+**NB! This release is NOT backwards-compatible!** It has the following **breaking changes**:
+
+ * `po2json.parse_po` has been replaced with `po2json.parse`
+ * `po2json.parse` has been replaced with `po2json.parseFile`
+ * `po2json.parseSync` has been replaced with `po2json.parseFileSync`
+
+Other changes in this release:
+
+  * The library has been competely rewritten, it now uses the [gettext-parser](https://github.com/andris9/gettext-parser) module to parse PO files. (Illimar Tambek)
+  * Tests have been completely rewritten (Illimar Tambek)
+  * Fixed issue with double-escaping quotes (Illimar Tambek)
+  * Option to skip/include fuzzy translations (Illimar Tambek)
+
+### 0.0.7 / 2012-10-26
+
+  * Fixed linting bugs and added a better fr.po fixture (Mike Edwards)
+  * Add tests for po2json.parse and po2json.parseSync (Dan MacTough)
+  * updated README.md with version history (Mike Edwards)
+  * updated history (Mike Edwards)
+
+### 0.0.6 / 2012-10-22
+
+  * Add AUTHORS to identify contributors (Dan MacTough)
+  * Update README with revision history and basic examples (Dan MacTough)
+
+### 0.0.5 / 2012-10-19
+
+  * cut out fake README example from grunt boilerplate (Mike Edwards)
+  * fixed README.md markdown (Mike Edwards)
+  * fixes tests (Mike Edwards)
+  * added first test for parse_po (Mike Edwards)
+  * Added boilerplate using grunt init (Mike Edwards)
+  * Changed exports.parse to use node's convetional error-first callback style. Added exports.parseSync for synchronous parsing. (Dan MacTough)
+
+### 0.0.4 / 2012-09-18
+
+  * Properly escape linebreaks (Zach Carter)
+  * Update package.json (Mike Edwards)
+  * package.json: define main module (Asbjørn Sloth Tønnesen)
+
+### 0.0.2 / 2012-07-03
+
+  * fix package, fix pretty print return, remove debug logs (gilles)
+  * upped version (Mike Edwards)
+
+### 0.0.1 / 2012-06-06
+
+  * Added build status to README (Mike Edwards)
+  * Removed built=ints from the dependencies (Mike Edwards)
+  * Added a .travis file for continuous integration (Mike Edwards)
+  * Added usage note to README.md (Mike Edwards)
+  * First working script! (Mike Edwards)
+  * Added new git repo (Mike Edwards)
+  * initial commit (Mike Edwards)
+  * Initial commit (Mike Edwards)
+
+## License
+Copyright (c) 2012 Joshua I. Miller
+Licensed under the GNU, Library, General, Public, License licenses.
diff --git a/bin/po2json b/bin/po2json
new file mode 100755
index 0000000..9eab188
--- /dev/null
+++ b/bin/po2json
@@ -0,0 +1,53 @@
+#!/usr/bin/env node
+
+var po2json = require('../'),
+	fs = require('fs'),
+  assert = require('assert'),
+  argv = process.argv;
+
+var opts = require("nomnom")
+  .script('po2json')
+  .option('pretty', {
+    abbr: 'p',
+    flag: true,
+    help: 'pretty-print JSON'
+  })
+  .option('fuzzy', {
+    abbr: 'F',
+    flag: true,
+    help: 'include fuzzy messages'
+  })
+  .option('format', {
+    abbr: 'f',
+    default: 'raw',
+    help: 'output format, one of: raw, jed, jed1.x, mf (messageformat)'
+  })
+  .option('domain', {
+    abbr: 'd',
+    default: 'messages',
+    help: 'domain'
+  })
+  .option('fallback-to-msgid', {
+    flag: true,
+    help: 'Use msgid if translation is missing (nplurals must match)'
+  })
+  .option('input', {
+    position: 0,
+    required: true,
+    list: false,
+    help: 'input file'
+  })
+  .option('output', {
+    position: 1,
+    required: true,
+    list: false,
+    help: 'output file'
+  })
+  .parse();
+
+opts.stringify = true;
+
+var result = po2json.parseFileSync(opts.input, opts),
+    stream = fs.createWriteStream(opts.output, {});
+
+stream.write(result);
diff --git a/bower.json b/bower.json
new file mode 100644
index 0000000..d4e250b
--- /dev/null
+++ b/bower.json
@@ -0,0 +1,21 @@
+{
+  "name": "po2json",
+  "version": "0.3.2",
+  "ignore": [
+    "**/.*",
+    "test",
+    "lib",
+    "*.md",
+    ".json",
+    ".yml",
+    "package.json",
+    "*.js"
+  ],
+  "keywords": [
+    "i18n",
+    "l10n",
+    "gettext",
+    "po"
+  ],
+  "license": "GPL"
+}
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..5be5888
--- /dev/null
+++ b/index.js
@@ -0,0 +1,5 @@
+module.exports = {
+  parse: require('./lib/parse'),
+  parseFile: require('./lib/parseFile'),
+  parseFileSync: require('./lib/parseFileSync')
+};
\ No newline at end of file
diff --git a/lib/parse.js b/lib/parse.js
new file mode 100644
index 0000000..e48ec58
--- /dev/null
+++ b/lib/parse.js
@@ -0,0 +1,98 @@
+/**
+ * Parse PO buffer to JSON
+ *
+ * @param {Buffer|String} buffer - Buffer PO object or unicode string with PO data
+ * @param {Object} [options]
+ * @return {Object|String} Translation JSON
+ */
+
+module.exports = function(buffer, options) {
+
+  // Setup options and load in defaults
+  options = options || {};
+  var defaults = {
+    pretty: false,
+    fuzzy: false,
+    stringify: false,
+    format: 'raw',
+    domain: 'messages',
+    charset: 'utf8'
+  };
+
+  for (var property in defaults) {
+    options[property] = 'undefined' !== typeof options[property] ? options[property] : defaults[property];
+  }
+
+  // Parse the PO file
+  var parsed = require('gettext-parser').po.parse( buffer, defaults.charset );
+
+  // Create gettext/Jed compatible JSON from parsed data
+  var result = {},
+      contexts = parsed.translations;
+
+  Object.keys(contexts).forEach(function (context) {
+    var translations = parsed.translations[context];
+
+    Object.keys(translations).forEach(function (key, i) {
+      var t = translations[key],
+          translationKey = context.length ? context + '\u0004' + key : key,
+          fuzzy = t.comments && t.comments.flag && t.comments.flag.match(/fuzzy/) !== null;
+
+      if (!fuzzy || options.fuzzy) {
+        if (options.format === 'mf') {
+          result[translationKey] = t.msgstr[0];
+        } else {
+          result[translationKey] = [ t.msgid_plural ? t.msgid_plural : null ].concat(t.msgstr);
+        }
+      }
+
+      // In the case of fuzzy or empty messages, use msgid(/msgid_plural)
+      if (options['fallback-to-msgid'] && (fuzzy && !options.fuzzy || t.msgstr[0] === '')) {
+        if (options.format === 'mf') {
+          result[translationKey] = key;
+        } else {
+          result[translationKey] = [ t.msgid_plural ? t.msgid_plural : null ]
+              .concat(t.msgid_plural ? [key, t.msgid_plural] : [key]);
+        }
+      }
+
+    });
+  });
+
+  // Attach headers (overwrites any empty translation keys that may have somehow gotten in)
+  result[''] = parsed.headers;
+
+  if (options.format === 'mf') {
+    delete result[''];
+  }
+
+  // Make JSON fully Jed-compatible
+  if (options.format.indexOf('jed') === 0) {
+    var jed = {
+      domain: options.domain,
+      locale_data: {}
+    };
+    if (options.format === 'jed1.x'){
+      for (key in result) {
+        if (result.hasOwnProperty(key) && key !== ''){
+          for (var i = 2; i < result[key].length; i++){
+            if ('' === result[key][i]){
+              result[key][i] = result[key][0];
+            }
+          }
+          result[key].shift();
+        }
+      }
+    }
+    jed.locale_data[options.domain] = result;
+    jed.locale_data[options.domain][''] = {
+      domain: options.domain,
+      plural_forms: result['']['plural-forms'],
+      lang: result['']['language']
+    };
+
+    result = jed;
+  }
+
+  return options.stringify ? JSON.stringify( result, null, options.pretty ? '   ' : null ) : result;
+}
diff --git a/lib/parseFile.js b/lib/parseFile.js
new file mode 100644
index 0000000..af7dc69
--- /dev/null
+++ b/lib/parseFile.js
@@ -0,0 +1,28 @@
+var fs = require("fs");
+
+/**
+ * Asynchronously parse a PO file to JSON
+ *
+ * @param {String} fileName - File name
+ * @param {Object} [options]
+ * @param {Function} cb - Callback function, takes 2 arguments: err and result
+ */
+
+module.exports = function(fileName, options, cb) {
+  options = options || {};
+
+  if (typeof options === 'function') {
+    cb = options;
+    options = {};
+  }
+
+  fs.realpath(fileName, function (err, realFile) {
+    if (err) return cb(err);
+
+    fs.readFile(realFile, function (err, data) {
+      if (err) return cb(err);
+
+      cb(null, require("./parse")( data, options ));
+    });
+  });
+};
\ No newline at end of file
diff --git a/lib/parseFileSync.js b/lib/parseFileSync.js
new file mode 100644
index 0000000..2110254
--- /dev/null
+++ b/lib/parseFileSync.js
@@ -0,0 +1,15 @@
+var fs = require("fs");
+
+/**
+ * Synchronously parse a PO file to JSON
+ *
+ * @param {String} fileName - File name
+ * @param {Object} [options]
+ * @return {Object|String} Translation JSON
+ */
+
+module.exports = function(fileName, options) {
+  var data = fs.readFileSync(fs.realpathSync(fileName));
+
+  return require("./parse")( data, options );
+};
\ No newline at end of file
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..835ee2b
--- /dev/null
+++ b/package.json
@@ -0,0 +1,72 @@
+{
+  "name": "po2json",
+  "description": "Convert PO files to JSON",
+  "version": "0.4.2",
+  "homepage": "https://github.com/mikeedwards/po2json",
+  "author": {
+    "name": "Joshua I. Miller",
+    "email": "unrtst at cpan.org"
+  },
+  "contributors": [
+    {
+      "name": "Zach Carter",
+      "email": "zcarter at cse.usf.edu"
+    },
+    {
+      "name": "Daniel Roberts",
+      "email": "danielrobertsdesign at gmail.com"
+    },
+    {
+      "name": "Mike Edwards",
+      "email": "michael.edwards at huffingtonpost.com"
+    },
+    {
+      "name": "Illimar Tambek",
+      "email": "illimar at sliptree.com"
+    },
+    {
+      "name": "mahata",
+      "email": "mahata777 at gmail.com"
+    },
+    {
+      "name": "Szigetvári Áron"
+    }
+  ],
+  "repository": {
+    "type": "git",
+    "url": "git://github.com/mikeedwards/po2json.git"
+  },
+  "bugs": {
+    "url": "https://github.com/mikeedwards/po2json/issues"
+  },
+  "licenses": [
+    {
+      "type": "GNU Library General Public License",
+      "url": "http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html"
+    }
+  ],
+  "bin": {
+    "po2json": "bin/po2json"
+  },
+  "main": "./lib/po2json",
+  "engines": {
+    "node": ">= 0.8.0"
+  },
+  "scripts": {
+    "test": "nodeunit test/"
+  },
+  "devDependencies": {
+    "nodeunit": "*",
+    "jed": "~1.0.2"
+  },
+  "keywords": [
+    "i18n",
+    "l10n",
+    "gettext",
+    "po"
+  ],
+  "dependencies": {
+    "nomnom": "1.8.1",
+    "gettext-parser": "1.1.0"
+  }
+}
diff --git a/test/fixtures/en-empty.json b/test/fixtures/en-empty.json
new file mode 100644
index 0000000..4216a1c
--- /dev/null
+++ b/test/fixtures/en-empty.json
@@ -0,0 +1,40 @@
+{
+   "": {
+      "project-id-version": "po2json",
+      "pot-creation-date": "2012-10-26 12:00+0000",
+      "po-revision-date": "2013-11-08 09:09+0200",
+      "last-translator": "Illimar Tambek <illimar.tambek at gmail.com>",
+      "language-team": "po2json",
+      "mime-version": "1.0",
+      "plural-forms": "nplurals=2; plural=(n != 1);",
+      "content-type": "text/plain; charset=UTF-8",
+      "content-transfer-encoding": "8bit",
+      "x-generator": "Poedit 1.5.7",
+      "language": "en"
+   },
+   "Hello, world!\n": [
+      null,
+      "Hello, world!\n"
+   ],
+   "string context\u0004the contextual phrase": [
+      null,
+      "the contextual phrase"
+   ],
+   "this is the first line\nthis is the next one\nbut this is the last\n": [
+      null,
+      "this is the first line\nthis is the next one\nbut this is the last\n"
+   ],
+   "one product": [
+      "%d products",
+      "one product",
+      "%d products"
+   ],
+   "A sentence with \"quotation\" marks.": [
+      null,
+      "A sentence with \"quotation\" marks."
+   ],
+   "A fuzzy translation": [
+      null,
+      "A fuzzy translation"
+   ]
+}
\ No newline at end of file
diff --git a/test/fixtures/en-empty.po b/test/fixtures/en-empty.po
new file mode 100644
index 0000000..b2cb6bd
--- /dev/null
+++ b/test/fixtures/en-empty.po
@@ -0,0 +1,45 @@
+# English empty translation for po2json text fixture.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: po2json\n"
+"POT-Creation-Date: 2012-10-26 12:00+0000\n"
+"PO-Revision-Date: 2013-11-08 09:09+0200\n"
+"Last-Translator: Illimar Tambek <illimar.tambek at gmail.com>\n"
+"Language-Team: po2json\n"
+"MIME-Version: 1.0\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: Poedit 1.5.7\n"
+"Language: en\n"
+
+#: test.js:1
+msgid "Hello, world!\n"
+msgstr ""
+
+#: test.js:2
+msgctxt "string context"
+msgid "the contextual phrase"
+msgstr ""
+
+#: test.js:3
+msgid ""
+"this is the first line\n"
+"this is the next one\n"
+"but this is the last\n"
+msgstr ""
+
+#: test.js:4
+msgid "one product"
+msgid_plural "%d products"
+msgstr[0] ""
+msgstr[1] ""
+
+#: test.js:5
+msgid "A sentence with \"quotation\" marks."
+msgstr ""
+
+#: test.js:6
+msgid "A fuzzy translation"
+msgstr ""
diff --git a/test/fixtures/en-mf-fallback-to-msgid.json b/test/fixtures/en-mf-fallback-to-msgid.json
new file mode 100644
index 0000000..8f4d790
--- /dev/null
+++ b/test/fixtures/en-mf-fallback-to-msgid.json
@@ -0,0 +1,9 @@
+{
+    "Hello, world!\n": "Hello, world!\n",
+    "this is the first line\nthis is the next one\nbut this is the last\n":
+       "this is the first line\nthis is the next one\nbut this is the last\n",
+    "A sentence with \"quotation\" marks.": "A sentence with \"quotation\" marks.",
+    "one product": "one product",
+    "string context\u0004the contextual phrase": "the contextual phrase",
+    "A fuzzy translation": "A fuzzy translation"
+}
\ No newline at end of file
diff --git a/test/fixtures/pl-jed.json b/test/fixtures/pl-jed.json
new file mode 100644
index 0000000..43f8c41
--- /dev/null
+++ b/test/fixtures/pl-jed.json
@@ -0,0 +1,40 @@
+{
+   "domain": "messages",
+   "locale_data": {
+      "messages": {
+         "": {
+            "domain": "messages",
+            "plural_forms": "nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);",
+            "lang": "pl"
+         },
+         "Hello, world!\n": [
+            null,
+            "Witaj, świecie!\n"
+         ],
+         "this is the first line\nthis is the next one\nbut this is the last\n": [
+            null,
+            "to jest pierwsza linia\nto jest następny\nale to jest ostatnia\n"
+         ],
+         "one product": [
+            "%d products",
+            "jeden produkt",
+            "%d produkty",
+            "%d produktów"
+         ],
+         "A sentence with \"quotation\" marks.": [
+            null,
+            "Zdanie w \"cudzysłowie\"."
+         ],
+         "string context\u0004the contextual phrase": [
+            null,
+            "zwrot kontekstowe"
+         ],
+         "a product": [
+            "%d products",
+            "",
+            "",
+            ""
+         ]
+      }
+   }
+}
diff --git a/test/fixtures/pl-jed1.x.json b/test/fixtures/pl-jed1.x.json
new file mode 100644
index 0000000..630ac3a
--- /dev/null
+++ b/test/fixtures/pl-jed1.x.json
@@ -0,0 +1,34 @@
+{
+   "domain": "messages",
+   "locale_data": {
+      "messages": {
+         "": {
+            "domain": "messages",
+            "plural_forms": "nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);",
+            "lang": "pl"
+         },
+         "Hello, world!\n": [
+            "Witaj, świecie!\n"
+         ],
+         "this is the first line\nthis is the next one\nbut this is the last\n": [
+            "to jest pierwsza linia\nto jest następny\nale to jest ostatnia\n"
+         ],
+         "one product": [
+            "jeden produkt",
+            "%d produkty",
+            "%d produktów"
+         ],
+         "A sentence with \"quotation\" marks.": [
+            "Zdanie w \"cudzysłowie\"."
+         ],
+         "string context\u0004the contextual phrase": [
+            "zwrot kontekstowe"
+         ],
+         "a product": [
+            "",
+            "%d products",
+            "%d products"
+         ]
+      }
+   }
+}
diff --git a/test/fixtures/pl-mf.json b/test/fixtures/pl-mf.json
new file mode 100644
index 0000000..19a3550
--- /dev/null
+++ b/test/fixtures/pl-mf.json
@@ -0,0 +1,7 @@
+{
+    "Hello, world!\n": "Witaj, świecie!\n",
+    "this is the first line\nthis is the next one\nbut this is the last\n":
+       "to jest pierwsza linia\nto jest następny\nale to jest ostatnia\n",
+    "A sentence with \"quotation\" marks.": "Zdanie w \"cudzysłowie\".",
+    "string context\u0004the contextual phrase": "zwrot kontekstowe"
+}
\ No newline at end of file
diff --git a/test/fixtures/pl-mf.po b/test/fixtures/pl-mf.po
new file mode 100644
index 0000000..f954710
--- /dev/null
+++ b/test/fixtures/pl-mf.po
@@ -0,0 +1,44 @@
+# Polish translation for po2json text fixture.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: po2json\n"
+"POT-Creation-Date: 2012-10-26 12:00+0000\n"
+"PO-Revision-Date: 2013-11-08 09:09+0200\n"
+"Last-Translator: Illimar Tambek <illimar.tambek at gmail.com>\n"
+"Language-Team: po2json\n"
+"MIME-Version: 1.0\n"
+"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
+"|| n%100>=20) ? 1 : 2);\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: Poedit 1.5.7\n"
+"Language: pl\n"
+
+#: test.js:1
+msgid "Hello, world!\n"
+msgstr "Witaj, świecie!\n"
+
+#: test.js:2
+msgctxt "string context"
+msgid "the contextual phrase"
+msgstr "zwrot kontekstowe"
+
+#: test.js:3
+msgid ""
+"this is the first line\n"
+"this is the next one\n"
+"but this is the last\n"
+msgstr ""
+"to jest pierwsza linia\n"
+"to jest następny\n"
+"ale to jest ostatnia\n"
+
+#: test.js:5
+msgid "A sentence with \"quotation\" marks."
+msgstr "Zdanie w \"cudzysłowie\"."
+
+#: test.js:6
+#, fuzzy
+msgid "A fuzzy translation"
+msgstr "Tłumaczenie rozmyta"
diff --git a/test/fixtures/pl.json b/test/fixtures/pl.json
new file mode 100644
index 0000000..8530ad4
--- /dev/null
+++ b/test/fixtures/pl.json
@@ -0,0 +1,43 @@
+{
+   "": {
+      "project-id-version": "po2json",
+      "pot-creation-date": "2012-10-26 12:00+0000",
+      "po-revision-date": "2013-11-08 09:09+0200",
+      "last-translator": "Illimar Tambek <illimar.tambek at gmail.com>",
+      "language-team": "po2json",
+      "mime-version": "1.0",
+      "plural-forms": "nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);",
+      "content-type": "text/plain; charset=UTF-8",
+      "content-transfer-encoding": "8bit",
+      "x-generator": "Poedit 1.5.7",
+      "language": "pl"
+   },
+   "Hello, world!\n": [
+      null,
+      "Witaj, świecie!\n"
+   ],
+   "this is the first line\nthis is the next one\nbut this is the last\n": [
+      null,
+      "to jest pierwsza linia\nto jest następny\nale to jest ostatnia\n"
+   ],
+   "one product": [
+      "%d products",
+      "jeden produkt",
+      "%d produkty",
+      "%d produktów"
+   ],
+   "A sentence with \"quotation\" marks.": [
+      null,
+      "Zdanie w \"cudzysłowie\"."
+   ],
+   "string context\u0004the contextual phrase": [
+      null,
+      "zwrot kontekstowe"
+   ],
+   "a product": [
+      "%d products",
+      "",
+      "",
+      ""
+   ]
+}
diff --git a/test/fixtures/pl.po b/test/fixtures/pl.po
new file mode 100644
index 0000000..4fda5f7
--- /dev/null
+++ b/test/fixtures/pl.po
@@ -0,0 +1,58 @@
+# Polish translation for po2json text fixture.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: po2json\n"
+"POT-Creation-Date: 2012-10-26 12:00+0000\n"
+"PO-Revision-Date: 2013-11-08 09:09+0200\n"
+"Last-Translator: Illimar Tambek <illimar.tambek at gmail.com>\n"
+"Language-Team: po2json\n"
+"MIME-Version: 1.0\n"
+"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
+"|| n%100>=20) ? 1 : 2);\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: Poedit 1.5.7\n"
+"Language: pl\n"
+
+#: test.js:1
+msgid "Hello, world!\n"
+msgstr "Witaj, świecie!\n"
+
+#: test.js:2
+msgctxt "string context"
+msgid "the contextual phrase"
+msgstr "zwrot kontekstowe"
+
+#: test.js:3
+msgid ""
+"this is the first line\n"
+"this is the next one\n"
+"but this is the last\n"
+msgstr ""
+"to jest pierwsza linia\n"
+"to jest następny\n"
+"ale to jest ostatnia\n"
+
+#: test.js:4
+msgid "one product"
+msgid_plural "%d products"
+msgstr[0] "jeden produkt"
+msgstr[1] "%d produkty"
+msgstr[2] "%d produktów"
+
+#: test.js:5
+msgid "A sentence with \"quotation\" marks."
+msgstr "Zdanie w \"cudzysłowie\"."
+
+#: test.js:6
+#, fuzzy
+msgid "A fuzzy translation"
+msgstr "Tłumaczenie rozmyta"
+
+#: test.js:7
+msgid "a product"
+msgid_plural "%d products"
+msgstr[0] ""
+msgstr[1] ""
+msgstr[2] ""
diff --git a/test/po2json_test.js b/test/po2json_test.js
new file mode 100644
index 0000000..337ed4f
--- /dev/null
+++ b/test/po2json_test.js
@@ -0,0 +1,116 @@
+var po2json = require(".."),
+    fs = require("fs"),
+    Jed = require("jed");
+
+module.exports["parse"] = {
+  setUp: function(callback){
+    this.po = fs.readFileSync(__dirname + "/fixtures/pl.po");
+    this.json = JSON.parse(fs.readFileSync(__dirname + "/fixtures/pl.json", "utf-8"));
+    callback();
+  },
+
+  parse: function(test){
+    var parsed = po2json.parse(this.po);
+    test.deepEqual(parsed, this.json);
+    test.done();
+  }
+}
+
+module.exports["parse with Jed format"] = {
+  setUp: function(callback){
+    this.po = fs.readFileSync(__dirname + "/fixtures/pl.po");
+    this.json = JSON.parse(fs.readFileSync(__dirname + "/fixtures/pl-jed.json", "utf-8"));
+    callback();
+  },
+
+  parse: function(test){
+    var parsed = po2json.parse(this.po, { format: 'jed' });
+    test.deepEqual(parsed, this.json);
+    test.doesNotThrow(function() { new Jed(parsed) }, Error)
+    test.done();
+  }
+};
+
+module.exports["parse with Jed1.x format"] = {
+  setUp: function(callback){
+    this.po = fs.readFileSync(__dirname + "/fixtures/pl.po");
+    this.json = JSON.parse(fs.readFileSync(__dirname + "/fixtures/pl-jed1.x.json", "utf-8"));
+    callback();
+  },
+
+  parse: function(test){
+    var parsed = po2json.parse(this.po, { format: 'jed1.x' });
+    test.deepEqual(parsed, this.json);
+    test.doesNotThrow(function() { new Jed(parsed) }, Error)
+    test.done();
+  }
+};
+
+module.exports["parse with MessageFormatter format"] = {
+  setUp: function(callback){
+    this.po = fs.readFileSync(__dirname + "/fixtures/pl-mf.po");
+    this.json = JSON.parse(fs.readFileSync(__dirname + "/fixtures/pl-mf.json", "utf-8"));
+    callback();
+  },
+
+  parse: function(test){
+    var parsed = po2json.parse(this.po, { format: 'mf' });
+    test.deepEqual(parsed, this.json);
+    test.done();
+  }
+}
+
+module.exports["parse with MessageFormatter format + fallback-to-msgid"] = {
+  setUp: function(callback){
+    this.po = fs.readFileSync(__dirname + "/fixtures/en-empty.po");
+    this.json = JSON.parse(fs.readFileSync(__dirname + "/fixtures/en-mf-fallback-to-msgid.json", "utf-8"));
+    callback();
+  },
+
+  parse: function(test){
+    var parsed = po2json.parse(this.po, { format: 'mf', 'fallback-to-msgid': true });
+    test.deepEqual(parsed, this.json);
+    test.done();
+  }
+}
+
+module.exports["parse with fallback-to-msgid"] = {
+  setUp: function(callback){
+    this.po = fs.readFileSync(__dirname + "/fixtures/en-empty.po");
+    this.json = JSON.parse(fs.readFileSync(__dirname + "/fixtures/en-empty.json", "utf-8"));
+    callback();
+  },
+
+  parse: function(test){
+    var parsed = po2json.parse(this.po, { 'fallback-to-msgid': true });
+    test.deepEqual(parsed, this.json);
+    test.done();
+  }
+}
+module.exports["parseFile"] = {
+  setUp: function(callback){
+    this.json = JSON.parse(fs.readFileSync(__dirname + "/fixtures/pl.json", "utf-8"));
+    callback();
+  },
+
+  parseFile: function(test){
+    var self = this;
+    po2json.parseFile(__dirname + "/fixtures/pl.po", null, function (err, parsed) {
+      test.deepEqual(parsed, self.json);
+      test.done();
+    });
+  }
+}
+
+module.exports["parseFileSync"] = {
+  setUp: function(callback){
+    this.json = JSON.parse(fs.readFileSync(__dirname + "/fixtures/pl.json", "utf-8"));
+    callback();
+  },
+
+  parseFileSync: function(test){
+    var parsed = po2json.parseFileSync(__dirname + "/fixtures/pl.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