Slang Helper
Slang Helper is a VS Code extension for Flutter projects that use
slang. It creates a translation key from
selected text, writes the entry to the base translation JSON file, and replaces
the selection with a generated translation accessor.
Features

- Select a string and press
⌘ + 4 on macOS.
- Or select a string, right click, and choose
添加多语言(⌘ + 4).
- Generates snake_case keys:
"Hello {userName}" -> hello_user_name
"hello world" -> hello_world
- Replaces selected text with a slang accessor:
Translations.of(context).hello_world
context.t.hello_world
- Writes the new key to the base JSON file detected from
slang.yaml.
- Can optionally run
dart run slang after adding a key.
Settings
{
"slangHelper.callPrefix": "Translations.of(context)",
"slangHelper.translationFile": "",
"slangHelper.generatedFile": "",
"slangHelper.slangCommand": "",
"slangHelper.autoImportGeneratedFile": true,
"slangHelper.accessorCase": "key",
"slangHelper.runSlangAfterAdd": true
}
When slangHelper.autoImportGeneratedFile is enabled, the extension imports
the generated slang Dart file into the current Dart file. It reads the package
name from pubspec.yaml, then auto-detects the generated file from
slang.yaml or common paths such as lib/generated/slang.g.dart.
When slangHelper.runSlangAfterAdd is enabled, the extension runs
the slang generator after updating the base translation file so the generated
accessor exists before the selected string is replaced. Flutter projects use
flutter pub run slang, and FVM projects use .fvm/flutter_sdk/bin/flutter
when available.
Set slangHelper.slangCommand when a project needs a custom generation command.
Leave it empty for auto-detection. Examples:
dart run slang
flutter pub run slang
fvm flutter pub run slang
melos exec -- dart run slang
For a Flutter project with a standard slang.yaml, the extension can auto-detect:
assets/translations/en.json
because slang.yaml contains:
base_locale: en
input_directory: assets/translations
input_file_pattern: .json
Development
npm install
npm run compile
Press F5 in VS Code to launch an Extension Development Host.
Package
npm run package
This creates a .vsix file that can be installed locally or published to the
VS Code Marketplace with vsce publish.