Gettext linting rules for ESLint.
We're using this rule to lint against misuse of the jed gettext integration and the django JS catalog; so we're confident it should work against any gettext integration.
- Install ESLint.
- Install eslint-plugin-gettext plugin.
npm install eslint --save-dev
npm install eslint-plugin-gettext --save-dev
- Load plugin.
- Enable rules.
{
"plugins": ["gettext"],
"rules": {
"gettext/no-variable-string": "error"
}
}
Disallow non literal strings inside common gettext
functions. This is a very common mistake that disallow translation system from statically collecting the translatable strings.
// 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')
MIT © App Annie