{"_id":"@cl0udw4lk3r/gettext-parser","_rev":"3-023a7bb5eadd6b9ffaf1277210d7a247","name":"@cl0udw4lk3r/gettext-parser","description":"Parse and compile gettext po and mo files to/from json, nothing more, nothing less","dist-tags":{"latest":"1.2.2"},"versions":{"1.2.2":{"name":"@cl0udw4lk3r/gettext-parser","description":"Parse and compile gettext po and mo files to/from json, nothing more, nothing less","version":"1.2.2","author":{"name":"Andris Reinman"},"homepage":"http://github.com/andris9/gettext-parser","repository":{"type":"git","url":"git+ssh://git@github.com/andris9/gettext-parser.git"},"scripts":{"test":"grunt"},"main":"./index","license":"MIT","dependencies":{"encoding":"^0.1.11"},"devDependencies":{"chai":"^3.3.0","grunt":"^0.4.5","grunt-contrib-jshint":"^0.11.3","grunt-mocha-test":"^0.12.7","mocha":"^2.3.3"},"keywords":["i18n","l10n","gettext","mo","po"],"gitHead":"b0cef01c70ab1440df6521fcff936609f1be636c","bugs":{"url":"https://github.com/andris9/gettext-parser/issues"},"_id":"@cl0udw4lk3r/gettext-parser@1.2.2","_shasum":"96485631248b99ba6fcabaf2ed7d2990dde5c52c","_from":".","_npmVersion":"3.7.3","_nodeVersion":"5.9.0","_npmUser":{"name":"cl0udw4lk3r","email":"baro.luc@gmail.com"},"dist":{"shasum":"96485631248b99ba6fcabaf2ed7d2990dde5c52c","tarball":"https://registry.npmjs.org/@cl0udw4lk3r/gettext-parser/-/gettext-parser-1.2.2.tgz","integrity":"sha512-8+uQgwmyuhNeM4DLEW2FuFk7itcSnELI2Xhdxg7k5p8TD+82mbuMn2yZx+DKztPrJM+TMFSavrKuYUSaPtBkPA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGu5QVcuT1hRG1gpj1dKhte5zzmXw2OCTt02uzJ/ZnyIAiEAi2kINm6LkXT12kBMOSCSkPeB9qMbxGshl+Nvj7bd+Aw="}]},"maintainers":[{"name":"cl0udw4lk3r","email":"baro.luc@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/gettext-parser-1.2.2.tgz_1459195068398_0.16333926026709378"}}},"readme":"gettext-parser\n==============\n\n[![Build Status](https://secure.travis-ci.org/andris9/gettext-parser.png)](http://travis-ci.org/andris9/gettext-parser)\n[![NPM version](https://badge.fury.io/js/gettext-parser.png)](http://badge.fury.io/js/gettext-parser)\n\nParse and compile gettext *po* and *mo* files with node.js, nothing more, nothing less.\n\nThis module is slightly based on my other gettext related module [node-gettext](https://github.com/andris9/node-gettext). The plan is to move all parsing and compiling logic from node-gettext to here and leave only translation related functions (domains, plural handling, lookups etc.).\n\n## Usage\n\nInclude the library:\n\n    var gettextParser = require(\"gettext-parser\");\n\n\n### Parse PO files\n\nParse a PO file with\n\n    gettextParser.po.parse(input[, defaultCharset]) → Object\n\nWhere\n\n  * **input** is a *po* file as a Buffer or an unicode string. Charset is converted to unicode from other encodings only if the input is a Buffer, otherwise the charset information is discarded\n  * **defaultCharset** is the charset to use if charset is not defined or is the default `\"CHARSET\"` (applies only if *input* is a Buffer)\n\nMethod returns gettext-parser specific translation object (see below)\n\n**Example**\n\n```javascript\nvar input = require('fs').readFileSync('en.po');\nvar po = gettextParser.po.parse(input);\nconsole.log(po.translations['']); // output translations for the default context\n```\n\n### Parse PO as a Stream\n\nPO files can also be parsed from a stream source. After all input is processed the parser emits a single 'data' event which contains the parsed translation object.\n\n    gettextParser.po.createParseStream([defaultCharset][, streamOptions]) → Transform Stream\n\nWhere\n\n  * **defaultCharset** is the charset to use if charset is not defined or is the default `\"CHARSET\"`\n  * **streamOptions** are the standard stream options\n\n**Example**\n\n```javascript\nvar input = require('fs').createReadStream('en.po');\nvar po = gettextParser.po.createParseStream();\ninput.pipe(po);\npo.on('data', function(data){\n    console.log(data.translations['']); // output translations for the default context\n});\n```\n\n### Compile PO from a translation object\n\nIf you have a translation object you can convert this to a valid PO file with\n\n    gettextParser.po.compile(data) → Buffer\n\nWhere\n\n  * **data** is a translation object either got from parsing a PO/MO file or composed by other means\n\n**Example**\n\n```javascript\nvar data = {\n    ...\n};\nvar output = gettextParser.po.compile(data);\nrequire('fs').writeFileSync(output);\n```\n\n### Parse MO files\n\nParse a MO file with\n\n    gettextParser.mo.parse(input[, defaultCharset]) → Object\n\nWhere\n\n  * **input** is a *mo* file as a Buffer\n  * **defaultCharset** is the charset to use if charset is not defined or is the default `\"CHARSET\"`\n\nMethod returns gettext-parser specific translation object (see below)\n\n**Example**\n\n```javascript\nvar input = require('fs').readFileSync('en.mo');\nvar mo = gettextParser.mo.parse(input);\nconsole.log(mo.translations['']); // output translations for the default context\n```\n\n### Compile MO from a translation object\n\nIf you have a translation object you can convert this to a valid MO file with\n\n    gettextParser.mo.compile(data) → Buffer\n\nWhere\n\n  * **data** is a translation object either got from parsing a PO/MO file or composed by other means\n\n**Example**\n\n```javascript\nvar data = {\n    ...\n};\nvar output = gettextParser.mo.compile(data);\nrequire('fs').writeFileSync(output);\n```\n\n### Notes\n\n#### Overriding charset\n\nIf you are compiling a previously parsed translation object, you can override the output charset with the `charset` property (applies both for compiling *mo* and *po* files).\n\n```javascript\nvar obj = gettextParser.po.parse(inputBuf);\nobj.charset = \"windows-1257\";\noutputBuf = gettextParser.po.compile(obj);\n```\n\nHeaders for the output are modified to match the updated charset.\n\n#### ICONV support\n\nBy default *gettext-parser* uses pure JS [iconv-lite](https://github.com/ashtuchkin/iconv-lite) for encoding and decoding non UTF-8 charsets. If you need to support more complex encodings that are not supported by *iconv-lite*, you need to add [iconv](https://github.com/bnoordhuis/node-iconv) as an additional dependency for your project (*gettext-parser* will detect if it is available and tries to use it instead of *iconv-lite*).\n\n## Data structure of parsed mo/po files\n\n### Character set\n\nParsed data is always in unicode but the original charset of the file can\nbe found from the `charset` property. This value is also used when compiling translations\nto a *mo* or *po* file.\n\n### Headers\n\nHeaders can be found from the `headers` object, all keys are lowercase and the value for a key is a string. This value will also be used when compiling.\n\n### Translations\n\nTranslations can be found from the `translations` object which in turn holds context objects for `msgctx`. Default context can be found from `translations[\"\"]`.\n\nContext objects include all the translations, where `msgid` value is the key. The value is an object with the following possible properties:\n\n  * **msgctx** context for this translation, if not present the default context applies\n  * **msgid** string to be translated\n  * **msgid_plural** the plural form of the original string (might not be present)\n  * **msgstr** an array of translations\n  * **comments** an object with the following properties: `translator`, `reference`, `extracted`, `flag`, `previous`.\n\nExample\n\n```json\n{\n  \"charset\": \"iso-8859-1\",\n\n  \"headers\": {\n    \"content-type\": \"text/plain; charset=iso-8859-1\",\n    \"plural-forms\": \"nplurals=2; plural=(n!=1);\"\n  },\n\n  \"translations\": {\n    \"\": {\n      \"\": {\n        \"msgid\": \"\",\n        \"msgstr\": [\"Content-Type: text/plain; charset=iso-8859-1\\n...\"]\n      }\n    }\n  },\n\n  \"another context\": {\n    \"%s example\": {\n      \"msgctx\": \"another context\",\n      \"msgid\": \"%s example\",\n      \"msgid_plural\": \"%s examples\",\n      \"msgstr\": [\"% näide\", \"%s näidet\"],\n      \"comments\": {\n        \"translator\": \"This is regular comment\",\n        \"reference\": \"/path/to/file:123\"\n      }\n    }\n  }\n}\n```\n\nNotice that the structure has both a `headers` object and a `\"\"` translation with the header string. When compiling the structure to a *mo* or a *po* file, the `headers` object is used to define the header. Header string in the `\"\"` translation is just for reference (includes the original unmodified data) but will not be used when compiling. So if you need to add or alter header values, use only the `headers` object.\n\nIf you need to convert *gettext-parser* formatted translation object to something else, eg. for *jed*, check out [po2json](https://github.com/mikeedwards/po2json).\n\n## License\n\n**MIT**\n","maintainers":[{"name":"cl0udw4lk3r","email":"baro.luc@gmail.com"}],"time":{"modified":"2022-06-12T16:04:06.963Z","created":"2016-03-28T19:57:49.307Z","1.2.2":"2016-03-28T19:57:49.307Z"},"homepage":"http://github.com/andris9/gettext-parser","keywords":["i18n","l10n","gettext","mo","po"],"repository":{"type":"git","url":"git+ssh://git@github.com/andris9/gettext-parser.git"},"author":{"name":"Andris Reinman"},"bugs":{"url":"https://github.com/andris9/gettext-parser/issues"},"license":"MIT","readmeFilename":"README.md"}