airglot_l10n_gen

Generates the airglot_l10n overlay for an app's gen-l10n AppLocalizations.

flutter gen-l10n
dart run airglot_l10n_gen

It reads l10n.yaml and the template ARB and writes airglot_localizations.g.dart next to gen-l10n's output, with:

  • AirglotAppLocalizations, which extends the generated class and resolves every getter and method through the over-the-air layers;
  • airglotSourceHashes, and a hash over the template ARB, the l10n.yaml options that change the overlay and the generator version;
  • the Flutter version whose gen-l10n output it was generated against. The generator warns when a regeneration changes it, and debug builds of the app report flutterVersionChanged through onReport when the app is built with a different Flutter;
  • AirglotLocalizationsDelegate, the airglot.delegate getter, and airglotLocalizationsDelegates(airglot), which replaces AppLocalizations.localizationsDelegates;
  • airglotLookupAppLocalizations(airglot, locale), for code outside the widget tree.

Code outside the widget tree

Calling gen-l10n's lookupAppLocalizations(locale) directly bypasses the overlay. Call airglotLookupAppLocalizations(airglot, locale) instead: it resolves through the same layers as the delegate, so remote strings come back.

final l10n = airglotLookupAppLocalizations(airglot, const Locale('es'));

Generation fails, naming the option or message, on use-deferred-loading: true, synthetic-package: true, an unknown l10n.yaml option, locale placeholder metadata that differs from the template, and messages gen-l10n compiles wrongly or not at all (a stray }, a duplicated select case, an unsupported plural case).

Installing

Depend on both packages from pub.dev:

dependencies:
  airglot_l10n: ^1.0.0
dev_dependencies:
  airglot_l10n_gen: ^1.0.0

A vendored copy of either package needs a dependency_overrides entry in the app's pubspec.yaml pointing airglot_l10n at the vendored path. Inside this repository the generator's own pubspec_overrides.yaml does the same.

Keeping the overlay current

The overlay's source hashes decide which remote translations a build accepts, so a stale overlay can let a translation of old copy through. Commit the generated file and check it in CI, after flutter gen-l10n:

flutter gen-l10n
dart run airglot_l10n_gen --check

The generator writes the file as dart format would, using the language version from the app's pubspec.yaml SDK constraint, so a format gate leaves it alone. --check compares formatted output, so it also passes after dart format has reflowed the file.

--check writes nothing and exits 1 when the file is missing or would change: after an edit to any ARB file or to l10n.yaml, a generator upgrade, or a Flutter upgrade. Debug builds also report overlayStale through onReport when the compiled source-locale strings no longer match the overlay.

Libraries

airglot_l10n_gen