0

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?

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Tonnanto
  • 15
  • 5

1 Answers1

4

You may adapt your plural on the prolongationRequested var inside the .arb file using this configuration or similar:

"{count,plural, =0{{count} sample0} =1{{count} sample1} =2{{count} sample2} few{{count} sampleFew} many{{count} sampleMany} other{{count} sampleOther}}"
  • While this answer was not very descriptive, it did indeed lead to solving this problem (see question edit). Thanks. – Tonnanto Apr 27 '22 at 20:13
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 28 '22 at 12:58