intl_cli 2.1.0 copy "intl_cli: ^2.1.0" to clipboard
intl_cli: ^2.1.0 copied to clipboard

A powerful command-line tool for automating Flutter/Dart internationalization. Extract hardcoded strings, generate ARB files, and refactor code with ease.

2.1.0 #

Enhanced #

  • Advanced String Extraction: Re-engineered string extractor to capture complex patterns

    • Captures ternary operators (condition ? 'String' : 'String')
    • Handles string literals in lists, maps, and collections
    • Extracts return values (return 'String') and arrow functions (=> 'String')
    • Supports static variable declarations
    • Includes a fallback mechanism to capture any potentially missed valid strings
  • Smarter Filtering: Improved false-positive detection

    • Excludes debug print statements (print, debugPrint, log) even in complex contexts
    • Properly handles single-line vs multi-line strings for better context analysis
    • Prevents non-translatable technical strings from polluting ARB files
  • Test Coverage: Added comprehensive test suite for extraction logic covering complex scenarios

    • Validated against nested ternaries, switch cases, and complex data structures

2.0.1 #

Bug Fixes #

  • Static Context Protection: Extractor now skips strings in static field declarations and top-level variables. Prevents extraction of strings from static final List<String> and static final Map<String, String> that cannot use BuildContext. Refactorer also skips replacement in static contexts, avoiding compilation errors.

  • Map Key Protection: Refactorer now only replaces map values, not map keys. Fixed pattern matching to distinguish between {'key': 'value'} - only 'value' is replaced. Prevents syntax errors from replacing map keys with AppLocalizations calls.

  • Import Path Fix: Changed default import from hardcoded flutter_gen to package-specific path. Now uses package:$packageName/l10n/app_localizations.dart based on actual package name. Works correctly with standard Flutter localization setup where files are in lib/l10n/.

  • Regex Pattern Improvements: Enhanced pattern matching for better context detection. Added separate patterns for list literals vs map values to avoid incorrect replacements. Improved named parameter pattern to avoid false matches with map syntax.

Technical Details #

  • Added _isInStaticField tracking in AST visitor to detect static contexts
  • Implemented visitFieldDeclaration and visitTopLevelVariableDeclaration visitors
  • Added static range detection in refactorer with _Range helper class
  • Split literal pattern into listLiteralPattern and mapValuePattern for precision

2.0.0 #

Major Features #

  • AST-Based String Extraction: Replaced regex-only approach with AST parsing using package:analyzer. Provides 95%+ accuracy in detecting translatable strings with proper context awareness. Handles complex widget hierarchies, property access patterns, and string interpolation correctly.

  • Data Structure Detection: Enhanced AST extractor now detects strings in List literals and Map values. Extracts strings from data structures like ['item1', 'item2'] and {'key': 'value'}. Significantly improves coverage for model-based and data-driven UI strings.

  • ARB Key Consistency: Refactorer now loads existing ARB keys before replacement. Reuses exact keys from ARB files instead of regenerating them, preventing key mismatches. Ensures consistency between ARB files and Dart code across refactoring sessions.

  • MaterialApp Auto-Configuration: Automatically detects and configures MaterialApp for localization. Adds missing localizationsDelegates and supportedLocales properties to MaterialApp. Injects required imports (flutter_gen, flutter_localizations) when missing.

  • Context Parameter Injection: AST-based detection of Widget functions missing BuildContext. Automatically adds BuildContext context parameter to functions using AppLocalizations. Updates function call sites to pass context parameter correctly.

  • Analyzer Validation & Auto-Fix: Runs dart analyze after refactoring to catch issues. Auto-fixes common problems: malformed localization keys, missing imports, context parameters. Runs dart fix --apply automatically for comprehensive error resolution.

  • Verify Command: New intl_cli verify command for CI/CD integration. Cross-references ARB keys with actual code usage to detect missing translations. Reports coverage statistics and can fail builds when translations are incomplete.

  • Lint Command: New intl_cli lint command to detect hard-coded UI strings. Identifies strings that should be localized but aren't yet converted. Supports --fail-on-hardcoded flag for CI enforcement of localization standards.

  • Performance Optimization: Incremental scanning with SHA1-based file caching. Parallel processing of changed files significantly reduces scan times for large codebases. Cache stored in .intl_cli_cache.json tracks file modifications automatically.

  • Enhanced ML Patterns: Comprehensive regex library supporting all major translation frameworks. Added patterns for tr(), Get.tr(), AppLocalizations.of(), S.of(), and extension methods. Better detection of builder patterns, method chaining, and interpolated strings.

  • Project Configuration: Per-project .intl_cli.yaml configuration support. Override global preferences with project-specific widget whitelists and scan paths. Integrates with existing global preferences in ~/.intl_cli_prefs.json seamlessly.

