From a89095b5c4d508d95e1ae5b8f03b895548451d41 Mon Sep 17 00:00:00 2001 From: Anthony G <1@anthony.sh> Date: Mon, 10 Aug 2026 15:34:34 +0200 Subject: [PATCH] feat: restructure routes under [locale], add LanguageSwitcher --- src/app/[locale]/layout.tsx | 43 +++++++++++++++++++++++++ src/app/[locale]/page.tsx | 17 ++++++++++ src/app/[locale]/status/[uuid]/page.tsx | 17 ++++++++++ src/app/layout.tsx | 12 +------ src/app/page.tsx | 10 ------ src/app/status/[uuid]/page.tsx | 15 --------- src/components/LanguageSwitcher.tsx | 39 ++++++++++++++++++++++ 7 files changed, 117 insertions(+), 36 deletions(-) create mode 100644 src/app/[locale]/layout.tsx create mode 100644 src/app/[locale]/page.tsx create mode 100644 src/app/[locale]/status/[uuid]/page.tsx delete mode 100644 src/app/page.tsx delete mode 100644 src/app/status/[uuid]/page.tsx create mode 100644 src/components/LanguageSwitcher.tsx diff --git a/src/app/[locale]/layout.tsx b/src/app/[locale]/layout.tsx new file mode 100644 index 0000000..a9c7a02 --- /dev/null +++ b/src/app/[locale]/layout.tsx @@ -0,0 +1,43 @@ +import type { Metadata } from 'next' +import { NextIntlClientProvider } from 'next-intl' +import { getTranslations, getMessages } from 'next-intl/server' +import { notFound } from 'next/navigation' +import { routing } from '@/i18n/routing' +import { LanguageSwitcher } from '@/components/LanguageSwitcher' + +export async function generateMetadata({ + params, +}: { + params: Promise<{ locale: string }> +}): Promise { + const { locale } = await params + const t = await getTranslations({ locale, namespace: 'meta' }) + return { title: t('title') } +} + +export default async function LocaleLayout({ + children, + params, +}: { + children: React.ReactNode + params: Promise<{ locale: string }> +}) { + const { locale } = await params + + if (!(routing.locales as readonly string[]).includes(locale)) { + notFound() + } + + const messages = await getMessages() + + return ( + + + + + {children} + + + + ) +} diff --git a/src/app/[locale]/page.tsx b/src/app/[locale]/page.tsx new file mode 100644 index 0000000..3db6997 --- /dev/null +++ b/src/app/[locale]/page.tsx @@ -0,0 +1,17 @@ +import { getTranslations } from 'next-intl/server' +import { SubmitForm } from '@/components/SubmitForm' + +export default async function Home({ + params, +}: { + params: Promise<{ locale: string }> +}) { + const { locale } = await params + const t = await getTranslations({ locale, namespace: 'home' }) + return ( +
+

{t('heading')}

+ +
+ ) +} diff --git a/src/app/[locale]/status/[uuid]/page.tsx b/src/app/[locale]/status/[uuid]/page.tsx new file mode 100644 index 0000000..f748b6f --- /dev/null +++ b/src/app/[locale]/status/[uuid]/page.tsx @@ -0,0 +1,17 @@ +import { getTranslations } from 'next-intl/server' +import { StatusView } from '@/components/StatusView' + +export default async function StatusPage({ + params, +}: { + params: Promise<{ locale: string; uuid: string }> +}) { + const { locale, uuid } = await params + const t = await getTranslations({ locale, namespace: 'status' }) + return ( +
+

{t('heading')}

+ +
+ ) +} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index ac7e01f..e86ddb1 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,13 +1,3 @@ -import type { Metadata } from 'next' - -export const metadata: Metadata = { - title: 'Ombrora — Telechargeur de videos', -} - export default function RootLayout({ children }: { children: React.ReactNode }) { - return ( - - {children} - - ) + return children } diff --git a/src/app/page.tsx b/src/app/page.tsx deleted file mode 100644 index 12a0357..0000000 --- a/src/app/page.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import { SubmitForm } from '@/components/SubmitForm' - -export default function Home() { - return ( -
-

Ombrora

- -
- ) -} diff --git a/src/app/status/[uuid]/page.tsx b/src/app/status/[uuid]/page.tsx deleted file mode 100644 index 92287cb..0000000 --- a/src/app/status/[uuid]/page.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { StatusView } from '@/components/StatusView' - -export default async function StatusPage({ - params, -}: { - params: Promise<{ uuid: string }> -}) { - const { uuid } = await params - return ( -
-

Statut du telechargement

- -
- ) -} diff --git a/src/components/LanguageSwitcher.tsx b/src/components/LanguageSwitcher.tsx new file mode 100644 index 0000000..8794495 --- /dev/null +++ b/src/components/LanguageSwitcher.tsx @@ -0,0 +1,39 @@ +'use client' + +import { useLocale } from 'next-intl' +import { useRouter, usePathname } from '@/navigation' +import { routing } from '@/i18n/routing' + +const FLAGS: Record = { + en: '🇺🇸', + fr: '🇫🇷', + es: '🇪🇸', + it: '🇮🇹', +} + +export function LanguageSwitcher() { + const locale = useLocale() + const router = useRouter() + const pathname = usePathname() + + return ( +
+ {routing.locales.map((loc) => ( + + ))} +
+ ) +}