Flutter apps keep their translations in ARB files: one JSON file per language, with the English template on one side and app_ar.arb, app_fr.arb and the others next to it. flutter gen-l10n reads them and generates the Dart code. When a file is badly broken, gen-l10n refuses it and you fix it. That part is fine.
The trouble is everything gen-l10n accepts without a word. A key defined twice in the same file: JSON parsers keep the last one silently, and the first translation is gone. An Arabic message that is still the English text, because someone copied the template and forgot one line. A translation that renamed {user} to {usr}. An Arabic plural with only one and other, when Arabic needs six categories. A key that no Dart file has used for a year.
None of these fail the build. They show up later, as a wrong sentence on a user's screen.
arb-lint is a linter and formatter for ARB files. It catches what flutter gen-l10n rejects, and what it silently lets through.
What it does
A run on the project's own bad fixture shows the idea:
$ arb-lint tests/fixtures/bad lib/l10n/app_ar.arb:3:3: warning[rtl-untranslated]: 'title' in RTL locale 'ar' has Latin text but no RTL letters lib/l10n/app_ar.arb:4:3: error[unknown-placeholder]: 'welcome' uses {usr}, which the template does not have lib/l10n/app_ar.arb:5:3: warning[plural-missing-category]: 'cartItems': plural 'n' for locale 'ar' lacks: zero, two, few, many lib/l10n/app_en.arb:3:3: error[duplicate-key]: key 'title' is defined more than once (the last one wins) lib/l10n/app_en.arb:13:3: error[icu-syntax]: 'broken': unclosed '{' (at character 6) lib/l10n/app_en.arb:15:3: warning[unused-key]: 'neverUsed' is not referenced in Dart code under lib lib/l10n/app_es.arb:1:23: error[invalid-json]: trailing comma at line 1 column 23 ... 6 error(s), 13 warning(s) Each finding has a file, a line, a column, a severity and a rule name. The rules fall into a few groups.
File-level errors. invalid-json for a file that is not a JSON object (trailing commas and so on). duplicate-key for a key defined twice. invalid-message and invalid-metadata for a non-string message or a malformed @key.
ICU syntax. icu-syntax reports unbalanced braces, a plural or select without other, a bad plural category, or a duplicate case.
Placeholders. undeclared-placeholder is an error when the template uses {x} without declaring it in @key.placeholders. unused-placeholder warns about a declared one that is never used. unknown-placeholder is an error when a translation uses a placeholder the template lacks, and missing-placeholder warns when a translation drops one.
Template against translations. missing-translation and extra-key report key sets that differ from the template. orphan-metadata is a @key without a message. empty-message is an empty translation. locale-mismatch is a @@locale that disagrees with the file name. missing-description appears with --require-descriptions.
Plurals. plural-missing-category checks the CLDR categories required by the locale. Arabic needs zero, one, two, few, many and other, and =0, =1 and =2 count as zero, one and two.
Unused keys. unused-key reports a template key that is never referenced in Dart code.
Right-to-left checks. rtl-untranslated flags a message in an RTL locale (ar, fa, he, ur and others) that has Latin text and no RTL letters. rtl-bidi-controls flags unbalanced embedding, override or isolate control characters.
A formatter. --fix puts translations in the template's key order, places each @key right after its message, puts @@ attributes first, adds a missing @@locale from the file name, and normalizes to 2-space JSON with a final newline. It never changes values and never adds or removes messages.
How to use it
Install it from GitHub with Cargo:
cargo install --git https://github.com/AbdeldjalilChougui/arb-lint --locked Then run it in a Flutter project:
arb-lint # in a Flutter project (reads l10n.yaml, scans lib/ for unused keys) arb-lint lib/l10n --template app_en.arb arb-lint --format sarif > arb.sarif # GitHub code scanning arb-lint --format json arb-lint --fix # canonical formatting, then lint arb-lint --deny-warnings --require-descriptions # strict CI mode The exit status is made for CI: 0 when clean or with only warnings, 1 for errors (or warnings with --deny-warnings), 2 for usage or IO problems.
The README also documents a GitHub Action:
- uses: actions/checkout@v5 - uses: AbdeldjalilChougui/arb-lint@v0.1.1 with: path: . # Flutter project root or a directory of .arb files fail-on: warning # error (default) | warning | never Its inputs are path, format (text, json or sarif), output, fail-on, template, require-descriptions, args for extra flags, and version. With format: sarif and GitHub's upload-sarif action, findings appear in GitHub code scanning, attached to the right file and line.
How it works
-
l10n.yamlis read forarb-dirandtemplate-arb-file, with Flutter's defaults. The template can also be guessed:app_en.arb, then anyenfile, then the file with the most metadata. - JSON is parsed with key order preserved. A second pass with a custom serde visitor finds duplicate keys, which a normal parser would hide.
-
icu.rsis a small recursive-descent parser for the ICU MessageFormat subset that gen-l10n accepts: arguments,plural(with=Nand#),select, and nesting. - For unused keys, every identifier after a
.in non-generated.dartfiles underlib/is collected, and template keys that never appear are reported. - SARIF 2.1.0 output includes rule metadata and file, line and column locations.
Things to know
- Unused-key detection is a heuristic. Keys built dynamically, for example with
lookup(name), are reported as unused.--no-unusedturns the check off. - Apostrophe escaping is not modelled. With
use-escaping: true, gen-l10n treats quotes specially. arb-lint treats quotes as literal text, as in gen-l10n's default. - Placeholder
typeandformatvalues are not validated. - Positions are per key. Only top-level keys get line and column positions. An error inside a message is reported as a character offset.
What is tested. cargo test runs unit tests for the ICU parser, the plural tables, locale detection, positions and the formatter. Two fixture projects are checked through the CLI in text, JSON and SARIF formats: tests/fixtures/good, a clean project that must also pass under the strict flags, and tests/fixtures/bad, which triggers every rule. There is also a --fix round trip.
Why I built it
Translation bugs are quiet. The compiler is happy, the tests pass, and the mistake sits in a language the developer may not read on a screen they rarely open. Arabic makes this sharper. An Arabic file with a line left in English looks fine in a diff, and a plural with two forms works for 1 and for 100 but reads wrong for 2, for 5 and for 11.
Reviewing ARB files by eye does not scale past a few dozen keys, and it should not be a human's job anyway. These are mechanical checks: compare key sets, parse the ICU syntax, look up the plural categories for the locale, see whether a message in an RTL locale has any RTL letters. I wanted them to run in CI on every pull request, with exact file and line positions, and with a formatter so that diffs between language files stay small and aligned with the template.
Get the code
The source, the fixtures and the action definition are on GitHub: https://github.com/AbdeldjalilChougui/arb-lint. It is MIT licensed. If the linter flags something that gen-l10n handles correctly, or misses something it should catch, an issue with a small ARB sample is the fastest way to get it fixed.
Originally published at abdeldjalilchougui.biz.
