easy_localization icon indicating copy to clipboard operation
easy_localization copied to clipboard

Keep the nested structure when the LocaleKeys are generated

Open ValentinVignal opened this issue 4 years ago • 7 comments

Let's say I have this en.json file:

{
  "project": {
    "name" : "project name",
    "date": "project date"
  },
  "user": {
    "name": "user name",
    "age": "age",
  }
}

Right now, running flutter pub run easy_localization:generate -f keys -o locale_keys.g.dart to generate the keys will flatten the nested structure and generate:

LocaleKeys.project_name;
LocaleKeys.project_date;
LocaleKeys.user_name;
LocaleKeys.user_age;

It would be nice if it could keep the nested structure and generate nested objects:

LocaleKeys.project.name;
LocaleKeys.project.date;
LocaleKeys.user.name;
LocaleKeys.user.age;

ValentinVignal avatar Jun 15 '21 03:06 ValentinVignal

Hello @aissat, is it an acceptable proposition? I'm willing to spend some time and contribute to make it available if you validate this request.

ValentinVignal avatar Jun 26 '21 11:06 ValentinVignal

@ValentinVignal i think it's god idea. PR welcom 😉

Overman775 avatar Jul 15 '21 14:07 Overman775

@ValentinVignal are you working on this? If not I can give it a try.

TarekkMA avatar Aug 20 '21 12:08 TarekkMA

@TarekkMA Not yet, I have been quite busy recently.

@Overman775 right now LocalKeys.project_name and the other are all const. Would It be okay to not make the nested object const:

LocalKeys.project.name;

would not be a const anymore, is that fine?

ValentinVignal avatar Aug 27 '21 15:08 ValentinVignal

@ValentinVignal take a look at my PR #418, I've managed to make nested objects private and const.

Your feedback is most appreciated.

TarekkMA avatar Aug 27 '21 16:08 TarekkMA

This idea is very useful!

btd1337 avatar Dec 16 '21 23:12 btd1337

any idea if this will be merged into the project anytime soon?

opanitch avatar Aug 03 '23 16:08 opanitch