localizely / flutter-intl-vscode

This VS Code extension generates boilerplate code for localization of Flutter apps with official Dart Intl library
MIT License
87 stars 1 forks source link

How to use list values for localization? #97

Closed elmar001 closed 1 year ago

elmar001 commented 1 year ago
Raw localization l10n has an example for entering lists like below:
"myListKey[0]": "value 1 here",
"myListKey[1]": "value 2 here",

But seems like Flutter Intl implementation intl_en.arb file does not support it? Adding as above example does not work as the key appear to be unrecognized when I try to use. How is it supposed to be entered then?

lzoran commented 1 year ago

Hi @elmar001,

Not sure what you mean by raw.
Have you found some docs that say arb files allow lists?

You are right. The current implementation does not support this.
However, the ICU Select kind of messages is similar. Maybe their usage can help you.

"selectExample1": "{choice, select, foo {Foo message} bar {Bar message} baz {Baz message} other {Other message}}",
"@selectExample1": {
    "placeholders": {
        "choice": {}
    }
},
"selectExample2": "{option, select, opt1 {Option 1} opt2 {Option 2} opt3 {Option 3} other {Other}}",
"@selectExample2": {
    "placeholders": {
        "option": {}
    }
}
elmar001 commented 1 year ago

Thanks @lzoran. WIth the word "raw" I mean localization implementation by l10n.yaml way without FLutter Intl. Here is the example: https://www.applanga.com/docs/formats/arb

So according your suggestion if I implement that way what key can I use? selectExample? Like this: S .of(context).selectExample?? But is is still not recognized as a key.

elmar001 commented 1 year ago

Update: Thanks, Turns out there is now way to use ready list as a key. So I'd need to create a list from the individiual keys where I need to use the list.

lzoran commented 1 year ago

The Flutter Intl and the gen_l10n are two different approaches in Flutter localization. Although they are different approaches, they work the same in the most cases, and the both are supported by the Localizely. Maybe this post can give you more info.

Regarding the provided docs, it looks like a different localization approach from the two mentioned at the beginning.

When it comes to the usage of the ICU Select kind of messages, you will need to pass the argument (string or enum) to access the proper localization message.

S.of(context).selectExample2('opt2')
elmar001 commented 1 year ago

Thanks. I needed it to assign to DropdownButton like below:

items: S
                                    .of(context)
                                    .myListKey
                                    .map((value) {}

Thought there may be a way to use ready list directly from the .arb file definition. But seems like it is not possible and I need to create a list by assigning these values where I need to use it.

lzoran commented 1 year ago

I'm glad if I was of help.

Closing this issue as resolved.