Socket
Socket
Sign inDemoInstall

eslint-plugin-gettext

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-gettext

Set of eslint rules for gettext API


Version published
Weekly downloads
2.2K
increased by5.05%
Maintainers
3
Weekly downloads
 
Created
Source

eslint-plugin-gettext NPM version Build Status Dependency Status Coverage percentage

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.

Installation

  1. Install ESLint.
  2. Install eslint-plugin-gettext plugin.
npm install eslint --save-dev
npm install eslint-plugin-gettext --save-dev

Configuration

  1. Load plugin.
  2. Enable rules.
{
  "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.

// 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)

License

MIT © App Annie

Keywords

FAQs

Package last updated on 01 Oct 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc