flutter-setup-localization

Add `flutter_localizations` and `intl` dependencies, enable "generate true" in `pubspec.yaml`, and create an `l10n.yaml` configuration file. Use when initializing localization support for a new Flutter project.

By flutter · 30,015 installs

npx skills add flutter/agent-plugins --skill flutter-setup-localization

Source repository · Upstream listing

Internationalizing Flutter Applications Contents [Core Concepts]( core concepts) [Setup Workflow]( setup workflow) [Implementation Workflow]( implementation workflow) [Advanced Formatting]( advanced formatting) [Examples]( examples) Core Concepts Flutter handles internationalization (i18n) and localization (l10n) via the flutter localizations and intl packages. The standard approach uses App Resource Bundle ( .arb ) files to define localized strings, which are then compiled into a generated AppLocalizations class for type safe access within the widget tree. Setup Workflow Copy and track this checklist when initializing internationalization in a Flutter project: [ ] Task Progress [ ] 1. Add dependencies to pubspec.yaml . [ ] 2. Enable the generate flag. [ ] 3. Create the l10n.yaml configuration file. [ ] 4. Configure MaterialApp or CupertinoApp . 1. Add Dependencies Add the required localization packages to the project. Execute the following commands in the terminal: Verify your pubspec.yaml includes the following under dependencies : 2. Enable Code Generation Open pubspec.yaml and enable the generate flag within the flutter section to automate localization tasks: 3. Create Configuration File Create a new file named l10n.yaml in the root directory of the Flutter project. Define the input directory, template file, and output file: 4. Configure the App Entry Point Import the generated localizations and the flutter localizations library in your main.dart . Inject the delegates and supported locales into your MaterialApp or CupertinoApp . Implementation Workflow Follow this workflow when adding or modifying localized content. 1. Define ARB Files If creating NEW content: Add the base string to the template file ( lib/l10n/app en.arb ). Include a description for context. If EDITING existing content: Locate the key in all supported .arb files and update the values. Create corresponding files for other locales (e.g., app es.arb ): 2. Generate Localization Classes Run the following command to trigger code generation: Feedback Loop: Run validator review terminal output for ARB syntax errors fix missing commas or mismatched placeholders re run flutter pub get . 3. Consume Localized Strings Access the localized strings in your widget tree using AppLocalizations.of(context) . Ensure the widget calling this is a descendant of MaterialApp . Advanced Formatting Use placeholders for dynamic data, plurals, and conditional selects. Placeholders Define parameters within curly braces and specify their type in the metadata object. Plurals Use the plural syntax to handle quantity based string variations. The other case is mandatory. Selects Use the select syntax for conditional strings, such as gendered text. Examples Complete l10n.yaml Complete Widget Implementation