Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feature Request: String? getMessageByKey(String messageKey) #12

Open
henry2man opened this issue Mar 1, 2022 · 1 comment
Open

Feature Request: String? getMessageByKey(String messageKey) #12

henry2man opened this issue Mar 1, 2022 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@henry2man
Copy link

TD;LR Read the title, I just want to have a dynamic way to resolve messages (if they exists) during runtime.

Full story:

I have a backend that is going to send both info & error messages using message-keys, ex: "{'id':302, 'error': 'itemNotFound'}". I want to dynamically resolve those keys using generated code but, for now, I don't have a method that can be used in order to solve the error message.

It would be great to have a method in the S class that would allow me to get the translated message if it exists, and if it doesn't, I can manually generate a generic message:

...
} catch BackendError {
  String? message  = getMessageByKey(errorKey);
  if(message == null) {
     print("ERROR: Unknown error: $errorKey")
  } else {
     print("ERROR: $message");
  }
}

Having such method probably will require the generation of a Map<String, String Function()> static member that will look like something like this:

{ 
  'itemNotFound': () => this.itemNotFound,
  'forbidden': () => this.forbidden,
  'notAuthorized': () => this.notAuthorized,
  ....
}

I've done something similar in bdlukaa/fluent_ui@b53288b#diff-ab7c9e25f588ae440e0de59542af84db24d60f230b9c7143d42b1afa9bc45da4R47 (In that case the motivation to generate a map was also to be able to search for the "icons" by name)

@jaumard
Copy link

jaumard commented Jun 8, 2022

That's indeed super interesting to add. If you can do a PR please do! If not I'll try to check that when I have some free time.

@jaumard jaumard added enhancement New feature or request help wanted Extra attention is needed labels Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants