localizely / intl_utils

Dart package that creates a binding between your translations from .arb files and your Flutter app
BSD 3-Clause "New" or "Revised" License
134 stars 78 forks source link

Support of ICU number placeholder "#" #82

Open Eric-Guan-Z opened 2 years ago

Eric-Guan-Z commented 2 years ago

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 Events_MeetingRoom_InactiveDaysLeft(num number) {
    return Intl.plural(
      number,
      one: 'Temporarily inactive (# day left)',
      other: 'Temporarily inactive (# days left)',
      name: 'Events_MeetingRoom_InactiveDaysLeft',
      desc: '',
      args: [number],
    );
  }

just wonder is there any way to achieve this kind of feature?

lzoran commented 2 years ago

Hi @Eric-Guan-Z,

As far as I know, Dart's intl package does not treat # as a placeholder in plural messages. However, some other localization libraries (e.g. react-intl) support such syntax in messages.

Alternatively, you can use a slightly different approach to achieve the same goal.

"pluralMessageExample": "{count, plural, one {{count} item} other {{count} items}}"

Some useful links:

Eric-Guan-Z commented 2 years ago

Hi @Eric-Guan-Z,

As far as I know, Dart's intl package does not treat # as a placeholder in plural messages. However, some other localization libraries (e.g. react-intl) support such syntax in messages.

Alternatively, you can use a slightly different approach to achieve the same goal.

"pluralMessageExample": "{count, plural, one {{count} item} other {{count} items}}"

Some useful links:

Thanks for the example, it clearly shows how to achieve dynamic data. However, the problem here is that there are multiple platforms developers following the same ICU standard in the company, so the arb files we could receive from the globalization team will always use "#" as a placeholder in plural messages. If dart will not support this kind of feature, I guess the only possible solution left for me is to use regex to force the replacement of all "#" to the first number param LOL