[localizations] Bug Placeholder type int need format if other placeholder type is double or num

This issue has been tracked since 2022-11-24.

Description

Why the placeholder with an int type does not need a format when it is alone, but needs a format when there are other placeholders.

Steps to Reproduce

  1. Execute flutter create my_app on the code sample
  2. Add flutter_localizations and intl and generate: true:
name: my_app
description: My App
version: 1.0.0+1
publish_to: none

environment:
sdk: '>=2.18.2 <3.0.0'
flutter: 3.3.6

dependencies:
flutter:
  sdk: flutter
flutter_localizations:
  sdk: flutter
intl: ^0.17.0

flutter:
uses-material-design: true
generate: true
  1. Add l10n.yaml file:
arb-dir: lib/l10n/arb
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
nullable-getter: false
  1. Add lib\l10n\arb\app_en.arb
{
  "@@locale": "en",
  "text": "a {number} {otherNumber}",
  "@text": {
    "placeholders": {
      "number": {
        "type": "int"
      },
      "otherNumber": {
        "type": "num",
        "format": "compact"
      }
    }
  }
}

Expected results:

No error

Actual results:

Generating synthetic localizations package failed with 1 error:

Exception: Number format null for the number placeholder does not have a corresponding NumberFormat constructor.
Check the intl library's NumberFormat class constructors for allowed number formats.
huycozy wrote this answer on 2022-11-25

@lsaudon As I see, there is missing format property for number placeholder, you can try this one:

"text": "a {number} {otherNumber}",
"@text": {
  "placeholders": {
    "number": {
      "type": "int",
      "format": "compact"
    },
    "otherNumber": {
      "type": "num",
      "format": "compact"
    }
  }
}
lsaudon wrote this answer on 2022-11-25

@huycozy I know this works, but compact is not the same as no format.

Why the code below works and not with num or double type in other placeholders ?

"text": "a {number} {otherNumber}",
"@text": {
  "placeholders": {
    "number": {
      "type": "int"
    },
    "otherNumber": {
      "type": "string"
    }
  }
}

or

"text": "a {number}",
"@text": {
  "placeholders": {
    "number": {
      "type": "int"
    }
  }
}
huycozy wrote this answer on 2022-11-25

@lsaudon I'm not sure I can get your expectation here. Can you be more specific and update the issue's description?

lsaudon wrote this answer on 2022-11-25

I would like to have in a translation, an integer without format and a double for a price like:

{
  "@@locale": "en",
  "customerNumberPaid": "Customer number {number} paid {price}",
  "@customerNumberPaid": {
    "placeholders": {
      "number": {
        "type": "int"
      },
      "price": {
        "type": "double",
        "format": "currency"
      }
    }
  }
}

Here is the difference between no format and compact.
image

{
  "@@locale": "en",
  "customerNumberPaid": "Customer number {number} paid {price}",
  "@customerNumberPaid": {
    "placeholders": {
      "number": {
        "type": "int",
        "format": "compact"
      },
      "price": {
        "type": "double",
        "format": "currency"
      }
    }
  },
  "customerNumber": "Customer number {number}",
  "@customerNumber": {
    "placeholders": {
      "number": {
        "type": "int"
      }
    }
  }
}

I don't understand why you put a int without format when number is alone, but if there is a double it is not possible.

More Details About Repo
Owner Name flutter
Repo Name flutter
Full Name flutter/flutter
Language Dart
Created Date 2015-03-06
Updated Date 2022-12-07
Star Count 147031
Watcher Count 3560
Fork Count 23915
Issue Count 11300

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date