feat: add next-intl, supports en/zh/de languages

This commit is contained in:
javayhu 2025-03-02 01:33:56 +08:00
parent a4e7a59e17
commit 72005865f3
19 changed files with 24 additions and 24 deletions

View File

@ -4,15 +4,17 @@ import { withContentCollections } from "@content-collections/next";
/** /**
* https://next-intl.dev/docs/getting-started/app-router/with-i18n-routing#next-config * 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(); const withNextIntl = createNextIntlPlugin();
module.exports = { // module.exports = {
experimental: { // experimental: {
// https://nextjs.org/docs/messages/missing-suspense-with-csr-bailout // // https://nextjs.org/docs/messages/missing-suspense-with-csr-bailout
missingSuspenseWithCSRBailout: false, // missingSuspenseWithCSRBailout: false,
}, // },
} // }
/** /**
* https://nextjs.org/docs/app/api-reference/config/next-config-js * https://nextjs.org/docs/app/api-reference/config/next-config-js

View File

@ -32,8 +32,6 @@ export default async function HomePage(props: HomePageProps) {
return ( return (
<> <>
{/* <PromotekitScript /> */}
<div className="mt-12 flex flex-col gap-16"> <div className="mt-12 flex flex-col gap-16">
<div className="text-center"> <div className="text-center">

View File

@ -21,18 +21,18 @@ interface LocaleLayoutProps {
params: Promise<{ locale: string }>; params: Promise<{ locale: string }>;
}; };
export function generateStaticParams() { // export function generateStaticParams() {
return routing.locales.map((locale) => ({ locale })); // return routing.locales.map((locale) => ({ locale }));
} // }
export async function generateMetadata(props: Omit<LocaleLayoutProps, 'children'>) { // export async function generateMetadata(props: Omit<LocaleLayoutProps, 'children'>) {
const { locale } = await props.params; // const { locale } = await props.params;
const t = await getTranslations({ locale, namespace: 'LocaleLayout' }); // const t = await getTranslations({ locale, namespace: 'LocaleLayout' });
return { // return {
title: t('title') // title: t('title')
}; // };
} // }
export default async function LocaleLayout({ children, params }: LocaleLayoutProps) { export default async function LocaleLayout({ children, params }: LocaleLayoutProps) {
const { locale } = await params; const { locale } = await params;

View File

@ -67,11 +67,11 @@ export async function generateMetadata(
}; };
} }
export async function generateStaticParams() { // export async function generateStaticParams() {
return allPosts.map((post) => ({ // return allPosts.map((post) => ({
slug: post.slugAsParams.split('/') // slug: post.slugAsParams.split('/')
})); // }));
} // }
export default async function BlogPostPage(props: NextPageProps) { export default async function BlogPostPage(props: NextPageProps) {
const post = await getBlogPostFromParams(props); const post = await getBlogPostFromParams(props);

View File

@ -10,7 +10,7 @@ export const config = {
// Set a cookie to remember the previous locale for // Set a cookie to remember the previous locale for
// all requests that have a locale prefix // all requests that have a locale prefix
'/(de|en)/:path*', '/(zh|de|en)/:path*',
// Enable redirects that add missing locales // Enable redirects that add missing locales
// (e.g. `/pathnames` -> `/en/pathnames`) // (e.g. `/pathnames` -> `/en/pathnames`)