From 470886bf520c6b073c5bd74310b38aa5ef5b81d7 Mon Sep 17 00:00:00 2001 From: 0ko <0ko@noreply.codeberg.org> Date: Sun, 31 Mar 2024 20:17:12 +0500 Subject: [PATCH] Rename ByteSize to ReadableSize --- modules/translation/mock.go | 4 ++-- modules/translation/translation.go | 12 ++++++------ templates/repo/sub_menu.tmpl | 2 +- tests/integration/size_translations_test.go | 1 + 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/translation/mock.go b/modules/translation/mock.go index c4f8822db3..fe3a1502ea 100644 --- a/modules/translation/mock.go +++ b/modules/translation/mock.go @@ -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 { diff --git a/modules/translation/translation.go b/modules/translation/translation.go index a6013a288f..16eb55e28e 100644 --- a/modules/translation/translation.go +++ b/modules/translation/translation.go @@ -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 { diff --git a/templates/repo/sub_menu.tmpl b/templates/repo/sub_menu.tmpl index 32e7e97954..ddf01b33ed 100644 --- a/templates/repo/sub_menu.tmpl +++ b/templates/repo/sub_menu.tmpl @@ -14,7 +14,7 @@ {{end}} - {{$fileSizeFields := ctx.Locale.TrSize .Repository.Size }} + {{$fileSizeFields := ctx.Locale.TrSize .Repository.Size}} {{svg "octicon-database"}} {{$fileSizeFields.PrettyNumber}} {{$fileSizeFields.TranslatedUnit}} {{end}} diff --git a/tests/integration/size_translations_test.go b/tests/integration/size_translations_test.go index 2edb0373c1..0a296ad385 100644 --- a/tests/integration/size_translations_test.go +++ b/tests/integration/size_translations_test.go @@ -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" )