forked from gitea/gitea
Make repo size style matches others (commits/branches/tags) (#24408)
The "unit" part shouldn't have bold style.
This commit is contained in:
parent
bc784a705b
commit
bc4e06109d
|
@ -18,3 +18,7 @@ func (su *StringUtils) HasPrefix(s, prefix string) bool {
|
||||||
func (su *StringUtils) Contains(s, substr string) bool {
|
func (su *StringUtils) Contains(s, substr string) bool {
|
||||||
return strings.Contains(s, substr)
|
return strings.Contains(s, substr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (su *StringUtils) Split(s, sep string) []string {
|
||||||
|
return strings.Split(s, sep)
|
||||||
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/options"
|
"code.gitea.io/gitea/modules/options"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/translation/i18n"
|
"code.gitea.io/gitea/modules/translation/i18n"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
"golang.org/x/text/message"
|
"golang.org/x/text/message"
|
||||||
|
@ -241,5 +242,12 @@ func (l *locale) TrN(cnt any, key1, keyN string, args ...any) string {
|
||||||
|
|
||||||
func (l *locale) PrettyNumber(v any) string {
|
func (l *locale) PrettyNumber(v any) string {
|
||||||
// TODO: this mechanism is not good enough, the complete solution is to switch the translation system to ICU message format
|
// TODO: this mechanism is not good enough, the complete solution is to switch the translation system to ICU message format
|
||||||
|
if s, ok := v.(string); ok {
|
||||||
|
if num, err := util.ToInt64(s); err == nil {
|
||||||
|
v = num
|
||||||
|
} else if num, err := util.ToFloat64(s); err == nil {
|
||||||
|
v = num
|
||||||
|
}
|
||||||
|
}
|
||||||
return l.msgPrinter.Sprintf("%v", number.Decimal(v))
|
return l.msgPrinter.Sprintf("%v", number.Decimal(v))
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,12 @@ func TestPrettyNumber(t *testing.T) {
|
||||||
|
|
||||||
l := NewLocale("id-ID")
|
l := NewLocale("id-ID")
|
||||||
assert.EqualValues(t, "1.000.000", l.PrettyNumber(1000000))
|
assert.EqualValues(t, "1.000.000", l.PrettyNumber(1000000))
|
||||||
|
assert.EqualValues(t, "1.000.000,1", l.PrettyNumber(1000000.1))
|
||||||
|
assert.EqualValues(t, "1.000.000", l.PrettyNumber("1000000"))
|
||||||
|
assert.EqualValues(t, "1.000.000", l.PrettyNumber("1000000.0"))
|
||||||
|
assert.EqualValues(t, "1.000.000,1", l.PrettyNumber("1000000.1"))
|
||||||
|
|
||||||
l = NewLocale("nosuch")
|
l = NewLocale("nosuch")
|
||||||
assert.EqualValues(t, "1,000,000", l.PrettyNumber(1000000))
|
assert.EqualValues(t, "1,000,000", l.PrettyNumber(1000000))
|
||||||
|
assert.EqualValues(t, "1,000,000.1", l.PrettyNumber(1000000.1))
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,9 @@
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<span>{{svg "octicon-database"}} <b>{{FileSize .Repository.Size}}</b></span>
|
{{$fileSizeFormatted := FileSize .Repository.Size}}{{/* the formatted string is always "{val} {unit}" */}}
|
||||||
|
{{$fileSizeFields := StringUtils.Split $fileSizeFormatted " "}}
|
||||||
|
<span>{{svg "octicon-database"}} <b>{{.locale.PrettyNumber (index $fileSizeFields 0)}}</b> {{index $fileSizeFields 1}}</span>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue