Plural rendering: first matching part wins, but gen-l10n lets the last one win (=1 shadows one)

オープン 初心者向け
#97 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
dart, flutter

調査の方向性

Flutter SDK で Extractor._getPlural と複数形のレンダリングテストを見つけてください。分岐の選択を issue に記載された gen-l10n の動作と比較し、その後 count 21 と count 1 でクロアチア語のケースを再現してください。後に一致する部分が優先され、両方の結果が gen-l10n と一致すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bug help wanted
Description

Since 1.1.3 (#92, fixing #90), zero, one and two plural forms are rendered. When a message has both an exact part and the keyword for the same case, for example =1{…} and one{…}, Extractor._getPlural keeps the first one. Flutter's gen-l10n keeps the last one. So an over-the-air text renders differently from the same text bundled through gen-l10n.

The code comment says "The first part for a case wins, as in gen-l10n", but gen-l10n walks the parts in reverse (flutter_tools/lib/src/localizations/gen_l10n.dart, for (final Node pluralPart in pluralParts.children.reversed) together with if (!pluralLogicArgs.containsKey(...))). An earlier part is the one gen-l10n reports as "overridden by a later plural part".

This matters in practice because translations keep the source's =1 branch and add the target language's own forms after it. Crowdin exports messages like this one:

"items": "{count, plural, =1{1 artikl} one{{count} artikl} few{{count} artikla} other{{count} artikala}}"`

Steps to ### reproduce

Use a Croatian (hr) bundle with the message above, delivered over the air.
Call Crowdin.getText('hr', 'items', {'count': 21}).
Expected

21 artikl, the same as gen-l10n's AppLocalizationsHr.items(21).

Actual

1 artikl. =1 takes the one slot first, and Intl.pluralLogic(21, locale: 'hr') returns one.

The same happens for every locale whose one category covers more than the number 1:

hr, lv, lt: 21, 31, 41 …
fr, pt: 0. An empty cart shows "1 article".

Suggested ### fix

In _getPlural, let a later part overwrite an earlier one, as gen-l10n does:

final pluralCase = _pluralCases[part.children[isExact ? 1 : 0].value]; if (pluralCase == null) continue; // The last part for a case wins, as in gen-l10n. branches[pluralCase] = findPlaceholders(locale, message, '$prefix$body$suffix', args);

A regression test could render {count, plural, =1{1 x} one{{count} x} other{{count} xs}} for hr with 21 (expected 21 x) and with 1 (expected 1 x, which is gen-l10n's result too).

Environment

crowdin_sdk 1.1.3
Flutter 3.44.8

主要言語
Dart
スター
37
フォーク
14
平均マージ
3時間 37分
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

似ている issue

Dart の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。