$npx -y skills add MADTeacher/mad-agents-skills --skill flutter-internationalizationAdd, fix, audit, and maintain Flutter internationalization with gen-l10n, ARB files, AppLocalizations, flutter_localizations, intl formatting, plural/select messages, RTL support, locale-specific number/date formatting, and localization build errors. Use when asked to add l10n or
| 1 | # Flutter Internationalization |
| 2 | |
| 3 | You are a Flutter localization implementer. Make localized apps build, generate, |
| 4 | and read naturally across target locales. |
| 5 | |
| 6 | ## Principle 0 |
| 7 | |
| 8 | Generated localization code must match the current Flutter project and SDK. Do |
| 9 | not copy stale `package:flutter_gen` imports or enable `synthetic-package`; use |
| 10 | source-generated `AppLocalizations` imports unless the project proves it is on an |
| 11 | older pinned Flutter workflow. |
| 12 | |
| 13 | ## Decision Guide |
| 14 | |
| 15 | - Use `gen-l10n` for new work, most migrations, ARB management, plural/select |
| 16 | messages, generated `AppLocalizations`, and Material/Cupertino apps. |
| 17 | - Use legacy `intl_translation` only when the project already uses |
| 18 | `Intl.message()` plus generated `messages_all.dart`, or the user explicitly |
| 19 | asks to keep that workflow. Confirm `intl_translation` is a dependency before |
| 20 | running its generators. |
| 21 | - Use custom map-based localizations only for tiny prototypes or existing code |
| 22 | that intentionally avoids code generation. Name this limitation in the final |
| 23 | response. |
| 24 | - If the project has an existing localization setup, follow its paths, class |
| 25 | names, locale list, and generation style before introducing defaults. |
| 26 | |
| 27 | ## Workflow |
| 28 | |
| 29 | 1. Inspect `pubspec.yaml`, `l10n.yaml`, existing `*.arb` files, generated imports, |
| 30 | `MaterialApp`/`CupertinoApp` setup, and current translation usage. |
| 31 | 2. Identify the requested change: bootstrap l10n, add a locale, replace hardcoded |
| 32 | UI text, add placeholders/plurals/selects, format values, fix generation, or |
| 33 | migrate stale imports/config. |
| 34 | 3. Use the decision guide to choose `gen-l10n`, legacy `intl_translation`, or a |
| 35 | custom fallback. Prefer the smallest change that fits the existing project. |
| 36 | 4. Read only the routed references needed for the task. |
| 37 | 5. Make the localization change: |
| 38 | - add `flutter_localizations` and `intl:any` when missing; |
| 39 | - set `flutter: generate: true`; |
| 40 | - create or update `l10n.yaml`; |
| 41 | - create or update ARB files with descriptions and placeholder metadata; |
| 42 | - wire `AppLocalizations` into `MaterialApp` or `CupertinoApp`; |
| 43 | - replace hardcoded UI strings with generated getters or methods. |
| 44 | 6. Generate and validate with `flutter gen-l10n`. Then run the narrowest relevant |
| 45 | project check, usually `flutter analyze` or affected tests. |
| 46 | 7. Report changed files, generated behavior, validation run, and any locales or |
| 47 | translation gaps that remain. |
| 48 | |
| 49 | ## Resource Routing |
| 50 | |
| 51 | | Task | Read or use | Why | |
| 52 | |---|---|---| |
| 53 | | Configure or debug `l10n.yaml`, generated output paths, nullable getters, deferred loading, or untranslated tracking | `references/l10n-config.md` | Current gen-l10n options and safe defaults | |
| 54 | | Create or repair ARB messages, placeholders, plurals, selects, escaping, or metadata | `references/arb-format.md` | ARB schema patterns and translator context rules | |
| 55 | | Add number, currency, percent, or date/time formatting | `references/number-date-formats.md` | Supported `NumberFormat` and `DateFormat` values | |
| 56 | | Bootstrap a new gen-l10n setup or run a smoke fixture | `assets/l10n.yaml`, `assets/app_en.arb` | Reusable minimal templates | |
| 57 | |
| 58 | ## gen-l10n Contract |
| 59 | |
| 60 | For new gen-l10n setup, the minimum current configuration is: |
| 61 | |
| 62 | ```yaml |
| 63 | flutter: |
| 64 | generate: true |
| 65 | ``` |
| 66 | |
| 67 | ```yaml |
| 68 | arb-dir: lib/l10n |
| 69 | template-arb-file: app_en.arb |
| 70 | output-localization-file: app_localizations.dart |
| 71 | ``` |
| 72 | |
| 73 | Use source imports that match the generated location, commonly: |
| 74 | |
| 75 | ```dart |
| 76 | import 'l10n/app_localizations.dart'; |
| 77 | ``` |
| 78 | |
| 79 | Prefer generated lists when possible: |
| 80 | |
| 81 | ```dart |
| 82 | localizationsDelegates: AppLocalizations.localizationsDelegates, |
| 83 | supportedLocales: AppLocalizations.supportedLocales, |
| 84 | ``` |
| 85 | |
| 86 | If generated files are written to a custom `output-dir`, update imports to that |
| 87 | directory. Do not import `package:flutter_gen/gen_l10n/app_localizations.dart` |
| 88 | unless the local project is intentionally pinned to an older Flutter workflow. |
| 89 | |
| 90 | ## Legacy Intl Fallback |
| 91 | |
| 92 | When preserving `Intl.message()`: |
| 93 | |
| 94 | - require `intl_translation` in dev dependencies before extraction/generation; |
| 95 | - keep generated files and imports consistent with the existing project; |
| 96 | - run extraction before generation; |
| 97 | - on Windows or shells without wildcard expansion, list ARB files explicitly. |
| 98 | |
| 99 | Typical commands: |
| 100 | |
| 101 | ```bash |
| 102 | dart run intl_translation:extract_to_arb --output-dir=lib/l10n lib/main.dart |
| 103 | dart run intl_translation:generate_from_arb --output-dir=lib/l10n --no-use-deferred-loading lib/main.dart lib/l |