Skip to content

Add support for multiple/nested plurals and selects in gen_l10n tool #86906

Description

@Delgan

Use case

Hi!

Internationalization of Flutter apps is getting more and more convenient thanks to the enhancements implemented during the last months. More recently, #86167 allowed to use plural and select in the middle of a string which is super useful.

However while internationalizing this app on top of this recent change, I noted a few cases for which it didn't produce the expected result:

"pluralThenString": "Indeed, {count, plural, =1 {she likes} other {they like}} {framework} a lot!",
"@pluralThenString": {
    "placeholders": {
        "count": {},
        "framework": {
            "type": "String"
        }
    }
},
"multiplePlurals": "There {count, plural, =1{is} other{are}} {count} world{count, plural, =1{} other{s}}.",
"@multiplePlurals": {
    "placeholders": {
        "count": {}
    }
},
"pluralInSelect": "I can see {fruit, select, apple{{count, plural, =0{no apple} =1{one apple} other{some apples}}} banana{{count, plural, =0{no banana} =1{one banana} other{{count} bananas}}}}.",
"@pluralInSelect": {
    "placeholders": {
        "count": {
            "type": "int"
        },
        "fruit": {}
    }
},
@override
String pluralThenString(int count, String framework) {
  final String pluralString = intl.Intl.pluralLogic(
    count,
    locale: localeName,
    one: 'she likes',
    other: 'they like',
  );

  return 'Indeed, $pluralString a lot!';
}

@override
String multiplePlurals(int count) {
  final String pluralString = intl.Intl.pluralLogic(
    count,
    locale: localeName,
    one: 'is',
    other: 'are',
  );

  return 'There ${pluralString}.';
}

@override
String pluralInSelect(int count, Object fruit) {
  final String pluralString = intl.Intl.pluralLogic(
    count,
    locale: localeName,
    zero: 'no apple',
    one: 'one apple',
    other: 'some apples',
  );

  return 'I can see ${pluralString}.';
}

Proposal

I would like to keep developing the l10n support to make it more powerful and reduce the risk of misuse (I personally have been surprised by the first use case).

I understand that Flutter is not intended to implement the ICU format in its entirety. I think it could improve the user experience to support these use cases though. My only references are the following, where we see that multiple plurals are being used:

I had started working on this improvement, but it requires some refactoring. I will open a PR so that it can be discussed.

Activity

  1. added
    in triagePresently being triaged by the triage team
    a: internationalizationSupporting other languages or locales. (aka i18n)
    frameworkflutter/packages/flutter repository. See also f: labels.
    c: proposalA detailed proposal for a change to Flutter
    toolAffects the "flutter" command-line tool. See also t: labels.
    and removed
    in triagePresently being triaged by the triage team
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Jul 23, 2021
  2. HansMuller commented on Sep 15, 2021

    @HansMuller
    Contributor

    May be related: #90094

  3. jakub-trzebiatowski commented on Jun 6, 2022

    @jakub-trzebiatowski

    While I don't know which parts of ICU are tricky to implement, I'd consider a message in the form Hello, {gender,select,female{Mrs}other{Mr}} {lastName} not something like an edge case. It would be really great if Flutter got support for such syntax ❤️

  4. thkim1011 commented on Sep 1, 2022

    @thkim1011
    Contributor

    Hey everyone, I know this has been a bug for awhile now, but I've written up a proposal for fixing this bug with long term maintenance and extensibility in mind. Feel free to leave any comment.

  5. self-assigned this
    on Sep 1, 2022
  6. Diamondemon commented on Sep 16, 2022

    @Diamondemon

    Hey everyone, I know this has been a bug for awhile now, but I've written up a proposal for fixing this bug with long term maintenance and extensibility in mind. Feel free to leave any comment.

    How will we know when/if your proposal has been accepted?

  7. thkim1011 commented on Sep 19, 2022

    @thkim1011
    Contributor

    Proposal has been accepted in that I've gained feedback from the team and am working on the implementation right now.

  8. github-actions commented on Nov 19, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  9. locked as resolved and limited conversation to collaborators on Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

a: internationalizationSupporting other languages or locales. (aka i18n)c: proposalA detailed proposal for a change to FluttertoolAffects the "flutter" command-line tool. See also t: labels.waiting for PR to land (fixed)A fix is in flight

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions