Introduction
This article was generated by GPT-4o. It explains how to build a multilingual static site using Next.js. In particular, it focuses on a configuration where the main language has no URL prefix while other languages have prefixes. It also includes configuration for deploying to GitHub Pages.
Project Setup
First, create a Next.js project. Initialize the project using create-next-app.
Installing Required Packages
Install next-intl for multilingual support.
Project Structure
The project directory structure is as follows.
src/app/[locale]/about/page.tsxsrc/app/about/page.tsxsrc/lib/i18n.tssrc/components/I18nProvider.tsxsrc/i18n/ja.jsonsrc/i18n/en.json
Implementing Multilingual Support
Using next-intl, messages are managed for each language. A function to retrieve messages is defined in src/lib/i18n.ts.
The I18nProvider component provides messages for each page.
SSG Configuration
The generateStaticParams function is used to set parameters for static page generation. The main language (Japanese) has no prefix, while other languages have prefixes.
Deploying to GitHub Pages
Deploy to GitHub Pages using GitHub Actions. Configure the deployment in .github/workflows/deploy.yml.
Links
- GitHub Repository: next-intl-ssg
- GitHub Pages: next-intl-ssg
Summary
This blog post introduced how to build a multilingual static site using Next.js, where the main language has no prefix and other languages have prefixes. By leveraging next-intl, multilingual support is easily achievable. Please give it a try.