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

node-gettext

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-gettext

Gettext client for Node.js to use .mo files for I18N

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
55K
increased by5.97%
Maintainers
1
Weekly downloads
 
Created
Source

node-gettext

node-gettext is a Node.JS module to use .MO files.

Installation

npm install node-gettext

Quirks

node-gettext currently messes a bit with Buffer an Number prototypes (adds some non-enumerable helpers)

Usage

Create a new Gettext object

var Gettext = require("node-gettext");

var gt = new Gettext();

Add a language - addTextdomain(domain, file)

Language data needs to be file contents in the Buffer format

addTextdomain(domain, file_contents)

var file_contents = fs.readFileSync("et.mo");
gt.addTextdomain("et", file_contents);

The first language added will become the default language for Gettext functions.

Change default language - textdomain(domain)

textdomain(domain)

gt.textdomain("et");

Load a string from default langauge file

gettext(msgid)

var greeting = gt.gettext("Hello!");

Load a string from a specific langauge file

dgettext(domain, msgid)

var greeting = gt.dgettext("et", "Hello!");

Load a plural string from default langauge file

ngettext(msgid, msgid_plural, count)

gt.ngettext("%d Comment", "%d Comments", 10);

Load a plural string from a specific language file

dngettext(domain, msgid, msgid_plural, count)

gt.dngettext("et", "%d Comment", "%d Comments", 10)

Load a string of a specific context

pgettext(msgctxt, msgid)

gt.pgettext("menu items", "File");

Load a string of a specific context from specific language file

dpgettext(domain, msgctxt, msgid)

gt.dpgettext("et", "menu items", "File");

Load a plural string of a specific context

npgettext(msgctxt, msgid, msgid_plural, count)

gt.npgettext("menu items", "%d Recent File", "%d Recent Files", 3);

Load a plural string of a specific context from specific language file

dnpgettext(domain, msgctxt, msgid, msgid_plural, count)

gt.dnpgettext("et", "menu items", "%d Recent File", "%d Recent Files", 3);

Keywords

FAQs

Package last updated on 04 Jul 2011

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