Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
eslint-plugin-gettext
Advanced tools
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.
npm install eslint --save-dev
npm install eslint-plugin-gettext --save-dev
{
"plugins": ["gettext"],
"rules": {
"gettext/no-variable-string": "error",
"gettext/required-positional-markers-for-multiple-variables": "error"
}
}
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.
// 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
.
// 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)
MIT © App Annie
FAQs
Set of eslint rules for gettext API
The npm package eslint-plugin-gettext receives a total of 1,725 weekly downloads. As such, eslint-plugin-gettext popularity was classified as popular.
We found that eslint-plugin-gettext demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.