npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

js-i18n-gettext

v1.0.0

Published

JavaScript library for internationalization using Gettext format (.po/.pot/.mo files)

Readme

js-i18n-gettext

JavaScript library for internationalization using Gettext format (.po/.pot/.mo files).

Features

  • Support for standard Gettext functions: _(), ngettext(), pgettext()
  • Load and parse .po/.pot files (text format)
  • Load and parse .mo files (binary format)
  • Plural forms support with complex expressions
  • Context-aware translations
  • TypeScript support
  • Browser and Node.js compatible
  • Lightweight and fast

Installation

npm install js-i18n-gettext

Usage

import { Gettext } from 'js-i18n-gettext';

// Initialize
const gt = new Gettext();

// Load from string (works in browser and Node.js)
const poContent = `
msgid "Hello world"
msgstr "Привет мир"
`;
gt.loadPoFromString(poContent);

// Load PO file (Node.js example)
import { promises as fs } from 'fs';
await gt.loadPo('/path/to/translations.po', (path) => fs.readFile(path, 'utf-8'));

// Load MO file (Node.js example)
await gt.loadMo('/path/to/translations.mo', async (path) => (await fs.readFile(path)).buffer);

// Simple translation
const message = gt._('Hello world');

// Plural forms
const count = 5;
const plural = gt.ngettext('One item', '%d items', count);

// Context-aware translation
const contextual = gt.pgettext('menu', 'File');

API

new Gettext(options?)

Create a new Gettext instance.

Options:

  • locale - Default locale (default: 'en')
  • domain - Text domain (default: 'messages')

loadPo(path: string, readFileFunction: (path: string) => Promise<string>): Promise<void>

Load translations from a .po/.pot file using provided file reader function.

loadPoFromString(content: string): void

Load translations from PO file content string.

loadMo(path: string, readFileFunction: (path: string) => Promise<ArrayBuffer>): Promise<void>

Load translations from a .mo file using provided file reader function.

loadMoFromBuffer(buffer: ArrayBuffer): void

Load translations from MO file buffer.

loadMoFromUint8Array(data: Uint8Array): void

Load translations from MO file Uint8Array data.

_(message: string): string

Translate a message.

ngettext(singular: string, plural: string, count: number): string

Handle plural forms.

pgettext(context: string, message: string): string

Context-aware translation.

File Formats

.po/.pot files (Text format)

Human-readable text files with translations. Easy to edit and review.

// Load from string
gt.loadPoFromString(`
msgid "Hello"
msgstr "Привет"
`);

// Load from file (Node.js)
import { promises as fs } from 'fs';
await gt.loadPo('messages.po', (path) => fs.readFile(path, 'utf-8'));

.mo files (Binary format)

Compiled binary files. Faster to load and smaller in size.

// Load from ArrayBuffer
const buffer = /* your ArrayBuffer */;
gt.loadMoFromBuffer(buffer);

// Load from file (Node.js)
import { promises as fs } from 'fs';
await gt.loadMo('messages.mo', async (path) => (await fs.readFile(path)).buffer);

// Load from Uint8Array (e.g., from fetch)
const response = await fetch('/translations.mo');
const data = new Uint8Array(await response.arrayBuffer());
gt.loadMoFromUint8Array(data);

Browser Usage

// Fetch and load MO file in browser
const response = await fetch('/locales/ru/messages.mo');
const buffer = await response.arrayBuffer();
gt.loadMoFromBuffer(buffer);

// Or with Uint8Array
const data = new Uint8Array(buffer);
gt.loadMoFromUint8Array(data);

License

GNU LGPL 3.0 - see LICENSE file.

Author

AnmiTaliDev [email protected]

Repository

https://github.com/AnmiTaliDev/js-i18n-gettext