KingWu / gen_lang

gen_lang is a dart library for internationalization. Extracts messages to generate dart files required by Intl, inspired by Intl_translation and Flutter i18n
BSD 2-Clause "Simplified" License
100 stars 23 forks source link

Best way to get all strings and save it in array? #12

Open frojnd opened 4 years ago

frojnd commented 4 years ago

Hi.

1) What would be the best way to get all the strings and save them in array? So I could use it in ListView?

2) Is it possible to "categorize" strings inside string_en.json file? Or if not, what would be the best logic to save into array just strings that starts with cardcategory1?

{
  "card_category1_test": "test",
  "card_category1_abc": "abc",
  "card_category2_test": "Another test",
  "card_category2_abc": "Another abc"
}
KingWu commented 4 years ago

For question 1, currently, need to write a helper function which contain many switch cases to map with a specific function

Maybe enhance for the future with following solutions.

S.of(context).localized(name, args) eg.

S.of(context).localized('card_category1.test')

For question 2, Thinking of using json structure

{
  "card_category1": {
    "test": "test"
    "abc": "abc"
  },
  "card_category2": {
    "test": "Another test"
    "abc": "Another abc"
  }
}

But, the generated function name will be tricky. Thats why we need a generalize function like S.of(context).localized(name, args)