summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-06-23 14:33:21 +0200
committerGitHub <noreply@github.com>2021-06-23 14:33:21 +0200
commitbe81dc8b20b86c87031cd1d2d7c9a2fe82f52ba8 (patch)
treeef1705f5c1dd04e8e1810af127aa5bd1afaed478 /services
parentd4ae87ea32aaef458da48404b8c7bc11d0165852 (diff)
downloadgitea-be81dc8b20b86c87031cd1d2d7c9a2fe82f52ba8.tar.gz
gitea-be81dc8b20b86c87031cd1d2d7c9a2fe82f52ba8.zip
Localize Email Templates (#16200)
close #14822
Diffstat (limited to 'services')
-rw-r--r--services/mailer/mail.go27
-rw-r--r--services/mailer/mail_release.go6
-rw-r--r--services/mailer/mail_repo.go6
3 files changed, 24 insertions, 15 deletions
diff --git a/services/mailer/mail.go b/services/mailer/mail.go
index fdc070e4be..7494d04f2b 100644
--- a/services/mailer/mail.go
+++ b/services/mailer/mail.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/translation"
@@ -67,13 +68,14 @@ func sendUserMail(language string, u *models.User, tpl base.TplName, code, subje
"ActiveCodeLives": timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, language),
"ResetPwdCodeLives": timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, language),
"Code": code,
- "i18n": locale,
"Language": locale.Language(),
+ // helper
+ "i18n": locale,
+ "Str2html": templates.Str2html,
}
var content bytes.Buffer
- // TODO: i18n templates?
if err := bodyTemplates.ExecuteTemplate(&content, string(tpl), data); err != nil {
log.Error("Template: %v", err)
return
@@ -104,13 +106,14 @@ func SendActivateEmailMail(u *models.User, email *models.EmailAddress) {
"ActiveCodeLives": timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, locale.Language()),
"Code": u.GenerateEmailActivateCode(email.Email),
"Email": email.Email,
- "i18n": locale,
"Language": locale.Language(),
+ // helper
+ "i18n": locale,
+ "Str2html": templates.Str2html,
}
var content bytes.Buffer
- // TODO: i18n templates?
if err := bodyTemplates.ExecuteTemplate(&content, string(mailAuthActivateEmail), data); err != nil {
log.Error("Template: %v", err)
return
@@ -129,13 +132,14 @@ func SendRegisterNotifyMail(u *models.User) {
data := map[string]interface{}{
"DisplayName": u.DisplayName(),
"Username": u.Name,
- "i18n": locale,
"Language": locale.Language(),
+ // helper
+ "i18n": locale,
+ "Str2html": templates.Str2html,
}
var content bytes.Buffer
- // TODO: i18n templates?
if err := bodyTemplates.ExecuteTemplate(&content, string(mailAuthRegisterNotify), data); err != nil {
log.Error("Template: %v", err)
return
@@ -157,13 +161,14 @@ func SendCollaboratorMail(u, doer *models.User, repo *models.Repository) {
"Subject": subject,
"RepoName": repoName,
"Link": repo.HTMLURL(),
- "i18n": locale,
"Language": locale.Language(),
+ // helper
+ "i18n": locale,
+ "Str2html": templates.Str2html,
}
var content bytes.Buffer
- // TODO: i18n templates?
if err := bodyTemplates.ExecuteTemplate(&content, string(mailNotifyCollaborator), data); err != nil {
log.Error("Template: %v", err)
return
@@ -239,12 +244,13 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
"ActionType": actType,
"ActionName": actName,
"ReviewComments": reviewComments,
- "i18n": locale,
"Language": locale.Language(),
+ // helper
+ "i18n": locale,
+ "Str2html": templates.Str2html,
}
var mailSubject bytes.Buffer
- // TODO: i18n templates?
if err := subjectTemplates.ExecuteTemplate(&mailSubject, string(tplName), mailMeta); err == nil {
subject = sanitizeSubject(mailSubject.String())
if subject == "" {
@@ -260,7 +266,6 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
var mailBody bytes.Buffer
- // TODO: i18n templates?
if err := bodyTemplates.ExecuteTemplate(&mailBody, string(tplName), mailMeta); err != nil {
log.Error("ExecuteTemplate [%s]: %v", string(tplName)+"/body", err)
}
diff --git a/services/mailer/mail_release.go b/services/mailer/mail_release.go
index 1e12fe13ac..ff008be1d8 100644
--- a/services/mailer/mail_release.go
+++ b/services/mailer/mail_release.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/modules/translation"
)
@@ -63,13 +64,14 @@ func mailNewRelease(lang string, tos []string, rel *models.Release) {
mailMeta := map[string]interface{}{
"Release": rel,
"Subject": subject,
- "i18n": locale,
"Language": locale.Language(),
+ // helper
+ "i18n": locale,
+ "Str2html": templates.Str2html,
}
var mailBody bytes.Buffer
- // TODO: i18n templates?
if err := bodyTemplates.ExecuteTemplate(&mailBody, string(tplNewReleaseMail), mailMeta); err != nil {
log.Error("ExecuteTemplate [%s]: %v", string(tplNewReleaseMail)+"/body", err)
return
diff --git a/services/mailer/mail_repo.go b/services/mailer/mail_repo.go
index c742101ee1..5ef67b7c65 100644
--- a/services/mailer/mail_repo.go
+++ b/services/mailer/mail_repo.go
@@ -9,6 +9,7 @@ import (
"fmt"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/modules/translation"
)
@@ -57,12 +58,13 @@ func sendRepoTransferNotifyMailPerLang(lang string, newOwner, doer *models.User,
"Repo": repo.FullName(),
"Link": repo.HTMLURL(),
"Subject": subject,
- "i18n": locale,
"Language": locale.Language(),
"Destination": destination,
+ // helper
+ "i18n": locale,
+ "Str2html": templates.Str2html,
}
- // TODO: i18n templates?
if err := bodyTemplates.ExecuteTemplate(&content, string(mailRepoTransferNotify), data); err != nil {
return err
}