3

我试图省略将名称和参数传递到Intl.message. Intl文档表明,提供了一个转换器,可以自动为您插入这些参数。

所以我添加了以下内容pubspec.yaml

dev_dependencies:
  intl_translation: ^0.17.3
transformers:
- intl_translation:
$include: lib/localization.dart

在我的localization.dart我有以下方法:

class AppLocalizations {
  ...
  String greetingMessage(String name) => Intl.message(
    "Hello $name!",
    desc: "Greet the user as they first open the application",
    examples: const {'name': "Emily"});
}

当我运行时flutter pub pub run intl_translation:extract_to_arb --output-dir=strings lib/localization.dart,出现以下错误:

<Intl.message("Hello $name!", desc: "Greet the user as they first open the application", examples: const {'name' : "Emily"})>
    reason: The 'args' argument for Intl.message must be specified for messages with parameters. Consider using rewrite_intl_messages.dart

我怎样才能启用那个变压器?

4

1 回答 1

0

你的错误:

原因:必须为带参数的消息指定 Intl.message 的“args”参数。考虑使用 rewrite_intl_messages.dart

是因为你Intl.message()有一个参数name,所以你还必须添加:args: [name]

String greetingMessage(String name) => Intl.message(
  "Hello $name!",
  args: [name]
  desc: "Greet the user as they first open the application",
  examples: const {'name': "Emily"});

见:https ://api.flutter.dev/flutter/intl/Intl/message.html

args 是一个包含封闭函数参数的列表。 如果没有参数,则可以省略 args。

但是你确实有一个论点,所以它不能被省略。

于 2020-02-06T22:24:17.930 回答