fix(i18n): honor default translation context count
This commit is contained in:
parent
fdb151a0af
commit
43cf530b9d
3 changed files with 16 additions and 1 deletions
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue