This repository serves as a boilerplate for creating a multilingual Next.js 15 project using the next-intl
library for internationalization. The boilerplate also integrates Tailwind CSS for styling and includes a basic project setup for rapid development.
en-US
, de-DE
, fr-FR
, etc.).Ensure you have the following installed on your development machine:
Clone the repository and install dependencies:
git clone <repository-url>
cd nextjs
npm install
# or
yarn install
# or
pnpm install
# or
bun install
Start the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
Open your browser and visit http://localhost:3000 to see the application.
Here’s an overview of the key files and directories in the project:
nextjs/
├── messages/ # JSON files for locale translations
├── src/
│ ├── app/ # Next.js app directory
│ │ ├── [locale]/ # Dynamic locale-based routing
│ │ ├── components/ # Reusable UI components
│ │ └── globals.css # Tailwind CSS global styles
│ ├── i18n/ # Internationalization logic (next-intl)
│ ├── middleware.ts # Middleware for locale-based routing
│ └── pages/ # (Optional) Custom Next.js pages (if required)
├── .eslintrc.json # ESLint configuration
├── next.config.ts # Next.js configuration with next-intl plugin
├── tailwind.config.ts # Tailwind CSS configuration
├── tsconfig.json # TypeScript configuration
└── README.md # You are here!
This boilerplate uses next-intl for i18n support. Here’s how it works:
messages/
directory.en-US.json
, de-DE.json
).{
"HomePage": {
"title": "Welcome!",
"about": "Go to the about page"
},
"Header": {
"navigation": {
"home": "Home",
"about": "About"
}
}
}
The [locale]
dynamic route handles locale-based routing. For example:
/en-US/
for English (US)/de-DE/
for German (Germany)The middleware.ts
file ensures only supported locales are routed:
import createMiddleware from "next-intl/middleware";
import { routing } from "./i18n/routing";
export default createMiddleware(routing);
export const config = {
matcher: ["/", "/(de-DE|en-US|fr-FR|...)/:path*"],
};
The LocaleSwitcher
component allows users to toggle between locales:
<Menu.Items>
{routing.locales.map((locale) => (
<Menu.Item key={locale}>
<button onClick={() => router.replace(pathname, { locale })}>
{localeNames[locale]}
</button>
</Menu.Item>
))}
</Menu.Items>
The project includes Tailwind CSS for utility-first styling.
Modify tailwind.config.ts
to extend the default theme or add custom configurations:
export default {
theme: {
extend: {
colors: {
background: "#f0f0f0",
foreground: "#333",
},
},
},
};
Global styles are defined in globals.css
:
@tailwind base;
@tailwind components;
@tailwind utilities;
The following npm scripts are available:
npm run dev
: Start the development server.npm run build
: Build the project for production.npm run start
: Start the production server.npm run lint
: Run ESLint checks.Deploy the project easily using Vercel:
Contributions are welcome! If you find a bug or have an idea for a new feature:
git checkout -b feature/my-feature
.git commit -m "Add my feature"
.git push origin feature/my-feature
.npm install
to install missing dependencies.tailwind.config.ts
includes the correct content
paths.messages/
and routing.ts
.Use console.log
or debugging tools like VS Code Debugger or Chrome DevTools.
This project is licensed under the MIT License.