fix(tr): Fix translation errors

This commit is contained in:
LinkinStar 2022-11-30 19:19:01 +08:00
parent 457c1cd798
commit 505fa7e6d3
2 changed files with 14 additions and 2 deletions

View File

@ -1,6 +1,8 @@
package handler
import (
"context"
"github.com/answerdev/answer/internal/base/constant"
"github.com/gin-gonic/gin"
"github.com/segmentfault/pacman/i18n"
@ -18,3 +20,12 @@ func GetLang(ctx *gin.Context) i18n.Language {
return i18n.DefaultLang
}
}
// GetLangByCtx get language from header
func GetLangByCtx(ctx context.Context) i18n.Language {
acceptLanguage, ok := ctx.Value(constant.AcceptLanguageFlag).(i18n.Language)
if ok {
return acceptLanguage
}
return i18n.DefaultLang
}

View File

@ -7,6 +7,7 @@ import (
"time"
"github.com/answerdev/answer/internal/base/constant"
"github.com/answerdev/answer/internal/base/handler"
"github.com/answerdev/answer/internal/base/reason"
"github.com/answerdev/answer/internal/base/translator"
"github.com/answerdev/answer/internal/base/validator"
@ -129,7 +130,7 @@ func (qs *QuestionService) AddQuestion(ctx context.Context, req *schema.Question
errorlist := make([]*validator.FormErrorField, 0)
errorlist = append(errorlist, &validator.FormErrorField{
ErrorField: "tags",
ErrorMsg: reason.RecommendTagEnter,
ErrorMsg: translator.GlobalTrans.Tr(handler.GetLangByCtx(ctx), reason.RecommendTagEnter),
})
err = errors.BadRequest(reason.RecommendTagEnter)
return errorlist, err
@ -350,7 +351,7 @@ func (qs *QuestionService) UpdateQuestion(ctx context.Context, req *schema.Quest
errorlist := make([]*validator.FormErrorField, 0)
errorlist = append(errorlist, &validator.FormErrorField{
ErrorField: "tags",
ErrorMsg: reason.RecommendTagEnter,
ErrorMsg: translator.GlobalTrans.Tr(handler.GetLangByCtx(ctx), reason.RecommendTagEnter),
})
err = errors.BadRequest(reason.RecommendTagEnter)
return errorlist, err