name: flutter-slang-i18n description: Add and maintain Slang localization in Flutter projects. Use when Codex needs to introduce slang, slang_flutter, or slang_build_runner, migrate hardcoded Flutter UI strings into Slang translations, scan Dart code for user-visible strings, or review existing Slang keys for semantic fit.
Flutter Slang I18n
Workflow
Check project state before edits.
- Run
git status --shortand follow the repository's change-safety policy before modifying files. - Find the Flutter package root containing
pubspec.yaml. - If
.fvm/fvm_config.jsonexists, run Flutter and Dart commands throughfvm. - Inspect existing localization (
slang.yaml,build.yaml,lib/i18n,intl, ARB,easy_localization) before adding another system. If replacing an existing i18n stack, call out migration risk first.
- Run
Add Slang using current package names.
- Prefer the official packages
slang,slang_flutter, and, when using build_runner,slang_build_runnerplusbuild_runner. - If a request mentions
flutter_slang, verify the package name before using it; Slang's Flutter support package is normallyslang_flutter. - Use the project command style:
Dropfvm flutter pub add slang slang_flutter fvm flutter pub add flutter_localizations --sdk=flutter fvm flutter pub add -d build_runner slang_build_runnerfvmonly when the project is not using FVM. - Add a base translation file such as
lib/i18n/en.i18n.jsonand a peer locale such aslib/i18n/zh-CN.i18n.jsonwhen the product supports Chinese. - Use
slang.yamlforfvm dart run slang; usebuild.yamlfor build_runner integration. Keep the generated output path consistent with the existing project style. - When creating a new Slang config, set
translate_var: Sinstead of Slang's defaultt:
For build_runner, put the same option undertranslate_var: Stargets.$default.builders.slang_build_runner.options. - If an existing project already uses the generated
tvariable, changingtranslate_vartoSis a breaking source change. Tell the user explicitly, then update everyt.<key>call site or keep the existing variable name if the user does not want that break. - Generate code with
fvm dart run slangorfvm dart run build_runner build -d, matching the chosen setup.
- Prefer the official packages
Wire Flutter integration.
- Import the generated file, usually
package:<app>/i18n/translations.g.dart. - Initialize locale handling in
main, for exampleLocaleSettings.useDeviceLocale(). - Wrap the app with
TranslationProviderwhen using Slang locale handling. - Set
MaterialApp.locale,supportedLocales, andlocalizationsDelegatesso Flutter framework strings also localize. - In widgets that must rebuild on locale changes, prefer
final S = Translations.of(context)or the project's context extension style.
- Import the generated file, usually
Scan hardcoded strings, then confirm by context.
- Run
scripts/scan_dart_strings.pyfrom this skill against the target Flutter project:
If the target environment does not useuv run python /path/to/flutter-slang-i18n/scripts/scan_dart_strings.py --root /path/to/flutter/projectuv, run the executable script directly. - Treat scanner output as candidates, not truth. Review surrounding code before changing anything.
- Localize user-visible UI strings:
Text, labels, hints, tooltips, dialogs, snackbars, validation messages, empty states, errors shown to users, semantics labels, and accessibility copy. - Usually skip non-UI strings: imports, asset paths, route paths, analytics event names, log/debug messages, test fixtures, protocol values, enum names, storage keys, and
KeyorValueKeyvalues.
- Run
Replace strings with semantic Slang keys.
- Add keys that describe product/UI intent, not only the current English words.
- Preserve interpolation and formatting with Slang parameters, pluralization, and contexts when applicable.
- Keep shared keys only for identical meaning across contexts. Do not reuse a key just because two English strings currently match.
- Update all locale files together. If a translation is unknown, add a clear placeholder consistent with the repo's localization policy and flag it in the final response.
Audit existing Slang usage.
- Find generated translation use:
rg -n "\b(context\.)?[tS]\.|Translations\.of\(context\)" lib - Compare each key path with the surrounding UI. Rename keys like
title,text1,ok, or stale copied feature names when they no longer describe the UI intent. - Key renames break source references and translation files. State this explicitly, update every call site and locale, and avoid hidden compatibility aliases unless the user agrees.
- Read
references/slang-review-guidelines.mdfor key naming and triage rules when the audit is non-trivial.
- Find generated translation use:
Validate.
- Run code generation after translation changes.
- Run
fvm dart run slang analyzewhen Slang CLI is configured, and fix missing or unused translations relevant to the change. - Run
fvm dart formaton changed Dart files. - Run the narrowest useful checks: generated i18n compile test, widget tests around changed screens, or
fvm flutter testwhen the change spans shared UI. - Report scan limitations and any strings intentionally left hardcoded.
Resources
scripts/scan_dart_strings.py: Regex/lexer-based Dart scanner for likely hardcoded UI strings.references/slang-review-guidelines.md: Triage rules for hardcoded strings and semantic Slang key review.