feat: add i18n support for errorx.Bomb and errorx.Dangerous #22
+29
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 headerX-Language
.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 rendersBusiness group team is required
under the HTTP input element. (By the way, this message is multi-languaged, which is supported by frontend.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:
Team
.errorx.Bomb
anderrorx.Dangerous
. Only i18n support forRender.Message
is provided.To make those translations for error messages in
i18n.go
actually work, I wrote two new functions withgin.Context
as additional parameter, to transform the message into related language version. Considering hundreds of olderrorx.Bomb
anderrorx.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.