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

feat: add i18n support for errorx.Bomb and errorx.Dangerous #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

debidong
Copy link

I was trying to create an business group using Flashcat. When submitting the form without any teams specified, the returning error message would be "members empty" in English, even if the request language is specified as zh_CN in header X-Language.

failing-precheck

How this problem was discovered:
If the HTTP input element for Team is expanded as default, frontend will do a precheck when the submit button is hit, and renders Business group team is required under the HTTP input element. (By the way, this message is multi-languaged, which is supported by frontend.

frontend-precheck-zh_cn frontend-precheck

This precheck is obviously done in frontend and has no relation with backend.) However, when the user choose not to fill in any team but to hide the input and submit the form, the frontend precheck will fail, and a global error message would pop up after backend responds to the request with error message members empty without the process of i18n.

Actually there are two bugs in the logic of creating a new business group:

  1. In frontend: The precheck before submitting the request would fail if the user simply hides the input for Team.
  2. In backend: There isn't any i18n support for errorx.Bomb and errorx.Dangerous. Only i18n support for Render.Message is provided.

To make those translations for error messages in i18n.go actually work, I wrote two new functions with gin.Context as additional parameter, to transform the message into related language version. Considering hundreds of old errorx.Bomb and errorx.Dangerous are used, a full replacement for two methods are unrealistic, but callers can choose to use these two new functions to make translations for error messages in i18n really work, from now on.

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.

1 participant