Skip to content

ESLint plugin for i18next. Prevent to display non-localized text for users

License

Notifications You must be signed in to change notification settings

edvardchen/eslint-plugin-i18next

Folders and files

NameName
Last commit message
Last commit date

Latest commit

171c4b1 · Nov 24, 2024
Nov 24, 2024
Sep 23, 2024
Sep 14, 2024
Nov 24, 2024
Nov 24, 2024
Sep 13, 2024
Aug 27, 2020
Nov 24, 2024
Mar 19, 2023
Sep 14, 2024
Mar 29, 2019
Nov 24, 2024
Sep 23, 2024
Sep 13, 2024
May 11, 2024

Repository files navigation

eslint-plugin-i18next

ESLint plugin for i18n

For old versions below v6, plz refer this document

Installation

npm install eslint-plugin-i18next --save-dev

Usage

For ESLint 9 flat configuration,

// eslint.config.mjs
import i18next from 'eslint-plugin-i18next';

export default [
  // your other configs
  i18next.configs['flat/recommended'],
];

For ESLint 8 and below,

// .eslintrc
{
  "extends": ["plugin:i18next/recommended"]
}

Rule no-literal-string

This rule aims to avoid developers to display literal string directly to users without translating them.

Note: Disable auto-fix because key in the call i18next.t(key) usually was not the same as the literal

Example of incorrect code:

/*eslint i18next/no-literal-string: "error"*/
<div>hello world</div>

Example of correct code:

/*eslint i18next/no-literal-string: "error"*/
<div>{i18next.t('HELLO_KEY')}</div>

More options can be found here

Breaking change

By default, it will only validate the plain text in JSX markup instead of all literal strings in previous versions. You can change it easily