Skip to content

Commit

Permalink
Fix Greetings/Signature not translated in some cases
Browse files Browse the repository at this point in the history
(cherry picked from commit 26d5fd7)
  • Loading branch information
cdujeu committed Feb 19, 2024
1 parent 8b609d8 commit 28e3124
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
9 changes: 3 additions & 6 deletions broker/mailer/grpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,11 @@ func (h *Handler) SendMail(ctx context.Context, req *proto.SendMailRequest) (*pr
body.FreeMarkdown = hermes.Markdown(m.ContentMarkdown)
}
} else {
body = templates.PrepareSimpleBody(to, languages...)
if m.ContentMarkdown != "" {
body = hermes.Body{
FreeMarkdown: hermes.Markdown(m.ContentMarkdown),
}
body.FreeMarkdown = hermes.Markdown(m.ContentMarkdown)
} else {
body = hermes.Body{
Intros: []string{m.ContentPlain},
}
body.Intros = []string{m.ContentPlain}
}
}
hermesMail := hermes.Email{Body: body}
Expand Down
15 changes: 15 additions & 0 deletions broker/mailer/templates/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ func GetHermes(languages ...string) hermes.Hermes {

}

// PrepareSimpleBody builds a simple hermes.Body with pre-translated Name, Greeting and Signature
func PrepareSimpleBody(user *mailer.User, languages ...string) hermes.Body {
configs := GetApplicationConfig(languages...)
body := hermes.Body{
Name: user.Name,
Greeting: configs.Greeting,
Signature: configs.Signature,
}
if user.Name == "" {
body.Name = user.Address
}
return body
}

// BuildTemplateWithId prepares a hermes.Body from a templateId
func BuildTemplateWithId(user *mailer.User, templateId string, templateData map[string]string, languages ...string) (subject string, body hermes.Body) {

T := lang.Bundle().GetTranslationFunc(languages...)
Expand Down

0 comments on commit 28e3124

Please sign in to comment.