0

I'm trying to translate an string like "filter [solved|date] clear". If I don't want to translate the parameters (solved|date), all works well.

MyLocalizations.of(context).clearFilter( filter.activeFilter)

But i want to translate the parameters, too. Because it's not possible do access the object properties dynamically, to following doesn't work:

MyLocalizations.of(context).clearFilter( MyLocalizations.of(context)[filter.activeFilter] )

I didn't find any examples :-( But I hope anybody can help me.

Best, Dominik

// edit: // the filter [solved|date] could be "solved" or "date"

Dominik00000
  • 311
  • 1
  • 3
  • 10

1 Answers1

0

In MyLocalizations, the translations should look like this:

String clearFilter(String value) => Intl.message("filter $value clear",
  args: [value],
  name: "clearFilter",
  desc: "clearFilter");

String get activeFilter => Intl.message("[solved|date]",
  name: "activeFilter",
  desc: "activeFilter");

Then you can use it like this:

MyLocalizations.of(context).clearFilter(MyLocalizations.of(context).activeFilter)

Take a look at the README file of intl package: https://github.com/dart-lang/intl#messages

alecsam
  • 566
  • 3
  • 10