From 38cf2910a934982cb2838f31dde45a927b88bca1 Mon Sep 17 00:00:00 2001 From: Erik Golinelli Date: Thu, 2 May 2024 19:59:17 +0200 Subject: [PATCH 1/3] replaces require with import --- README.md | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 83eb19f..f1eba2d 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Parse and compile gettext *po* and *mo* files with node.js, nothing more, nothin Include the library: - var gettextParser = require("gettext-parser"); + import gettextParser from "gettext-parser"; ### Parse PO files @@ -34,9 +34,15 @@ Method returns gettext-parser specific translation object (see below) **Example** ```javascript -var input = require('fs').readFileSync('en.po'); -var po = gettextParser.po.parse(input); -console.log(po.translations['']); // output translations for the default context +import fs from "node:fs"; +import gettextParser from "gettext-parser"; + +const input = await fs + .readFile("en.po") + // read the PO file + .then((buf) => gettextParser.po.parse(buf)) + // output translations for the default context + .then((translations) => console.log(translations)); ``` ### Parse PO as a Stream @@ -53,10 +59,13 @@ Where **Example** ```javascript -var input = require('fs').createReadStream('en.po'); -var po = gettextParser.po.createParseStream(); -input.pipe(po); -po.on('data', function(data){ +import fs from "node:fs"; +import gettextParser from "../index.js"; + +const input = fs.createReadStream("en.po"); +const stream = input.pipe(gettextParser.po.createParseStream()); + +stream.on('data', function(data){ console.log(data.translations['']); // output translations for the default context }); ``` @@ -83,7 +92,7 @@ var data = { ... }; var output = gettextParser.po.compile(data); -require('fs').writeFileSync('filename.po', output); +fs.writeFileSync('filename.po', output); ``` ### @@ -104,7 +113,7 @@ Method returns gettext-parser specific translation object (see below) **Example** ```javascript -var input = require('fs').readFileSync('en.mo'); +var input = fs.readFileSync('en.mo'); var mo = gettextParser.mo.parse(input); console.log(mo.translations['']); // output translations for the default context ``` @@ -126,7 +135,7 @@ var data = { ... }; var output = gettextParser.mo.compile(data); -require('fs').writeFileSync('filename.mo', output); +fs.writeFileSync('filename.mo', output); ``` ### Notes From 49b4c8de8e581519dc8fa5e475233de2e64d47da Mon Sep 17 00:00:00 2001 From: Erik Golinelli Date: Thu, 2 May 2024 19:59:34 +0200 Subject: [PATCH 2/3] installation instructions --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index f1eba2d..d400d46 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,11 @@ Parse and compile gettext *po* and *mo* files with node.js, nothing more, nothin > *Please note:* starting with version 3 only latest LTS and latest stable node versions are supported. **Use version 2 with older node versions.** +## Installation +To install the library, run the following command: + + npm install gettext-parser --save-dev + ## Usage Include the library: From 07c29d854838dae7e47a9872d0e6b2e2c4e35e40 Mon Sep 17 00:00:00 2001 From: Erik Golinelli Date: Sun, 5 May 2024 01:10:47 +0200 Subject: [PATCH 3/3] Update README.md Co-authored-by: John Hooks --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d400d46..5b0097e 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Parse and compile gettext *po* and *mo* files with node.js, nothing more, nothin ## Installation To install the library, run the following command: - npm install gettext-parser --save-dev + npm install gettext-parser --save ## Usage