-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Use case
Hi!
Internationalization of Flutter apps is getting more and more convenient thanks to the enhancements implemented during the last months. More recently, #86167 allowed to use plural and select in the middle of a string which is super useful.
However while internationalizing this app on top of this recent change, I noted a few cases for which it didn't produce the expected result:
"pluralThenString": "Indeed, {count, plural, =1 {she likes} other {they like}} {framework} a lot!",
"@pluralThenString": {
"placeholders": {
"count": {},
"framework": {
"type": "String"
}
}
},
"multiplePlurals": "There {count, plural, =1{is} other{are}} {count} world{count, plural, =1{} other{s}}.",
"@multiplePlurals": {
"placeholders": {
"count": {}
}
},
"pluralInSelect": "I can see {fruit, select, apple{{count, plural, =0{no apple} =1{one apple} other{some apples}}} banana{{count, plural, =0{no banana} =1{one banana} other{{count} bananas}}}}.",
"@pluralInSelect": {
"placeholders": {
"count": {
"type": "int"
},
"fruit": {}
}
},@override
String pluralThenString(int count, String framework) {
final String pluralString = intl.Intl.pluralLogic(
count,
locale: localeName,
one: 'she likes',
other: 'they like',
);
return 'Indeed, $pluralString a lot!';
}
@override
String multiplePlurals(int count) {
final String pluralString = intl.Intl.pluralLogic(
count,
locale: localeName,
one: 'is',
other: 'are',
);
return 'There ${pluralString}.';
}
@override
String pluralInSelect(int count, Object fruit) {
final String pluralString = intl.Intl.pluralLogic(
count,
locale: localeName,
zero: 'no apple',
one: 'one apple',
other: 'some apples',
);
return 'I can see ${pluralString}.';
}Proposal
I would like to keep developing the l10n support to make it more powerful and reduce the risk of misuse (I personally have been surprised by the first use case).
I understand that Flutter is not intended to implement the ICU format in its entirety. I think it could improve the user experience to support these use cases though. My only references are the following, where we see that multiple plurals are being used:
- Formatting Messages - ICU Documentation
- The Missing Guide to the ICU Message Format
- ICU message editor
I had started working on this improvement, but it requires some refactoring. I will open a PR so that it can be discussed.