Skip to content
better-i18n.com
En esta página

Scan your codebase for hardcoded strings that need translation. Better i18n CLI uses a robust AST parser to differentiate between UI text and developer symbols.

Usage #

Bash
better-i18n scan                    # Scan current directory
better-i18n scan --dir ./src        # Scan specific directory
better-i18n scan --format json      # JSON output for tooling
better-i18n scan --ci               # Exit code 1 if issues found
better-i18n scan --staged           # Only staged files
better-i18n scan --verbose          # Detailed output with scan stats

Options #

OptionDescription
--dir <path>Directory to scan
--format <type>eslint (default) or json
--ciExit with code 1 if issues found. Useful for blocking PRs.
--stagedOnly scan git staged files. Perfect for pre-commit hooks.
--verboseShows detailed output and a Scan Audit summary.

Example Output #

Text
✓ Project: better-i18n/landing
✓ Found 246 files

components/sign-up.tsx (3)
  24:13  missing  "Create an account"  i18n/jsx-text
  32:22  missing  "Name"  i18n/jsx-text
  40:22  missing  "Email"  i18n/jsx-text

✖ 87 problems (87 missing translations)

Scanned 246 files in 0.85s

Scan Details (with --verbose) #

When running with --verbose, the CLI provides a breakdown of its discovery process:

Text
🔍 Scan Details:
  - Root-scoped translators: 4
  - Unbound translators: 0
  - Dynamic namespaces skipped: 12
  - Dynamic keys skipped: 5

Detection Rules #

RuleCatchesExample
jsx-textHardcoded JSX text<h1>Hello</h1>
jsx-attributeHardcoded attributes<img alt="Logo" />
toast-messageToast notificationstoast.error("Failed")
ternary-localeLocale-based logiclocale === 'en' ? 'Hi' : 'Hola'
string-variableString variablesconst x = "Hello"

Ignored Patterns #

The CLI is smart enough to ignore common developer symbols and technical strings:

  • HTML entities: &quot;, &amp;, &#39;
  • Tailwind/CSS classes: className="flex items-center bg-blue-500"
  • URLs & Paths: href="https://...", src="/images/..."
  • Technical strings: SCREAMING_CASE, variables, and numbers.

CI/CD Integration #

GitHub Actions #

Enforce zero hardcoded strings in your main branch:

YAML
name: i18n Check
on: [push, pull_request]
jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npx @better-i18n/cli scan --ci

Pre-commit Hook #

Catch issues before they are even committed:

Bash
# Using husky
npx husky init
echo "npx @better-i18n/cli scan --staged --ci" > .husky/pre-commit