# gettext-extractor

> Gettext extractor for JavaScript, TypeScript, JSX and HTML

Latest version **4.0.6** (published 2026-02-16) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 4.0.6 |
| Published | 2026-02-16 |
| First published | 2017-03-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=20 |
| Dependencies | 6 |
| Unpacked size | 70.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 112 |
| Author | Connected Cars |
| Maintainers | mex, mtjcc, urcra, viter, chribsen, madspelt, sta-cc, aabnpm, lmfros, gbullock, rljconnected |
| Keywords | gettext, extractor, typescript, po-files, i18n, l10n, translation |

## Links

- npm: https://www.npmjs.com/package/gettext-extractor
- Repository: https://github.com/connectedcars/gettext-extractor
- Homepage: https://github.com/connectedcars/gettext-extractor#readme
- Issues: https://github.com/connectedcars/gettext-extractor/issues
- npm.io page: https://npm.io/package/gettext-extractor

## Dependencies (6)

- [glob](https://npm.io/package/glob.md) 11.1.0
- [parse5](https://npm.io/package/parse5.md) 5 - 6
- [pofile](https://npm.io/package/pofile.md) 1.0.x
- [typescript](https://npm.io/package/typescript.md) ^5.4.0
- [@types/parse5](https://npm.io/package/@types/parse5.md) ^5
- [css-selector-parser](https://npm.io/package/css-selector-parser.md) ^1.3

## Alternatives

- [messageformat](https://npm.io/package/messageformat.md) — 329.7K weekly downloads
- [@mintlify/scraping](https://npm.io/package/@mintlify/scraping.md) — 294.8K weekly downloads
- [@mintlify/previewing](https://npm.io/package/@mintlify/previewing.md) — 209.5K weekly downloads
- [@mintlify/prebuild](https://npm.io/package/@mintlify/prebuild.md) — 209.5K weekly downloads
- [@mintlify/link-rot](https://npm.io/package/@mintlify/link-rot.md) — 206.3K weekly downloads

## Recent versions

- 4.0.6 (latest) — 2026-02-16
- 4.0.5 — 2026-01-09
- 4.0.4 — 2025-12-18
- 4.0.3 — 2025-12-01
- 4.0.2 — 2025-12-01
- 4.0.1 — 2025-07-14
- 4.0.0 — 2025-07-11
- 3.8.0 — 2023-07-15
- 3.7.2 — 2023-04-21
- 3.7.1 — 2023-04-10
- 3.7.0 — 2023-03-13
- 3.6.2 — 2023-02-07
- 3.6.1 — 2022-12-31
- 3.6.0 — 2022-10-27
- 3.5.4 — 2022-02-12
- … 20 more at https://npm.io/package/gettext-extractor/versions

## README

# Gettext Extractor [![Tests Status][status-tests-badge]][status-tests-link]

*A flexible and powerful Gettext message extractor with support for JavaScript, TypeScript, JSX and HTML*

It works by running your files through a parser and then uses the AST (Abstract Syntax Tree) to find and extract translatable strings from your source code. All extracted strings can then be saved as `.pot` file to act as template for translation files.

Unlike many of the alternatives, this library is highly configurable and is designed to work with most existing setups.

For the full documentation check out the [Github Wiki][wiki].

</br>

## Installation

> **Note:** This package requires Node.js version 20 or higher.

#### NPM

```text
npm install gettext-extractor
```

</br>

## Getting Started

Let's start with a code example:

```javascript
const { GettextExtractor, JsExtractors, HtmlExtractors } = require('gettext-extractor');

let extractor = new GettextExtractor();

extractor
    .createJsParser([
        JsExtractors.callExpression('getText', {
            arguments: {
                text: 0,
                context: 1
            }
        }),
        JsExtractors.callExpression('getPlural', {
            arguments: {
                text: 1,
                textPlural: 2,
                context: 3
            }
        })
    ])
    .parseFilesGlob('./src/**/*.@(ts|js|tsx|jsx)');

extractor
    .createHtmlParser([
        HtmlExtractors.elementContent('translate, [translate]')
    ])
    .parseFilesGlob('./src/**/*.html');

extractor.savePotFile('./messages.pot');

extractor.printStats();
```

A detailed explanation of this code example and much more can be found in the [Github Wiki][wiki-introduction].

<br/>

## Contributing

From reporting a bug to submitting a pull request: every contribution is appreciated and welcome.
Report bugs, ask questions and request features using [Github issues][github-issues].
If you want to contribute to the code of this project, please read the [Contribution Guidelines][contributing].

[status-tests-badge]: https://github.com/connectedcars/gettext-extractor/actions/workflows/tests.yml/badge.svg
[status-tests-link]: https://github.com/connectedcars/gettext-extractor/actions/workflows/tests.yml
[wiki]: https://github.com/connectedcars/gettext-extractor/wiki
[wiki-introduction]: https://github.com/connectedcars/gettext-extractor/wiki/Introduction
[github-issues]: https://github.com/connectedcars/gettext-extractor/issues
[contributing]: CONTRIBUTING.md

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