From 72005865f373a425b8f6697b611e16b8e3f69d50 Mon Sep 17 00:00:00 2001 From: javayhu Date: Sun, 2 Mar 2025 01:33:56 +0800 Subject: [PATCH] feat: add next-intl, supports en/zh/de languages --- next.config.ts | 14 +++++++------ .../(protected)/dashboard/page.tsx | 0 src/app/[locale]/(public)/(home)/page.tsx | 2 -- src/app/[locale]/layout.tsx | 20 +++++++++---------- src/app/{[locale] => }/auth/error/page.tsx | 0 .../auth/forgot-password/page.tsx | 0 src/app/{[locale] => }/auth/layout.tsx | 0 src/app/{[locale] => }/auth/loading.tsx | 0 src/app/{[locale] => }/auth/login/page.tsx | 0 .../{[locale] => }/auth/new-password/page.tsx | 0 src/app/{[locale] => }/auth/register/page.tsx | 0 .../blog/(blog)/category/[slug]/loading.tsx | 0 .../(public) => }/blog/(blog)/layout.tsx | 0 .../(public) => }/blog/(blog)/loading.tsx | 0 .../(public) => }/blog/(blog)/page.tsx | 0 .../(public) => }/blog/[...slug]/layout.tsx | 0 .../(public) => }/blog/[...slug]/loading.tsx | 0 .../(public) => }/blog/[...slug]/page.tsx | 10 +++++----- src/middleware.ts | 2 +- 19 files changed, 24 insertions(+), 24 deletions(-) rename src/app/{[locale] => }/(protected)/dashboard/page.tsx (100%) rename src/app/{[locale] => }/auth/error/page.tsx (100%) rename src/app/{[locale] => }/auth/forgot-password/page.tsx (100%) rename src/app/{[locale] => }/auth/layout.tsx (100%) rename src/app/{[locale] => }/auth/loading.tsx (100%) rename src/app/{[locale] => }/auth/login/page.tsx (100%) rename src/app/{[locale] => }/auth/new-password/page.tsx (100%) rename src/app/{[locale] => }/auth/register/page.tsx (100%) rename src/app/{[locale]/(public) => }/blog/(blog)/category/[slug]/loading.tsx (100%) rename src/app/{[locale]/(public) => }/blog/(blog)/layout.tsx (100%) rename src/app/{[locale]/(public) => }/blog/(blog)/loading.tsx (100%) rename src/app/{[locale]/(public) => }/blog/(blog)/page.tsx (100%) rename src/app/{[locale]/(public) => }/blog/[...slug]/layout.tsx (100%) rename src/app/{[locale]/(public) => }/blog/[...slug]/loading.tsx (100%) rename src/app/{[locale]/(public) => }/blog/[...slug]/page.tsx (97%) diff --git a/next.config.ts b/next.config.ts index c136589..1999a78 100644 --- a/next.config.ts +++ b/next.config.ts @@ -4,15 +4,17 @@ import { withContentCollections } from "@content-collections/next"; /** * https://next-intl.dev/docs/getting-started/app-router/with-i18n-routing#next-config + * + * Explicitly specify the path to the request config file */ const withNextIntl = createNextIntlPlugin(); -module.exports = { - experimental: { - // https://nextjs.org/docs/messages/missing-suspense-with-csr-bailout - missingSuspenseWithCSRBailout: false, - }, -} +// module.exports = { +// experimental: { +// // https://nextjs.org/docs/messages/missing-suspense-with-csr-bailout +// missingSuspenseWithCSRBailout: false, +// }, +// } /** * https://nextjs.org/docs/app/api-reference/config/next-config-js diff --git a/src/app/[locale]/(protected)/dashboard/page.tsx b/src/app/(protected)/dashboard/page.tsx similarity index 100% rename from src/app/[locale]/(protected)/dashboard/page.tsx rename to src/app/(protected)/dashboard/page.tsx diff --git a/src/app/[locale]/(public)/(home)/page.tsx b/src/app/[locale]/(public)/(home)/page.tsx index 970c2d2..20addea 100644 --- a/src/app/[locale]/(public)/(home)/page.tsx +++ b/src/app/[locale]/(public)/(home)/page.tsx @@ -32,8 +32,6 @@ export default async function HomePage(props: HomePageProps) { return ( <> - {/* */} -
diff --git a/src/app/[locale]/layout.tsx b/src/app/[locale]/layout.tsx index 5b85f38..2eccdf9 100644 --- a/src/app/[locale]/layout.tsx +++ b/src/app/[locale]/layout.tsx @@ -21,18 +21,18 @@ interface LocaleLayoutProps { params: Promise<{ locale: string }>; }; -export function generateStaticParams() { - return routing.locales.map((locale) => ({ locale })); -} +// export function generateStaticParams() { +// return routing.locales.map((locale) => ({ locale })); +// } -export async function generateMetadata(props: Omit) { - const { locale } = await props.params; - const t = await getTranslations({ locale, namespace: 'LocaleLayout' }); +// export async function generateMetadata(props: Omit) { +// const { locale } = await props.params; +// const t = await getTranslations({ locale, namespace: 'LocaleLayout' }); - return { - title: t('title') - }; -} +// return { +// title: t('title') +// }; +// } export default async function LocaleLayout({ children, params }: LocaleLayoutProps) { const { locale } = await params; diff --git a/src/app/[locale]/auth/error/page.tsx b/src/app/auth/error/page.tsx similarity index 100% rename from src/app/[locale]/auth/error/page.tsx rename to src/app/auth/error/page.tsx diff --git a/src/app/[locale]/auth/forgot-password/page.tsx b/src/app/auth/forgot-password/page.tsx similarity index 100% rename from src/app/[locale]/auth/forgot-password/page.tsx rename to src/app/auth/forgot-password/page.tsx diff --git a/src/app/[locale]/auth/layout.tsx b/src/app/auth/layout.tsx similarity index 100% rename from src/app/[locale]/auth/layout.tsx rename to src/app/auth/layout.tsx diff --git a/src/app/[locale]/auth/loading.tsx b/src/app/auth/loading.tsx similarity index 100% rename from src/app/[locale]/auth/loading.tsx rename to src/app/auth/loading.tsx diff --git a/src/app/[locale]/auth/login/page.tsx b/src/app/auth/login/page.tsx similarity index 100% rename from src/app/[locale]/auth/login/page.tsx rename to src/app/auth/login/page.tsx diff --git a/src/app/[locale]/auth/new-password/page.tsx b/src/app/auth/new-password/page.tsx similarity index 100% rename from src/app/[locale]/auth/new-password/page.tsx rename to src/app/auth/new-password/page.tsx diff --git a/src/app/[locale]/auth/register/page.tsx b/src/app/auth/register/page.tsx similarity index 100% rename from src/app/[locale]/auth/register/page.tsx rename to src/app/auth/register/page.tsx diff --git a/src/app/[locale]/(public)/blog/(blog)/category/[slug]/loading.tsx b/src/app/blog/(blog)/category/[slug]/loading.tsx similarity index 100% rename from src/app/[locale]/(public)/blog/(blog)/category/[slug]/loading.tsx rename to src/app/blog/(blog)/category/[slug]/loading.tsx diff --git a/src/app/[locale]/(public)/blog/(blog)/layout.tsx b/src/app/blog/(blog)/layout.tsx similarity index 100% rename from src/app/[locale]/(public)/blog/(blog)/layout.tsx rename to src/app/blog/(blog)/layout.tsx diff --git a/src/app/[locale]/(public)/blog/(blog)/loading.tsx b/src/app/blog/(blog)/loading.tsx similarity index 100% rename from src/app/[locale]/(public)/blog/(blog)/loading.tsx rename to src/app/blog/(blog)/loading.tsx diff --git a/src/app/[locale]/(public)/blog/(blog)/page.tsx b/src/app/blog/(blog)/page.tsx similarity index 100% rename from src/app/[locale]/(public)/blog/(blog)/page.tsx rename to src/app/blog/(blog)/page.tsx diff --git a/src/app/[locale]/(public)/blog/[...slug]/layout.tsx b/src/app/blog/[...slug]/layout.tsx similarity index 100% rename from src/app/[locale]/(public)/blog/[...slug]/layout.tsx rename to src/app/blog/[...slug]/layout.tsx diff --git a/src/app/[locale]/(public)/blog/[...slug]/loading.tsx b/src/app/blog/[...slug]/loading.tsx similarity index 100% rename from src/app/[locale]/(public)/blog/[...slug]/loading.tsx rename to src/app/blog/[...slug]/loading.tsx diff --git a/src/app/[locale]/(public)/blog/[...slug]/page.tsx b/src/app/blog/[...slug]/page.tsx similarity index 97% rename from src/app/[locale]/(public)/blog/[...slug]/page.tsx rename to src/app/blog/[...slug]/page.tsx index 3467e64..83ad24f 100644 --- a/src/app/[locale]/(public)/blog/[...slug]/page.tsx +++ b/src/app/blog/[...slug]/page.tsx @@ -67,11 +67,11 @@ export async function generateMetadata( }; } -export async function generateStaticParams() { - return allPosts.map((post) => ({ - slug: post.slugAsParams.split('/') - })); -} +// export async function generateStaticParams() { +// return allPosts.map((post) => ({ +// slug: post.slugAsParams.split('/') +// })); +// } export default async function BlogPostPage(props: NextPageProps) { const post = await getBlogPostFromParams(props); diff --git a/src/middleware.ts b/src/middleware.ts index 348faa8..719e9ec 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -10,7 +10,7 @@ export const config = { // Set a cookie to remember the previous locale for // all requests that have a locale prefix - '/(de|en)/:path*', + '/(zh|de|en)/:path*', // Enable redirects that add missing locales // (e.g. `/pathnames` -> `/en/pathnames`)