Home > OS >  Flutter intl support of ICU number placeholder "#
Flutter intl support of ICU number placeholder "#

Time:06-09

According to ICU document, In a pluralized form message like

The film won {n, plural,
one {# award}
other {# awards}}

The special # symbol will display the given count in the active locale’s number system.

Currently it seems

flutterw pub run intl_utils:generate

will not replace # to the given number param.

For example:

{number, plural, one {Temporarily inactive (# day left)} other {Temporarily inactive (# days left)}}

will generate

  String InactiveDaysLeft(num number) {
    return Intl.plural(
      number,
      one: 'Temporarily inactive (# day left)',
      other: 'Temporarily inactive (# days left)',
      name: 'Events_MeetingRoom_InactiveDaysLeft',
      desc: '',
      args: [number],
    );
  }

And when using this message, flutter intl does not support this kind of feature either. If a number of 2 is passed to this massage, it will directly return

Temporarily inactive (# days left)

Does any one know this is by design or its because I did something wrong in practice?

CodePudding user response:

Please check the below example. It is somewhat similar to your requirement with dynamic data.

String howManyPeople(int numberOfPeople, String place) => Intl.plural(
      numberOfPeople,
      zero: 'I see no one at all in $place.',
      one: 'I see $numberOfPeople other person in $place.',
      other: 'I see $numberOfPeople other people in $place.',
      name: 'howManyPeople',
      args: [numberOfPeople, place],
      desc: 'Description of how many people are seen in a place.',
      examples: const {'numberOfPeople': 3, 'place': 'London'},
    );

CodePudding user response:

If you are using arb file based localization:

Try

"msg": "The film won {n, plural, =1{{n} award} other{{n} awards}}",
@"msg": {
"description": "A generic description",
  "placeholders": {
    "count": {
      "type": "int"
    }
}
  • Related