Add Extended Text Extraction and Enhanced Filtering Features #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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:
Performance Impact
Testing on the example codebase shows significant improvement:
--include-literals: 73 strings extracted (JSX only)--include-literals: 98 strings extractedChanges
Core Implementation
--filter-non-alpha/-fflag with character validation--include-literals/-lflag with AST traversal for:ObjectPropertynodes (with advanced key filtering)NewExpressionnodes (Error constructors)CallExpressionnodes (toast, console, Zod methods)isUserFacingText()function to filter technical stringsDocumentation
--separatorTesting
example/src/test-literals.tsxwith comprehensive test casesexample/src/App.tsxtoApp.jsxto demonstrate the--extflag usage with JavaScript files