Skip to content

Commit 9149383

Browse files
6543AbdulrhmnGhanem
authored andcommitted
Localize Email Templates (go-gitea#16200)
close go-gitea#14822
1 parent 4e39331 commit 9149383

13 files changed

+143
-71
lines changed

options/locale/locale_en-US.ini

+46-1
Original file line numberDiff line numberDiff line change
@@ -317,19 +317,64 @@ password_pwned = The password you chose is on a <a target="_blank" rel="noopener
317317
password_pwned_err = Could not complete request to HaveIBeenPwned
318318
319319
[mail]
320+
view_it_on = View it on %s
321+
link_not_working_do_paste = Not working? Try copying and pasting it to your browser.
322+
hi_user_x = Hi <b>%s</b>,
323+
320324
activate_account = Please activate your account
325+
activate_account.title = %s, please activate your account
326+
activate_account.test_1 = Hi <b>%[1]s</b>, thanks for registering at %[2]s!
327+
activate_account.test_2 = Please click the following link to activate your account within <b>%s</b>:
328+
321329
activate_email = Verify your email address
330+
activate_email.title = %s, please verify your e-mail address
331+
activate_email.text = Please click the following link to verify your email address within <b>%s</b>:
332+
333+
register_notify = Welcome to Gitea
334+
register_notify.title = %[1]s, welcome to %[2]s
335+
register_notify.text_1 = this is your registration confirmation email for %s!
336+
register_notify.text_2 = You can now login via username: %s.
337+
register_notify.text_3 = If this account has been created for you, please <a href="%s">set your password</a> first.
338+
322339
reset_password = Recover your account
340+
reset_password.title = %s, you have requested to recover your account
341+
reset_password.text = Please click the following link to recover your account within <b>%s</b>:
342+
323343
register_success = Registration successful
324-
register_notify = Welcome to Gitea
344+
345+
issue_assigned.pull = @%[1]s assigned you to the pull request %[2]s in repository %[3]s.
346+
issue_assigned.issue = @%[1]s assigned you to the issue %[2]s in repository %[3]s.
347+
348+
issue.x_mentioned_you = <b>@%s</b> mentioned you:
349+
issue.action.force_push = <b>%[1]s</b> force-pushed the <b>%[2]s</b> from %[3]s to %[4]s.
350+
issue.action.push_1 = <b>@%[1]s</b> pushed 1 commit to %[2]s
351+
issue.action.push_n = <b>@%[1]s</b> pushed %[3]d commits to %s: %[2]s
352+
issue.action.close = <b>@%[1]s</b> closed #%[2]d.
353+
issue.action.reopen = <b>@%[1]s</b> reopened #%[2]d.
354+
issue.action.merge = <b>@%[1]s</b> merged #%[2]d into #%[3]s.
355+
issue.action.approve = <b>@%[1]s</b> approved this pull request.
356+
issue.action.reject = <b>@%[1]s</b> requested changes on this pull request.
357+
issue.action.review = <b>@%[1]s</b> commented on this pull request.
358+
issue.action.review_dismissed = <b>@%[1]s</b> dismissed last review from %[2]s for this pull request.
359+
issue.action.ready_for_review = <b>@%[1]s</b> marked this pull request ready for review.
360+
issue.action.new = Created #%[2]d.
361+
issue.in_tree_path = In %s:
325362
326363
release.new.subject = %s in %s released
364+
release.new.text = <b>@%[1]s</b> released %[2]s in %[3]s
365+
release.title = Title: %s
366+
release.note = Note:
367+
release.downloads = Downloads:
368+
release.download.zip = Source Code (ZIP)
369+
release.download.targz = Source Code (TAR.GZ)
327370
328371
repo.transfer.subject_to = %s would like to transfer "%s" to %s
329372
repo.transfer.subject_to_you = %s would like to transfer "%s" to you
330373
repo.transfer.to_you = you
374+
repo.transfer.body = To accept or reject it visit %s or just ignore it.
331375
332376
repo.collaborator.added.subject = %s added you to %s
377+
repo.collaborator.added.text = You have been added as a collaborator of repository:
333378
334379
[modal]
335380
yes = Yes

services/mailer/mail.go

+16-11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"code.gitea.io/gitea/modules/markup"
2323
"code.gitea.io/gitea/modules/markup/markdown"
2424
"code.gitea.io/gitea/modules/setting"
25+
"code.gitea.io/gitea/modules/templates"
2526
"code.gitea.io/gitea/modules/timeutil"
2627
"code.gitea.io/gitea/modules/translation"
2728

@@ -67,13 +68,14 @@ func sendUserMail(language string, u *models.User, tpl base.TplName, code, subje
6768
"ActiveCodeLives": timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, language),
6869
"ResetPwdCodeLives": timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, language),
6970
"Code": code,
70-
"i18n": locale,
7171
"Language": locale.Language(),
72+
// helper
73+
"i18n": locale,
74+
"Str2html": templates.Str2html,
7275
}
7376

