Static Site Generation
How to support static site generation for your i18n app
Overview
This guide will show you how to setup your i18n app to support static site generation.
What is static site generation?
Static site generation (SSG) is a feature of Next.js that allows you to generate static pages at build time. This is useful for performance and SEO.
SSG for the app
router
Requirements
There are a few requirements to enable static site generation for your i18n app.
Depending on whether you are using the app
or pages
directory, the requirements are slightly different.
- Your app must be using the Next.js app router.
- Your app must support i18n routing (see i18n routing)
- Your app must be using local translations (see local translations)
Steps
Step 1:
First, make sure your app has a <GTProvider>
component at the root layout.
Since the app is using i18n routing, the provider should be placed in the [locale]/layout.tsx
file.
Step 2:
Next, make sure your app is using the loadTranslations
function to load translations.
Additionally, pass in the locale as a parameter to the <GTProvider>
. You can obtain the locale from the params
object.
Step 3:
Then, make sure all of your hooks and components are importing from gt-next/client
.
This is important because hooks and components imported from gt-next/client
never read headers, which don't exist at build time for statically generated pages.
Make sure you have configured your Next.js app to use the getStaticParams
function correctly!
That's it! Your app should now support static site generation for multiple languages!
SSG for the pages
router
🚧 This section is currently under construction. 🚧