【问题标题】:Int placeholder on flutter localizations颤振本地化的 int 占位符
【发布时间】:2022-01-01 04:10:29
【问题描述】:

我正在尝试使用 int 占位符将文本条目添加到“arb”文件,但没有成功,因为我收到以下错误:

Number format null for the times placeholder does not have a corresponding NumberFormat constructor.
Check the intl library's NumberFormat class constructors for allowed number formats.
Generating synthetic localizations package has failed.

条目如下:

  "increment_message": "You have pushed the button this many times: {times}",
  "@increment_message": {
    "placeholders": {
      "times": {
        "type": "int",
        "example": "123"
      }
    }
  }

我知道其他所有设置都已正确设置,因为将占位符更改为字符串可以正常工作:

  "increment_message": "You have pushed the button this many times: {times}",
  "@increment_message": {
    "placeholders": {
      "times": {
        "type": "String",
        "example": "123"
      }
    }
  }

如果你想运行,完整的代码托管在 github 上:

Working using String

Failing int branch

所以我的问题是,如何在 arb 文件上使用整数占位符,这似乎与 NumberFormat 有关,但我不知道如何。

【问题讨论】:

    标签: flutter localization integer intl flutter-localizations


    【解决方案1】:

    我已经启动了你的 repo(String 和 int 分支)并且一切正常。你试过flutter clean 吗?

    【讨论】:

    • 有趣,是的,我确实尝试过清理,我想知道您使用的是哪个颤振版本。
    • 天哪,就是这样,我在 Flutter 2.2.3Dart 2.13.4 上运行,更新到 Flutter 2.5.2Dart 2.14.3 它也对我有用,谢谢你的报告。
    【解决方案2】:

    添加格式属性应该可以解决这个问题。

     "increment_message": "You have pushed the button this many times: {times}",
      "@increment_message": {
        "placeholders": {
          "times": {
            "type": "int",
            "format": "decimalPattern",
            "example": "123"
          }
        }
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-27
      • 1970-01-01
      • 1970-01-01
      • 2021-09-03
      • 2020-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多