loc_checker 1.0.0 copy "loc_checker: ^1.0.0" to clipboard
loc_checker: ^1.0.0 copied to clipboard

A tool to detect non-localized strings in Flutter projects and generate ARB files with camelCase keys.

loc_checker #

A Dart command-line tool to detect non-localized strings in Flutter projects and generate ARB files for localization. Designed for developers who want to ensure their Flutter apps are fully localized, loc_checker scans Dart files, identifies UI-related strings that need translation, and outputs them into a structured en.arb file with camelCase keys and named placeholders.

🚀 Features #

  • 🔍 String Detection: Identifies non-localized strings in Dart files, focusing on UI-related contexts (e.g., Text, TextFormField).
  • 📂 ARB Generation: Creates an en.arb file with camelCase keys (e.g., myAccount) and deduplicated values.
  • 🔢 Placeholder Support: Converts Dart string interpolations (e.g., $variable) into named placeholders (e.g., {param0}) with proper ARB metadata.
  • ⚙️ Custom UI Patterns: Allows users to specify custom UI components (e.g., CustomTextField) to include in the scan.
  • 📜 Verbose Logging: Provides detailed output for debugging when enabled.
  • 🔧 Scalable Design: Modular code structure for easy extension and maintenance.

📥 Installation #

As a dev dependency: #

dart pub add --dev loc_checker
copied to clipboard

Install globally: #

dart pub global activate loc_checker
copied to clipboard

🚀 Usage #

Run loc_checker on your Flutter project to scan for non-localized strings and optionally generate an ARB file.

🔍 Basic Command: Scan a project and output a report #

dart run loc_checker /path/to/your/flutter/project -o report.txt
copied to clipboard

📂 Generate ARB File: Scan and create an en.arb file #

dart run loc_checker --generate-arb --arb-output /path/to/your/flutter/project/lib/l10n /path/to/your/flutter/project -o report.txt
copied to clipboard

🛠️ With Verbose Logging: Enable detailed logs #

dart run loc_checker --verbose --generate-arb /path/to/your/flutter/project -o report.txt
copied to clipboard

🎯 Custom UI Components: Include custom UI widgets in the scan #

dart run loc_checker --custom-ui "CustomTextField,validator" /path/to/your/flutter/project -o report.txt
copied to clipboard

🏆 Full Example: Scan, generate ARB, and use all options #

dart run loc_checker --verbose --generate-arb --custom-ui "CustomTextField,validator" --scan-paths "/path/to/lib,/path/to/src" /path/to/your/flutter/project -o report.txt --arb-output /path/to/your/flutter/project/lib/l10n
copied to clipboard

📌 Command-Line Options #

Option Description Default
--verbose, -v Enable detailed logging false
--generate-arb Generate an en.arb file false
--arb-output Directory to save the en.arb file Project root
--scan-paths Comma-separated paths to scan lib/ in project root
--custom-ui Comma-separated custom UI patterns to include None
-o, --output Path for the report file report.txt
[project_path] Root directory of the Flutter project Current directory

📜 Output #

📋 Report File (report.txt) #

A text file listing non-localized strings with file paths, line numbers, and context:

Found 2 non-localized strings:

1. lib/widgets/custom.dart:1 - "Username"
   Context:
     1: CustomTextField(label: 'Username')
     2: TextFormField(validator: (v) => v.isEmpty ? 'Required field' : null)

2. lib/widgets/custom.dart:2 - "Required field"
   Context:
     1: CustomTextField(label: 'Username')
     2: TextFormField(validator: (v) => v.isEmpty ? 'Required field' : null)
copied to clipboard

📂 ARB File (en.arb) #

A localization file with camelCase keys and named placeholders:

{
  "username": "Username",
  "requiredField": "Required field",
  "uploadFailedWithStatusMessage": "Upload failed with status: {param0}, message: {param1}",
  "@uploadFailedWithStatusMessage": {
    "description": "String with placeholders from lib/network.dart:10",
    "placeholders": {
      "param0": {},
      "param1": {}
    }
  }
}
copied to clipboard

🔍 How It Works #

  1. Scanning: Analyzes Dart files in the specified paths (default: lib/), excluding common non-source directories (build, .dart_tool).
  2. Detection: Uses AST parsing to find string literals in UI-related contexts, skipping localized strings (AppLocalizations.of(context).key).
  3. Filtering: Ignores non-UI strings, empty strings, URLs, and other non-translatable content.
  4. ARB Generation: Converts detected strings into a deduplicated en.arb file with camelCase keys and proper placeholder metadata.

📌 Contribution #

Feel free to submit issues, feature requests, or pull requests to improve loc_checker.

📜 License #

This project is licensed under the MIT License.


Made with ❤️ for Flutter developers! 🚀

4
likes
130
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

2024.09.09 - 2025.03.24

A tool to detect non-localized strings in Flutter projects and generate ARB files with camelCase keys.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

analyzer, args, file, glob, path

More

Packages that depend on loc_checker