From 4246197d8a45532a790b86996c8cca0112046b1c Mon Sep 17 00:00:00 2001 From: cesalberca Date: Tue, 16 Jul 2024 18:36:24 +0200 Subject: [PATCH] Break into middleware --- src/app/[locale]/about.tsx | 8 ++++++++ src/app/{locale => [locale]}/layout.tsx | 0 src/app/about.tsx | 17 ----------------- src/app/components/posts.tsx | 3 ++- src/app/links.tsx | 10 +--------- src/app/page.tsx | 5 +++-- src/core/i18n/i18n.ts | 2 +- .../middleware.ts => i18n.middleware.ts} | 6 +----- src/middleware.ts | 1 + 9 files changed, 17 insertions(+), 35 deletions(-) create mode 100644 src/app/[locale]/about.tsx rename src/app/{locale => [locale]}/layout.tsx (100%) delete mode 100644 src/app/about.tsx rename src/{app/middleware/middleware.ts => i18n.middleware.ts} (51%) create mode 100644 src/middleware.ts diff --git a/src/app/[locale]/about.tsx b/src/app/[locale]/about.tsx new file mode 100644 index 0000000..23a98d3 --- /dev/null +++ b/src/app/[locale]/about.tsx @@ -0,0 +1,8 @@ +import type { NextPage } from 'next' +import { AboutPage } from '../../features/about/delivery/about.page' + +const Index: NextPage = () => { + return +} + +export default Index diff --git a/src/app/locale/layout.tsx b/src/app/[locale]/layout.tsx similarity index 100% rename from src/app/locale/layout.tsx rename to src/app/[locale]/layout.tsx diff --git a/src/app/about.tsx b/src/app/about.tsx deleted file mode 100644 index 1215ae4..0000000 --- a/src/app/about.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import type { NextPage } from 'next' -import type { GetStaticProps } from 'next' -import { AboutPage } from '../features/about/delivery/about.page' - -const Index: NextPage = () => { - return -} - -export const getStaticProps: GetStaticProps = async ({ locale }) => { - return { - props: { - messages: (await import(`../core/i18n/${locale}.json`)).default, - }, - } -} - -export default Index diff --git a/src/app/components/posts.tsx b/src/app/components/posts.tsx index de8c94e..80f6fea 100644 --- a/src/app/components/posts.tsx +++ b/src/app/components/posts.tsx @@ -1,7 +1,8 @@ import Link from 'next/link' import { getBlogPosts } from '../utils' +import type { FC } from 'react' -export function BlogPosts() { +export const BlogPosts: FC = () => { let allBlogs = getBlogPosts() return ( diff --git a/src/app/links.tsx b/src/app/links.tsx index d7fa16b..a234f2a 100644 --- a/src/app/links.tsx +++ b/src/app/links.tsx @@ -1,16 +1,8 @@ -import type { GetStaticProps, NextPage } from 'next' +import type { NextPage } from 'next' import { LinksPage } from '../features/links/delivery/links.page' const Index: NextPage = () => { return } -export const getStaticProps: GetStaticProps = async ({ locale }) => { - return { - props: { - messages: (await import(`../core/i18n/${locale}.json`)).default, - }, - } -} - export default Index diff --git a/src/app/page.tsx b/src/app/page.tsx index 4f9dd90..c5307d8 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,6 +1,7 @@ -import { HomePage } from '../features/home/ui/home.page' import { BlogPosts } from './components/posts' +import { useTranslations } from 'next-intl' export default function Home() { - return + const t = useTranslations() + return

{t('common.coverage')}

} diff --git a/src/core/i18n/i18n.ts b/src/core/i18n/i18n.ts index 56a5648..a986d1b 100644 --- a/src/core/i18n/i18n.ts +++ b/src/core/i18n/i18n.ts @@ -9,6 +9,6 @@ export default getRequestConfig(async ({ locale }) => { if (!locales.includes(locale as any)) notFound() return { - messages: (await import(`../translations/${locale}.json`)).default, + messages: (await import(`./translations/${locale}.json`)).default, } }) diff --git a/src/app/middleware/middleware.ts b/src/i18n.middleware.ts similarity index 51% rename from src/app/middleware/middleware.ts rename to src/i18n.middleware.ts index cc4be13..e44e6f5 100644 --- a/src/app/middleware/middleware.ts +++ b/src/i18n.middleware.ts @@ -1,14 +1,10 @@ import createMiddleware from 'next-intl/middleware' -export default createMiddleware({ - // A list of all locales that are supported +export const i18nMiddleware = createMiddleware({ locales: ['en', 'de'], - - // Used when no locale matches defaultLocale: 'en', }) export const config = { - // Match only internationalized pathnames matcher: ['/', '/(en|es)/:path*'], } diff --git a/src/middleware.ts b/src/middleware.ts new file mode 100644 index 0000000..65b3552 --- /dev/null +++ b/src/middleware.ts @@ -0,0 +1 @@ +export { i18nMiddleware as default, config } from './i18n.middleware'