# gettext-converter

> po2js and js2po and i18next2po and po2i18next converter gettext resource utils

Latest version **1.4.0** (published 2026-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install gettext-converter
pnpm add gettext-converter
yarn add gettext-converter
bun add gettext-converter
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 1.4.0 |
| Published | 2026-09-07 |
| First published | 2020-04-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 931.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | adrai |
| Maintainers | adrai, jamuhl |
| Keywords | gettext, json, js, translation, converter |

## Links

- npm: https://www.npmjs.com/package/gettext-converter
- Repository: https://github.com/locize/gettext-converter
- Homepage: http://locize.com
- Issues: https://github.com/locize/gettext-converter/issues
- npm.io page: https://npm.io/package/gettext-converter

## Dependencies (3)

- [arrify](https://npm.io/package/arrify.md) ^2.0.1
- [encoding](https://npm.io/package/encoding.md) 0.1.13
- [content-type](https://npm.io/package/content-type.md) 1.0.5

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.4.0 (latest) — 2026-09-07
- 1.3.4 — 2026-08-23
- 1.3.3 — 2026-06-12
- 1.3.2 — 2026-05-13
- 1.3.1 — 2026-01-23
- 1.3.0 — 2024-03-12
- 1.2.4 — 2023-11-28
- 1.2.3 — 2022-07-07
- 1.2.2 — 2022-03-15
- 1.2.1 — 2022-03-15
- 1.2.0 — 2021-11-14
- 1.1.3 — 2021-11-14
- 1.1.2 — 2021-11-14
- 1.1.1 — 2021-11-13
- 1.1.0 — 2021-09-15
- … 9 more at https://npm.io/package/gettext-converter/versions

## README

[![npm](https://img.shields.io/npm/v/gettext-converter.svg)](https://npmjs.org/package/gettext-converter)

## Download

The source is available for download from
[GitHub](https://github.com/locize/gettext-converter/archive/master.zip).
Alternatively, you can install using npm:

```sh
npm install --save gettext-converter
```

You can then `import` or `require()` gettext-converter as normal:

```js
import gettext from 'gettext-converter'
// or
const gettext = require('gettext-converter')

const js = gettext.po2js(po)
```

Or you can direclty `import` or `require()` its functions:

```js
import po2js from 'gettext-converter/po2js'
// or
const po2js = require('gettext-converter/cjs/po2js')
```

## Usage

```js

const po = `msgid ""
msgstr ""
"Project-Id-Version: gettext-converter\n"
"mime-version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2020-04-17T10:46:16.313Z\n"
"PO-Revision-Date: 2020-04-17T10:46:16.313Z\n"

msgid "my-key"
msgstr "myvalue"`

const js = {
  charset: 'utf-8',
  headers: {
    'Project-Id-Version': 'gettext-converter',
    'mime-version': '1.0',
    'Content-Type': 'text/plain; charset=utf-8',
    'Content-Transfer-Encoding': '8bit',
    'Plural-Forms': 'nplurals=2; plural=(n != 1)',
    'POT-Creation-Date': '2020-04-17T10:46:16.313Z',
    'PO-Revision-Date': '2020-04-17T10:46:16.313Z'
  },
  translations: {
  '': {
    '': {
      msgid: '',
      msgstr: [
        'Project-Id-Version: gettext-converter\n' +
          'mime-version: 1.0\n' +
          'Content-Type: text/plain; charset=utf-8\n' +
          'Content-Transfer-Encoding: 8bit\n' +
          'Plural-Forms: nplurals=2; plural=(n != 1)\n' +
          'POT-Creation-Date: 2020-04-17T10:46:16.313Z\n' +
          'PO-Revision-Date: 2020-04-17T10:46:16.313Z\n'
      ]
    },
    'my-key': { msgid: 'my-key', msgstr: [ 'myvalue' ] }
  }
}


import po2js from 'gettext-converter/po2js'
const res = po2js(po)
// res is like js

import js2po from 'gettext-converter/js2po'
const res = js2po(js)
// res is like po


const i18nextJs = { 'my-key': 'myvalue' }

import po2i18next from 'gettext-converter/po2i18next'
const res = po2i18next(po)
// res is like i18nextJs

import i18next2po from 'gettext-converter/i18next2po'
const res = i18next2po('en', i18nextJs)
// res is like po
```

### fuzzy entries

`i18next2po` / `i18next2js` flag the entries of the given keys with `#, fuzzy` (`fuzzy` takes an array, a `Set` or a `(key) => boolean`; a plural or context entry is flagged when any of its forms is listed). `po2i18next` / `js2i18next` with `fuzzy: true` return `{ resources, fuzzy }` instead of the resources alone: `fuzzy` lists the i18next keys (paths joined with `.`) of the fuzzy entries (with `skipUntranslated` fuzzy entries are dropped instead, as before):

```js
const po = i18next2po('en', { greeting: 'hi', bye: 'bye' }, { fuzzy: ['bye'] })
// ...
// #, fuzzy
// msgid "bye"
// msgstr "bye"

const { resources, fuzzy } = po2i18next(po, { fuzzy: true })
// resources => { greeting: 'hi', bye: 'bye' }, fuzzy => ['bye']
```

### i18next json format v4 support

```javascript
const i18nextJs = {
  'key_one': 'a value',
  'key_other': 'some values'
}

import i18next2po from 'gettext-converter/i18next2po'
const res = i18next2po('en', i18nextJs, { compatibilityJSON: 'v4' })

import po2i18next from 'gettext-converter/po2i18next'
const res = po2i18next(po, { compatibilityJSON: 'v4' })
```

---
_Source: https://npm.io/package/gettext-converter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