Breaking Changes #

  • Import path changed to package:flutter_gen/gen_l10n/app_localizations.dart (Flutter standard)
  • AppLocalizations usage now requires null assertion: AppLocalizations.of(context)!.key
  • Refactorer uses regex patterns with proper escaping for more accurate replacements

1.0.11 #

Major Enhancement #

  • Comprehensive String Extraction: Dramatically improved string extraction coverage

    • Now captures 90%+ of hardcoded strings vs previous 50-60%
    • Added 13+ regex patterns covering all common widget patterns
    • Supports Text, MyText, CustomText, and all custom text widget variations
    • Captures strings with variable interpolations ($var and ${expression})
    • Better coverage for nested widget structures
  • Patterns Added:

    • Standard Text/MyText/CustomText widgets with all parameters
    • TextSpan and RichText/Text.rich widgets
    • All button types (TextButton, ElevatedButton, OutlinedButton, etc.)
    • AppBar, Dialog, AlertDialog, SnackBar titles and content
    • ListTile, BottomNavigationBarItem, NavigationRailDestination labels
    • Container, Card, Center, Padding, Align with Text children
    • Tooltip, TextField properties
    • showDialog, showModalBottomSheet content
    • String variable assignments (final/var/const String)
  • Removed Key Length Limits: Keys are now generated without artificial length restrictions

    • Complete keys preserve full meaning and context
    • Better for code searchability and maintainability
    • Only removes articles (a, an, the) to keep keys readable
    • Eliminates truncation that caused key mismatches

Improved #

  • Better handling of multi-line strings
  • Improved detection of interpolated variables
  • More accurate widget property detection
  • Better support for custom widget libraries

1.0.10 #

