Creation and support of the multilingual project Next.js
npm install @locanext/ntsbash
npx @locanext/nts create
`
This uses the official create-next-app@latest, so your project follows Next.js best practices.
After running the command, you get a ready-to-use multilingual Next.js app.
---
Quick Start: Existing Project
1. Go to locanext.com and create a project. If you already have JSON files, you can create a project from them.
2. Install the nts package:
`bash
npm i @locanext/nts
`
3. Link your local project and create the config:
`bash
npx nts init
`
4. Download the latest translations:
`bash
npx nts update
`
By default, the CLI adds translations to the /locales folder.
---
Update Translation Files
To get the newest translation JSON files from your project, run:
`bash
npx nts update
`
---
Variables
1. On the website, use the {{variable}} pattern. For example: Hi, {{name}}.
2. In your Next.js project, use the t function:
`ts
import { t } from "@locanext/nts";
const greeting = t(dictionary.greeting, { name: "John" }); // typed variables
`
Typings are refreshed every time you run npx nts update`.