A Rust CLI tool that scans Flutter/Dart projects to extract translatable strings, making internationalization (i18n) easier by automatically identifying all string literals in your codebase.
This is my first Rust project! It combines the power of Rust's performance and safety with Dart's analysis capabilities to help Flutter developers prepare their apps for localization. The scanner traverses your Flutter project's source code, extracts all string literals, and exports them to a structured JSON format.
- Automatic Discovery: Recursively scans all
.dartfiles in your Flutter project'slibdirectory - Smart Validation: Verifies the target directory is a valid Flutter project (checks for
pubspec.yamlandlibfolder) - String Extraction: Uses a Dart analyzer script to identify and extract translatable strings
- JSON Export: Outputs all extracted strings to a formatted JSON file for easy processing
- Clean Architecture: Modular design with separate concerns (scanning, analyzing, exporting, validation)
scanner/
βββ src/
β βββ analyzer/ # Runs Dart analyzer to extract strings
β β βββ mod.rs
β β βββ dart_analyzer.rs
β βββ scanner/ # File system traversal logic
β β βββ mod.rs
β β βββ file_scanner.rs
β βββ exporter/ # JSON export functionality
β β βββ mod.rs
β β βββ json_exporter.rs
β βββ validators/ # Path and directory validation
β β βββ mod.rs
β β βββ path.rs
β βββ main.rs # Entry point
βββ extract_strings/ # Dart analyzer script
βββ Cargo.toml
- Rust: Install from rustup.rs
- Dart SDK: Required to run the string extraction script
- Clone the repository:
git clone <repository-url>
cd scanner- Build the project:
cargo build --releaseThe compiled binary will be available at target/release/scanner
- Run the scanner:
cargo run- When prompted, enter the path to your Flutter project:
ποΈ Please enter the path of your flutter app to scan:
/path/to/your/flutter/project
- The tool will:
- Validate the Flutter project structure
- Scan all
.dartfiles in thelibdirectory - Extract strings from each file
- Display progress and statistics
- Generate
output.jsonwith all extracted strings
β
The path is a valid Flutter app directory. Continuing...
π Found 45 Dart files:
- 12 strings extracted from /path/to/project/lib/main.dart
- 8 strings extracted from /path/to/project/lib/screens/home.dart
- 15 strings extracted from /path/to/project/lib/widgets/button.dart
...
The generated output.json will contain:
{
"welcome": "Welcome to the app",
"login": "Login",
"signup": "Sign Up",
...
}-
Path Validation (
validators/path.rs): Checks if the provided path is a valid Flutter project by verifying the existence ofpubspec.yamland thelibdirectory -
File Scanning (
scanner/file_scanner.rs): Uses depth-first search (DFS) to recursively traverse thelibdirectory and collect all.dartfiles -
String Extraction (
analyzer/dart_analyzer.rs): Executes the Dart analyzer script on each file to extract string literals, filtering out:- Strings starting with
$(interpolated variables) - Single-character strings
- Strings starting with
-
JSON Export (
exporter/json_exporter.rs): Aggregates all extracted strings and exports them to a formatted JSON file using the first word of each string as the key
serde(1.0): Serialization frameworkserde_json(1.0): JSON support for serde
As my first Rust project, I learned about:
- Rust's module system and code organization
- File I/O and path handling with
std::fsandstd::path - Process spawning with
Commandto interact with Dart - Error handling with
Resultandexpect - String manipulation and ownership
- Working with vectors and iterators
- Using external crates (serde/serde_json)
- Add command-line arguments support (remove interactive prompt)
- Support custom output file paths
- Add progress bars for better UX
- Handle duplicate strings more intelligently
- Add configuration file support
- Implement parallel file processing
- Add unit tests
- Support for other file formats (CSV, YAML, etc.)
See LICENSE.md for details.
This is a learning project, but suggestions and improvements are welcome! Feel free to open an issue or submit a pull request.
Note: This project requires the extract_strings Dart script to be present in the project directory for string extraction to work properly.