smf_gen_l10n 0.4.0 copy "smf_gen_l10n: ^0.4.0" to clipboard
smf_gen_l10n: ^0.4.0 copied to clipboard

The SMF module of localization with gen-l10n for the Flutter app that SMF generates. It keeps the texts of the app in ARB files, one for each language.

example/README.md

Generate a Flutter app with its texts in ARB files #

gen_l10n is the module of the SMF CLI that keeps the texts of the app in ARB files, from which Flutter generates the code that reads them. Choose it with -m:

dart pub global activate smf_flutter_cli
smf create my_app -m gen_l10n --no-input

The module adds to the app:

  • l10n.yaml, the options of gen-l10n, and generate: true in pubspec.yaml, with which flutter pub get generates the AppLocalizations class in lib/l10n;
  • lib/l10n/app_en.arb with every text of the modules of the app in English, and a file for each other language that the texts are in, with the translations;
  • lib/core/l10n/l10n.dart with context.l10n, the AppLocalizations of a BuildContext.

The localization role adds lib/core/l10n/app_locale.dart with the languages of the app and the one that the user chose, and gives the root of the app its locale, its supported locales and the delegates of Flutter's own texts. The app remembers that choice in its preferences, so smf create adds shared_preferences too, the only module that provides them.

To add a text of your own, add it to lib/l10n/app_en.arb, and its translations to the files of the other languages:

{
  "@@locale": "en",
  "cartTitle": "Your cart"
}

After flutter gen-l10n, read it where a BuildContext below the root of the app is at hand:

import 'package:my_app/core/l10n/l10n.dart';

Text(context.l10n.cartTitle)

A text without a translation into a language reads in English there. Run flutter gen-l10n after every change of the ARB files, a new file included. The README of the app tells how to add a language.

Without -m, smf create asks which module provides the localization of the app.

The documentation has more on the gen_l10n module.

0
likes
160
points
0
downloads

Documentation

Documentation
API reference

Publisher

verified publishersaymyframe.com

Weekly Downloads

The SMF module of localization with gen-l10n for the Flutter app that SMF generates. It keeps the texts of the app in ARB files, one for each language.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#flutter #localization #l10n #i18n #arb

License

Apache-2.0 (license)

Dependencies

mason, smf_contracts

More

Packages that depend on smf_gen_l10n