diff --git a/handler.go b/handler.go index aa03e2f..092faae 100644 --- a/handler.go +++ b/handler.go @@ -156,7 +156,9 @@ func isPluralisableWordDisplay(s string) bool { case unicode.IsLetter(r): hasLetter = true case unicode.IsSpace(r): - continue + // Multi-word vocabulary entries should stay exact. The count handler + // prefixes the quantity, but does not invent a plural form for phrases. + return false default: return false } diff --git a/handler_test.go b/handler_test.go index 12644a2..45a413f 100644 --- a/handler_test.go +++ b/handler_test.go @@ -224,6 +224,34 @@ func TestCountHandler_PreservesExactWordDisplay(t *testing.T) { } } +func TestCountHandler_PreservesPhraseDisplay(t *testing.T) { + svc, err := New() + if err != nil { + t.Fatalf("New() failed: %v", err) + } + SetDefault(svc) + + data := GetGrammarData("en") + if data == nil { + t.Fatal("GetGrammarData(\"en\") returned nil") + } + original, existed := data.Words["up_to_date"] + data.Words["up_to_date"] = "up to date" + t.Cleanup(func() { + if existed { + data.Words["up_to_date"] = original + return + } + delete(data.Words, "up_to_date") + }) + + h := CountHandler{} + got := h.Handle("i18n.count.up_to_date", []any{2}, nil) + if got != "2 up to date" { + t.Fatalf("CountHandler.Handle(up_to_date, 2) = %q, want %q", got, "2 up to date") + } +} + func TestRunHandlerChain(t *testing.T) { handlers := DefaultHandlers() fallback := func() string { return "missed" }