r/FlutterDev • • 12h ago

Discussion flutter gen-l10n output changes when I reorder keys in the template ARB. Is that intended?

I noticed that moving keys around in app_en.arb changes the generated Dart files, even though key order has no meaning in ARB.

Minimal repro (Flutter 3.44.9):

  1. l10n.yaml: arb-dir: lib/l10n, template-arb-file: app_en.arb
  2. app_en.arb has alpha, beta, gamma, in that order. Run flutter gen-l10n.
  3. Move gamma to the top and run it again.

The getters in app_localizations_en.dart and the abstract getters in app_localizations.dart come out in the new order. So sorting or reorganizing an ARB file shows up as a diff in generated code.

Is this known or intended? I'd expect stable output, such as sorting by key. I can't file this on GitHub, so I'm asking here in case someone can confirm it or open an issue.

3 Upvotes

2 comments sorted by

2

u/Ok_Gur_9033 3h ago

Still happens on 3.50.2, I just ran your repro. Moving gamma to the top moved its getter in app_localizations_en.dart.

What worked when I tried it is sorting the template before generating: jq -S . lib/l10n/app_en.arb > tmp && mv tmp lib/l10n/app_en.arb, then flutter gen-l10n. The output came out byte-identical to the alphabetical original. The one thing I checked because I expected it to break: jq puts @beta above beta since @ sorts first, and gen-l10n didn't care. The description and the placeholder still came through. As a pre-commit step that keeps the generated files stable however people shuffle the ARB.

1

u/Discordbothost 12h ago

Keep a fixed order in the template ARB to avoid that churn. In 3.44.9, gen_l10n builds its message list from the template's resourceIds without sorting them. That explains the output; it doesn't establish whether it's intentional.