7477
var content bytes.Buffer
7578

76-
// TODO: i18n templates?
7779
if err := bodyTemplates.ExecuteTemplate(&content, string(tpl), data); err != nil {
7880
log.Error("Template: %v", err)
7981
return
@@ -104,13 +106,14 @@ func SendActivateEmailMail(u *models.User, email *models.EmailAddress) {
104106
"ActiveCodeLives": timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, locale.Language()),
105107
"Code": u.GenerateEmailActivateCode(email.Email),
106108
"Email": email.Email,
107-
"i18n": locale,
108109
"Language": locale.Language(),
110+
// helper
111+
"i18n": locale,
112+
"Str2html": templates.Str2html,
109113
}
110114

111115
var content bytes.Buffer
112116

113-
// TODO: i18n templates?
114117
if err := bodyTemplates.ExecuteTemplate(&content, string(mailAuthActivateEmail), data); err != nil {
115118
log.Error("Template: %v", err)
116119
return
@@ -129,13 +132,14 @@ func SendRegisterNotifyMail(u *models.User) {
129132
data := map[string]interface{}{
130133
"DisplayName": u.DisplayName(),
131134
"Username": u.Name,
132-
"i18n": locale,
133135
"Language": locale.Language(),
136+
// helper
137+
"i18n": locale,
138+
"Str2html": templates.Str2html,
134139
}
135140

136141
var content bytes.Buffer
137142

138-
// TODO: i18n templates?
139143
if err := bodyTemplates.ExecuteTemplate(&content, string(mailAuthRegisterNotify), data); err != nil {
140144
log.Error("Template: %v", err)
141145
return
@@ -157,13 +161,14 @@ func SendCollaboratorMail(u, doer *models.User, repo *models.Repository) {
157161
"Subject": subject,
158162
"RepoName": repoName,
159163
"Link": repo.HTMLURL(),
160-
"i18n": locale,
161164
"Language": locale.Language(),
165+
// helper
166+
"i18n": locale,
167+
"Str2html": templates.Str2html,
162168
}
163169

164170
var content bytes.Buffer
165171

166-
// TODO: i18n templates?
167172
if err := bodyTemplates.ExecuteTemplate(&content, string(mailNotifyCollaborator), data); err != nil {
168173
log.Error("Template: %v", err)
169174
return
@@ -239,12 +244,13 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
239244
"ActionType": actType,
240245
"ActionName": actName,
241246
"ReviewComments": reviewComments,
242-
"i18n": locale,
243247
"Language": locale.Language(),
248+
// helper
249+
"i18n": locale,
250+
"Str2html": templates.Str2html,
244251
}
245252

246253
var mailSubject bytes.Buffer
247-
// TODO: i18n templates?
248254
if err := subjectTemplates.ExecuteTemplate(&mailSubject, string(tplName), mailMeta); err == nil {
249255
subject = sanitizeSubject(mailSubject.String())
250256
if subject == "" {
@@ -260,7 +266,6 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
260266

261267
var mailBody bytes.Buffer
262268

263-
// TODO: i18n templates?
264269
if err := bodyTemplates.ExecuteTemplate(&mailBody, string(tplName), mailMeta); err != nil {
265270
log.Error("ExecuteTemplate [%s]: %v", string(tplName)+"/body", err)
266271
}

services/mailer/mail_release.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"code.gitea.io/gitea/modules/markup"
1414
"code.gitea.io/gitea/modules/markup/markdown"
1515
"code.gitea.io/gitea/modules/setting"
16+
"code.gitea.io/gitea/modules/templates"
1617
"code.gitea.io/gitea/modules/translation"
1718
)
1819

@@ -63,13 +64,14 @@ func mailNewRelease(lang string, tos []string, rel *models.Release) {
6364
mailMeta := map[string]interface{}{
6465
"Release": rel,
6566
"Subject": subject,
66-
"i18n": locale,
6767
"Language": locale.Language(),
68+
// helper
69+
"i18n": locale,
70+
"Str2html": templates.Str2html,
6871
}
6972

7073
var mailBody bytes.Buffer
7174

72-
// TODO: i18n templates?
7375
if err := bodyTemplates.ExecuteTemplate(&mailBody, string(tplNewReleaseMail), mailMeta); err != nil {
7476
log.Error("ExecuteTemplate [%s]: %v", string(tplNewReleaseMail)+"/body", err)
7577
return

services/mailer/mail_repo.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010

1111
"code.gitea.io/gitea/models"
12+
"code.gitea.io/gitea/modules/templates"
1213
"code.gitea.io/gitea/modules/translation"
1314
)
1415

@@ -57,12 +58,13 @@ func sendRepoTransferNotifyMailPerLang(lang string, newOwner, doer *models.User,
5758
"Repo": repo.FullName(),
5859
"Link": repo.HTMLURL(),
5960
"Subject": subject,
60-
"i18n": locale,
6161
"Language": locale.Language(),
6262
"Destination": destination,
63+
// helper
64+
"i18n": locale,
65+
"Str2html": templates.Str2html,
6366
}
6467

65-
// TODO: i18n templates?
6668
if err := bodyTemplates.ExecuteTemplate(&content, string(mailRepoTransferNotify), data); err != nil {
6769
return err
6870
}

templates/mail/auth/activate.tmpl

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
<html>
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5-
<title>{{.DisplayName}}, please activate your account</title>
5+
<title>{{.i18n.Tr "mail.activate_account.title" .DisplayName}}</title>
66
</head>
77

8+
{{ $activate_url := printf "%suser/activate?code=%s" AppUrl .Code}}
89
<body>
9-
<p>Hi <b>{{.DisplayName}}</b>, thanks for registering at {{AppName}}!</p>
10-
<p>Please click the following link to activate your account within <b>{{.ActiveCodeLives}}</b>:</p>
11-
<p><a href="{{AppUrl}}user/activate?code={{.Code}}">{{AppUrl}}user/activate?code={{.Code}}</a></p>
12-
<p>Not working? Try copying and pasting it to your browser.</p>
10+
<p>{{.i18n.Tr "mail.activate_account.test_1" .DisplayName AppName | Str2html}}</p><br>
11+
<p>{{.i18n.Tr "mail.activate_account.test_2" .ActiveCodeLives | Str2html}}</p><p><a href="{{$activate_url}}">{{$activate_url}}</a></p><br>
12+
<p>{{.i18n.Tr "mail.link_not_working_do_paste" .DisplayName AppName | Str2html}}</p>
13+
1314
<p>© <a target="_blank" rel="noopener noreferrer" href="{{AppUrl}}">{{AppName}}</a></p>
1415
</body>
1516
</html>

templates/mail/auth/activate_email.tmpl

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
<html>
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5-
<title>{{.DisplayName}}, please verify your e-mail address</title>
5+
<title>{{.i18n.Tr "mail.activate_email.title" .DisplayName}}</title>
66
</head>
77

8+
{{ $activate_url := printf "%suser/activate_email?code=%s&email=%s" AppUrl .Code .Email}}
89
<body>
9-
<p>Hi <b>{{.DisplayName}}</b>,</p>
10-
<p>Please click the following link to verify your email address within <b>{{.ActiveCodeLives}}</b>:</p>
11-
<p><a href="{{AppUrl}}user/activate_email?code={{.Code}}&email={{.Email}}">{{AppUrl}}user/activate_email?code={{.Code}}&email={{.Email}}</a></p>
12-
<p>Not working? Try copying and pasting it to your browser.</p>
10+
<p>{{.i18n.Tr "mail.hi_user_x" .DisplayName | Str2html}}</p><br>
11+
<p>{{.i18n.Tr "mail.activate_email.text" .ActiveCodeLives | Str2html}}</p><p><a href="{{$activate_url}}">{{$activate_url}}</a></p><br>
12+
<p>{{.i18n.Tr "mail.link_not_working_do_paste" .DisplayName AppName | Str2html}}</p>
13+
1314
<p>© <a target="_blank" rel="noopener noreferrer" href="{{AppUrl}}">{{AppName}}</a></p>
1415
</body>
1516
</html>

templates/mail/auth/register_notify.tmpl

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
<html>
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5-
<title>{{.DisplayName}}, welcome to {{AppName}}</title>
5+
<title>{{.i18n.Tr "mail.register_notify.title" .DisplayName AppName}}</title>
66
</head>
77

8+
{{$set_pwd_url := printf "%[1]suser/forgot_password" AppUrl}}
89
<body>
9-
<p>Hi <b>{{.DisplayName}}</b>, this is your registration confirmation email for {{AppName}}!</p>
10-
<p>You can now login via username: {{.Username}}.</p>
11-
<p><a href="{{AppUrl}}user/login">{{AppUrl}}user/login</a></p>
12-
<p>If this account has been created for you, please <a href="{{AppUrl}}user/forgot_password">set your password</a> first.</p>
10+
<p>{{.i18n.Tr "mail.hi_user_x" .DisplayName | Str2html}}</p><br>
11+
<p>{{.i18n.Tr "mail.register_notify.text_1" AppName}}</p><br>
12+
<p>{{.i18n.Tr "mail.register_notify.text_2" .Username}}</p><p><a href="{{AppUrl}}user/login">{{AppUrl}}user/login</a></p><br>
13+
<p>{{.i18n.Tr "mail.register_notify.text_3" $set_pwd_url | Str2html}}</p><br>
14+
1315
<p>© <a target="_blank" rel="noopener noreferrer" href="{{AppUrl}}">{{AppName}}</a></p>
1416
</body>
1517
</html>

templates/mail/auth/reset_passwd.tmpl

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
<html>
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5-
<title>{{.DisplayName}}, you have requested to recover your account</title>
5+
<title>{{.i18n.Tr "mail.reset_password.title" .DisplayName}}</title>
66
</head>
77

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

12-
<p><a href="{{AppUrl}}user/recover_account?code={{.Code}}">{{AppUrl}}user/recover_account?code={{.Code}}</a></p>
13-
<p>Not working? Try copying and pasting it to your browser.</p>
1414
<p>© <a target="_blank" rel="noopener noreferrer" href="{{AppUrl}}">{{AppName}}</a></p>
1515
</body>
1616
</html>

templates/mail/issue/assigned.tmpl

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@
88
<title>{{.Subject}}</title>
99
</head>
1010

11+
{{$repo_url := printf "<a href='%s'>%s</a>" .Release.Repo.HTMLURL .Release.Repo.FullName}}
12+
{{$link := printf "<a href='%s'>#%d</a>" .Link .Issue.Index}}
1113
<body>
12-
<p>@{{.Doer.Name}} assigned you to the {{if .IsPull}}pull request{{else}}issue{{end}} <a href="{{.Link}}">#{{.Issue.Index}}</a> in repository {{.Repo}}.</p>
14+
<p>
15+
{{if .IsPull}}
16+
{{.i18n.Tr "mail.issue_assigned.pull" .Doer.Name $link $repo_url | Str2html}}
17+
{{else}}
18+
{{.i18n.Tr "mail.issue_assigned.issue" .Doer.Name $link $repo_url | Str2html}}
19+
{{end}}
20+
</p>
1321
<div class="footer">
1422
<p>
1523
---
1624
<br>
17-
<a href="{{.Link}}">View it on {{AppName}}</a>.
25+
<a href="{{.Link}}">{{.i18n.Tr "mail.view_it_on" AppName}}</a>.
1826
</p>
1927
</div>
2028
</body>

0 commit comments

Comments
 (0)