diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2022-02-08 11:02:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-08 11:02:30 +0800 |
commit | a60e8be8d15e90a44f2a746a4e8d81a81e03d2db (patch) | |
tree | 256934930648471f3eddb1e4dcf2f077aaf95e0c /templates/repo | |
parent | 7b25a010c89835e036f1b0cc5af65249bfd2781b (diff) | |
download | gitea-a60e8be8d15e90a44f2a746a4e8d81a81e03d2db.tar.gz gitea-a60e8be8d15e90a44f2a746a4e8d81a81e03d2db.zip |
Refactor i18n, use Locale to provide i18n/translation related functions (#18648)
* remove unnecessary web context data fields, and unify the i18n/translation related functions to `Locale`
* in development, show an error if a translation key is missing
* remove the unnecessary loops `for _, lang := range translation.AllLangs()` for every request, which improves the performance slightly
* use `ctx.Locale.Language()` instead of `ctx.Data["Lang"].(string)`
* add more comments about how the Locale/LangType fields are used
Diffstat (limited to 'templates/repo')
-rw-r--r-- | templates/repo/activity.tmpl | 12 | ||||
-rw-r--r-- | templates/repo/commit_page.tmpl | 4 | ||||
-rw-r--r-- | templates/repo/commits_list.tmpl | 4 | ||||
-rw-r--r-- | templates/repo/diff/comments.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/issue/milestone_issues.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/issue/milestones.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/issue/view_content.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/issue/view_content/comments.tmpl | 6 | ||||
-rw-r--r-- | templates/repo/issue/view_content/pull.tmpl | 4 | ||||
-rw-r--r-- | templates/repo/issue/view_title.tmpl | 4 | ||||
-rw-r--r-- | templates/repo/projects/list.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/projects/view.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/release/list.tmpl | 4 | ||||
-rw-r--r-- | templates/repo/settings/lfs.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/settings/lfs_file_find.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/settings/lfs_locks.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/view_list.tmpl | 4 | ||||
-rw-r--r-- | templates/repo/wiki/pages.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/wiki/revision.tmpl | 2 | ||||
-rw-r--r-- | templates/repo/wiki/view.tmpl | 2 |
20 files changed, 33 insertions, 33 deletions
diff --git a/templates/repo/activity.tmpl b/templates/repo/activity.tmpl index 3086ca8e8d..36108dddcb 100644 --- a/templates/repo/activity.tmpl +++ b/templates/repo/activity.tmpl @@ -131,7 +131,7 @@ {{if not .IsTag}} <a class="title" href="{{$.RepoLink}}/src/{{.TagName | PathEscapeSegments}}">{{.Title | RenderEmoji}}</a> {{end}} - {{TimeSinceUnix .CreatedUnix $.Lang}} + {{TimeSinceUnix .CreatedUnix $.i18n.Lang}} </p> {{end}} </div> @@ -150,7 +150,7 @@ <p class="desc"> <span class="ui purple label">{{$.i18n.Tr "repo.activity.merged_prs_label"}}</span> #{{.Index}} <a class="title" href="{{$.RepoLink}}/pulls/{{.Index}}">{{.Issue.Title | RenderEmoji}}</a> - {{TimeSinceUnix .MergedUnix $.Lang}} + {{TimeSinceUnix .MergedUnix $.i18n.Lang}} </p> {{end}} </div> @@ -169,7 +169,7 @@ <p class="desc"> <span class="ui green label">{{$.i18n.Tr "repo.activity.opened_prs_label"}}</span> #{{.Index}} <a class="title" href="{{$.RepoLink}}/pulls/{{.Index}}">{{.Issue.Title | RenderEmoji}}</a> - {{TimeSinceUnix .Issue.CreatedUnix $.Lang}} + {{TimeSinceUnix .Issue.CreatedUnix $.i18n.Lang}} </p> {{end}} </div> @@ -188,7 +188,7 @@ <p class="desc"> <span class="ui red label">{{$.i18n.Tr "repo.activity.closed_issue_label"}}</span> #{{.Index}} <a class="title" href="{{$.RepoLink}}/issues/{{.Index}}">{{.Title | RenderEmoji}}</a> - {{TimeSinceUnix .ClosedUnix $.Lang}} + {{TimeSinceUnix .ClosedUnix $.i18n.Lang}} </p> {{end}} </div> @@ -207,7 +207,7 @@ <p class="desc"> <span class="ui green label">{{$.i18n.Tr "repo.activity.new_issue_label"}}</span> #{{.Index}} <a class="title" href="{{$.RepoLink}}/issues/{{.Index}}">{{.Title | RenderEmoji}}</a> - {{TimeSinceUnix .CreatedUnix $.Lang}} + {{TimeSinceUnix .CreatedUnix $.i18n.Lang}} </p> {{end}} </div> @@ -231,7 +231,7 @@ {{else}} <a class="title" href="{{$.RepoLink}}/issues/{{.Index}}">{{.Title | RenderEmoji}}</a> {{end}} - {{TimeSinceUnix .UpdatedUnix $.Lang}} + {{TimeSinceUnix .UpdatedUnix $.i18n.Lang}} </p> {{end}} </div> diff --git a/templates/repo/commit_page.tmpl b/templates/repo/commit_page.tmpl index 931201fed6..331c439c02 100644 --- a/templates/repo/commit_page.tmpl +++ b/templates/repo/commit_page.tmpl @@ -47,7 +47,7 @@ {{avatarByEmail .Commit.Author.Email .Commit.Author.Email 28 "mr-3"}} <strong>{{.Commit.Author.Name}}</strong> {{end}} - <span class="text grey ml-3" id="authored-time">{{TimeSince .Commit.Author.When $.Lang}}</span> + <span class="text grey ml-3" id="authored-time">{{TimeSince .Commit.Author.When $.i18n.Lang}}</span> {{if or (ne .Commit.Committer.Name .Commit.Author.Name) (ne .Commit.Committer.Email .Commit.Author.Email)}} <span class="text grey mx-3">{{.i18n.Tr "repo.diff.committed_by"}}</span> {{if ne .Verification.CommittingUser.ID 0}} @@ -169,7 +169,7 @@ {{else}} <strong>{{.NoteCommit.Author.Name}}</strong> {{end}} - <span class="text grey" id="note-authored-time">{{TimeSince .NoteCommit.Author.When $.Lang}}</span> + <span class="text grey" id="note-authored-time">{{TimeSince .NoteCommit.Author.When $.i18n.Lang}}</span> </div> <div class="ui bottom attached info segment git-notes"> <pre class="commit-body">{{RenderNote $.Context .Note $.RepoLink $.Repository.ComposeMetas}}</pre> diff --git a/templates/repo/commits_list.tmpl b/templates/repo/commits_list.tmpl index e8ac4020f4..86ad835202 100644 --- a/templates/repo/commits_list.tmpl +++ b/templates/repo/commits_list.tmpl @@ -76,9 +76,9 @@ {{end}} </td> {{if .Committer}} - <td class="text right aligned">{{TimeSince .Committer.When $.Lang}}</td> + <td class="text right aligned">{{TimeSince .Committer.When $.i18n.Lang}}</td> {{else}} - <td class="text right aligned">{{TimeSince .Author.When $.Lang}}</td> + <td class="text right aligned">{{TimeSince .Author.When $.i18n.Lang}}</td> {{end}} </tr> {{end}} diff --git a/templates/repo/diff/comments.tmpl b/templates/repo/diff/comments.tmpl index 9ec42a8d11..3b8f1c2a9c 100644 --- a/templates/repo/diff/comments.tmpl +++ b/templates/repo/diff/comments.tmpl @@ -1,6 +1,6 @@ {{range .comments}} -{{ $createdStr:= TimeSinceUnix .CreatedUnix $.root.Lang }} +{{ $createdStr:= TimeSinceUnix .CreatedUnix $.root.i18n.Lang }} <div class="comment" id="{{.HashTag}}"> {{if .OriginalAuthor }} <span class="avatar"><img src="{{AppSubUrl}}/assets/img/avatar_default.png"></span> diff --git a/templates/repo/issue/milestone_issues.tmpl b/templates/repo/issue/milestone_issues.tmpl index 3f4a13570f..cb2779db32 100644 --- a/templates/repo/issue/milestone_issues.tmpl +++ b/templates/repo/issue/milestone_issues.tmpl @@ -22,7 +22,7 @@ </div> <div class="ui one column stackable grid"> <div class="column"> - {{ $closedDate:= TimeSinceUnix .Milestone.ClosedDateUnix $.Lang }} + {{ $closedDate:= TimeSinceUnix .Milestone.ClosedDateUnix $.i18n.Lang }} {{if .IsClosed}} {{svg "octicon-clock"}} {{$.i18n.Tr "repo.milestones.closed" $closedDate|Str2html}} {{else}} diff --git a/templates/repo/issue/milestones.tmpl b/templates/repo/issue/milestones.tmpl index 448d758e3e..dc168bdc1a 100644 --- a/templates/repo/issue/milestones.tmpl +++ b/templates/repo/issue/milestones.tmpl @@ -68,7 +68,7 @@ </div> </div> <div class="meta"> - {{ $closedDate:= TimeSinceUnix .ClosedDateUnix $.Lang }} + {{ $closedDate:= TimeSinceUnix .ClosedDateUnix $.i18n.Lang }} {{if .IsClosed}} {{svg "octicon-clock"}} {{$.i18n.Tr "repo.milestones.closed" $closedDate|Str2html}} {{else}} diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index 86d9e6da84..820055c136 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -15,7 +15,7 @@ <input type="hidden" id="issueIndex" value="{{.Issue.Index}}"/> <input type="hidden" id="type" value="{{.IssueType}}"> - {{ $createdStr:= TimeSinceUnix .Issue.CreatedUnix $.Lang }} + {{ $createdStr:= TimeSinceUnix .Issue.CreatedUnix $.i18n.Lang }} <div class="twelve wide column comment-list prevent-before-timeline"> <ui class="ui timeline"> <div id="{{.Issue.HashTag}}" class="timeline-item comment first"> diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 03e2728299..7b0941148f 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -1,7 +1,7 @@ {{ template "base/alert" }} {{range .Issue.Comments}} {{if call $.ShouldShowCommentType .Type}} - {{ $createdStr:= TimeSinceUnix .CreatedUnix $.Lang }} + {{ $createdStr:= TimeSinceUnix .CreatedUnix $.i18n.Lang }} <!-- 0 = COMMENT, 1 = REOPEN, 2 = CLOSE, 3 = ISSUE_REF, 4 = COMMIT_REF, 5 = COMMENT_REF, 6 = PULL_REF, 7 = COMMENT_LABEL, 12 = START_TRACKING, @@ -146,7 +146,7 @@ {{else if eq .RefAction 2 }} {{ $refTr = "repo.issues.ref_reopening_from" }} {{end}} - {{ $createdStr:= TimeSinceUnix .CreatedUnix $.Lang }} + {{ $createdStr:= TimeSinceUnix .CreatedUnix $.i18n.Lang }} <div class="timeline-item event" id="{{.HashTag}}"> <span class="badge">{{svg "octicon-bookmark"}}</span> <a href="{{.Poster.HomeLink}}"> @@ -557,7 +557,7 @@ <div id="code-comments-{{(index $comms 0).ID}}" class="comment-code-cloud ui segment{{if $resolved}} hide{{end}}"> <div class="ui comments mb-0"> {{range $comms}} - {{ $createdSubStr:= TimeSinceUnix .CreatedUnix $.Lang }} + {{ $createdSubStr:= TimeSinceUnix .CreatedUnix $.i18n.Lang }} <div class="comment code-comment pb-4" id="{{.HashTag}}"> <div class="content"> <div class="header comment-header"> diff --git a/templates/repo/issue/view_content/pull.tmpl b/templates/repo/issue/view_content/pull.tmpl index 85076027d1..fef868af1f 100644 --- a/templates/repo/issue/view_content/pull.tmpl +++ b/templates/repo/issue/view_content/pull.tmpl @@ -4,7 +4,7 @@ <div class="ui segment"> <h4>{{$.i18n.Tr "repo.issues.review.reviewers"}}</h4> {{range .PullReviewers}} - {{ $createdStr:= TimeSinceUnix .Review.UpdatedUnix $.Lang }} + {{ $createdStr:= TimeSinceUnix .Review.UpdatedUnix $.i18n.Lang }} <div class="ui divider"></div> <div class="review-item"> <div class="review-item-left"> @@ -82,7 +82,7 @@ </div> {{end}} {{range .OriginalReviews}} - {{ $createdStr:= TimeSinceUnix .UpdatedUnix $.Lang }} + {{ $createdStr:= TimeSinceUnix .UpdatedUnix $.i18n.Lang }} <div class="ui divider"></div> <div class="review-item"> <div class="review-item-left"> diff --git a/templates/repo/issue/view_title.tmpl b/templates/repo/issue/view_title.tmpl index 07c700afea..707b8252f4 100644 --- a/templates/repo/issue/view_title.tmpl +++ b/templates/repo/issue/view_title.tmpl @@ -40,7 +40,7 @@ {{$baseHref = printf "<a href=\"%s\">%s</a>" (.BaseBranchHTMLURL | Escape) $baseHref}} {{end}} {{if .Issue.PullRequest.HasMerged}} - {{ $mergedStr:= TimeSinceUnix .Issue.PullRequest.MergedUnix $.Lang }} + {{ $mergedStr:= TimeSinceUnix .Issue.PullRequest.MergedUnix $.i18n.Lang }} {{if .Issue.OriginalAuthor }} {{.Issue.OriginalAuthor}} <span class="pull-desc">{{$.i18n.Tr "repo.pulls.merged_title_desc" .NumCommits $headHref $baseHref $mergedStr | Safe}}</span> @@ -88,7 +88,7 @@ </span> {{end}} {{else}} - {{ $createdStr:= TimeSinceUnix .Issue.CreatedUnix $.Lang }} + {{ $createdStr:= TimeSinceUnix .Issue.CreatedUnix $.i18n.Lang }} <span class="time-desc"> {{if .Issue.OriginalAuthor }} {{$.i18n.Tr "repo.issues.opened_by_fake" $createdStr (.Issue.OriginalAuthor|Escape) | Safe}} diff --git a/templates/repo/projects/list.tmpl b/templates/repo/projects/list.tmpl index f152d20915..a8c51d668e 100644 --- a/templates/repo/projects/list.tmpl +++ b/templates/repo/projects/list.tmpl @@ -42,7 +42,7 @@ <li class="item"> {{svg "octicon-project"}} <a href="{{$.RepoLink}}/projects/{{.ID}}">{{.Title}}</a> <div class="meta"> - {{ $closedDate:= TimeSinceUnix .ClosedDateUnix $.Lang }} + {{ $closedDate:= TimeSinceUnix .ClosedDateUnix $.i18n.Lang }} {{if .IsClosed }} {{svg "octicon-clock"}} {{$.i18n.Tr "repo.milestones.closed" $closedDate|Str2html}} {{end}} diff --git a/templates/repo/projects/view.tmpl b/templates/repo/projects/view.tmpl index 1db52a3d79..6db1025539 100644 --- a/templates/repo/projects/view.tmpl +++ b/templates/repo/projects/view.tmpl @@ -202,7 +202,7 @@ <div class="meta my-2"> <span class="text light grey"> #{{.Index}} - {{ $timeStr := TimeSinceUnix .GetLastEventTimestamp $.Lang }} + {{ $timeStr := TimeSinceUnix .GetLastEventTimestamp $.i18n.Lang }} {{if .OriginalAuthor }} {{$.i18n.Tr .GetLastEventLabelFake $timeStr (.OriginalAuthor|Escape) | Safe}} {{else if gt .Poster.ID 0}} diff --git a/templates/repo/release/list.tmpl b/templates/repo/release/list.tmpl index 01f01cdeff..26d78df3cc 100644 --- a/templates/repo/release/list.tmpl +++ b/templates/repo/release/list.tmpl @@ -65,7 +65,7 @@ <li class="ui grid"> <div class="ui four wide column meta mt-2"> {{if .IsTag}} - {{if .CreatedUnix}}<span class="time">{{TimeSinceUnix .CreatedUnix $.Lang}}</span>{{end}} + {{if .CreatedUnix}}<span class="time">{{TimeSinceUnix .CreatedUnix $.i18n.Lang}}</span>{{end}} {{else}} {{if .IsDraft}} <span class="ui yellow label">{{$.i18n.Tr "repo.release.draft"}}</span> @@ -132,7 +132,7 @@ {{$.i18n.Tr "repo.released_this"}} </span> {{if .CreatedUnix}} - <span class="time">{{TimeSinceUnix .CreatedUnix $.Lang}}</span> + <span class="time">{{TimeSinceUnix .CreatedUnix $.i18n.Lang}}</span> {{end}} {{if not .IsDraft}} | <span class="ahead"><a href="{{$.RepoLink}}/compare/{{.TagName | PathEscapeSegments}}...{{.Target | PathEscapeSegments}}">{{$.i18n.Tr "repo.release.ahead.commits" .NumCommitsBehind | Str2html}}</a> {{$.i18n.Tr "repo.release.ahead.target" .Target}}</span> diff --git a/templates/repo/settings/lfs.tmpl b/templates/repo/settings/lfs.tmpl index 69db43cf6b..9b5c646209 100644 --- a/templates/repo/settings/lfs.tmpl +++ b/templates/repo/settings/lfs.tmpl @@ -23,7 +23,7 @@ </span> </td> <td>{{FileSize .Size}}</td> - <td>{{TimeSince .CreatedUnix.AsTime $.Lang}}</td> + <td>{{TimeSince .CreatedUnix.AsTime $.i18n.Lang}}</td> <td class="right aligned"> <a class="ui primary show-panel button" href="{{$.Link}}/find?oid={{.Oid}}&size={{.Size}}">{{$.i18n.Tr "repo.settings.lfs_findcommits"}}</a> <button class="ui basic show-modal icon button" data-modal="#delete-{{.Oid}}"> diff --git a/templates/repo/settings/lfs_file_find.tmpl b/templates/repo/settings/lfs_file_find.tmpl index f5a0e0081c..60caf46fe8 100644 --- a/templates/repo/settings/lfs_file_find.tmpl +++ b/templates/repo/settings/lfs_file_find.tmpl @@ -37,7 +37,7 @@ {{$.i18n.Tr "repo.diff.commit"}} <a class="ui blue sha label" href="{{$.RepoLink}}/commit/{{.SHA}}">{{ShortSha .SHA}}</a> </td> - <td>{{TimeSince .When $.Lang}}</td> + <td>{{TimeSince .When $.i18n.Lang}}</td> </tr> {{else}} <tr> diff --git a/templates/repo/settings/lfs_locks.tmpl b/templates/repo/settings/lfs_locks.tmpl index 2d311d59ea..6f52358708 100644 --- a/templates/repo/settings/lfs_locks.tmpl +++ b/templates/repo/settings/lfs_locks.tmpl @@ -39,7 +39,7 @@ {{$lock.Owner.DisplayName}} </a> </td> - <td>{{TimeSince .Created $.Lang}}</td> + <td>{{TimeSince .Created $.i18n.Lang}}</td> <td class="right aligned"> <form action="{{$.LFSFilesLink}}/locks/{{$lock.ID}}/unlock" method="POST"> {{$.CsrfTokenHtml}} diff --git a/templates/repo/view_list.tmpl b/templates/repo/view_list.tmpl index b123096777..bc56041c7d 100644 --- a/templates/repo/view_list.tmpl +++ b/templates/repo/view_list.tmpl @@ -34,7 +34,7 @@ </span> {{end}} </th> - <th class="text grey right age">{{if .LatestCommit}}{{if .LatestCommit.Committer}}{{TimeSince .LatestCommit.Committer.When $.Lang}}{{end}}{{end}}</th> + <th class="text grey right age">{{if .LatestCommit}}{{if .LatestCommit.Committer}}{{TimeSince .LatestCommit.Committer.When $.i18n.Lang}}{{end}}{{end}}</th> </tr> </thead> <tbody> @@ -87,7 +87,7 @@ {{end}} </span> </td> - <td class="text right age three wide">{{if $commit}}{{TimeSince $commit.Committer.When $.Lang}}{{end}}</td> + <td class="text right age three wide">{{if $commit}}{{TimeSince $commit.Committer.When $.i18n.Lang}}{{end}}</td> </tr> {{end}} </tbody> diff --git a/templates/repo/wiki/pages.tmpl b/templates/repo/wiki/pages.tmpl index 43766771bc..74674c6f1c 100644 --- a/templates/repo/wiki/pages.tmpl +++ b/templates/repo/wiki/pages.tmpl @@ -20,7 +20,7 @@ {{svg "octicon-file"}} <a href="{{$.RepoLink}}/wiki/{{.SubURL}}">{{.Name}}</a> </td> - {{$timeSince := TimeSinceUnix .UpdatedUnix $.Lang}} + {{$timeSince := TimeSinceUnix .UpdatedUnix $.i18n.Lang}} <td class="text right grey">{{$.i18n.Tr "repo.wiki.last_updated" $timeSince | Safe}}</td> </tr> {{end}} diff --git a/templates/repo/wiki/revision.tmpl b/templates/repo/wiki/revision.tmpl index d74c99152a..4e55da82fb 100644 --- a/templates/repo/wiki/revision.tmpl +++ b/templates/repo/wiki/revision.tmpl @@ -13,7 +13,7 @@ <a class="file-revisions-btn ui basic button" title="{{.i18n.Tr "repo.wiki.back_to_wiki"}}" href="{{.RepoLink}}/wiki/{{.PageURL}}" ><span>{{.revision}}</span> {{svg "octicon-home"}}</a> {{$title}} <div class="ui sub header word-break"> - {{$timeSince := TimeSince .Author.When $.Lang}} + {{$timeSince := TimeSince .Author.When $.i18n.Lang}} {{.i18n.Tr "repo.wiki.last_commit_info" .Author.Name $timeSince | Safe}} </div> </div> diff --git a/templates/repo/wiki/view.tmpl b/templates/repo/wiki/view.tmpl index db0ce14878..ce1b00b4f2 100644 --- a/templates/repo/wiki/view.tmpl +++ b/templates/repo/wiki/view.tmpl @@ -40,7 +40,7 @@ <a class="file-revisions-btn ui basic button" title="{{.i18n.Tr "repo.wiki.file_revision"}}" href="{{.RepoLink}}/wiki/{{.PageURL}}?action=_revision" ><span>{{.CommitCount}}</span> {{svg "octicon-history"}}</a> {{$title}} <div class="ui sub header"> - {{$timeSince := TimeSince .Author.When $.Lang}} + {{$timeSince := TimeSince .Author.When $.i18n.Lang}} {{.i18n.Tr "repo.wiki.last_commit_info" .Author.Name $timeSince | Safe}} </div> </div> |