easy_localization icon indicating copy to clipboard operation
easy_localization copied to clipboard

plural and arguments don't work in nested keys

Open sasarivera opened this issue 4 years ago • 2 comments

Hi,

This doesn't work:

{
    "category": {
         "result": {
             "zero": "You not have money",
             "one": "You have {} dollar",
             "many": "You have {} dollars",
             "other": "You have {} dollars"
         },
         "total": "{} items"
    }
}

Text('category_result').plural(Count)
Text('cateory_total').tr(args: [total]);

but if I remove the nested keys it works

{
         "result": {
             "zero": "You not have money",
             "one": "You have {} dollar",
             "many": "You have {} dollars",
             "other": "You have {} dollars"
         },
         "total": "{} items"
}

Text('result').plural(Count)
Text('total').tr(args: [total]);

I'm using the 2 commands to generate the keys:

flutter pub run easy_localization:generate -S "assets/translations" -O "lib/translations"
flutter pub run easy_localization:generate -S "assets/translations" -O "lib/translations" -o "locale.keys.g.dart" -f keys

and I can see the keys being generated

abstract class  LocaleKeys {
  static const category_result = 'category.result';
  static const category.total = 'category_total';
}

in the UI appears as category_result.many (not the translation)

Thanks for any help you can provide

sasarivera avatar Jul 07 '21 17:07 sasarivera

update package and rerun your generator, i have difrent keys in my output

abstract class  LocaleKeys {
  static const category_result = 'category.result';
  static const category_total = 'category.total';
  static const category = 'category';
}

then you need get translation like this: Text(LocaleKeys.category_result.plural(Count)) Text(LocaleKeys.category_total).tr(args: [total]);

Overman775 avatar Jul 26 '21 11:07 Overman775

I have the latest package. I still have problems with using plural for nested keys. The workaround is just add those key to the root

sasarivera avatar Jul 28 '21 19:07 sasarivera

Closing since we could not reproduce with the given code. @sasarivera please comment if the issue persists

bw-flagship avatar May 14 '23 10:05 bw-flagship