颤动:使用没有args和名称参数的Intl.message

问题描述 投票:0回答:1

当我运行flutter pub pub run intl_translation:extract_to_arb --output-dir=lib/l10n lib/localizations.dart时,生成器会跳过所有只包含字符串的Intl.message文件,打印:

Skipping invalid Intl.message invocation
    <Intl.message("MESSAGE")>
    reason: The 'args' argument for Intl.message must be specified for messages with parameters. Consider using rewrite_intl_messages.dart
    from lib/main.dart    line: 125, column: 9

doc for the internationalization packageThe name and args parameters must match the name (or ClassName_methodName) and arguments list of the function respectively. For messages without parameters, both of these can be omitted.但在我看来,在这种情况下,我的消息是没有参数!

我是否误解了Dart devs的参数含义?

dart flutter internationalization flutter-dependencies
1个回答
1
投票

将它从构造函数移到单独的函数中。您可以从构造函数中调用该函数,但它必须是函数中的单个消息。

原因是支持带参数的消息。至少在概念上,翻译作为单独的功能生成。所以我们有

foo(String name) => Intl.message('Hello $name', name: 'foo', args: [name]);

在某个延迟的库fr_FR中

foo(String name) => 'Bonjour $name'

Intl.message的实现在概念上

currentLanguage.lookup('foo').call(args)

因此,函数中只能有一条消息,因为我们要用其他东西替换该函数。它不能是构造函数,因为我们不能只委托给它。

© www.soinside.com 2019 - 2024. All rights reserved.