fix(time): pluralize nil-service relative time fallback
All checks were successful
Security Scan / security (push) Successful in 10s
Test / test (push) Successful in 1m58s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 05:14:43 +00:00
parent 5449026041
commit 9f76b3ee3d
2 changed files with 15 additions and 1 deletions

View file

@ -43,7 +43,7 @@ func FormatAgo(count int, unit string) string {
svc := Default()
unit = normalizeAgoUnit(unit)
if svc == nil {
return core.Sprintf("%d %ss ago", count, unit)
return core.Sprintf("%d %s ago", count, Pluralize(unit, count))
}
key := "time.ago." + unit
result := svc.T(key, map[string]any{"Count": count})

View file

@ -192,6 +192,20 @@ func TestFormatAgo_Good_SingularUnit(t *testing.T) {
assert.Equal(t, "1 fortnight ago", got)
}
func TestFormatAgo_Good_NoDefaultService(t *testing.T) {
prev := Default()
SetDefault(nil)
t.Cleanup(func() {
SetDefault(prev)
})
got := FormatAgo(1, "second")
assert.Equal(t, "1 second ago", got)
got = FormatAgo(5, "second")
assert.Equal(t, "5 seconds ago", got)
}
func TestFormatAgo_Good_FrenchRelativeTime(t *testing.T) {
prev := Default()
svc, err := New()