Compare commits

..

1 Commits

Author SHA1 Message Date
bae2ebf22a Merge pull request 'develop' (#3) from develop into main
Reviewed-on: #3
2024-11-26 15:46:59 +00:00
4 changed files with 17 additions and 33 deletions

View File

@ -1,12 +1,11 @@
"use client"; "use client"
import * as React from "react"; import * as React from "react"
import { ThemeProvider as NextThemesProvider } from "next-themes"; import { ThemeProvider as NextThemesProvider } from "next-themes"
export function ThemeProvider({ export function ThemeProvider({
children, children,
...props ...props
}: React.ComponentProps<typeof NextThemesProvider>) { }: React.ComponentProps<typeof NextThemesProvider>) {
// eslint-disable-next-line react/jsx-props-no-spreading return <NextThemesProvider {...props}>{children}</NextThemesProvider>
return <NextThemesProvider {...props}>{children}</NextThemesProvider>;
} }

View File

@ -20,7 +20,7 @@ export default async function layout(
) { ) {
const { params, children } = props; const { params, children } = props;
const { lang } = await params; const { lang } = await params;
await initI18next({ lng: lang }); const { resources } = await initI18next({ lng: lang });
return ( return (
<html lang={lang} suppressHydrationWarning> <html lang={lang} suppressHydrationWarning>
<body <body
@ -32,7 +32,9 @@ export default async function layout(
enableSystem enableSystem
disableTransitionOnChange disableTransitionOnChange
> >
<TranslationsProvider lng={lang}>{children}</TranslationsProvider> <TranslationsProvider lng={lang} resources={resources}>
{children}
</TranslationsProvider>
</ThemeProvider> </ThemeProvider>
</body> </body>
</html> </html>

View File

@ -2,24 +2,16 @@
import { I18nextProvider } from "react-i18next"; import { I18nextProvider } from "react-i18next";
import { i18nInstance, initI18next, LANGS } from "@/bootstrap/i18n/i18n"; import { i18nInstance, initI18next, LANGS } from "@/bootstrap/i18n/i18n";
import { PropsWithChildren, useEffect, useState } from "react"; import { Resource } from "i18next";
import storeLang from "@/bootstrap/i18n/store-lang-action"; import { PropsWithChildren } from "react";
import { i18n } from "i18next";
export default function TranslationsProvider( export default function TranslationsProvider({
props: PropsWithChildren & { lng: LANGS }, children,
) { lng,
const { lng, children } = props; resources,
const [i18n, setI18n] = useState<i18n>(); }: PropsWithChildren & { lng: LANGS; resources: Resource }) {
if (!resources) return children;
useEffect(() => { initI18next({ lng, resources });
(async () => {
storeLang(lng);
setI18n((await initI18next({ lng })).i18n);
})();
}, [lng]);
if (!i18n) return null;
return <I18nextProvider i18n={i18nInstance}>{children}</I18nextProvider>; return <I18nextProvider i18n={i18nInstance}>{children}</I18nextProvider>;
} }

View File

@ -1,9 +0,0 @@
"use server";
import { LANGS } from "@/bootstrap/i18n/i18n";
import { cookieName } from "@/bootstrap/i18n/settings";
import { cookies } from "next/headers";
export default async function storeLang(lng: LANGS) {
(await cookies()).set(cookieName, lng);
}