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

docs: add rfc for move i18n logic to frontend #1436

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kakcy
Copy link
Contributor

@kakcy kakcy commented Jan 9, 2025

This pull request proposes moving the i18n (internationalization) logic entirely to the frontend to simplify the backend code. The changes include adding detailed documentation and examples of the new error handling design using GRPC's ErrorInfo and removing the existing LocalizedMessage code from the backend.

#1253

Comment on lines +83 to +95
dt, err := statusEmailIsEmpty.WithDetails(
&errdetails.ErrorInfo{
Reason: "INVALID",
Domain: "account.bucketeer.io",
Metadata: map[string]string{
"messageKey": "account.invalid.empty",
"feild": "email",
},
})
if err != nil {
return statusInternal.Err()
}
return dt.Err()
Copy link
Member

@cre8ivejp cre8ivejp Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to put this log logic into a common function.
Depending on the function, we handle many errors, making the function too long.
One of the reasons for moving the localizer to the front end is also to improve code readability.

WDYT?

Suggested change
dt, err := statusEmailIsEmpty.WithDetails(
&errdetails.ErrorInfo{
Reason: "INVALID",
Domain: "account.bucketeer.io",
Metadata: map[string]string{
"messageKey": "account.invalid.empty",
"feild": "email",
},
})
if err != nil {
return statusInternal.Err()
}
return dt.Err()
return error.NewError(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Good idea!

It's certainly more readable that way, so I do that when coding.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kakcy, can you update the RFC using the code above? Leave it as it is a bit confusing.
I'm more interested in how the code will look in the end. How readable the code will be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```

## Release Steps
1. Releases a process that returns an ErrorInfo for each package for The backend.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, we will use canary release to switch i18n logic from backend to fronted, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's right. Bucketeer essentially uses a canary release.

@cre8ivejp
Copy link
Member

@Ubisoft-potato, @hvn2k1, can you check the latest changes?
It looks much better to me now. It's much simpler and clean.

@Ubisoft-potato
Copy link
Collaborator

@cre8ivejp Looks great! 🎉

...
```

### Point3:Remove localize massage code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @kakcy, I see the relation between point 1 and point 2, it looks great, but I don't understand point 3, what is it relation to point 1 and 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hvn2k1

Currently, error messages are localized on the backend using errdetails.LocalizedMessage as shown below.

dt, err := statusEmailIsEmpty.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalizeWithTemplate(locale.InvalidArgumentError, "email"),
})

Modify Point1 and Point2 to use errdetails.ErrorInfo to send error details to the front end.

The content described in Point 3 is
Once the localization of error messages using errdetails.ErrorInfo is completed on the front end, errdetails.LocalizedMessage will no longer be necessary, so it should be deleted.

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants