Plural rendering: first matching part wins, but gen-l10n lets the last one win (=1 shadows one)
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
Línea de trabajo
Encuentra Extractor._getPlural y las pruebas de representación de plurales en el Flutter SDK. Compara la selección de ramas con el comportamiento de gen-l10n descrito en el issue y luego reproduce el caso croata con count 21 y count 1. Se considera terminado cuando las partes coincidentes posteriores tienen prioridad y ambos resultados coinciden con gen-l10n.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Dart
- Estrellas
- 37
- Forks
- 14
- Merge medio
- 3 h 37 min
- PR fusionados (30 d)
- 5
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Issues similares
-
Python example: list a model's scenes and their camerasPosiblemente ocupada @rudraparmar76 la tomó hoy. Abiertodocumentation good first issue python
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
iamahsanmehmood/openskp#796 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
documentation priority: low
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
Los mantenedores suelen responder en 1 día
-
needs triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 63/100
MrSpideyNihal/lockfeed#16 ·
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
InlitX/GymMane#529 · 1 comentario ·
Los mantenedores suelen responder en 1 día