Skip to content

Commit

Permalink
Localize Email Templates (#16200)
Browse files Browse the repository at this point in the history
close #14822
  • Loading branch information
6543 committed Jun 23, 2021
1 parent d4ae87e commit be81dc8
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 71 deletions.
47 changes: 46 additions & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -317,19 +317,64 @@ password_pwned = The password you chose is on a <a target="_blank" rel="noopener
password_pwned_err = Could not complete request to HaveIBeenPwned
[mail]
view_it_on = View it on %s
link_not_working_do_paste = Not working? Try copying and pasting it to your browser.
hi_user_x = Hi <b>%s</b>,
activate_account = Please activate your account
activate_account.title = %s, please activate your account
activate_account.test_1 = Hi <b>%[1]s</b>, thanks for registering at %[2]s!
activate_account.test_2 = Please click the following link to activate your account within <b>%s</b>:
activate_email = Verify your email address
activate_email.title = %s, please verify your e-mail address
activate_email.text = Please click the following link to verify your email address within <b>%s</b>:
register_notify = Welcome to Gitea
register_notify.title = %[1]s, welcome to %[2]s
register_notify.text_1 = this is your registration confirmation email for %s!
register_notify.text_2 = You can now login via username: %s.
register_notify.text_3 = If this account has been created for you, please <a href="%s">set your password</a> first.
reset_password = Recover your account
reset_password.title = %s, you have requested to recover your account
reset_password.text = Please click the following link to recover your account within <b>%s</b>:
register_success = Registration successful
register_notify = Welcome to Gitea
issue_assigned.pull = @%[1]s assigned you to the pull request %[2]s in repository %[3]s.
issue_assigned.issue = @%[1]s assigned you to the issue %[2]s in repository %[3]s.
issue.x_mentioned_you = <b>@%s</b> mentioned you:
issue.action.force_push = <b>%[1]s</b> force-pushed the <b>%[2]s</b> from %[3]s to %[4]s.
issue.action.push_1 = <b>@%[1]s</b> pushed 1 commit to %[2]s
issue.action.push_n = <b>@%[1]s</b> pushed %[3]d commits to %s: %[2]s
issue.action.close = <b>@%[1]s</b> closed #%[2]d.
issue.action.reopen = <b>@%[1]s</b> reopened #%[2]d.
issue.action.merge = <b>@%[1]s</b> merged #%[2]d into #%[3]s.
issue.action.approve = <b>@%[1]s</b> approved this pull request.
issue.action.reject = <b>@%[1]s</b> requested changes on this pull request.
issue.action.review = <b>@%[1]s</b> commented on this pull request.
issue.action.review_dismissed = <b>@%[1]s</b> dismissed last review from %[2]s for this pull request.
issue.action.ready_for_review = <b>@%[1]s</b> marked this pull request ready for review.
issue.action.new = Created #%[2]d.
issue.in_tree_path = In %s:
release.new.subject = %s in %s released
release.new.text = <b>@%[1]s</b> released %[2]s in %[3]s
release.title = Title: %s
release.note = Note:
release.downloads = Downloads:
release.download.zip = Source Code (ZIP)
release.download.targz = Source Code (TAR.GZ)
repo.transfer.subject_to = %s would like to transfer "%s" to %s
repo.transfer.subject_to_you = %s would like to transfer "%s" to you
repo.transfer.to_you = you
repo.transfer.body = To accept or reject it visit %s or just ignore it.
repo.collaborator.added.subject = %s added you to %s
repo.collaborator.added.text = You have been added as a collaborator of repository:
[modal]
yes = Yes
Expand Down
27 changes: 16 additions & 11 deletions services/mailer/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 == "" {
Expand All @@ -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)
}
Expand Down
6 changes: 4 additions & 2 deletions services/mailer/mail_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions services/mailer/mail_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/modules/translation"
)

Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 6 additions & 5 deletions templates/mail/auth/activate.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{{.DisplayName}}, please activate your account</title>
<title>{{.i18n.Tr "mail.activate_account.title" .DisplayName}}</title>
</head>

{{ $activate_url := printf "%suser/activate?code=%s" AppUrl .Code}}
<body>
<p>Hi <b>{{.DisplayName}}</b>, thanks for registering at {{AppName}}!</p>
<p>Please click the following link to activate your account within <b>{{.ActiveCodeLives}}</b>:</p>
<p><a href="{{AppUrl}}user/activate?code={{.Code}}">{{AppUrl}}user/activate?code={{.Code}}</a></p>
<p>Not working? Try copying and pasting it to your browser.</p>
<p>{{.i18n.Tr "mail.activate_account.test_1" .DisplayName AppName | Str2html}}</p><br>
<p>{{.i18n.Tr "mail.activate_account.test_2" .ActiveCodeLives | Str2html}}</p><p><a href="{{$activate_url}}">{{$activate_url}}</a></p><br>
<p>{{.i18n.Tr "mail.link_not_working_do_paste" .DisplayName AppName | Str2html}}</p>

<p>© <a target="_blank" rel="noopener noreferrer" href="{{AppUrl}}">{{AppName}}</a></p>
</body>
</html>
11 changes: 6 additions & 5 deletions templates/mail/auth/activate_email.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{{.DisplayName}}, please verify your e-mail address</title>
<title>{{.i18n.Tr "mail.activate_email.title" .DisplayName}}</title>
</head>

