fix(i18n): honor default translation context count
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

This commit is contained in:
Virgil 2026-04-02 13:41:48 +00:00
parent fdb151a0af
commit 43cf530b9d
3 changed files with 16 additions and 1 deletions

View file

@ -133,6 +133,11 @@ func TestCountHandler(t *testing.T) {
t.Errorf("CountHandler.Handle(file, TranslationContext.Count=3) = %q, want %q", got, "3 files")
}
got = h.Handle("i18n.count.file", []any{C("file")}, nil)
if got != "1 file" {
t.Errorf("CountHandler.Handle(file, TranslationContext default count) = %q, want %q", got, "1 file")
}
got = h.Handle("i18n.count.", nil, func() string { return "fallback" })
if got != "fallback" {
t.Errorf("CountHandler.Handle(empty) = %q, want %q", got, "fallback")

View file

@ -31,7 +31,7 @@ func getCount(data any) int {
return toInt(c)
}
}
return 0
return d.count
case map[string]any:
if c, ok := d["Count"]; ok {
return toInt(c)

View file

@ -30,6 +30,16 @@ func TestGetCount_Good(t *testing.T) {
}
}
func TestGetCount_Good_TranslationContextDefault(t *testing.T) {
ctx := C("test")
assert.Equal(t, 1, getCount(ctx))
}
func TestGetCount_Good_TranslationContextExtraCount(t *testing.T) {
ctx := C("test").Set("Count", 3)
assert.Equal(t, 3, getCount(ctx))
}
// --- toInt ---
func TestToInt_Good(t *testing.T) {