- Add dependencies to
pubspec.yaml
dependencies:
flutter_localizations:
sdk: flutter
intl: ^0.17.0
- Add the following to
pubspec.yaml
- Add a file called
l10n.yaml
with the following content
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
# output-class: AppLocalizations
untranslated-messages-file: untranslated_messages.txt
# NOTE: AppLocalizations is nullable by default
nullable-getter: false
# NOTE: without this the output file is not generated
synthetic-package: false
# To format generated classes: https://github.com/flutter/flutter/issues/98122
format: true
- Add the
app_en.arb
template file to lib/l10n
- Run
flutter gen-l10n
(not sure if needed though)
- Use
AppLocalizations
in MaterialApp
const MaterialApp(
locale: const Locale('en'),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
);
- Add the following to
.gitignore
lib/l10n/*.dart
untranslated_messages.txt