Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-gettext

Package Overview
Dependencies
Maintainers
2
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-gettext

A JavaScript implementation of gettext, a localization framework

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
148K
increased by17.25%
Maintainers
2
Weekly downloads
 
Created

What is node-gettext?

node-gettext is a JavaScript library that provides internationalization (i18n) and localization (l10n) functionalities. It allows developers to manage translations and localize their applications by using GNU gettext style .po and .mo files.

What are node-gettext's main functionalities?

Loading Translations

This feature allows you to load translation files into the node-gettext instance. The example demonstrates how to read a .po file and add it to the gettext instance under a specific domain.

const Gettext = require('node-gettext');
const fs = require('fs');
const gt = new Gettext();
const translations = fs.readFileSync('path/to/your/translation/file.po');
gt.addTextdomain('your_domain', translations);

Translating Strings

This feature allows you to translate strings using the loaded translations. The example shows how to translate the string 'Hello, world!' using the gettext instance.

const translatedString = gt.gettext('Hello, world!');
console.log(translatedString);

Setting Locale

This feature allows you to set the locale for translations. The example demonstrates how to set the locale to Spanish ('es') and then translate the string 'Hello, world!'.

gt.setLocale('es');
const translatedString = gt.gettext('Hello, world!');
console.log(translatedString);

Plural Forms

This feature allows you to handle plural forms in translations. The example shows how to translate singular and plural forms of a string based on the count.

const singular = gt.ngettext('%d apple', '%d apples', 1);
const plural = gt.ngettext('%d apple', '%d apples', 2);
console.log(singular);
console.log(plural);

Other packages similar to node-gettext

Keywords

FAQs

Package last updated on 31 Mar 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc