plural_lint is a developer tool to check plural translations in your project. It detects both missing and unused plural quantities in the ARB files for each locale according to the Unicode CLDR plural rules.
plural_lint bases on custom_lint. To use it, you have 2 options.
Either add the dependencies to your pubspec.yaml
:
dev_dependencies:
custom_lint:
plural_lint:
Or install them from the command line:
flutter pub add --dev custom_lint plural_lint
Next, enable the custom_lint
analyzer plugin in your analysis_options.yaml
:
analyzer:
plugins:
- custom_lint
This lint detects missing plural quantities in your translations. For example in English (en
),
you need to provide translations for one
and other
quantities. In Polish (pl
),
you need one
, few
, many
and other
.
If you don't provide all the required quantities the lint will report that as a warning.
For instance, the following entry in English ARB file:
{ "things" : "{count, plural, other{things}}" }
Will trigger a warning:
warning: These quantities: [one] are missing for locale: en (missing_quantity at [app] lib/l10n/intl_en.arb:3)
This lint detects unused plural quantities in your translations. For example in English (en
),
few
and many
quantities will never be used. Note that zero
, one
and two
are supported by dart's intl package in all languages. Even if
they are not listed in CLDR rules.
For example you can provide zero
quantity in English despite that English doesn't distinguish
a special case for zero. See intl implementation
for more details.
For instance, the following entry in English ARB file:
{ "things2" : "{count, plural, one{thing} few{things} many{things} other{things}}" }
Will trigger a warning:
info: These quantities: [few, many] are not used in locale: en (unused_quantity at [app] lib/l10n/intl_en.arb:4)
This package has embedded CLDR rules for plural forms in plurals.xml. That file is taken from the official Unicode CLDR repository.
By default all the lints are be enabled. You can disable specific rules by modifying
the analysis_options.yaml
file like this:
custom_lint:
rules:
- unused_quantity: false
- missing_quantity: false
Custom lint rules may not show-up in dart analyze
.
To fix this, invoke a custom_lint
in the terminal:
dart run custom_lint