fix(phrasebook): translate the pl string message and the numeric min/max lines (quick-261104-fx1)

- pl validation.yaml string line is Polish (Winter's pl file leaves it
  in English); the header notes the deliberate divergence
- pl validate.yaml min and max use Winter's numeric wording, since those
  keys only serve numeric and integer bounds
This commit is contained in:
Jakub Zych
2026-11-04 11:42:48 +01:00
parent 335f8e608e
commit 145251481b
3 changed files with 36 additions and 3 deletions

View File

@@ -541,3 +541,34 @@ func TestValidateLengthWithoutStringRuleTranslated(t *testing.T) {
}
}
}
// TestValidatePolishStringAndNumericLines: the pl request catalog answers a
// string failure in Polish, and lagoon.Validate's numeric min and max
// failures read as numbers, not character counts.
func TestValidatePolishStringAndNumericLines(t *testing.T) {
rules := []RequestRule{{Field: "s", Rules: ParseRules("string")}}
if got := mustValidate(t, inLocale("pl"), map[string]any{"s": 123}, rules)["s"]; !slices.Equal(got, []string{"s musi być ciągiem znaków."}) {
t.Fatalf("pl string = %q", got)
}
if got := mustValidate(t, inLocale("en"), map[string]any{"s": 123}, rules)["s"]; !slices.Equal(got, []string{"The s must be a string."}) {
t.Fatalf("en string = %q", got)
}
tr := requestTranslator(t)
cases := []struct {
rule string
value any
want string
}{
{"integer|max:10", 11, "views nie może być większy niż 10."},
{"integer|min:0", -1, "views musi być nie mniejszy od 0."},
}
for _, tc := range cases {
errs, err := Validate(inLocale("pl"), nil, nil, map[string]string{"views": tc.rule}, map[string]any{"views": tc.value}, tr)
if err != nil {
t.Fatal(err)
}
if got := errs["views"]; !slices.Equal(got, []string{tc.want}) {
t.Fatalf("%q on %v = %q, want %q", tc.rule, tc.value, got, tc.want)
}
}
}