VincentGarreau/po2json được TopGit xếp vào nhóm dự án mã nguồn mở, với 5 sao trên GitHub, viết chủ yếu bằng JavaScript. Pure Javascript implementation of Uniforum message translation. Based on a great gist.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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 (jed, raw 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.
Release History
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 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)
VincentGarreau/po2json có 5 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/VincentGarreau/po2json. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
VincentGarreau/po2json có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho VincentGarreau/po2json. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
VincentGarreau/po2json còn đang phát triển không?
Commit gần nhất trên VincentGarreau/po2json là 10.8 năm trước (theo timestamp GitHub). Repo có 0 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
VincentGarreau/po2json là gì?
VincentGarreau/po2json (VincentGarreau/po2json) là dự án JavaScript trên GitHub. Theo mô tả gốc: Pure Javascript implementation of Uniforum message translation. Based on a great gist.
VincentGarreau/po2json viết bằng ngôn ngữ gì?
VincentGarreau/po2json chủ yếu viết bằng JavaScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
po2json có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về po2json.