Skip to content

Commit ddfe42f

Browse files
Georgi2704Ruben van Leeuwen
authored andcommitted
translations setup v1
1 parent 3ef82df commit ddfe42f

File tree

11 files changed

+370
-13
lines changed

11 files changed

+370
-13
lines changed

frontend/apps/example/src/app/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export default function Home() {
9191
labelProvider: pydanticLabelProvider,
9292
customDataProvider: pydanticCustomDataProvider,
9393
componentMatcher: componentMatcher,
94+
translations : {} // key-value thing this will override the messages
9495
}}
9596
/>
9697
</div>

frontend/package-lock.json

Lines changed: 130 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"devDependencies": {
1717
"@changesets/cli": "^2.27.1",
18+
"@types/lodash": "^4.17.16",
1819
"turbo": "^2.3.3"
1920
},
2021
"engines": {
@@ -27,6 +28,7 @@
2728
"packages/*"
2829
],
2930
"dependencies": {
31+
"lodash.merge": "^4.6.2",
3032
"typescript": "^5.8.2"
3133
}
3234
}

frontend/packages/pydantic-forms/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
"@hookform/resolvers": "^3.9.1",
5959
"dayjs": "^1.11.13",
6060
"i18next": "^24.1.2",
61+
"lodash": "^4.17.21",
62+
"next-intl": "^4.0.2",
6163
"react-hook-form": "^7.54.1",
6264
"swr": "^2.3.0",
6365
"zod": "^3.24.1",

frontend/packages/pydantic-forms/src/components/form/Footer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const Footer = () => {
2020
allowUntouchedSubmit,
2121
} = usePydanticFormContext();
2222

23+
// const t = useTranslations('nms.services.ports');
24+
2325
return (
2426
<div style={{ height: '200px' }}>
2527
{footerComponent && <div>{footerComponent}</div>}{' '}

frontend/packages/pydantic-forms/src/components/render/RenderForm.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ const RenderForm = (contextProps: PydanticFormContextProps) => {
3434
componentMatcher: customComponentMatcher,
3535
} = config || {};
3636

37+
// const t = useTranslations('newTranslations')
38+
3739
const LoadingComponent = loadingComponent ?? (
38-
<div>Formulier aan het ophalen...</div>
40+
// <div>{t('loading')}</div>
41+
<div></div>
3942
);
4043

4144
if (isLoading && !isSending) {
@@ -66,6 +69,10 @@ const RenderForm = (contextProps: PydanticFormContextProps) => {
6669
customComponentMatcher,
6770
);
6871

72+
console.log('pydanticFormComponents', pydanticFormComponents);
73+
console.log("pydanticFormSchema", pydanticFormSchema)
74+
console.log("customComponentMatcher", customComponentMatcher)
75+
6976
return (
7077
<form action={''} onSubmit={submitForm}>
7178
{title !== false &&

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
import { getHashForArray } from '@/utils';
4343

4444
import translation from './translations/nl.json';
45+
import {TranslationsProvider} from "@/core/translations/translationsProvider";
4546

4647
// lng and resources key depend on your locale.
4748
i18next.init({
@@ -148,7 +149,10 @@ function PydanticFormContextProvider({
148149
const [rawSchema, setRawSchema] = useState<PydanticFormSchemaRawJson>();
149150

150151
// extract the JSON schema to a more usable custom schema
151-
const { pydanticFormSchema, isLoading: isParsingSchema } =
152+
153+
const { pydanticFormSchema, isLoading: isParsingSchema } = //rawSchema is the response from the backend
154+
155+
//form labels are matched to the definition
152156
usePydanticFormParser(
153157
rawSchema,
154158
formLabels?.labels,
@@ -385,9 +389,11 @@ function PydanticFormContextProvider({
385389
};
386390

387391
return (
388-
<PydanticFormContext.Provider value={PydanticFormContextState}>
389-
{children(PydanticFormContextState)}
390-
</PydanticFormContext.Provider>
392+
<TranslationsProvider>
393+
<PydanticFormContext.Provider value={PydanticFormContextState}>
394+
{children(PydanticFormContextState)}
395+
</PydanticFormContext.Provider>
396+
</TranslationsProvider>
391397
);
392398
}
393399

0 commit comments

Comments
 (0)