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
This commit is contained in:
wxiaoguang 2022-02-08 11:02:30 +08:00 committed by GitHub
parent 7b25a010c8
commit a60e8be8d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 75 additions and 75 deletions

View file

@ -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}}

View file

@ -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>

View file

@ -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>