Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localize Email Templates #16200

Merged
merged 21 commits into from
Jun 23, 2021
Merged
42 changes: 41 additions & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -317,19 +317,59 @@ password_pwned = The password you chose is on a <a target="_blank" rel="noopener
password_pwned_err = Could not complete request to HaveIBeenPwned

[mail]
footer = <p>© <a target="_blank" rel="noopener noreferrer" href="%[1]s">%[2]s</a></p>
view_it_on_footer = <a href="%[1]s">View it on %[2]s</a>.

activate_account = Please activate your account
activate_account.title = %s, please activate your account
activate_account.body = <p>Hi <b>%[1]s</b>, thanks for registering at %[4]s!</p><br><p>Please click the following link to activate your account within <b>%[2]s</b>:</p><br><p><a href="%[3]s">%[3]s</a></p><br><p>Not working? Try copying and pasting it to your browser.</p>

activate_email = Verify your email address
activate_email.title = %s, please verify your e-mail address
activate_email.body = <p>Hi <b>%[1]s</b>,</p><br><p>Please click the following link to verify your email address within <b>%[2]s</b>:</p><br><p><a href="%[3]s">%[3]s</a></p><br><p>Not working? Try copying and pasting it to your browser.</p>

register_notify = Welcome to Gitea
register_notify.title = %[1]s, welcome to %[2]s
register_notify.body = <p>Hi <b>%[1]s</b>, this is your registration confirmation email for %[4]s!</p><br><br><p>You can now login via username: %[2]s.</p><br><p><a href="%[3]suser/login">%[3]suser/login</a></p><br><p>If this account has been created for you, please <a href="%[3]suser/forgot_password">set your password</a> first.</p>

reset_password = Recover your account
reset_password.title = %s, you have requested to recover your account
reset_password.body = <p>Hi <b>%[1]s</b>,</p><br><p>Please click the following link to recover your account within <b>%[2]s</b>:</p><br><br><p><a href="%[3]s">%[3]s</a></p><br><p>Not working? Try copying and pasting it to your browser.</p>

register_success = Registration successful
register_notify = Welcome to Gitea

issue_assigned.pull = @%[1]s assigned you to the pull request <a href="@%[2]s">#@%[3]d</a> in repository %[4]s.
issue_assigned.issue = @%[1]s assigned you to the issue <a href="@%[2]s">#@%[3]d</a> in repository %[4]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 <a href="%[3]s"><b>%[4]s</b></a> to <a href="%[5]s"><b>%[6]s</b></a>.
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 = Closed #%[2]d.
issue.action.reopen = Reopened #%[2]d.
issue.action.merge = 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.new = Created #%[2]d.
issue.in_tree_path = In %s:

release.new.subject = %s in %s released
release.new.body = <b>@%[1]s</b> released <a href="%[2]s">%[3]s</a> in <a href="%[4]s">%[5]s</a>
release.title = Title: %s
release.note = Note:
release.downloads = Downloads:
release.download.zip = <a href="%s" rel="nofollow"><strong> Source Code (ZIP)</strong></a>
release.download.targz = <a href="%s"><strong> Source Code (TAR.GZ)</strong></a>

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 <a href="%[1]s">%[2]s</a> or just ignore it.

repo.collaborator.added.subject = %s added you to %s
repo.collaborator.added.body = <p>You have been added as a collaborator of repository: <code>%[1]s</code></p>

[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: 5 additions & 6 deletions templates/mail/auth/activate.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
<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>© <a target="_blank" rel="noopener noreferrer" href="{{AppUrl}}">{{AppName}}</a></p>
{{.i18n.Tr "mail.activate_account.body" .DisplayName .ActiveCodeLives $activate_url AppName | Str2html}}

{{.i18n.Tr "mail.footer" AppUrl AppName | Str2html}}
</body>
</html>
11 changes: 5 additions & 6 deletions templates/mail/auth/activate_email.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
<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>© <a target="_blank" rel="noopener noreferrer" href="{{AppUrl}}">{{AppName}}</a></p>
{{.i18n.Tr "mail.activate_email.body" .DisplayName .ActiveCodeLives $activate_url | Str2html}}

{{.i18n.Tr "mail.footer" AppUrl AppName | Str2html}}
</body>
</html>
10 changes: 4 additions & 6 deletions templates/mail/auth/register_notify.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
<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>

<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>© <a target="_blank" rel="noopener noreferrer" href="{{AppUrl}}">{{AppName}}</a></p>
{{.i18n.Tr "mail.register_notify.body" .DisplayName .Username AppUrl AppName | Str2html}}

{{.i18n.Tr "mail.footer" AppUrl AppName | Str2html}}
</body>
</html>
10 changes: 4 additions & 6 deletions templates/mail/auth/reset_passwd.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
<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>
{{.i18n.Tr "mail.reset_password.body" .DisplayName .ResetPwdCodeLives $recover_url | Str2html}}

<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>
{{.i18n.Tr "mail.footer" AppUrl AppName | Str2html}}
</body>
</html>
10 changes: 8 additions & 2 deletions templates/mail/issue/assigned.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@
</head>

<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 .Issue.Index .Repo | Str2html}}
{{else}}
{{.i18n.Tr "mail.issue_assigned.issue" .Doer.Name .Link .Issue.Index .Repo | Str2html}}
{{end}}
</p>
<div class="footer">
<p>
---
<br>
<a href="{{.Link}}">View it on {{AppName}}</a>.
{{.i18n.Tr "mail.view_it_on_footer" .Link AppName | Str2html}}
</p>
</div>
</body>
Expand Down
38 changes: 18 additions & 20 deletions templates/mail/issue/default.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,51 @@
</head>

