A handy VS Code extension that helps Flutter developers extract internationalized strings directly from their codebase and add them to all i18n files.
This extension is a companion to the slang packages.
✨ Features
✅ Extract i18n Strings
Put the cursor on any string in a Dart file and extract it to your i18n files in one click.
The extension updates all locale files automatically.
🔍 Auto-detect Variables: Automatically detects embedded variables in strings
⚙️ Slang Initialization Command
Quickly scaffold the slang dependency and configuration files (slang.yaml, translations, etc.) in your Flutter app.
🛠️ Usage
🏗️ Initialize Slang i18n
Open the command palette: Ctrl + Shift + P (or Cmd + Shift + P on macOS).
Run: Slang Gen : Initialize.
This will:
Add slang, slang_flutter and slang_build_runner to your pubspec.yaml
Create a basic slang.yaml config file
Generate the initial i18n files (str_en.i18n.json)
🔤 Extract Strings to i18n
Place the cursor on a hardcoded string in a Dart file. eg. "Hello World" or "Hello ${name}".
Click the light bulb icon (💡) or press Ctrl+. to open quick fixes.
Select "Extract to Tr".
This will:
Prompts to update the translation key if needed (e.g., helloWorld)
Moves the string to all i18n.json files.
Replaces the string in code with t.helloWorld or Tr.of(context).helloWorld.
This also works with strings with variables. eg. "Hello ${name}" will be replaced with t.hello(name:name) or Tr.of(context).hello(name:name)
🔧 Extension Settings
This extension provides configuration options under extractToTr:
Setting
Default
Description
slangGen.useContext
false
if true, use Tr.of(context)
📦 Requirements
Your project must contain a pubspec.yaml file.
The slang dependencies (added automatically by this extension)