Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of ICU number placeholder "#" #82

Open
Eric-Guan-Z opened this issue Jun 9, 2022 · 2 comments
Open

Support of ICU number placeholder "#" #82

Eric-Guan-Z opened this issue Jun 9, 2022 · 2 comments

Comments

@Eric-Guan-Z
Copy link

Eric-Guan-Z commented Jun 9, 2022

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
Copy link
Collaborator

lzoran commented Jun 9, 2022

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants