feat(email): translator email template using receiver language.

This commit is contained in:
LinkinStars 2023-05-17 11:10:45 +08:00
parent 15439d2260
commit 8e46fe3ecd
2 changed files with 14 additions and 0 deletions

View File

@ -25,6 +25,7 @@ import (
"github.com/answerdev/answer/pkg/encryption"
"github.com/answerdev/answer/pkg/uid"
"github.com/segmentfault/pacman/errors"
"github.com/segmentfault/pacman/i18n"
"github.com/segmentfault/pacman/log"
)
@ -616,6 +617,10 @@ func (as *AnswerService) notificationAnswerTheQuestion(ctx context.Context,
UserID: userInfo.ID,
}
// If receiver has set language, use it to send email.
if len(userInfo.Language) > 0 {
ctx = context.WithValue(ctx, constant.AcceptLanguageFlag, i18n.Language(userInfo.Language))
}
title, body, err := as.emailService.NewAnswerTemplate(ctx, rawData)
if err != nil {
log.Error(err)

View File

@ -22,6 +22,7 @@ import (
"github.com/answerdev/answer/pkg/uid"
"github.com/jinzhu/copier"
"github.com/segmentfault/pacman/errors"
"github.com/segmentfault/pacman/i18n"
"github.com/segmentfault/pacman/log"
)
@ -504,6 +505,10 @@ func (cs *CommentService) notificationQuestionComment(ctx context.Context, quest
UserID: receiverUserInfo.ID,
}
// If receiver has set language, use it to send email.
if len(receiverUserInfo.Language) > 0 {
ctx = context.WithValue(ctx, constant.AcceptLanguageFlag, i18n.Language(receiverUserInfo.Language))
}
title, body, err := cs.emailService.NewCommentTemplate(ctx, rawData)
if err != nil {
log.Error(err)
@ -560,6 +565,10 @@ func (cs *CommentService) notificationAnswerComment(ctx context.Context,
UserID: receiverUserInfo.ID,
}
// If receiver has set language, use it to send email.
if len(receiverUserInfo.Language) > 0 {
ctx = context.WithValue(ctx, constant.AcceptLanguageFlag, i18n.Language(receiverUserInfo.Language))
}
title, body, err := cs.emailService.NewCommentTemplate(ctx, rawData)
if err != nil {
log.Error(err)