# eslint-plugin-gettext

> Set of eslint rules for gettext API

Latest version **1.2.0** (published 2021-10-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install eslint-plugin-gettext
pnpm add eslint-plugin-gettext
yarn add eslint-plugin-gettext
bun add eslint-plugin-gettext
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2021-10-01 |
| First published | 2017-11-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 1 |
| Unpacked size | 17.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | App Annie Engineering |
| Maintainers | sboudrias, jiuyue, aanpmjs |
| Keywords | gettext, gettext-eslint, literal, eslint, eslint-plugin, i18n, internationalization, localization |

## Links

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

## Dependencies (1)

- [gettext-parser](https://npm.io/package/gettext-parser.md) ^4.0.4

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@inrupt/eslint-config-base](https://npm.io/package/@inrupt/eslint-config-base.md) — 4.5K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2021-10-01
- 1.1.0 — 2018-04-24
- 1.0.0 — 2017-11-13

## README

# eslint-plugin-gettext [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage percentage][coveralls-image]][coveralls-url]

[Gettext](https://en.wikipedia.org/wiki/Gettext) linting rules for ESLint.

We're using this rule to lint against misuse of the [jed gettext integration](https://github.com/messageformat/Jed) and the [django JS catalog](https://docs.djangoproject.com/en/1.11/topics/i18n/translation/#internationalization-in-javascript-code); so we're confident it should work against any gettext integration.

## Installation

1. Install [ESLint](https://www.github.com/eslint/eslint).
1. Install [eslint-plugin-gettext](https://github.com/appannie/eslint-plugin-gettext) plugin.

```sh
npm install eslint --save-dev
npm install eslint-plugin-gettext --save-dev
```

## Configuration

1. Load plugin.
1. Enable rules.

```json
{
  "plugins": ["gettext"],
  "rules": {
    "gettext/no-variable-string": "error",
    "gettext/required-positional-markers-for-multiple-variables": "error"
  }
}
```

## Rules

### `gettext/no-variable-string`

Disallow non literal strings inside common `gettext` functions. This is a very common mistake that disallow translation system from statically collecting the translatable strings.

```js
// Disallows any non string literals in string reserved fields:
gettext(variable)
gettext(123)
ngettext(varA, varB, 5)
pgettext(varA, varB)
npgettext(varA, varB, varC, 5)

// Allows:
gettext('hello')
ngettext('cat', '%d cats', 5)
pgettext('homepage', 'hello')
npgettext('homepage', 'cat', '%d cats', 5)
i18n.gettext('hello') // any object can expose the gettext API
this.gettext('hello')
```

### `gettext/required-positional-markers-for-multiple-variables`

Require that all strings containing multiple variables also includes positional marker. This allows translator to reorder variables, and prevents `sprintf()` errors if someone change the order of `%s` and `%d`.

```js
// Disallows:
gettext('There is %d more event in the %s.')
gettext('There is %d more event in the %1$s.')

// Allows:
gettext('There is %d more event in the game.')
ngettext('cat %1$s $2$s', '%1$d cats %2$d dogs', count)
```

## License

MIT © [App Annie](https://www.appannie.com/en/about/careers/engineering/)

[npm-image]: https://badge.fury.io/js/eslint-plugin-gettext.svg
[npm-url]: https://npmjs.org/package/eslint-plugin-gettext
[travis-image]: https://travis-ci.org/appannie/eslint-plugin-gettext.svg?branch=master
[travis-url]: https://travis-ci.org/appannie/eslint-plugin-gettext
[daviddm-image]: https://david-dm.org/appannie/eslint-plugin-gettext.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/appannie/eslint-plugin-gettext
[coveralls-image]: https://coveralls.io/repos/appannie/eslint-plugin-gettext/badge.svg
[coveralls-url]: https://coveralls.io/r/appannie/eslint-plugin-gettext

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