Skip to content

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

@Delgan

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.

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