Skip to content

Commit 77af6aa

Browse files
Georgi2704Ruben van Leeuwen
authored andcommitted
Cleanup
1 parent a0c8c62 commit 77af6aa

File tree

5 files changed

+62
-28
lines changed

5 files changed

+62
-28
lines changed

frontend/apps/example/src/app/[locale]/layout.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import type { Metadata } from 'next';
22
import localFont from 'next/font/local';
3-
import {NextIntlClientProvider} from 'next-intl';
4-
53
import '../globals.css';
6-
import {notFound} from "next/navigation";
4+
import {handleInvalidLocale} from "@/app/[locale]/useGetTranslationMessages";
75
import {hasLocale} from "next-intl";
86
import {routing} from "@/i18n/routing";
7+
import {notFound} from "next/navigation";
98

109
const geistSans = localFont({
1110
src: '../fonts/GeistVF.woff',
@@ -35,18 +34,10 @@ export default async function RootLayout({
3534
notFound();
3635
}
3736

38-
const messages = (await import(`../../../messages/${locale}.json`)).default;
39-
40-
console.log('locale', locale);
41-
console.log("MESSAGE HERE", messages);
42-
43-
4437
return (
4538
<html lang={locale}>
4639
<body className={`${geistSans.variable} ${geistMono.variable}`}>
47-
<NextIntlClientProvider locale={locale} messages={messages}>
4840
{children}
49-
</NextIntlClientProvider>
5041
</body>
5142
</html>
5243
);

frontend/apps/example/src/app/[locale]/page.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,47 @@
11
'use client';
22

3+
<<<<<<< HEAD
34
import { useParams } from 'next/navigation';
45
import {
56
PydanticForm,
67
PydanticFormFieldFormat,
78
PydanticFormFieldType,
89
} from 'pydantic-forms';
10+
=======
11+
>>>>>>> 6b4540b (Cleanup)
912
import type {
1013
PydanticComponentMatcher,
1114
PydanticFormApiProvider,
1215
PydanticFormCustomDataProvider,
1316
PydanticFormLabelProvider,
1417
} from 'pydantic-forms';
18+
import {PydanticForm, PydanticFormFieldFormat, PydanticFormFieldType,} from 'pydantic-forms';
1519

20+
<<<<<<< HEAD
1621
import { TextArea } from '@/fields';
1722

1823
import NLnl from '../../../messages/nl-NL.json';
24+
=======
25+
import {TextArea} from '@/fields';
26+
import {useParams} from "next/navigation";
27+
28+
>>>>>>> 6b4540b (Cleanup)
1929
import styles from '../page.module.css';
30+
import {handleInvalidLocale, useGetTranslationMessages} from "@/app/[locale]/useGetTranslationMessages";
2031

32+
<<<<<<< HEAD
2133
export default function Home({
2234
messages,
2335
}: {
2436
messages: Record<string, string>;
2537
}) {
2638
const params = useParams();
2739
const locale = params?.locale as string; // Get locale from URL params
40+
=======
41+
export default function Home() {
42+
const {locale} = useParams();
43+
const validLocale = handleInvalidLocale(locale);
44+
>>>>>>> 6b4540b (Cleanup)
2845

2946
const pydanticFormApiProvider: PydanticFormApiProvider = async ({
3047
requestBody,
@@ -83,9 +100,12 @@ export default function Home({
83100
];
84101
};
85102

103+
<<<<<<< HEAD
86104
// const translations = getMessages(locale);
87105
// console.log('NEW translations', translations);
88106

107+
=======
108+
>>>>>>> 6b4540b (Cleanup)
89109
return (
90110
<div className={styles.page}>
91111
<h1 style={{ marginBottom: '20px' }}>Pydantic Form ({locale})</h1>
@@ -103,7 +123,11 @@ export default function Home({
103123
labelProvider: pydanticLabelProvider,
104124
customDataProvider: pydanticCustomDataProvider,
105125
componentMatcher: componentMatcher,
126+
<<<<<<< HEAD
106127
translations: NLnl,
128+
=======
129+
translations : useGetTranslationMessages(validLocale)
130+
>>>>>>> 6b4540b (Cleanup)
107131
}}
108132
/>
109133
</div>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {Locale, TranslationsJSON} from "pydantic-forms";
2+
import enGB from "../../../messages/en-GB.json";
3+
import nlNL from "../../../messages/nl-NL.json";
4+
import {hasLocale} from "next-intl";
5+
import {routing} from "@/i18n/routing";
6+
import {notFound} from "next/navigation";
7+
import {ParamValue} from "next/dist/server/request/params";
8+
9+
export const handleInvalidLocale = (locale: ParamValue) => {
10+
if (!hasLocale(routing.locales, locale)) {
11+
notFound();
12+
}
13+
return locale;
14+
}
15+
16+
export const useGetTranslationMessages = (locale: string | undefined): TranslationsJSON => {
17+
18+
const getLocalMessages = () => {
19+
switch (locale) {
20+
case Locale.enGB:
21+
return enGB;
22+
case Locale.nlNL:
23+
return nlNL;
24+
default:
25+
return enGB;
26+
}
27+
};
28+
29+
const localMessages = getLocalMessages();
30+
31+
return {
32+
...localMessages,
33+
};
34+
};
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1 @@
1-
import {getRequestConfig} from 'next-intl/server';
2-
import {hasLocale} from 'next-intl';
3-
import {routing} from './routing';
4-
5-
export default getRequestConfig(async ({requestLocale}) => {
6-
// Typically corresponds to the `[locale]` segment
7-
const requested = await requestLocale;
8-
console.log('requested', requested);
9-
const locale = hasLocale(routing.locales, requested)
10-
? requested
11-
: routing.defaultLocale;
12-
13-
return {
14-
locale,
15-
messages: (await import(`../../messages/${locale}.json`)).default
16-
};
17-
});
1+
//This path is supported by default ./(src/)i18n/request.fjs,jsx,ts,tsx}

frontend/packages/pydantic-forms/src/core/translations/translationsProvider.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export const TranslationsProvider = ({
5959
<NextIntlClientProvider
6060
locale={locale || Locale.enGB}
6161
messages={messages}
62+
timeZone={'Europe/Amsterdam'}
6263
onError={onError}
6364
>
6465
{children}

0 commit comments

Comments
 (0)