feat(i18n): add template alias for numeric shorthand
Some checks failed
Security Scan / security (push) Successful in 14s
Test / test (push) Has been cancelled

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 05:07:09 +00:00
parent 2f43e2731f
commit c7e5ee8512
2 changed files with 27 additions and 0 deletions

View file

@ -843,6 +843,7 @@ func TemplateFuncs() template.FuncMap {
"title": Title,
"lower": Lower,
"upper": Upper,
"n": N,
"past": PastTense,
"gerund": Gerund,
"plural": Pluralize,

View file

@ -1001,6 +1001,7 @@ func TestTemplateFuncs(t *testing.T) {
"title",
"lower",
"upper",
"n",
"past",
"gerund",
"plural",
@ -1089,6 +1090,31 @@ func TestTemplateFuncs_PromptAndLang(t *testing.T) {
}
}
func TestTemplateFuncs_NumericAlias(t *testing.T) {
svc, err := New()
if err != nil {
t.Fatalf("New() failed: %v", err)
}
SetDefault(svc)
tmpl, err := template.New("").Funcs(TemplateFuncs()).Parse(
`{{n "number" 1234567}}|{{n "ago" 3 "hours"}}`,
)
if err != nil {
t.Fatalf("Parse() failed: %v", err)
}
var buf strings.Builder
if err := tmpl.Execute(&buf, nil); err != nil {
t.Fatalf("Execute() failed: %v", err)
}
got := buf.String()
if !strings.HasPrefix(got, "1,234,567|3 hours ago") {
t.Fatalf("template numeric alias = %q, want prefix %q", got, "1,234,567|3 hours ago")
}
}
func TestTemplateFuncs_TimeHelpers(t *testing.T) {
svc, err := New()
if err != nil {