![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
node-gettext
Advanced tools
node-gettext is a Node.JS module to use .MO and .PO files.
npm install node-gettext
var Gettext = require("node-gettext");
var gt = new Gettext();
addTextdomain(domain, file)
Language data needs to be in the Buffer format - it can be either contents of a MO or PO file.
addTextdomain(domain[, fileContents])
Load from a MO file
var fileContents = fs.readFileSync("et.mo");
gt.addTextdomain("et", fileContents);
or load from a PO file
var fileContents = fs.readFileSync("et.po");
gt.addTextdomain("et", fileContents);
If you do not include the file contents, then a blank language template object is created which can be edited with setTranslation, deleteTranslation methods etc.
Plural rules are automatically detected from the language code
gt.addTextdomain("et");
gt.setTranslation("et", false, "hello!", "tere!");
textdomain(domain)
gt.textdomain("et");
The function also returns the current texdomain value
var curlang = gt.textdomain();
gettext(msgid)
var greeting = gt.gettext("Hello!");
dgettext(domain, msgid)
var greeting = gt.dgettext("et", "Hello!");
ngettext(msgid, msgid_plural, count)
gt.ngettext("%d Comment", "%d Comments", 10);
dngettext(domain, msgid, msgid_plural, count)
gt.dngettext("et", "%d Comment", "%d Comments", 10)
pgettext(msgctxt, msgid)
gt.pgettext("menu items", "File");
dpgettext(domain, msgctxt, msgid)
gt.dpgettext("et", "menu items", "File");
npgettext(msgctxt, msgid, msgid_plural, count)
gt.npgettext("menu items", "%d Recent File", "%d Recent Files", 3);
dnpgettext(domain, msgctxt, msgid, msgid_plural, count)
gt.dnpgettext("et", "menu items", "%d Recent File", "%d Recent Files", 3);
getComment(domain, msgctxt, msgid)
gt.getComment("et", "menu items", "%d Recent File");
Returns an object in the form of {comment: "", code: "", note: ""}
setComment(domain, msgctxt, msgid, comment)
gt.getComment("et", "menu items", "%d Recent File", "This is a comment");
comment
can either be a string or an object with the following properties: {comment: "", code: "", note: ""}
.
In order to make things really easy, it is possible to attach the gettext functions directly to string
prototypes with gettext.registerStringHelpers()
Example:
// setup gettext
var gettext = new Gettext();
gettext.registerStringHelpers();
gettext.addTextdomain("et", fs.readFileSync("et.mo"));
// translate any string
var translated = "translate this string".gettext();
// or
var plural = "translate %s string".ngettext("translate %s strings", 10);
// you can even change the default textdomain
"".textdomain("en");
The parameters for the gettext functions are the same as with regular gettext methods, except that the msgid
parameter is not needed.
setTranslation(domain, context, msgid, translation)
gt.setTranslation("et", "", "Hello", "Tere");
Use an array for plurals
gt.setTranslation("et", "", "%s comments", ["%s kommentaar", "%s kommentaari"]);
deleteTranslation(domain, context, msgid)
gt.deleteTranslation("et", "", "Hello");
listContextNames([domain])
var contextStrArr = gt.listContextNames("et");
listKeys([domain], [context])
var originalsStrArr = gt.listKeys("et", "");
Compile current translation table to a MO file
compileMO([domain])
fs.writeFile("out.mo", gt.compileMO("et"));
Compile current translation table to a PO file
compilePO([domain])
fs.writeFile("out.po", gt.compilePO("et"));
MIT
FAQs
A JavaScript implementation of gettext, a localization framework
The npm package node-gettext receives a total of 88,677 weekly downloads. As such, node-gettext popularity was classified as popular.
We found that node-gettext demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.