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 2 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.

```

## 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.

&errdetails.ErrorInfo{
Reason: "INVALID",
Domain: "account.bucketeer.io",
Metadata: map[string]string{
Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering if we can add multiple error metadata, e.g.

[]map[string]string{
  {
    "messageKey": "account.invalid.empty",
    "field":      "email",
  },
  {
    "messageKey": "account.invalid.empty",
    "field":      "phone_number",
  },
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although it is stated in the RFC, it uses GRPC's ErrorInfo, so the type of Metadata cannot be changed.
If multiple errors are returned, we plan to return multiple ErrorInfo's.

		dt, err := statusEmailIsEmpty.WithDetails(
			&errdetails.LocalizedMessage{
				Locale:  localizer.GetLocale(),
				Message: localizer.MustLocalizeWithTemplate(locale.InvalidArgumentError, "email"),
			},
			&errdetails.ErrorInfo{
				Reason: "INVALID",
				Domain: "account.bucketeer.io",
				Metadata: map[string]string{
					"messageKey": "account.invalid.empty",
					"feild":      "email",
				},
			},
			&errdetails.ErrorInfo{
				Reason: "INVALID",
				Domain: "account.bucketeer.io",
				Metadata: map[string]string{
					"messageKey": "account.invalid.empty",
					"feild":      "phone_number",
				},
			})

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