diff --git a/modules/lagoon/validate_test.go b/modules/lagoon/validate_test.go index 15c248e4..0baf47fe 100644 --- a/modules/lagoon/validate_test.go +++ b/modules/lagoon/validate_test.go @@ -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) + } + } +} diff --git a/modules/phrasebook/lang/pl/validate.yaml b/modules/phrasebook/lang/pl/validate.yaml index 396f3bab..fb32f817 100644 --- a/modules/phrasebook/lang/pl/validate.yaml +++ b/modules/phrasebook/lang/pl/validate.yaml @@ -7,8 +7,8 @@ confirmed: "Potwierdzenie :attribute nie zgadza się." different: ":attribute oraz :other muszą się różnić." integer: ":attribute musi być liczbą całkowitą." numeric: ":attribute musi być liczbą." -max: ":attribute nie może być dłuższy niż :max znaków." -min: ":attribute musi mieć przynajmniej :min znaków." +max: ":attribute nie może być większy niż :max." +min: ":attribute musi być nie mniejszy od :min." oneof: "Zaznaczony :attribute jest nieprawidłowy." mimes: ":attribute musi być plikiem typu :values." string: ":attribute musi być ciągiem znaków." diff --git a/modules/phrasebook/lang/pl/validation.yaml b/modules/phrasebook/lang/pl/validation.yaml index 8f6a138c..0f6a25f1 100644 --- a/modules/phrasebook/lang/pl/validation.yaml +++ b/modules/phrasebook/lang/pl/validation.yaml @@ -1,6 +1,8 @@ # Port of WinterCMS modules/system/lang/pl/validation.php (Laravel validator # messages). Text is copied verbatim; keys absent from this locale fall back to # app.fallback_locale as in Winter. Loaded as lagoon::validation.* +# `string`, which Winter's pl file leaves in English, is translated here, so a +# pl request gets a Polish line where the PHP backend answers in English. accepted: ":attribute musi zostać zaakceptowany." active_url: ":attribute jest nieprawidłowym adresem URL." after: ":attribute musi być datą późniejszą od :date." @@ -61,7 +63,7 @@ size: file: ":attribute musi mieć :size kilobajtów." string: ":attribute musi mieć :size znaków." array: ":attribute musi zawierać :size elementów." -string: "The :attribute must be a string." +string: ":attribute musi być ciągiem znaków." timezone: ":attribute musi być prawidłową strefą czasową." unique: "Taki :attribute już występuje." url: "Format :attribute jest nieprawidłowy."