A complete but unopinionated internationalization solution for nextjs
This is a Next.js Template implementing Internationalization (i18n).
I wrote this because I found it hard to compose all the demos and docs together into what resembled a fully functioning content-centric website.
This template:
Current locales are defined within next.config.js
:
File: next.config.js
module.exports = {
i18n: {
locales: ["en", "es"],
defaultLocale: "en",
},
}
The content/
directory contains a TypeScript definition file ensuring you never miss mapping a new value.
File: content\translation.d.ts
export type Nav = {
home: string,
chapter1: string,
}
export type Translation = {
nav: Nav,
welcome: string,
}
next.config.js
/content
translation.ts
under the new locale directory, implementing the Translation
type.Node environment:
File: .nvmrc
v16.14.2
Install dependencies:
npm ci
Then, run the development server:
npm run dev
Option one: One-click deploy to Vercel
Option two: Manual clone
git clone [email protected]:bmuenzenmeyer/next-i18n-starter.git
npm ci
npm run dev
I composed some resources to get this far. Thank you to: