1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-25 13:19:37 -05:00

Rename ByteSize to ReadableSize

This commit is contained in:
0ko 2024-03-31 20:17:12 +05:00 committed by GitHub
parent d2cd1342bf
commit 470886bf52
4 changed files with 10 additions and 9 deletions

View file

@ -31,8 +31,8 @@ func (l MockLocale) TrN(cnt any, key1, keyN string, args ...any) template.HTML {
return template.HTML(key1)
}
func (l MockLocale) TrSize(s int64) ByteSize {
return ByteSize{fmt.Sprint(s), ""}
func (l MockLocale) TrSize(s int64) ReadableSize {
return ReadableSize{fmt.Sprint(s), ""}
}
func (l MockLocale) PrettyNumber(v any) string {

View file

@ -15,8 +15,8 @@ import (
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/translation/i18n"
"code.gitea.io/gitea/modules/util"
"github.com/dustin/go-humanize"
"github.com/dustin/go-humanize"
"golang.org/x/text/language"
"golang.org/x/text/message"
"golang.org/x/text/number"
@ -34,7 +34,7 @@ type Locale interface {
Tr(key string, args ...any) template.HTML
TrN(cnt any, key1, keyN string, args ...any) template.HTML
TrSize(size int64) ByteSize
TrSize(size int64) ReadableSize
PrettyNumber(v any) string
}
@ -255,18 +255,18 @@ func (l *locale) TrN(cnt any, key1, keyN string, args ...any) template.HTML {
return l.Tr(keyN, args...)
}
type ByteSize struct {
type ReadableSize struct {
PrettyNumber string
TranslatedUnit string
}
func (bs ByteSize) String() string {
func (bs ReadableSize) String() string {
return bs.PrettyNumber + " " + bs.TranslatedUnit
}
// TrSize returns array containing pretty formatted size and localized output of FileSize
// output of humanize.IBytes has to be split in order to be localized
func (l *locale) TrSize(s int64) ByteSize {
func (l *locale) TrSize(s int64) ReadableSize {
us := uint64(s)
if s < 0 {
us = uint64(-s)
@ -281,7 +281,7 @@ func (l *locale) TrSize(s int64) ByteSize {
}
numberVal = l.PrettyNumber(numberVal)
unitVal = l.TrString("munits.data." + strings.ToLower(unitVal))
return ByteSize{numberVal, unitVal}
return ReadableSize{numberVal, unitVal}
}
func (l *locale) PrettyNumber(v any) string {

View file

@ -14,7 +14,7 @@
</a>
{{end}}
<span class="item not-mobile" {{if not (eq .Repository.Size 0)}}data-tooltip-content="{{.Repository.SizeDetailsString ctx.Locale}}"{{end}}>
{{$fileSizeFields := ctx.Locale.TrSize .Repository.Size }}
{{$fileSizeFields := ctx.Locale.TrSize .Repository.Size}}
{{svg "octicon-database"}} <b>{{$fileSizeFields.PrettyNumber}}</b> {{$fileSizeFields.TranslatedUnit}}
</span>
{{end}}

View file

@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
files_service "code.gitea.io/gitea/services/repository/files"
"github.com/PuerkitoBio/goquery"
"github.com/stretchr/testify/assert"
)