Skip to content

Instantly share code, notes, and snippets.

@sullenel
Last active August 20, 2022 10:41
Show Gist options
  • Save sullenel/5d3eb4ce26f75d35f9faab266a541915 to your computer and use it in GitHub Desktop.
Save sullenel/5d3eb4ce26f75d35f9faab266a541915 to your computer and use it in GitHub Desktop.
Flutter I18n Setup

Flutter I18n Setup

  1. Add dependencies to pubspec.yaml
dependencies:
  flutter_localizations:
    sdk: flutter
  intl: ^0.17.0
  1. Add the following to pubspec.yaml
flutter:
  generate: true
  1. 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
  1. Add the app_en.arb template file to lib/l10n
  2. Run flutter gen-l10n (not sure if needed though)
  3. Use AppLocalizations in MaterialApp
const MaterialApp(
  locale: const Locale('en'),
  localizationsDelegates: AppLocalizations.localizationsDelegates,
  supportedLocales: AppLocalizations.supportedLocales,
);
  1. Add the following to .gitignore
lib/l10n/*.dart
untranslated_messages.txt

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment