Skip to content

Commit bc4e061

Browse files
authored
Make repo size style matches others (commits/branches/tags) (#24408)
The "unit" part shouldn't have bold style.
1 parent bc784a7 commit bc4e061

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

modules/templates/util_string.go

+4
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ func (su *StringUtils) HasPrefix(s, prefix string) bool {
1818
func (su *StringUtils) Contains(s, substr string) bool {
1919
return strings.Contains(s, substr)
2020
}
21+
22+
func (su *StringUtils) Split(s, sep string) []string {
23+
return strings.Split(s, sep)
24+
}

modules/translation/translation.go

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"code.gitea.io/gitea/modules/options"
1414
"code.gitea.io/gitea/modules/setting"
1515
"code.gitea.io/gitea/modules/translation/i18n"
16+
"code.gitea.io/gitea/modules/util"
1617

1718
"golang.org/x/text/language"
1819
"golang.org/x/text/message"
@@ -241,5 +242,12 @@ func (l *locale) TrN(cnt any, key1, keyN string, args ...any) string {
241242

242243
func (l *locale) PrettyNumber(v any) string {
243244
// TODO: this mechanism is not good enough, the complete solution is to switch the translation system to ICU message format
245+
if s, ok := v.(string); ok {
246+
if num, err := util.ToInt64(s); err == nil {
247+
v = num
248+
} else if num, err := util.ToFloat64(s); err == nil {
249+
v = num
250+
}
251+
}
244252
return l.msgPrinter.Sprintf("%v", number.Decimal(v))
245253
}

modules/translation/translation_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ func TestPrettyNumber(t *testing.T) {
2121

2222
l := NewLocale("id-ID")
2323
assert.EqualValues(t, "1.000.000", l.PrettyNumber(1000000))
24+
assert.EqualValues(t, "1.000.000,1", l.PrettyNumber(1000000.1))
25+
assert.EqualValues(t, "1.000.000", l.PrettyNumber("1000000"))
26+
assert.EqualValues(t, "1.000.000", l.PrettyNumber("1000000.0"))
27+
assert.EqualValues(t, "1.000.000,1", l.PrettyNumber("1000000.1"))
2428

2529
l = NewLocale("nosuch")
2630
assert.EqualValues(t, "1,000,000", l.PrettyNumber(1000000))
31+
assert.EqualValues(t, "1,000,000.1", l.PrettyNumber(1000000.1))
2732
}

templates/repo/sub_menu.tmpl

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
</div>
1616
{{end}}
1717
<div class="item">
18-
<span>{{svg "octicon-database"}} <b>{{FileSize .Repository.Size}}</b></span>
18+
{{$fileSizeFormatted := FileSize .Repository.Size}}{{/* the formatted string is always "{val} {unit}" */}}
19+
{{$fileSizeFields := StringUtils.Split $fileSizeFormatted " "}}
20+
<span>{{svg "octicon-database"}} <b>{{.locale.PrettyNumber (index $fileSizeFields 0)}}</b> {{index $fileSizeFields 1}}</span>
1921
</div>
2022
{{end}}
2123
</div>

0 commit comments

Comments
 (0)