slang-i18n / slang

Type-safe i18n for Dart and Flutter
https://pub.dev/packages/slang
MIT License
419 stars 36 forks source link

Combine lists and enums #220

Open gregorscholz opened 1 month ago

gregorscholz commented 1 month ago

Motivation I want to use lists from a csv in combination with a custom enum.

E.g: I have multiple sets of instruction with a different number of steps. In code i want to access it like this:

final instructions = t.instructions(context: level);
...
List.generate(instructions.length, (index) => Text(instructions[index])),
Tienisto commented 1 month ago

You can specify lists in csv by adding numbers to the key:

instructions.beginner.0,First Step
instructions.beginner.1,Second Step
gregorscholz commented 1 month ago

Thank you for the quick response, but this can not be used in combination with enums. I get the following error:

Unhandled exception:
The leaf "instructions(context=Level).beginner.1" cannot be added because there are missing indices.

This is my csv entry

instructions(context=Level).beginner.1,first step,first step
gregorscholz commented 1 month ago

Ok i guess this problem occured because i started with 1, my bad...

But still i get an error.

Unhandled exception:
type 'ListNode' is not a subtype of type 'StringTextNode' in type cast

when this is the complete csv

key,de,en
instructions(context=Level).beginner.0,first step, first step
instructions(context=Level).beginner.1,sec step, sec step