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

This issue has been created 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.

huycozy wrote this answer on 2022-11-28

@lsaudon thanks for providing more info, I see the issue now. It's reproducible on Flutter stable 3.3.9 but it seems to be fixed on Flutter master channel 3.6.0. Please retry and confirm the issue has been fixed.

flutter doctor -v (stable and master)
[✓] Flutter (Channel stable, 3.3.9, on macOS 13.0 22A380 darwin-x64, locale en-VN)
    • Flutter version 3.3.9 on channel stable at /Users/huynq/Documents/GitHub/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b8f7f1f986 (31 hours ago), 2022-11-23 06:43:51 +0900
    • Engine revision 8f2221fbef
    • Dart version 2.18.5
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-33, build-tools 31.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A400
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] IntelliJ IDEA Community Edition (version 2022.2.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 70.0.5
    • Dart plugin version 222.4167.21

[✓] IntelliJ IDEA Community Edition (version 2022.1.1)
    • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.73.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.52.0

[✓] Connected device (3 available)
    • SM T225 (mobile) • R9JT3004VRJ • android-arm64  • Android 12 (API 31)
    • macOS (desktop)  • macos       • darwin-x64     • macOS 13.0 22A380 darwin-x64
    • Chrome (web)     • chrome      • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
[!] Flutter (Channel master, 3.6.0-7.0.pre.52, on macOS 13.0 22A380 darwin-x64, locale en-VN)
    • Flutter version 3.6.0-7.0.pre.52 on channel master at /Users/huynq/Documents/GitHub/flutter_master
    ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ff59250dbe (4 hours ago), 2022-11-24 18:08:30 -0500
    • Engine revision 7665ae5184
    • Dart version 2.19.0 (build 2.19.0-429.0.dev)
    • DevTools version 2.19.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-33, build-tools 31.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A400
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] IntelliJ IDEA Community Edition (version 2022.2.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 70.0.5
    • Dart plugin version 222.4167.21

[✓] IntelliJ IDEA Community Edition (version 2022.1.1)
    • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.73.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.52.0

[✓] Connected device (3 available)
    • Pixel 3a (mobile) • 964AY0WL20 • android-arm64  • Android 12 (API 32)
    • macOS (desktop)   • macos      • darwin-x64     • macOS 13.0 22A380 darwin-x64
    • Chrome (web)      • chrome     • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.
lsaudon wrote this answer on 2022-11-28

The issue has been fixed on master.

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-10
Star Count 147243
Watcher Count 3561
Fork Count 23950
Issue Count 11325

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Efeito hover no menu principal 2 2022-09-13 2022-11-30
Assertion error when compiling to PCal 1 2021-10-19 2022-10-16
Adding extra '\' when unnecessary in MPCal to PCal translation 0 2021-10-27 2022-10-22
ios 手机型号ND097LL/A 系统版本10.3.4 Unable to bridge NSNumber to CGFloat: file 0 2022-01-07 2022-11-14
Provide fine-grained control over which PLC connection a tag uses 1 2021-11-25 2022-11-11
Setup failed for alarmo: Unable to import component: cannot import name 'STATE_ALARM_ARMED_VACATION' 8 2022-03-10 2022-07-20
Installation problem (novice) 3 2022-02-08 2022-11-21
添加多个相同的组件,代码中怎么控制其中一个 0 2022-10-18 2022-12-01
No synchronization between tasks in copies of an in-order queue 6 2021-11-03 2022-10-21
Datasets have been cancelled 0 2021-09-02 2022-09-22
Usage displays arguments unspaced of the command qpdf--help 1 2022-03-08 2022-12-08
Inconsistent behavior of `issquare(::fmpq)` and `issquare(::nf_elem)` 1 2022-01-06 2022-07-14
Installation ended with unknown error 3 2021-09-25 2022-11-14
bug(ios): FirstVoices keyboard list gets out of sync and stops working 0 2022-03-29 2022-10-22
parseInt() / parseFloat() are converted to a method call in UnityScript.Lang.UnityBuiltins 0 2021-08-23 2022-11-16
[SUGGESTION] we need a chat script plz 3 2021-11-01 2022-11-18
[BUG] TDVT: date string format vary according to OS date format settings 2 2021-11-18 2022-11-21
research durable rename for WAL archiving 1 2021-05-13 2022-11-20
refreshVersions should automatically configure the buildSrc if present, or tell the user to do it 0 2021-12-19 2022-08-22
Formatting possible but invalid numbers 1 2022-05-05 2022-12-03
Bump buildkit 0.8.3 -> 0.9.1 1 2021-10-14 2022-07-06
https redirects are not properly handled 0 2021-07-31 2022-09-23
Invalid player NBT tag types crash the server 0 2021-12-13 2022-08-16
large integral numbers in Oracle Number column are imported into Tablesaw DoubleColumns 0 2021-05-22 2022-10-13
Suggestion: Display test invoice with PIN embedded on /grab response page 6 2021-08-22 2022-10-18
tensorflow=2.6.0 TypeError: Unable to convert function return value to a Python type! 1 2021-11-17 2022-11-23
[bug] unable to start workspaces in desktop VSCode 5 2022-05-05 2022-11-06
Noise on Microsoft.OperationsManagement/solutions/SecurityInsights 0 2022-02-25 2022-11-30
Improve documentation and move possible validations via OpenAPI 2 2022-01-26 2022-09-15
Extend array filling to deal with member type that is a map or array 0 2021-11-18 2022-11-18
try_fopen destroys error handler in specific contexts 3 2020-02-12 2022-12-05
[BUG] w2field enum autoAdd+onNew 0 2021-06-18 2022-10-08
像weasel那样重启算法服务,同文有吗?? 1 2022-12-07 2022-12-02
Parse C Source does not recognize function pointer array in struct definition 2 2022-01-24 2022-11-16
[Starrocks on ES] support configurable node sniffing propertity for external ES table 0 2022-05-19 2022-10-29
Doesn't seem to support memo<Props>() syntax 5 2019-01-04 2022-07-27
Add shell completion 3 2022-09-16 2022-09-30
Add benchark with missings 3 2018-12-05 2022-12-03
Can't processe multiline expect strings. 1 2021-04-02 2022-11-30
UnicodeDecodeError in Jupyter interactive window in VSCode that doesn't appear outside 0 2022-03-01 2022-10-17
sqlite3.dll missing when installing in a venv on Windows 2 2022-03-02 2022-08-31
Changes to Included Files should restart/rebuild function 0 2022-03-14 2022-10-17
gtk-update-icon-cache: The generated cache was invalid 0 2019-01-15 2022-11-25
Define sky layout 4 2021-11-23 2022-01-20
Gluster split_brain issue 4 2022-02-22 2022-11-08
Full Green Jenkins - Fix API tests in 4.2 1 2021-08-26 2022-10-30
Extract jsx string to constant 0 2022-01-26 2022-10-06
How to use object file with cmake? 3 2022-01-21 2022-12-08
使用kotlin开发的项目,报 compileReleaseKotlin 错误 1 2019-04-26 2022-12-02
[Web app] How to handle back/forward and refresh buttons on the browser 2 2021-12-13 2022-09-05