Hi,
I am looking for a solution using Prismic and Next.js that allows me to support two languages, such as English and French, while using the same templates and codebase. The language should be determined by the domain name: website.com for English and website.fr for French.
I had a look at the guide here https://prismic.io/blog/nextjs-i18n on how to enable internationalization, but it doesnät explain how it can be used with two domains, normal URL structure, default locale and how to fetch the correct content for the page with Prismic.
My next config looks like this:
const nextConfig = {
i18n: {
locales: ['en-us', 'fr-fr'],
defaultLocale: 'en-us',
domains: [
{
domain: 'website.com',
defaultLocale: 'en-us',
},
{
domain: 'website.fr',
defaultLocale: 'fr-fr',
}
]
}
}
But I am not sure what changes I need to do in my middleware.ts file function or in page.tsx to fetch the correct content from Prismic based on the language used for the domain.
export async function middleware(request: NextRequest) {
const client = createClient()
const repository = await client.getRepository()
const locales = repository.languages.map((lang) => lang.id)
???
}
Then lastly what needs to be added to the page template to get the locales and fetch content. I am not sure how I can get the params.lang on page level, it doesn't exist on my Prismic setup.
type Params = { uid: string, lang: string }
export default async function Page({ params }: { params: Params }) {
let page
const client = createClient()
page = await client.getByUID('page', params.uid, { lang: params.lang }).catch(() => notFound())
???
return (
<main>
<SliceZone slices={page.data.slices} components={components} />
</main>
)
}
It would be appriciated if anyone can give me some example how this can be achieved.