This tool automates the generation of localization files in a Flutter project. It updates the l10n.yaml file, validates ARB files, and runs flutter gen-l10n to generate the necessary Dart files for localization.
Ensure you have the following installed:
- Flutter (latest stable version)
- Dart (included with Flutter)
- Logging package (pre-installed with Flutter)
- Clone this repository or download the script.
- Move the script to your project’s
bin/directory. - Make the script executable:
chmod +x bin/flutter_localisation.dart
To generate localization files, run:
dart run bin/flutter_localisation.dart <flavors-folder> <flavor-name>dart run bin/flutter_localisation.dart lib/l10n defaultThis will:
- Check if the specified flavor folder exists.
- Validate or create the
l10n.yamlfile. - Validate that
.arbfiles exist in the folder. - Run
flutter gen-l10nto generate the localization files.
Ensure your localization files are structured as follows:
lib/
├── l10n/
│ ├── default/
│ │ ├── app_en.arb
│ │ ├── app_fr.arb
│ ├── other_flavor/
│ ├── app_en.arb
│ ├── app_es.arb
├── localization/
│ ├── generated/
│ ├── app_localizations.dart
{
"@@locale": "en",
"hello_world": "Hello, World!"
}After running the script, you should find the generated localization files inside lib/localization/generated/.
- Missing arguments: Ensure both
<flavors-folder>and<flavor-name>are provided. - Invalid folder path: The specified flavor folder must exist.
- Missing ARB files: The script requires
.arbfiles in the flavor directory. - Flutter command errors: If
flutter gen-l10nfails, check for syntax issues inl10n.yamlor ARB files.
- This tool modifies
l10n.yaml. If you prefer using command-line options, remove the file. - Supports multiple flavors by specifying different folders.
This tool is open-source and available for modification.