Repository navigation
[gen_l10n] Add use-explicit-plural-values option - #194816
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Adds an opt-in `use-explicit-plural-values` option to `flutter gen-l10n`. When enabled, explicit plural values such as `=0` and `=1` match only that exact count and take precedence over plural categories, as specified by ICU. Previously they were mapped to the `zero`, `one` and `two` categories, which `Intl.pluralLogic` also selects for other counts in many locales (for example `one` covers 21 and 31 in Ukrainian, and 0 in French). With the option enabled, any non-negative integer can be used as an explicit value, and explicit values no longer collide with the plural category of the same name. The default behavior is unchanged.
fbf8b4d to
db67848
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces a new option, use-explicit-plural-values, to the Flutter localization generator. When enabled, explicit plural cases (such as =1) are treated as exact-match checks that take precedence over plural categories (such as one), rather than being mapped directly to those categories. This change updates the command-line arguments, YAML configuration parsing, code generation templates, and parser logic, and includes comprehensive unit tests to verify the new behavior. There are no review comments, so no additional feedback is provided.
bkonyi
left a comment
There was a problem hiding this comment.
Thanks for putting this together! The approach is sound, and making this an opt-in option is the right choice so existing ARB files aren't silently broken in locales like Ukrainian or French.
I've left a few comments below on a template placeholder substitution bug that corrupts translated messages containing @(count) or @(pluralLogicArgs), along with a missing CLI forwarding test. Once those are addressed, this should be good to go!
- Substitute `@(explicitPluralCases)` last and only once, so message text containing template placeholders such as `@(count)` is not rewritten. - Add a command test for `--use-explicit-plural-values`. - Simplify test expectations and remove a redundant test.
bkonyi
left a comment
There was a problem hiding this comment.
LGTM! Thanks for the quick turnaround on the feedback!
flutter/flutter@fffd8c2...b98afb5 2026-11-11 [email protected] Roll Dart SDK from 172cf8f121c0 to 8f15c4ca2d41 (1 revision) (flutter/flutter#196367) 2026-11-11 [email protected] Roll Skia from 657283e78115 to cc4c54f752ba (5 revisions) (flutter/flutter#196365) 2026-11-11 [email protected] Roll Skia from 2605c4a9761c to 657283e78115 (1 revision) (flutter/flutter#196358) 2026-11-11 [email protected] Roll Dart SDK from 890c6d15334c to 172cf8f121c0 (1 revision) (flutter/flutter#196352) 2026-11-11 [email protected] [flutter_tools] Migrate general.shard project, runner, and web tests off globals (flutter/flutter#196128) 2026-11-11 [email protected] [flutter_tools] Migrate test helpers and integration tests off globals (flutter/flutter#196124) 2026-11-11 [email protected] [web] Report skwasm WebGL context creation failure instead of hanging (flutter/flutter#193293) 2026-11-11 [email protected] [flutter_tools] Migrate commands.shard tests off globals (flutter/flutter#196139) 2026-11-11 [email protected] [devicelab] Fix memory benchmark tap synchronization and swipe flakes (flutter/flutter#194457) 2026-11-11 [email protected] Roll Skia from 06062e36d938 to 2605c4a9761c (2 revisions) (flutter/flutter#196350) 2026-11-11 [email protected] Do not wait again for a closed mock event stream in tear down (flutter/flutter#196110) 2026-11-11 [email protected] [gen_l10n] Add `use-explicit-plural-values` option (flutter/flutter#194816) 2026-11-11 [email protected] Roll Skia from 7bd33f8a3b70 to 06062e36d938 (2 revisions) (flutter/flutter#196340) 2026-11-11 [email protected] Skip redundant work in plugin_test_* (flutter/flutter#196258) 2026-11-10 [email protected] Drop test_timeout_secs from shards that no longer need it (flutter/flutter#196277) 2026-11-10 [email protected] Roll Dart SDK from 15c1699d3eeb to 890c6d15334c (1 revision) (flutter/flutter#196321) 2026-11-10 [email protected] iOS: Extract FlutterPlatformViewsController platform-thread state to Obj-C (flutter/flutter#196142) 2026-11-10 [email protected] Remove `Mac web_tool_tests` and take new subshard builders out of bringup (flutter/flutter#196276) 2026-11-10 [email protected] Roll Skia from 9c3d43d8a04b to 7bd33f8a3b70 (12 revisions) (flutter/flutter#196317) 2026-11-10 [email protected] Take customer_testing_devtools out of bringup (flutter/flutter#196239) 2026-11-10 [email protected] Roll ICU from a0ea93436c52 to b09986242cfb (1 revision) (flutter/flutter#196316) 2026-11-10 [email protected] [flutter_tools] Avoid unlinking native_assets.json and handle EXDEV (flutter/flutter#196134) 2026-11-10 [email protected] Remove old `Windows tool_integration_tests` builders and take the new shards out of bringup (flutter/flutter#196275) 2026-11-10 [email protected] [SwiftPM] Disable tests for when settings fail to compile (flutter/flutter#196310) 2026-11-10 [email protected] Roll Fuchsia Test Scripts from PXc5D7S_q6sIYpfFJ... to oEU515sDqSTvD8Spx... (flutter/flutter#196289) 2026-11-10 [email protected] Fix ime insets animation jump (flutter/flutter#191453) 2026-11-10 [email protected] Link to original PR in automatic cherry-pick PRs (flutter/flutter#196130) 2026-11-10 [email protected] Roll Packages from 565c657 to 08faf64 (9 revisions) (flutter/flutter#196296) 2026-11-10 [email protected] Roll Skia from b11315d0a096 to 9c3d43d8a04b (45 revisions) (flutter/flutter#196295) 2026-11-10 [email protected] Replace type-specific window widgets with a single Window widget (flutter/flutter#196002) 2026-11-10 [email protected] Roll Dart SDK from a2baae273bb2 to 15c1699d3eeb (2 revisions) (flutter/flutter#196294) If this roll has caused a breakage, revert this CL and set the roller to dry run mode using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter gen-l10ncurrently maps the ICU explicit plural values=0,=1and=2to the CLDR plural categorieszero,oneandtwo. In many localesIntl.pluralLogicselects those categories for more than the exact number, so a message such asshows "exactly one" for 21, 31 and 101 in Ukrainian, and for 0 in French. In ICU and CLDR, an explicit value matches only that exact number and takes precedence over the plural categories. Because of the mapping,
=1andonealso cannot be used in the same message (one of them is dropped with an "overridden by a later plural part" warning), and explicit values other than 0, 1 and 2 are rejected.This PR adds an opt-in
use-explicit-plural-valuesoption (l10n.yamland--use-explicit-plural-values). When it is enabled, explicit values are generated as exact checks in front of theIntl.pluralLogiccall, and only the category cases are passed toIntl.pluralLogic:With the option enabled:
=3or=10.=1andone, can be used in the same message without a warning.Intl.pluralLogicalready applies tozero,oneandtwo.The option defaults to
false, and the generated code is unchanged when it is off. As discussed in #84291, changing the default would be a breaking change, so that is left for a follow-up.The generated code uses conditional expressions rather than a switch expression so that it still compiles in packages that use older language versions.
Fixes #84291
Related: #133276 (in Latvian,
=0is currently also used for 10-20 because it is mapped to thezerocategory; this no longer happens when the option is enabled)Website documentation: flutter/website#13993
Tests
dart test test/general.shard/generate_localizations_test.dart test/general.shard/build_system/targets/localizations_test.dart test/commands.shard/hermetic/generate_localizations_test.dart test/general.shard/message_parser_test.dart test/integration.shard/gen_l10n_test.dartdart analyze --fatal-infosanddart format --output=none --set-exit-if-changedon the changed filesen,frandukARB files. With the option enabled,=1is used only for 1 in Ukrainian (21, 31 and 101 fall through to the category cases) and=0is used for 0 in French. With the option disabled, the behavior is unchanged.AI assistance disclosure
AI tools (Cursor) assisted with the implementation, tests and verification.
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.