Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Write nested keys as nested objects #418

Merged
merged 6 commits into from
Feb 13, 2024

Conversation

TarekkMA
Copy link

@TarekkMA TarekkMA commented Aug 20, 2021

Fixes: #390

I had to add a method that gets the object value String val() => 'gender'; to get around the previous behavior where gender/plural objects has other objects inside also.

I'm open to any changes.

@bw-flagship
Copy link
Collaborator

@TarekkMA sorry that nobody reviewed here. If you are still willing to put work in this, please update your branch (maybe update the readme) and I will review

@TarekkMA
Copy link
Author

TarekkMA commented Feb 8, 2024

@bw-flagship Thank you for your comment, I've changed val method to be key getter instead. Also I've added toString method so users can use "${LocalKeys.test3.test1}" and have it evaluate the key.

Input:

{
  "test1": "a",
  "test2": "hello",
  "test3": {
    "test1": "z",
    "test2": {
      "test1": "a"
    }
  },
  "test": "اختبار",
  "day": {
    "zero": "{} يوم",
    "one": "{} يوم",
    "two": "{} أيام",
    "few": "{} أيام",
    "many": "{} يوم",
    "other": "{} يوم"
  }
}

Previous output:

// DO NOT EDIT. This is code generated via package:easy_localization/generate.dart

abstract class  LocaleKeys {
  static const test1 = 'test1';
  static const test2 = 'test2';
  static const test3_test1 = 'test3.test1';
  static const test3_test2_test1 = 'test3.test2.test1';
  static const test3_test2 = 'test3.test2';
  static const test3 = 'test3';
  static const test = 'test';
  static const day = 'day';

}

New output:

// DO NOT EDIT. This is code generated via package:easy_localization/generate.dart

abstract class LocaleKeys {
  static const test1 = 'test1';
  static const test2 = 'test2';
  static const test3 = _test3();
  static const test = 'test';
  static const day = 'day';
}

class _test3 {
  const _test3();
  String get key => 'test3';
  @override
  String toString() => 'test3';
  final test1 = 'test3.test1';
  final test2 = const _test3_test2();
}

class _test3_test2 {
  const _test3_test2();
  String get key => 'test3.test2';
  @override
  String toString() => 'test3.test2';
  final test1 = 'test3.test2.test1';
}

@bw-flagship
Copy link
Collaborator

@TarekkMA Thanks for updating the branch and explaining the idea.
I'm a big fan and think that the nested stucture is better than the previous one, especially regarding autocomplete.

However, it is a huge breaking change because people would need to switch from

LocaleKeys.test1_test2

to

LocalKeys.test1.test2

For my apps, it would be thousands of changes.

I would suggest to "save" it for the next big version (4.0.0) and document the breaking change properly then.
What do you think?

@TarekkMA
Copy link
Author

TarekkMA commented Feb 9, 2024

I agree this is a breaking change; we need to have it in v4, and I can explore if I can write a simple migration tool, so moving to it would be a minimal manual change.

@bw-flagship bw-flagship changed the base branch from develop to future-releases/v4.0 February 13, 2024 07:19
@bw-flagship
Copy link
Collaborator

@aissat I created the branch future-releases/v4.0. There we can keep approved features that are too breaking to release them in 3.0. This way, people can use those features already if they want via github references in pubspec.yml.

@bw-flagship
Copy link
Collaborator

@TarekkMA It seems like there are some linter problems that prevent a merge. Also, could you add a small section in the changelog to describe migrating to the new style?
Thanks!

@bw-flagship bw-flagship merged commit 1b3e300 into aissat:future-releases/v4.0 Feb 13, 2024
2 of 3 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keep the nested structure when the LocaleKeys are generated
2 participants