3

I am trying to omit passing name and arguments into Intl.message. Intl documentation suggests that, there is a transformer provided that will automatically insert those parameters for you.

So I added following into pubspec.yaml:

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

In my localization.dart I have following method:

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

When I run flutter pub pub run intl_translation:extract_to_arb --output-dir=strings lib/localization.dart I have the following error:

<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

How I can enable that transformer?

Rostyslav Roshak
  • 3,859
  • 2
  • 35
  • 56

1 Answers1

0

Your error:

reason: The 'args' argument for Intl.message must be specified for messages with parameters. Consider using rewrite_intl_messages.dart

Is because your Intl.message() has an argument in it, name, so you must also add: 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"});

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

The args is a list containing the arguments of the enclosing function. If there are no arguments, args can be omitted.

But you do have an argument, so it cannot be omitted.

TWL
  • 6,228
  • 29
  • 65