{{ $activate_url := printf "%suser/activate_email?code=%s&email=%s" AppUrl .Code .Email}}
<body>
<p>Hi <b>{{.DisplayName}}</b>,</p>
<p>Please click the following link to verify your email address within <b>{{.ActiveCodeLives}}</b>:</p>
<p><a href="{{AppUrl}}user/activate_email?code={{.Code}}&email={{.Email}}">{{AppUrl}}user/activate_email?code={{.Code}}&email={{.Email}}</a></p>
<p>Not working? Try copying and pasting it to your browser.</p>
<p>{{.i18n.Tr "mail.hi_user_x" .DisplayName | Str2html}}</p><br>
<p>{{.i18n.Tr "mail.activate_email.text" .ActiveCodeLives | Str2html}}</p><p><a href="{{$activate_url}}">{{$activate_url}}</a></p><br>
<p>{{.i18n.Tr "mail.link_not_working_do_paste" .DisplayName AppName | Str2html}}</p>

<p>© <a target="_blank" rel="noopener noreferrer" href="{{AppUrl}}">{{AppName}}</a></p>
</body>
</html>
12 changes: 7 additions & 5 deletions templates/mail/auth/register_notify.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{{.DisplayName}}, welcome to {{AppName}}</title>
<title>{{.i18n.Tr "mail.register_notify.title" .DisplayName AppName}}</title>
</head>

{{$set_pwd_url := printf "%[1]suser/forgot_password" AppUrl}}
<body>
<p>Hi <b>{{.DisplayName}}</b>, this is your registration confirmation email for {{AppName}}!</p>
<p>You can now login via username: {{.Username}}.</p>
<p><a href="{{AppUrl}}user/login">{{AppUrl}}user/login</a></p>
<p>If this account has been created for you, please <a href="{{AppUrl}}user/forgot_password">set your password</a> first.</p>
<p>{{.i18n.Tr "mail.hi_user_x" .DisplayName | Str2html}}</p><br>
<p>{{.i18n.Tr "mail.register_notify.text_1" AppName}}</p><br>
<p>{{.i18n.Tr "mail.register_notify.text_2" .Username}}</p><p><a href="{{AppUrl}}user/login">{{AppUrl}}user/login</a></p><br>
<p>{{.i18n.Tr "mail.register_notify.text_3" $set_pwd_url | Str2html}}</p><br>

<p>© <a target="_blank" rel="noopener noreferrer" href="{{AppUrl}}">{{AppName}}</a></p>
</body>
</html>
10 changes: 5 additions & 5 deletions templates/mail/auth/reset_passwd.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{{.DisplayName}}, you have requested to recover your account</title>
<title>{{.i18n.Tr "mail.reset_password.title" .DisplayName}}</title>
</head>

{{ $recover_url := printf "%suser/recover_account?code=%s" AppUrl .Code}}
<body>
<p>Hi <b>{{.DisplayName}}</b>,</p>
<p>Please click the following link to recover your account within <b>{{.ResetPwdCodeLives}}</b>:</p>
<p>{{.i18n.Tr "mail.hi_user_x" .DisplayName | Str2html}}</p><br>
<p>{{.i18n.Tr "mail.reset_password.text" .ResetPwdCodeLives | Str2html}}</p><p><a href="{{$recover_url}}">{{$recover_url}}</a></p><br>
<p>{{.i18n.Tr "mail.link_not_working_do_paste" .DisplayName AppName | Str2html}}</p>

<p><a href="{{AppUrl}}user/recover_account?code={{.Code}}">{{AppUrl}}user/recover_account?code={{.Code}}</a></p>
<p>Not working? Try copying and pasting it to your browser.</p>
<p>© <a target="_blank" rel="noopener noreferrer" href="{{AppUrl}}">{{AppName}}</a></p>
</body>
</html>
12 changes: 10 additions & 2 deletions templates/mail/issue/assigned.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@
<title>{{.Subject}}</title>
</head>

{{$repo_url := printf "<a href='%s'>%s</a>" .Release.Repo.HTMLURL .Release.Repo.FullName}}
{{$link := printf "<a href='%s'>#%d</a>" .Link .Issue.Index}}
<body>
<p>@{{.Doer.Name}} assigned you to the {{if .IsPull}}pull request{{else}}issue{{end}} <a href="{{.Link}}">#{{.Issue.Index}}</a> in repository {{.Repo}}.</p>
<p>
{{if .IsPull}}
{{.i18n.Tr "mail.issue_assigned.pull" .Doer.Name $link $repo_url | Str2html}}
{{else}}
{{.i18n.Tr "mail.issue_assigned.issue" .Doer.Name $link $repo_url | Str2html}}
{{end}}
</p>
<div class="footer">
<p>
---
<br>
<a href="{{.Link}}">View it on {{AppName}}</a>.
<a href="{{.Link}}">{{.i18n.Tr "mail.view_it_on" AppName}}</a>.
</p>
</div>
</body>
Expand Down
Loading

0 comments on commit be81dc8

Please sign in to comment.