# gettext-nunjucks

> Extract translatable strings from Nunjucks templates

Latest version **0.0.2** (published 2017-03-04) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2017-03-04 |
| First published | 2016-12-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Eldar Cejvanovic |
| Maintainers | eldarc |
| Keywords | nunjucks, gettext, njk, i18n, translate, translation |

## Links

- npm: https://www.npmjs.com/package/gettext-nunjucks
- Repository: https://github.com/ministryofprogramming/gettext-nunjucks
- Homepage: https://github.com/ministryofprogramming/gettext-nunjucks/gettext-swig
- Issues: https://github.com/ministryofprogramming/gettext-nunjucks/issues
- npm.io page: https://npm.io/package/gettext-nunjucks

## Dependencies (3)

- [marked](https://npm.io/package/marked.md) ^0.3.6
- [nunjucks](https://npm.io/package/nunjucks.md) ^3.0.0
- [nunjucks-markdown](https://npm.io/package/nunjucks-markdown.md) ^2.0.1

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

- 0.0.2 (latest) — 2017-03-04
- 0.0.1 — 2016-12-15

## README

# gettext-nunjucks [![build status](https://secure.travis-ci.org/ministryofprogramming/gettext-nunjucks.png)](http://travis-ci.org/ministryofprogramming/gettext-nunjucks)

Extract translatable strings from [Nunjucks](https://github.com/mozilla/nunjucks) 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
  },
  npgettext: {
    msgctxt: 0,
    msgid: 1,
    msgid_plural: 2
  },
  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 Nunjucks expression looks like `{{ gettext("string") }}`.

#### .parse(template)
Parses the `template` string for Nunjucks 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:ministryofprogramming/gettext-nunjucks.git
npm i
```

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

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