Skip to content

Conversation

@KhaliLounis
Copy link

Summary

This PR introduces two new features that significantly expand the tool's capabilities beyond JSX text extraction, making it more comprehensive for real-world i18n workflows.

Features Added

1. Non-Alphabetic Character Filtering (--filter-non-alpha)

Filters out text containing only non-alphabetic characters (symbols, numbers, emojis) to reduce noise in extraction output.

Use Case: Prevents extraction of standalone symbols like $, single letters, or number-only strings that aren't meaningful for translation.

Example:

# Before:
[ProductCard.tsx:30] $
[ProductCard.tsx:33] In Stock

# With --filter-non-alpha:
[ProductCard.tsx:33] In Stock  # $ is filtered out

2. Extended Literal Extraction (--include-literals)

Extracts user-facing strings from sources beyond JSX, including:

Object Properties

Extracts strings from objects with user-facing keys like message, error, label, title, description, etc.

Zod Schema Validation Messages

Supports all common Zod validation patterns:

Function Calls

Extracts from common user-facing function calls:

Advanced Filtering

The tool now automatically skips technical strings to prevent false positives:

  • Import paths and URLs, CSS class names and IDs, camelCase identifiers and CONSTANTS, Single characters and code-like patterns.

Performance Impact

Testing on the example codebase shows significant improvement:

  • Without --include-literals: 73 strings extracted (JSX only)
  • With --include-literals: 98 strings extracted

Changes

Core Implementation

  • Added --filter-non-alpha / -f flag with character validation
  • Added --include-literals / -l flag with AST traversal for:
    • ObjectProperty nodes (with advanced key filtering)
    • NewExpression nodes (Error constructors)
    • CallExpression nodes (toast, console, Zod methods)
  • Implemented isUserFacingText() function to filter technical strings
  • Added configurable sets for user-facing keys, functions, and skip patterns

Documentation

  • Updated README with comprehensive examples
  • Added "What it extracts" section with detailed code samples
  • Clarified npm script usage with -- separator
  • Added example output comparisons

Testing

  • Added example/src/test-literals.tsx with comprehensive test cases
  • Renamed example/src/App.tsx to App.jsx to demonstrate the --ext flag usage with JavaScript files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant