# gettext-handlebars

> Extract translatable strings from Handlebars templates

Latest version **3.0.0** (published 2026-10-17) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2026-10-17 |
| First published | 2014-08-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=22 |
| Dependencies | 1 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Sam Hauglustaine |
| Maintainers | gabegorelick, smhg |
| Keywords | handlebars, gettext, hbs, i18n, translate, translation |

## Links

- npm: https://www.npmjs.com/package/gettext-handlebars
- Repository: https://github.com/smhg/gettext-handlebars
- Issues: https://github.com/smhg/gettext-handlebars/issues
- npm.io page: https://npm.io/package/gettext-handlebars

## Dependencies (1)

- [handlebars](https://npm.io/package/handlebars.md) ^4.7.10

## 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

- 3.0.0 (latest) — 2026-10-17
- 2.0.0 — 2025-12-26
- 1.1.1 — 2023-01-08
- 1.1.0 — 2021-08-30
- 1.0.2 — 2020-03-21
- 1.0.1 — 2019-11-16
- 0.7.1 — 2019-02-26
- 1.0.0 — 2019-02-26
- 0.7.0 — 2017-01-09
- 0.6.1 — 2016-12-20
- 0.6.0 — 2016-10-08
- 0.5.0 — 2016-04-09
- 0.4.1 — 2016-01-10
- 0.4.0 — 2015-10-26
- 0.3.0 — 2015-01-18
- … 4 more at https://npm.io/package/gettext-handlebars/versions

## README

# gettext-handlebars [![ci](https://github.com/smhg/gettext-handlebars/actions/workflows/ci.yml/badge.svg)](https://github.com/smhg/gettext-handlebars/actions/workflows/ci.yml)

Extract translatable strings from [Handlebars](http://handlebarsjs.com/) template strings.

It can be used stand-alone or through [xgettext-template](https://github.com/gmarty/xgettext).

### API

#### new Parser(keywordSpec)
Creates a new parser.
The `keywordSpec` parameter is optional, with the default being:
```javascript
{
  _: {
    msgid: 0
  },
  gettext: {
    msgid: 0
  },
  dgettext: {
    msgid: 1
  },
  dcgettext: {
    msgid: 1
  },
  ngettext: {
    msgid: 0,
    msgid_plural: 1
  },
  dngettext: {
    msgid: 1,
    msgid_plural: 2
  },
  pgettext: {
    msgctxt: 0,
    msgid: 1
  },
  dpgettext: {
    msgctxt: 1,
    msgid: 2
  }
}
```
Each keyword (key) requires an object with argument positions. The `msgid` position is required. `msgid_plural` and `msgctxt` are optional.
For example `gettext: {msgid: 0}` indicates that the Handlebars expression looks like `{{gettext "string"}}`.

#### .parse(template)
Parses the `template` string for Handlebars expressions using the keywordspec.
It returns an object with this structure:
```javascript
{
  msgid1: {
    line: [1, 3]
  },
  msgid2: {
    line: [2],
    plural: 'msgid_plural'
  },
  context\u0004msgid2: {
    line: [4]
  }
}
```

### Development

#### Install
```shell
git clone git@github.com:smhg/gettext-handlebars.git
npm i
```

#### Test
```shell
npm run lint
npm test
```

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