一键导入
internationalization
Best practices for internationalization (i18n) and localization (l10n) in Flutter.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Best practices for internationalization (i18n) and localization (l10n) in Flutter.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Drives a Dart or Flutter package to a fully green state through an autonomous verify-fix-rerun loop across four quality gates — analyze, format, test, and coverage. Exits only when a single final iteration proves all four pass with observed numbers.
VGV-specific reference for bumping Dart and Flutter SDK constraints across packages. Covers pubspec.yaml environment constraints, CI workflow Flutter versions, and SDK upgrade PR preparation. CI uses ^MAJOR.MINOR.x to resolve to the latest patch; pubspec pins the exact patch version (e.g., ^3.50.1).
Upgrade very_good_analysis lint package to new version across Dart/Flutter projects. Handles version bump, lint fixes, and PR creation.
Best practices for Dart unit tests, Flutter widget tests, and golden file tests.
Audit or remediate Flutter widgets against WCAG 2.2 accessibility conformance levels A, AA, or AAA across iOS, Android, Web, macOS, Windows, and Linux.
Best practices for Flutter animations using the built-in animation framework. Use when creating, modifying, or reviewing animations, transitions, motion, or animated widgets. Covers implicit animations, explicit animations, page transitions, and Material 3 motion tokens.
| name | internationalization |
| description | Best practices for internationalization (i18n) and localization (l10n) in Flutter. |
| when_to_use | Use when adding, modifying, or reviewing ARB translations, locale setup, BuildContext l10n extensions, or RTL/directional layout support. |
| allowed-tools | Read Glob Grep |
| model | sonnet |
Internationalization (i18n) and localization (l10n) best practices for Flutter applications using Flutter's built-in localization system with ARB files as the single source of truth.
Apply these standards to ALL internationalization work:
flutter_localizations + intl, never third-party i18n librariesBuildContext extension for cleaner l10n access — use context.l10n instead of AppLocalizations.of(context)AppLocalizationsEdgeInsetsDirectional (start/end) instead of EdgeInsets (left/right) — ensures correct layout in RTL languages| Term | Definition |
|---|---|
| Locale | Set of properties defining user region, language, and preferences (currency, time, numbers) |
| Localization (l10n) | Process of adapting software for a specific language by translating text and adding regional layouts |
| Internationalization (i18n) | Process of designing software so it can be adapted to different languages without engineering changes |
Add flutter_localizations and intl as dependencies, enable generate: true in pubspec.yaml, configure l10n.yaml, create ARB files in lib/l10n/arb/, run flutter gen-l10n, and wire up MaterialApp with localizationsDelegates and supportedLocales. ARB files support simple strings, placeholders, and ICU plural syntax.
See references/setup.md for the full step-by-step setup pipeline and ARB file format examples.
Create an extension for ergonomic l10n access throughout the codebase:
extension AppLocalizationsX on BuildContext {
AppLocalizations get l10n => AppLocalizations.of(this);
}
Usage:
// Preferred
Text(context.l10n.helloWorld);
// Avoid
Text(AppLocalizations.of(context).helloWorld);
Shared widgets that live in separate packages should not depend on AppLocalizations directly. Instead, pass localized strings as constructor parameters:
// Shared widget — no l10n dependency
class ConfirmDialog extends StatelessWidget {
const ConfirmDialog({
required this.title,
required this.message,
required this.confirmLabel,
required this.cancelLabel,
super.key,
});
final String title;
final String message;
final String confirmLabel;
final String cancelLabel;
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text(title),
content: Text(message),
actions: [
TextButton(onPressed: () => Navigator.pop(context), child: Text(cancelLabel)),
FilledButton(onPressed: () => Navigator.pop(context, true), child: Text(confirmLabel)),
],
);
}
}
// App-level usage — passes localized strings
showDialog<bool>(
context: context,
builder: (_) => ConfirmDialog(
title: context.l10n.deleteTitle,
message: context.l10n.deleteMessage,
confirmLabel: context.l10n.confirm,
cancelLabel: context.l10n.cancel,
),
);
Use EdgeInsetsDirectional (start/end) instead of EdgeInsets (left/right) for all padding and margins. Use directional widget variants (PositionedDirectional, AlignDirectional, BorderDirectional) for RTL-aware layouts. Icons mirror automatically in RTL; images require matchTextDirection: true.
See references/directionality.md for the full directionality guide including visual vs directional widgets, icon/image mirroring rules, and Material Design bidirectionality standards.
Store backend content with per-locale translations and require clients to transmit the user's locale. For error messages, map HTTP status codes or custom backend error constants to l10n keys on the frontend.
See references/backend.md for multi-language content storage patterns and error message localization approaches.
app_<locale>.arb in lib/l10n/arb/ (e.g., app_fr.arb)flutter gen-l10nAppLocalizations.supportedLocalesapp_en.arb)@key metadata with description and placeholders if neededflutter gen-l10ncontext.l10n.newKey"type": "int"context.l10n.itemCount(items.length)| Package | Purpose |
|---|---|
flutter_localizations | Flutter's built-in localization support |
intl | Internationalization utilities |
| Command | Purpose |
|---|---|
flutter gen-l10n | Generate localization classes from ARB files |
| File | Purpose |
|---|---|
l10n.yaml | Localization configuration (ARB dir, output, etc.) |
app_en.arb | Template ARB file (source of truth) |
app_<locale>.arb | Translated ARB file for each locale |