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

Aperta Adatta ai principianti
#97 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
dart, flutter

Direzione di ricerca

Trova Extractor._getPlural e i test di rendering dei plurali nel Flutter SDK. Confronta la selezione dei rami con il comportamento di gen-l10n descritto nell’issue, poi riproduci il caso croato con count 21 e count 1. Il lavoro è concluso quando le parti corrispondenti successive hanno la precedenza e entrambi i risultati corrispondono a gen-l10n.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Dart
Stelle
37
Fork
14
Merge medio
3h 37m
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Issue simili

Altre issue su Dart

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.