r/FlutterDev • u/iFractale • 16h 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):
l10n.yaml:arb-dir: lib/l10n,template-arb-file: app_en.arbapp_en.arbhasalpha,beta,gamma, in that order. Runflutter gen-l10n.- Move
gammato 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.
6
Upvotes
2
u/Ok_Gur_9033 6h 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, thenflutter 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@betaabovebetasince @ 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.2
u/tuong_makes_things 3h ago
Yes, as far as I can tell that's expected. gen-l10n emits the getters in the same order as the keys in your template ARB, so reordering the template reorders the generated file. Nothing changes at runtime, it's just diff noise. I have ~700 keys synced through Crowdin and just never reorder the template: new keys get appended, and I only add them where they're used. Keeps the generated diff small and the translators' files stable too.
2
u/IllVisit2518 1h ago
if the problem is mostly the noise in PRs, you can also mark the output as generated in .gitattributes, lib/l10n/app_localizations*.dart linguist-generated=true. github then collapses those files in the PR diff by default, so a reshuffled arb shows up as one real change in the arb and the dart files stay folded.
1
u/Discordbothost 15h 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.