mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-11-16 14:54:23 +08:00
fix(i18n): use English runtime text and localize system UI
This commit is contained in:
+14
-7
@@ -43,28 +43,35 @@ func Bytes2Size(num int64) string {
|
||||
return numStr + " " + unit
|
||||
}
|
||||
|
||||
// Seconds2Time converts a number of seconds to a human-readable Chinese duration string.
|
||||
// Seconds2Time converts a number of seconds to a human-readable English duration string.
|
||||
func Seconds2Time(num int) (time string) {
|
||||
if num/secondsPerYear > 0 {
|
||||
time += strconv.Itoa(num/secondsPerYear) + " 年 "
|
||||
time += durationPart(num/secondsPerYear, "year") + " "
|
||||
num %= secondsPerYear
|
||||
}
|
||||
if num/secondsPerMonth > 0 {
|
||||
time += strconv.Itoa(num/secondsPerMonth) + " 个月 "
|
||||
time += durationPart(num/secondsPerMonth, "month") + " "
|
||||
num %= secondsPerMonth
|
||||
}
|
||||
if num/secondsPerDay > 0 {
|
||||
time += strconv.Itoa(num/secondsPerDay) + " 天 "
|
||||
time += durationPart(num/secondsPerDay, "day") + " "
|
||||
num %= secondsPerDay
|
||||
}
|
||||
if num/secondsPerHour > 0 {
|
||||
time += strconv.Itoa(num/secondsPerHour) + " 小时 "
|
||||
time += durationPart(num/secondsPerHour, "hour") + " "
|
||||
num %= secondsPerHour
|
||||
}
|
||||
if num/secondsPerMinute > 0 {
|
||||
time += strconv.Itoa(num/secondsPerMinute) + " 分钟 "
|
||||
time += durationPart(num/secondsPerMinute, "minute") + " "
|
||||
num %= secondsPerMinute
|
||||
}
|
||||
time += strconv.Itoa(num) + " 秒"
|
||||
time += durationPart(num, "second")
|
||||
return
|
||||
}
|
||||
|
||||
func durationPart(value int, unit string) string {
|
||||
if value != 1 {
|
||||
unit += "s"
|
||||
}
|
||||
return strconv.Itoa(value) + " " + unit
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@ func TestSeconds2Time(t *testing.T) {
|
||||
input int
|
||||
expected string
|
||||
}{
|
||||
{0, "0 秒"},
|
||||
{30, "30 秒"},
|
||||
{60, "1 分钟 0 秒"},
|
||||
{125, "2 分钟 5 秒"},
|
||||
{3600, "1 小时 0 秒"},
|
||||
{86400, "1 天 0 秒"},
|
||||
{0, "0 seconds"},
|
||||
{30, "30 seconds"},
|
||||
{60, "1 minute 0 seconds"},
|
||||
{125, "2 minutes 5 seconds"},
|
||||
{3600, "1 hour 0 seconds"},
|
||||
{86400, "1 day 0 seconds"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in New Issue
Block a user