<body>
{{if .IsMention}}<p><b>@{{.Doer.Name}}</b> mentioned you:</p>{{end}}
{{if .IsMention}}<p>{{.i18n.Tr "mail.issue.x_mentioned_you" .Doer.Name | Str2html}}</p>{{end}}
{{if eq .ActionName "push"}}
<p>
<b>{{.Doer.Name}}</b>
{{if .Comment.IsForcePush}}
{{ $oldCommitLink:= printf "%s%s/%s/commit/%s" AppUrl .Comment.Issue.PullRequest.BaseRepo.OwnerName .Comment.Issue.PullRequest.BaseRepo.Name .Comment.OldCommit}}
{{ $newCommitLink:= printf "%s%s/%s/commit/%s" AppUrl .Comment.Issue.PullRequest.BaseRepo.OwnerName .Comment.Issue.PullRequest.BaseRepo.Name .Comment.NewCommit}}
force-pushed the <b>{{.Comment.Issue.PullRequest.HeadBranch}}</b> from
<a href="{{$oldCommitLink}}"><b>{{ShortSha .Comment.OldCommit}}</b></a>
to
<a href="{{$newCommitLink}}"><b>{{ShortSha .Comment.NewCommit}}</b></a>.
{{$oldCommitLink := printf "%s%s/%s/commit/%s" AppUrl .Comment.Issue.PullRequest.BaseRepo.OwnerName .Comment.Issue.PullRequest.BaseRepo.Name .Comment.OldCommit}}
{{$oldShortSha := ShortSha .Comment.OldCommit}}
{{$newCommitLink := printf "%s%s/%s/commit/%s" AppUrl .Comment.Issue.PullRequest.BaseRepo.OwnerName .Comment.Issue.PullRequest.BaseRepo.Name .Comment.NewCommit}}
{{$newShortSha := ShortSha .Comment.NewCommit}}
{{.i18n.Tr "mail.issue.action.force_push" .Doer.Name .Comment.Issue.PullRequest.HeadBranch $oldCommitLink $oldShortSha $newCommitLink $newShortSha | Str2html}}
{{else}}
{{if eq .Comment.Commits.Len 1}}
{{printf "pushed 1 commit to %s:" .Comment.Issue.PullRequest.HeadBranch}}
{{.i18n.Tr "mail.issue.action.push_1" .Doer.Name .Comment.Issue.PullRequest.HeadBranch | Str2html}}
{{else}}
{{printf "pushed %d commits to %s:" .Comment.Commits.Len .Comment.Issue.PullRequest.HeadBranch}}
{{.i18n.Tr "mail.issue.action.push_1" .Doer.Name .Comment.Issue.PullRequest.HeadBranch .Comment.Commits.Len | Str2html}}
{{end}}
{{end}}
</p>
{{end}}
<p>
{{if eq .ActionName "close"}}
Closed #{{.Issue.Index}}.
{{.i18n.Tr "mail.issue.action.close" .Doer.Name .Issue.Index | Str2html}}
{{else if eq .ActionName "reopen"}}
Reopened #{{.Issue.Index}}.
{{.i18n.Tr "mail.issue.action.reopen" .Doer.Name .Issue.Index | Str2html}}
{{else if eq .ActionName "merge"}}
Merged #{{.Issue.Index}} into {{.Issue.PullRequest.BaseBranch}}.
{{.i18n.Tr "mail.issue.action.merge" .Doer.Name .Issue.Index .Issue.PullRequest.BaseBranch | Str2html}}
{{else if eq .ActionName "approve"}}
<b>@{{.Doer.Name}}</b> approved this pull request.
{{.i18n.Tr "mail.issue.action.approve" .Doer.Name | Str2html}}
{{else if eq .ActionName "reject"}}
<b>@{{.Doer.Name}}</b> requested changes on this pull request.
{{.i18n.Tr "mail.issue.action.reject" .Doer.Name | Str2html}}
{{else if eq .ActionName "review"}}
<b>@{{.Doer.Name}}</b> commented on this pull request.
{{.i18n.Tr "mail.issue.action.review" .Doer.Name | Str2html}}
{{else if eq .ActionName "review_dismissed"}}
<b>@{{.Doer.Name}}</b> dismissed last review from {{.Comment.Review.Reviewer.Name}} for this pull request.
{{.i18n.Tr "mail.issue.action.review_dismissed" .Doer.Name .Comment.Review.Reviewer.Name | Str2html}}
{{end}}

{{- if eq .Body ""}}
{{if eq .ActionName "new"}}
Created #{{.Issue.Index}}.
{{.i18n.Tr "mail.issue.action.new" .Doer.Name .Issue.Index | Str2html}}
{{end}}
{{else}}
{{.Body | Str2html}}
{{end -}}
{{- range .ReviewComments}}
<hr>
In {{.TreePath}}:
{{.i18n.Tr "mail.issue.in_tree_path" .TreePath}}
<div class="review">
<pre>{{.Patch}}</pre>
<div>{{.RenderedContent | Safe}}</div>
Expand All @@ -85,7 +83,7 @@
<p>
---
<br>
<a href="{{.Link}}">View it on {{AppName}}</a>.
{{.i18n.Tr "mail.view_it_on_footer" .Link AppName | Str2html}}
</p>
</div>
</body>
Expand Down
Loading