pofile-tspofile-ts

Introduction

The fast, modern PO file toolkit for JavaScript

pofile-ts is a complete solution for working with GNU gettext PO files in modern JavaScript and TypeScript projects. Whether you're building translation pipelines, integrating with i18n frameworks like Lingui or FormatJS, or creating custom localization tooling — pofile-ts gives you everything you need.

Why pofile-ts?

  • Battle-tested parsing — Handles edge cases, malformed files, and complex escape sequences
  • Complete i18n toolkit — Not just a parser: includes CLDR plural rules, ICU conversion, and workflow helpers
  • Production-ready — Fully tested against CLDR 48 specification
  • Runs everywhere — Node.js, browsers, edge runtimes, and build tools
  • Lightweight — Zero dependencies, ~14KB gzipped, tree-shakeable to ~5KB

Features

Core

  • Parse PO Files — Read PO files from strings, 8× faster than alternatives
  • Serialize PO Files — Convert PO data back to strings, 5× faster than alternatives
  • Full PO Support — Headers, comments, flags, plurals, and message context

i18n Toolkit

  • CLDR 48 Plural Rules — 100% compliant for all major languages (140+ locales)
  • ICU MessageFormat — Convert between Gettext plurals and ICU syntax
  • ICU Parser — Parse ICU v1 messages, 2.5× faster and 4× smaller than FormatJS
  • ICU Compiler — Compile ICU to JavaScript functions, 6× faster than Lingui at runtime
  • Plural Helpers — Get categories, sample numbers, and Plural-Forms headers

Developer Experience

  • Zero Dependencies — No bloat, works in browsers and edge runtimes
  • Tree-Shakeable — Only bundle what you use (~5KB for parsing only)
  • TypeScript-First — Full type definitions, excellent IDE support
  • CSP-Safe — No eval() or new Function()

Installation

npm install pofile-ts

Quick Example

import { parsePo, stringifyPo } from "pofile-ts"

// Parse a PO file
const po = parsePo(`
msgid "Hello"
msgstr "Hallo"
`)

console.log(po.items[0].msgid) // "Hello"
console.log(po.items[0].msgstr) // ["Hallo"]

// Serialize back to string
console.log(stringifyPo(po))

Performance

Benchmarked on Apple M1 Ultra, Node.js 22. Relative performance is consistent across different hardware.

PO File Parsing

10,000 entries (~10% plurals):

LibraryParsingSerialization
pofile-ts185 ops/s217 ops/s
gettext-parser27 ops/s53 ops/s
pofile8 ops/s100 ops/s

8× faster parsing, 5× faster serialization

ICU MessageFormat Parsing

Realistic messages with plurals, selects, nested structures, and tags:

LibrarySpeedBundle (gzip)
pofile-ts2.5× faster~2KB
@formatjs/icu-messageformat-parserbaseline~9KB

2.5× faster, 4× smaller bundle

ICU Compilation & Runtime

Metricpofile-tsvs intl-messageformatvs @lingui
Compilation470k ops/s8× faster
Runtime1.2M ops/s5× faster6× faster

6× faster than Lingui at runtime (even with pre-compiled AST)

Bundle Size

The library is fully tree-shakeable. Import only what you need:

ImportGzipped
Full library~14KB
parsePo + stringifyPo only~5KB
+ CLDR plural helpers+3KB
+ ICU conversion+2KB
+ ICU parser+3KB

All exports are named exports — modern bundlers automatically eliminate unused code.

On this page