From 7f239eee93ce41e103ca245b17046f700d41eadb Mon Sep 17 00:00:00 2001 From: Philip <17368112+vHeemstra@users.noreply.github.com> Date: Wed, 10 Jul 2024 16:07:24 +0200 Subject: [PATCH] Update README.md Updated docs and examples to match new [ESM standard](https://github.com/smhg/gettext-parser/releases/tag/v8.0.0). --- README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 83eb19f..c18d1a4 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,7 +34,8 @@ Method returns gettext-parser specific translation object (see below) **Example** ```javascript -var input = require('fs').readFileSync('en.po'); +import { readFileSync } from 'node:fs'; +var input = readFileSync('en.po'); var po = gettextParser.po.parse(input); console.log(po.translations['']); // output translations for the default context ``` @@ -53,7 +54,8 @@ Where **Example** ```javascript -var input = require('fs').createReadStream('en.po'); +import { createReadStream } from 'node:fs'; +var input = createReadStream('en.po'); var po = gettextParser.po.createParseStream(); input.pipe(po); po.on('data', function(data){ @@ -79,11 +81,12 @@ Where **Example** ```javascript +import { writeFileSync } from 'node:fs'; var data = { ... }; var output = gettextParser.po.compile(data); -require('fs').writeFileSync('filename.po', output); +writeFileSync('filename.po', output); ``` ### @@ -104,7 +107,8 @@ Method returns gettext-parser specific translation object (see below) **Example** ```javascript -var input = require('fs').readFileSync('en.mo'); +import { readFileSync } from 'node:fs'; +var input = readFileSync('en.mo'); var mo = gettextParser.mo.parse(input); console.log(mo.translations['']); // output translations for the default context ``` @@ -122,11 +126,12 @@ Where **Example** ```javascript +import { writeFileSync } from 'node:fs'; var data = { ... }; var output = gettextParser.mo.compile(data); -require('fs').writeFileSync('filename.mo', output); +writeFileSync('filename.mo', output); ``` ### Notes