Skip to content

Commit 34228b9

Browse files
author
Ruben van Leeuwen
committed
2076: Removes custom translations and falls back to standard translation provided by zod/v4
1 parent b2fb531 commit 34228b9

File tree

3 files changed

+25
-31
lines changed

3 files changed

+25
-31
lines changed

frontend/packages/pydantic-forms/src/components/zodValidationsPresets.ts

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -69,38 +69,23 @@ export const zodValidationPresets: PydanticFormZodValidationPresets = {
6969
let validationRule = z.number().int();
7070

7171
if (minimum) {
72-
validationRule = validationRule.gte(
73-
minimum,
74-
`Dit veld heeft een minimum waarde van ${minimum}`,
75-
);
72+
validationRule = validationRule.gte(minimum);
7673
}
7774

7875
if (exclusiveMinimum) {
79-
validationRule = validationRule.gt(
80-
exclusiveMinimum,
81-
`Dit veld heeft een minimum waarde van meer dan ${exclusiveMinimum}`,
82-
);
76+
validationRule = validationRule.gt(exclusiveMinimum);
8377
}
8478

8579
if (maximum) {
86-
validationRule = validationRule.lte(
87-
maximum,
88-
`Dit veld heeft een maximum waarde van${maximum}`,
89-
);
80+
validationRule = validationRule.lte(maximum);
9081
}
9182

9283
if (exclusiveMaximum) {
93-
validationRule = validationRule.lt(
94-
exclusiveMaximum,
95-
`Dit veld heeft een maximum waarde van minder dan ${exclusiveMaximum}`,
96-
);
84+
validationRule = validationRule.lt(exclusiveMaximum);
9785
}
9886

9987
if (multipleOf) {
100-
validationRule = validationRule.multipleOf(
101-
multipleOf,
102-
`De waarde van dit veld moet een veelvoud zijn van ${multipleOf}`,
103-
);
88+
validationRule = validationRule.multipleOf(multipleOf);
10489
}
10590

10691
return validationRule;
@@ -111,17 +96,11 @@ export const zodValidationPresets: PydanticFormZodValidationPresets = {
11196
let validationRule = z.array(z.boolean());
11297

11398
if (minimum) {
114-
validationRule = validationRule.min(
115-
minimum,
116-
`Dit veld heeft een minimum waarde van ${minimum}`,
117-
);
99+
validationRule = validationRule.min(minimum);
118100
}
119101

120102
if (maximum) {
121-
validationRule = validationRule.max(
122-
maximum,
123-
`Dit veld heeft een maximum waarde van ${maximum}`,
124-
);
103+
validationRule = validationRule.max(maximum);
125104
}
126105

127106
return validationRule;

frontend/packages/pydantic-forms/src/core/PydanticFormContextProvider.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@ import {
3333
usePydanticFormParser,
3434
} from '@/core/hooks';
3535
import {
36+
Locale,
3637
PydanticFormContextProps,
3738
PydanticFormInitialContextProps,
3839
PydanticFormSchemaRawJson,
3940
PydanticFormValidationErrorDetails,
4041
} from '@/types';
4142
import { getHashForArray } from '@/utils';
4243

43-
z.config(z.locales.nl());
44-
4544
export const PydanticFormContext =
4645
createContext<PydanticFormContextProps | null>(null);
4746

@@ -71,6 +70,7 @@ function PydanticFormContextProvider({
7170
allowUntouchedSubmit,
7271
skipSuccessNotice,
7372
componentMatcherExtender,
73+
locale,
7474
cancelButton,
7575
} = config;
7676

@@ -90,6 +90,21 @@ function PydanticFormContextProvider({
9090
}
9191
}, [formKey]);
9292

93+
useEffect(() => {
94+
const getLocale = () => {
95+
switch (locale) {
96+
case Locale.enGB:
97+
return z.locales.en();
98+
case Locale.nlNL:
99+
return z.locales.nl();
100+
default:
101+
return z.locales.en();
102+
}
103+
};
104+
105+
z.config(getLocale());
106+
}, [locale]);
107+
93108
const updateHistory = async (
94109
formInput: object,
95110
previousSteps: object[],

frontend/packages/pydantic-forms/src/messages/translationsProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const TranslationsProvider = ({
5454

5555
return (
5656
<NextIntlClientProvider
57-
locale={locale || Locale.enGB}
57+
locale={locale}
5858
messages={messages}
5959
timeZone={DEFAULT_TIMEZONE}
6060
onError={onError}

0 commit comments

Comments
 (0)