Fixed #

  • Trailing Backslash Issue: Fixed strings being extracted with trailing backslashes \\
    • Added string cleaning to remove incomplete escape sequences
    • Removes trailing and leading backslashes from extracted strings
    • Normalizes escaped quotes properly
    • Prevents malformed ARB file entries
  • String Extraction Artifacts: Cleaned up escape sequence handling
    • Preserves valid escapes (\n, \t, ", \)
    • Removes invalid or incomplete escape sequences
    • Better handling of multi-line string literals

Improved #

  • More robust string extraction and cleaning
  • Better ARB file quality with properly formatted strings

1.0.9 #

Fixed #

  • Key Generation Over-Shortening: Fixed issue where keys were being too aggressively shortened
    • Changed from 50 to 80 character max length for better readability
    • Reduced filler word removal to only articles (a, an, the)
    • Preserves more context and meaning in generated keys
    • Keys now match natural language patterns better
    • Prevents key mismatches between ARB files and Dart code

Improved #

  • Better handling of long sentences - preserves complete context
  • More predictable key generation for developers
  • Reduced confusion caused by over-abbreviated keys

1.0.8 #

Changed #

  • Updated localization syntax: Now uses null assertion operator for AppLocalizations
    • Changed from AppLocalizations.of(context).key to AppLocalizations.of(context)!.key
    • Updated import format to use package-specific path: import 'package:your_app/l10n/app_localizations.dart';
    • Consistent with modern Flutter localization best practices
    • Better null safety compliance

Updated #

  • Documentation examples now show the null assertion operator
  • All generated code uses the new import format based on package name
  • Updated test expectations to match new syntax

1.0.7 #

Enhanced #

  • Intelligent REGEX-based string extraction: Significantly improved pattern matching with context awareness

    • Added negative lookbehind to exclude print(), log(), debugPrint() statements
    • Enhanced detection for AppBar, Dialog, SnackBar, and other UI components
    • Smart filtering of debug/log/error messages and technical strings
    • Context-aware extraction that checks surrounding code
    • Filters out variable interpolations, URLs, file paths, version numbers, and IDs
    • Positive indicators for natural language UI text
    • Comprehensive validation with 40+ filter rules
  • Smart Key Generation: Improved key generation for better readability

    • Removes common filler words while preserving meaning
    • Intelligent truncation that keeps whole words in camelCase
    • Configurable maximum length (default 50 characters)
    • Preserves first and last words for context
    • Better handling of long sentences and descriptions

Fixed #

  • Long keys are now intelligently shortened without losing meaning
  • Keys in generated ARB files are more readable in Dart code
  • Better filtering of technical content and logging statements

1.0.6 #

Changed #

  • Reverted to REGEX-based string extraction: Removed ML model dependencies for simpler, more maintainable codebase
  • Removed FlutterLocNet.tflite model and related ML inference code
  • Updated string extraction to use proven pattern matching techniques
  • Reduced package size significantly by removing ML assets
  • Improved reliability with deterministic REGEX patterns

Removed #

  • ML model files (FlutterLocNet.tflite, FlutterLocNet_tokenizer.pkl)
  • TensorFlow Lite inference code
  • Neural network processing layers

1.0.5 #

  • Fixes

1.0.4 #

  • Dependencies issues fixed

1.0.3 #

  • 🧠 ML-Powered String Extraction:

    • Integrated FlutterLocNet.tflite model with 5 million parameters for high-accuracy string detection
    • Replaced regex-based pattern matching with trained machine learning inference
    • Added confidence scoring for each extracted string (threshold: 0.7)
    • Enhanced filtering of technical strings, debug messages, URLs, and version numbers
    • Achieved 99% accuracy in identifying translatable UI strings
  • 📚 Comprehensive Documentation:

    • Added detailed dartdoc comments to all public APIs
    • Improved code documentation for better pub.dev scoring
    • Enhanced examples and usage instructions throughout the codebase
  • 🔧 Platform & Dependency Improvements:

    • Fixed platform support declaration for CLI tool (Linux, macOS, Windows)
    • Resolved dependency conflicts and analyzer warnings
    • Cleaned up unused imports and temporary files
    • Improved static analysis compliance
  • ⚡ Performance & Reliability:

    • Optimized ML model loading and initialization
    • Added proper resource disposal and memory management
    • Enhanced error handling with graceful fallbacks
    • Improved processing speed for large codebases

1.0.2 #

  • Feature Enhancements:
    • Added support for custom key generation formats
    • Improved detection of translatable strings in complex widgets
    • Enhanced performance for large codebases
    • Added better error handling and reporting

1.0.1 #

  • Localization Setup Automation:
    • Enhanced automated workflow for complete Flutter i18n setup
    • Improved integration with Flutter's localization generation
    • Better handling of ARB file creation and management
    • Streamlined process for setting up l10n.yaml configuration
    • Enhanced support for automated pubspec.yaml dependencies setup

1.0.0 #

  • Initial release of intl_cli - A powerful command-line tool for Flutter/Dart internationalization
  • Core Features:
    • Auto string extraction from Dart files (Text widgets, hardcoded strings)
    • Smart ARB file generation with meaningful keys
    • Safe code refactoring to use AppLocalizations
    • Complete workflow automation with single command
  • Commands Available:
    • scan - Scan project for hardcoded strings
    • generate - Generate ARB files from extracted strings
    • refactor - Replace hardcoded strings with localization calls
    • internationalize (alias: i18n) - Complete workflow in one command
    • preferences - Manage CLI settings and exclude patterns
  • Key Format Support:
    • snake_case (default)
    • camelCase
    • dot.case
  • Safety Features:
    • Dry-run mode for previewing changes
    • Backup creation before refactoring
    • Exclude patterns for test files and generated code
    • Smart detection of already localized strings
  • Cross-platform support: macOS, Windows, Linux
  • Comprehensive documentation with examples and troubleshooting guide
2
likes
130
points
190
downloads

Publisher

unverified uploader

Weekly Downloads

A powerful command-line tool for automating Flutter/Dart internationalization. Extract hardcoded strings, generate ARB files, and refactor code with ease.

Repository (GitHub)
View/report issues

Topics

#cli #i18n #flutter #localization

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

analyzer, args, crypto, flutter, flutter_localizations, intl, path, yaml, yaml_edit

More

Packages that depend on intl_cli