Flutter localization with ARB files

Flutter localization is built in. The gen-l10n tool reads Application Resource Bundle files, one app_<locale>.arb per language, and generates a Dart class your widgets call for every string, while flutter_localizations supplies the Material and Cupertino widgets' own translations.

What an ARB file holds

An ARB file is JSON. Plain keys are messages. A key starting with @ holds metadata for the message of the same name, such as a description for translators. @@locale names the language of the file.

LocalizeMe writes @@locale on every export and turns each key's description into its @key block, so translator notes survive the round trip.

lib/l10n/app_de.arb
{
  "@@locale": "de",
  "checkoutPayButton": "Jetzt bezahlen",
  "@checkoutPayButton": {
    "description": "Primary button on the checkout screen"
  }
}

Setting up gen-l10n

Point l10n.yaml at the folder with your ARB files and name the template file. Flutter generates AppLocalizations from it on the next build.

l10n.yaml
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart

Plurals in ARB files

Flutter expresses plurals as ICU messages inside one value. LocalizeMe stores plurals as one key per form instead, and reads camel-case plural keys such as itemCountOne and itemCountOther from an imported ARB file. The ARB export writes each form as its own key today, not as an ICU message, so plural messages need a template you maintain in code for now.

Keeping ARB files out of merge conflicts

Pull the ARB files before running flutter gen-l10n, and translators never touch the repository.

terminal
localizeme init --project 42 --format arb --path 'lib/l10n/app_{locale}.arb'
localizeme pull
flutter gen-l10n

Questions

Does the export keep translator descriptions?

Yes. A key's description in LocalizeMe is written to its @key block, and metadata entries are ignored on import, so they never come back as keys.

Can I import existing ARB files?

Yes. Messages import as keys, @ entries are skipped, and camel-case plural keys are recognised as plural forms.

Other guides

Unlimited strings, one flat price

LocalizeMe never counts keys, strings or languages. Try Pro free for 14 days, no card needed.