eslint-plugin-local-i18n
v0.2.2
Published
An ESLint plugin to enforce internationalization (i18n) best practices and disable hardcoded strings in your codebase.
Downloads
455
Maintainers
Readme
eslint-plugin-local-i18n
An ESLint plugin that helps enforce internationalization (i18n) best practices by detecting hardcoded strings in your JavaScript, TypeScript, and JSX code.
Features
- 🌐 Detect Hardcoded Strings: Automatically identifies strings that should be internationalized
- ⚙️ Configurable: Flexible rules and exceptions to match your project needs
- 🎯 Attribute Checking: Validates text in JSX attributes like
label,title,placeholder, and more - 🚫 Smart Ignoring: Support for regex patterns and component-specific ignoring
- 📏 Minimum Length: Optional threshold to ignore very short strings
Installation
npm install --save-dev eslint-plugin-local-i18nOr using your preferred package manager:
pnpm add -D eslint-plugin-local-i18nyarn add --dev eslint-plugin-local-i18nConfiguration
Add the plugin to your ESLint configuration in eslint.config.js:
import localI18n from 'eslint-plugin-local-i18n';
export default defineConfig([
{
// React component files
files: ['**/*.{js,jsx,ts,tsx}'],
ignores: ['eslint.config.js', 'babel.config.js'],
plugins: {'local-i18n': localI18n},
rules: {
'local-i18n/no-hardcoded-strings': [
'error',
{
// optional config (defaults shown)
attributes: [
'label',
'title',
'placeholder',
'alt',
'aria-label',
'accessibilityLabel',
'accessibilityHint',
'header',
'headerTitle',
'message',
],
ignore: ['^https?://', '^[A-Z0-9_]+$'], // regex strings to allow
ignoreComponents: ['Icon', 'Trans'], // skip these components' children
minLength: 2, // ignore very short strings
},
],
},
},
]);Rules
no-hardcoded-strings
Detects hardcoded strings that should be internationalized.
Options
attributes(array of strings): JSX attribute names to check for hardcoded strings- Default:
['label', 'title', 'placeholder', 'alt', 'aria-label']
- Default:
ignore(array of regex strings): Patterns to exclude from the rule- Example:
['^https?://', '^[A-Z0-9_]+$']- ignores URLs and constant-like strings
- Example:
ignoreComponents(array of strings): Component names whose children should not be checked- Example:
['Icon', 'Trans']- useful for components that typically don't need translation
- Example:
minLength(number): Minimum string length to trigger the rule- Default:
1 - Useful to ignore very short strings like single characters
- Default:
License
See LICENSE file for details.
Tests
Tests are written using RuleTester. To run the tests, use the following command:
pnpm testContributing
Contributions are welcome! For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the MIT License - see the LICENSE file for details.
