🔥🔥🔥
I released a better solution: next-i18next-static-site
This package brings youreact-i18nextandi18nextto your static sites build with thenext exportfuture from Next.js.
- 🗲 Translation is already rendered (SSG), client will receive the final translated site.
- 🔥 Hot reload works also when you update your locale (translation) files.
- 🚀 Automatic browser language detection can be realized.
- 🍪 Cookie stores the client language.
It's highly recommend to use next-i18next-static-site instead of this starter if you want to use all functions from
react-i18next.
This starter allows you to use the next export future from Next.js in combination with i18n to create a complete static site.
Clients will directly redirected from / to /[lang] based on the detected language.
Packages included:
- i18next
- i18next-browser-languagedetector
- tailwindcss
- twin.macro
- styled-components
- Custom 404 page with i18n support
Clone the repository and run npm ci (recommend) or npm install.
- Set the supported languages, default language, namespaces and default namespace in
/src/i18n/config.js - Locales are located in
/src/locales/- To prevent mess, you can split the
.jsontranslation file(s) into multiple namespaces
- To prevent mess, you can split the
Run npm run dev to start the development server on http://localhost:3000.
Visit http://localhost:3000 to view this starter.
There is a custom wrapper for <Link> that will handle the i18n linking, just replace next/link with src/components/link.
Set locale to force a specific language for a given href:
<Link href="/somesite" locale="en">
<a>Somesite (EN)</a>
</Link>
To change the language of the current site you only need locale, href will be grabbed automatically:
<Link locale="de">
<a>Current site (DE)</a>
</Link>
npm run exportTipp: You could deploy static sites totally for free on Cloudflare Pages.
npm run serve- https://nextjs-i18n-static-page-starter.pages.dev (this repo)
- https://www.meatandme.info (based on this starter)