TranslateHelper VS Code Extension
Overview
TranslateHelper is a VS Code extension designed to assist with extracting, replacing, and managing translations in Flutter projects. It helps automate the process of identifying and replacing hardcoded strings in Dart files with translation keys using Easy Localization or any other packages.
Features
- Generate a Prepaire File: Creates a configuration file (
prepaire.json
) to specify exceptions and translation rules.
- Extract Strings: Scans Dart files to extract translatable strings.
- Replace Strings: Replaces hardcoded strings using values from
replace.json
, while keeping the keys from prepaire.json
.
- Auto-import Easy Localization: Ensures required import statements are added when replacing strings.
Installation
- Open the project in VS Code.
- Search in VS Code extensions for TranslateHelper.
Commands
Command |
Description |
translatehelper.makePrepairefile |
Creates prepaire.json and replace.json to configure translation settings. |
translatehelper.extractStrings |
Extracts translatable strings from Dart files in a selected folder. |
translatehelper.translatereplace |
Replaces extracted strings with values from replace.json while keeping keys from prepaire.json . |
Usage
1. Generate the Prepaire File
Run translatehelper.makePrepairefile
to create prepaire.json
in assets/translationsHelper/
.
Example prepaire.json
Format:
{
"textExceptions": ["import"],
"lineExceptions": ["line_start_to_skip"],
"contentExceptions": ["substring_to_skip"],
"folderExceptions": ["domain"],
"extractFilter": [
"['](https://github.com/yourusername/repohelper/blob/HEAD/[-ۿ].*?)[']",
"["](https://github.com/yourusername/repohelper/blob/HEAD/[-ۿ].*?)["]"
],
"import": ["import 'package:easy_localization/easy_localization.dart';"],
"key": "'{key}'.tr()",
"keyWithVariable": "'{key}'.tr(args: [{args}])"
}
Right-click a folder and select translatehelper.extractStrings
. The extracted strings are saved in en2.json
.
3. Replace Strings
Right-click a folder and select translatehelper.translatereplace
. The extension will replace hardcoded strings using values from replace.json
, while keeping the keys from prepaire.json
.
File Structure
📁 assets/
📁 translationsHelper/
📄 prepaire.json
📄 replace.json
📄 en2.json
Notes
- Strings in
prepaire.json
will be ignored during extraction.
- The extension automatically adds import statements if missing.
- Uses regex to find and replace strings dynamically.
Contribution
Feel free to contribute by improving regex filters or adding more features. Open a pull request or submit issues.
License
MIT License