Gathering detailed insights and metrics for po2json
Gathering detailed insights and metrics for po2json
Gathering detailed insights and metrics for po2json
Gathering detailed insights and metrics for po2json
Pure Javascript implementation of Uniforum message translation. Based on a great gist.
npm install po2json
96.8
Supply Chain
97.2
Quality
75.4
Maintenance
25
Vulnerability
80.2
License
Beta not pout, I'm telling you why
Published on 19 Jul 2020
Beta watch out, beta not cry
Published on 09 Jan 2020
Alphabetter Soup
Published on 24 Sept 2018
Jeds Jedi Jeda and Other Difficult Plurals
Published on 13 Oct 2016
The headless plurals ride again!
Published on 29 Aug 2016
Plurals makes the worlds goes rounds!
Published on 27 Aug 2016
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
178 Stars
170 Commits
62 Forks
14 Watching
20 Branches
19 Contributors
Updated on 10 Sept 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-2.6%
9,894
Compared to previous day
Last week
9%
54,034
Compared to previous week
Last month
20.5%
216,701
Compared to previous month
Last year
25.6%
2,345,312
Compared to previous year
2
Convert PO files to Javascript objects or JSON strings. The result is Jed-compatible.
Install the module with: npm install po2json
var po2json = require('po2json');
po2json translation.po translation.json
If you are using Jed >= 1.1.0, be sure to specify that format specifically.
po2json translation.po translation.json -f jed1.x
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 outputjed
produces an output that is 100% compatible with Jed >= 1.1.0jedold
produces an output that is 100% compatible with Jed < 1.1.0mf
produces simple key:value output.domain
- the domain the messages will be wrapped inside. Only has effect if format: 'jed'
.fallback-to-msgid
If true
, 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.Parse a PO file to JSON
po2json.parseFile(fileName[,options], cb)
fileName
- path to the po fileoptions
- 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 fileoptions
- same as for po2json.parse
po2json in command-line parametrization support added to allow override default options.
Note: 'format': 'mf'
means the json format used by messageFormatter in github.com/SlexAxton/messageformat.js
and jedold
refers to Jed formats below 1.1.0
var po2json = require('po2json'),
fs = require('fs');
fs.readFile('messages.po', function (err, buffer) {
var jsonData = po2json.parse(buffer);
// do something interesting ...
});
var po2json = require('po2json');
po2json.parseFile('messages.po', function (err, jsonData) {
// do something interesting ...
});
var po2json = require('po2json');
var jsonData = '';
try {
jsonData = po2json.parseFileSync('messages.po');
// do something interesting ...
} catch (e) {}
var po2json = require('po2json'),
MessageFormat = require('messageformat');
po2json.parseFile('es.po', { format: 'mf' }, function (err, translations) {
var pFunc = function (n) {
return (n==1 ? 'p0' : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 'p1' : 'p2');
};
pFunc.cardinal = [ 'p0', 'p1', 'p2' ];
var mf = new MessageFormat(
{
'es': pFunc
}
);
var i18n = mf.compile( translations );
});
var po2json = require('po2json'),
MessageFormat = require('messageformat');
po2json.parseFile('messages.po', { format: 'mf', fullMF: true }, function (err, jsonData) {
var mf = new MessageFormat(
{ [jsonData.headers.language]: jsonData.pluralFunction }
);
var i18n = mf.compile( jsonData.translations );
});
var po2json = require('po2json'),
Jed = require('jed');
po2json.parseFile('messages.po', { format: 'jed' }, function (err, jsonData) {
var i18n = new Jed( jsonData );
});
If you are using an older version of Jed, be sure to specify this format specifically.
var po2json = require('po2json'),
Jed = require('jed');
po2json.parseFile('messages.po', { format: 'jedold' }, function (err, jsonData) {
var i18n = new Jed( jsonData );
});
npm test
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.
jed
now refers to versions >= 1.1.0.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:
Copyright (c) 2012 Joshua I. Miller Licensed under the GNU, Library, General, Public, License licenses.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 2/9 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
20 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More