feat(ui): pretty-print commit counts and other numbers (#8704)

Currently on https://codeberg.org/forgejo/forgejo for instance, the commit count is shown as "23378 commits", instead of "23,378 commits".

This makes sure such numbers are printed with thousands separators if they are big enough.

Preview:
- https://codeberg.org/attachments/681add48-337b-42c0-a0ae-ac5ad4671b39
- https://codeberg.org/attachments/8b5d4e40-bdd6-4942-905f-6ddeac8509a9

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8704
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
Co-authored-by: Antonin Delpeuch <antonin@delpeuch.eu>
Co-committed-by: Antonin Delpeuch <antonin@delpeuch.eu>
This commit is contained in:
Antonin Delpeuch 2025-07-28 15:16:27 +02:00 committed by 0ko
commit 106707b40f
2 changed files with 4 additions and 4 deletions

View file

@ -1,7 +1,7 @@
<h4 class="ui top attached header commits-table tw-flex tw-items-center tw-justify-between">
<div class="commits-table-left tw-flex tw-items-center">
{{if or .PageIsCommits (gt .CommitCount 0)}}
{{ctx.Locale.TrN .CommitCount "repo.n_commit_one" "repo.n_commit_few" (StringUtils.ToString .CommitCount)}}
{{ctx.Locale.TrN .CommitCount "repo.n_commit_one" "repo.n_commit_few" (ctx.Locale.PrettyNumber .CommitCount)}}
{{else if .IsNothingToCompare}}
{{ctx.Locale.Tr "repo.commits.nothing_to_compare"}}
{{else}}

View file

@ -3,14 +3,14 @@
<div class="ui segment repository-menu">
{{if and (.Permission.CanRead $.UnitTypeCode) (not .IsEmptyRepo)}}
<a class="item muted {{if .PageIsCommits}}active{{end}}" href="{{.RepoLink}}/commits/{{.BranchNameSubURL}}">
{{svg "octicon-history"}} {{ctx.Locale.TrN .CommitsCount "repo.n_commit_one" "repo.n_commit_few" (printf "<b>%d</b>" .CommitsCount | SafeHTML)}}
{{svg "octicon-history"}} {{ctx.Locale.TrN .CommitsCount "repo.n_commit_one" "repo.n_commit_few" (printf "<b>%s</b>" (ctx.Locale.PrettyNumber .CommitsCount) | SafeHTML)}}
</a>
<a class="item muted {{if .PageIsBranches}}active{{end}}" href="{{.RepoLink}}/branches">
{{svg "octicon-git-branch"}} {{ctx.Locale.TrN .BranchesCount "repo.n_branch_one" "repo.n_branch_few" (printf "<b>%d</b>" .BranchesCount | SafeHTML)}}
{{svg "octicon-git-branch"}} {{ctx.Locale.TrN .BranchesCount "repo.n_branch_one" "repo.n_branch_few" (printf "<b>%s</b>" (ctx.Locale.PrettyNumber .BranchesCount) | SafeHTML)}}
</a>
{{if $.Permission.CanRead $.UnitTypeCode}}
<a class="item muted {{if .PageIsTagList}}active{{end}}" href="{{.RepoLink}}/tags">
{{svg "octicon-tag"}} {{ctx.Locale.TrN .NumTags "repo.n_tag_one" "repo.n_tag_few" (printf "<b>%d</b>" .NumTags | SafeHTML)}}
{{svg "octicon-tag"}} {{ctx.Locale.TrN .NumTags "repo.n_tag_one" "repo.n_tag_few" (printf "<b>%s</b>" (ctx.Locale.PrettyNumber .NumTags) | SafeHTML)}}
</a>
{{end}}
<span class="item" {{if not (eq .Repository.Size 0)}}data-tooltip-content="{{.Repository.SizeDetailsString ctx.Locale}}"{{end}}>