'Flutter localisation method not generating correctly with plural placeholder
I'm currently localizing my flutter app using the intl package.
I have a localised text that contains two placeholders: userName and dayCount, where I have used the plural syntax for dayCount.
Here is the snippet from my .arb file:
"prolongationRequested": "{userName} requested prolongation by {daysCount, plural, =1{1 day} other{{daysCount} days}}",
"@prolongationRequested": {
"placeholders": {
"userName": {},
"daysCount": {}
}
},
So far so good, but the auto generated method in the AppLocalizationsEn class completely ignores everything from the text except the daysCount placeholder. This is the generated method:
String prolongationRequested(Object userName, num daysCount) {
return intl.Intl.pluralLogic(
daysCount,
locale: localeName,
one: '1 day',
other: '$daysCount days',
);
}
My expectation would be for the method to look like this:
String prolongationRequested(Object userName, num daysCount) {
final String pluralString = intl.Intl.pluralLogic(
daysCount,
locale: localeName,
one: '1 day',
other: '$daysCount days',
);
return '$userName requested prolongation by ${pluralString}';
}
Interestingly enough the method gets generated correctly if I remove one of the placeholders, or if I remove the plural syntax from daysCount.
Why is the method not being generated as expected?
Solution 1:[1]
"{count,plural, =0{{count} sample0} =1{{count} sample1} =2{{count} sample2} few{{count} sampleFew} many{{count} sampleMany} other{{count} sampleOther}}",
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Starry-sta L |
