intl_cli library
A powerful command-line tool for automating Flutter/Dart internationalization.
This library provides automated extraction of hardcoded strings from Dart/Flutter source code using pattern matching and context analysis. It generates ARB files, creates localization keys, and refactors code efficiently.
Key features:
- REGEX-based string extraction with context analysis
- Automatic ARB file generation
- Smart key generation with meaningful names
- Code refactoring with localization
- Multi-language support via translation APIs
Example usage:
// Scan directory for translatable strings
final results = await scanDirectoryEnhanced('/path/to/flutter/project');
// Generate ARB files
await generateArbFiles(results, '/path/to/l10n');
Classes
- AnalysisResult
- AnalyzerIssue
- AnalyzerValidator
- Runs dart/flutter analyze and provides auto-fix capabilities
- ArbGenerator
- ArbLoader
- Utility class to load ARB files and extract existing keys
- ASTStringExtractor
- CacheManager
- ContextInjector
- Injects BuildContext parameter into Widget-returning functions that need it
- ExtractedString
- A small data type describing a found string and its context
- FileScanner
- LocalizationRefactorer
- MaterialAppConfigChecker
- Checker to ensure MaterialApp has proper localization configuration
- MLStringExtractor
- REGEX-based string extractor for Dart/Flutter code.
- PreferencesManager
- Class to manage user preferences for the CLI tool
- StringExtractorFactory
- Factory class for managing string extraction.
- Translator
Extensions
Functions
-
detectPackageName(
String directoryPath) → String -
ensureFlutterLocalizationsDependency(
String directoryPath) → bool - Check if flutter_localizations dependency exists in pubspec.yaml If not, add it automatically
-
ensureFlutterLocalizationsDependencySafe(
String directoryPath) → bool - Enhanced version using yaml_edit for safer YAML manipulation Checks if flutter_localizations and intl dependencies exist in pubspec.yaml If not, adds them automatically using structured YAML editing
-
generateArbFile(
Map< String, List< extractedStrings, String outputPath, {String keyFormat = 'camelCase'}) → StringString> > - Generate ARB file from extracted strings.
-
isLikelyUserFacingString(
String str) → bool - Heuristic to check if a string is likely a user-facing translatable string.
-
printProgress(
String message) → void -
refactorFiles(
Map< String, List< extractedStrings, {bool dryRun = false, bool useAppLocalizations = true, String packageName = 'app', bool preserveOriginalImports = true, bool preserveConst = false, String? arbFilePath, String keyFormat = 'camelCase'}) → Map<String> >String, String> - Refactor code to use localization keys with meaningful key names.
-
scanDirectory(
String directoryPath, {List< String> ? excludePatterns}) → Future<Map< String, List< >String> > - Scan directory function with REGEX-based string extraction.
-
scanDirectoryEnhanced(
String directoryPath, {List< String> ? excludePatterns}) → Future<Map< String, List< >String> > - Enhanced scan directory with pattern-based string extraction.
-
setupFlutterLocalizationConfiguration(
String projectRoot) → bool - Setup complete Flutter localization configuration including l10n.yaml and pubspec.yaml updates This ensures the project is properly configured for Flutter's localization generation
-
tr(
String key) → String