An open API service indexing awesome lists of open source software.

https://github.com/tanmayshil/next-language-translate

A modern multilingual product landing page built with Next.js 15, TypeScript, Tailwind CSS, shadcn/ui, Magic UI, React Query, and i18next. Supports English, Hindi, and Bengali translations for both static UI text and dynamic FakeStore API product data using google-translate-api-x.
https://github.com/tanmayshil/next-language-translate

fakestoreapi google-translate-api i18n-react i18next internationalization language-switcher magicui multilingual nextjs shadcn-ui tailwindcss typescript

Last synced: 17 days ago
JSON representation

A modern multilingual product landing page built with Next.js 15, TypeScript, Tailwind CSS, shadcn/ui, Magic UI, React Query, and i18next. Supports English, Hindi, and Bengali translations for both static UI text and dynamic FakeStore API product data using google-translate-api-x.

Awesome Lists containing this project

README

          

### Next.js Language Translator Store ๐ŸŒ

A modern multilingual product landing page built with Next.js 15, TypeScript, Tailwind CSS, shadcn/ui, Magic UI, React Query, and i18next.
The application supports dynamic language translation for both static UI text and API product data using google-translate-api-x.

### ๐Ÿš€ Features
---
### ๐ŸŒ Multi-language support
- English
- Hindi
- Bengali
### ๐ŸŽจ Modern UI using:
- Tailwind CSS
- shadcn/ui
- Magic UI
### ๐Ÿ“ฆ Product listing using FakeStore API
### ๐Ÿ”„ Dynamic product translation
- Product title
- Description
- Category
### โšก React Query caching
### ๐ŸŒ Language auto-detection using:
- i18next-browser-languagedetector
### ๐Ÿง  Custom translation hooks

---
### ๐Ÿ›  Tech Stack

| Technology | Purpose |
| ---------------------- | ----------------------- |
| Next.js | React Framework |
| TypeScript | Type Safety |
| Tailwind CSS | Styling |
| shadcn/ui | UI Components |
| Magic UI | Animation/UI Effects |
| i18next | Internationalization |
| React Query | API State Management |
| FakeStore API | Product Data |
| google-translate-api-x | Dynamic Translation API |

---
### ๐Ÿ“‚ Project Structure

```
โ”œโ”€โ”€ ๐Ÿ“ public/
โ”‚ โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ file.svg
โ”‚ โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ globe.svg
โ”‚ โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ next.svg
โ”‚ โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ vercel.svg
โ”‚ โ””โ”€โ”€ ๐Ÿ–ผ๏ธ window.svg
โ”œโ”€โ”€ ๐Ÿ“ src/
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ @type/
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ product.ts
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ JSON/
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ data/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ about.ts
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ contact.ts
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“ lottie/
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ api/
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ api.function.ts
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ axios.instance.ts
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ app/
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ (userpannel)/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ layout.tsx
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ page.tsx
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ api/
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“ translate/
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ route.ts
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ favicon.ico
โ”‚ โ”‚ โ”œโ”€โ”€ ๐ŸŽจ globals.css
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ layout.tsx
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ providers.tsx
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ assets/
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ json/
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ โš™๏ธ about.json
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ banner1.jpg
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ banner2.jpg
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ–ผ๏ธ banner3.jpg
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ components/
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ ui/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ badge.tsx
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ border-beam.tsx
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ button.tsx
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ card.tsx
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ input.tsx
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ lens.tsx
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ magic-card.tsx
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ morphing-text.tsx
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ scroll-area.tsx
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ select.tsx
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ separator.tsx
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ shimmer-button.tsx
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ sparkles-text.tsx
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ textarea.tsx
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ tooltip.tsx
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ LanguageSwitcher.tsx
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ ProductCard.tsx
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ ProductSkleton.tsx
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ ThemeToggle.tsx
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ hook/
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ useProducts.ts
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ useTranslate.ts
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ i18n/
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“ locales/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ โš™๏ธ bn.json
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ โš™๏ธ en.json
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ โš™๏ธ hi.json
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ index.ts
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ layout/
โ”‚ โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ Footer.tsx
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ Navbar.tsx
โ”‚ โ”œโ”€โ”€ ๐Ÿ“ lib/
โ”‚ โ”‚ โ””โ”€โ”€ ๐Ÿ“„ utils.ts
โ”‚ โ””โ”€โ”€ ๐Ÿ“ section/
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ About.tsx
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ Banner.tsx
โ”‚ โ”œโ”€โ”€ ๐Ÿ“„ Contact.tsx
โ”‚ โ””โ”€โ”€ ๐Ÿ“„ Products.tsx
โ”œโ”€โ”€ โš™๏ธ .gitignore
โ”œโ”€โ”€ ๐Ÿ“ AGENTS.md
โ”œโ”€โ”€ ๐Ÿ“ CLAUDE.md
โ”œโ”€โ”€ ๐Ÿ“ README.md
โ”œโ”€โ”€ โš™๏ธ components.json
โ”œโ”€โ”€ ๐Ÿ“„ eslint.config.mjs
โ”œโ”€โ”€ ๐Ÿ“„ next.config.ts
โ”œโ”€โ”€ โš™๏ธ package-lock.json
โ”œโ”€โ”€ โš™๏ธ package.json
โ”œโ”€โ”€ ๐Ÿ“„ postcss.config.mjs
โ””โ”€โ”€ โš™๏ธ tsconfig.json
```
---
### ๐Ÿ“Œ Step 1 โ€” Install Dependencies
```
npm install i18next react-i18next i18next-browser-languagedetector
npm install @tanstack/react-query
npm install google-translate-api-x
npx shadcn@latest init
```
---
### ๐Ÿ“Œ Step 2 โ€” Configure i18next
---
## What is i18next? ๐ŸŒ
i18next is an internationalization library used for translating static UI text.

Example:
```
t("About Us")
```
Depending on selected language:
| Language | Output |
| -------- | --------------- |
| English | About Us |
| Hindi | เคนเคฎเคพเคฐเฅ‡ เคฌเคพเคฐเฅ‡ เคฎเฅ‡เค‚ |
| Bengali | เฆ†เฆฎเฆพเฆฆเง‡เฆฐ เฆธเฆฎเงเฆชเฆฐเงเฆ•เง‡ |

---
## Why Use i18next?
Because:
- Easy translation management
- Multi-language support
- Automatic language detection
- Reusable translation keys
- Supports React perfectly
---
## i18n Configuration
```
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import LanguageDetector from "i18next-browser-languagedetector";

import en from "@/locales/en/common.json";
import hi from "@/locales/hi/common.json";
import bn from "@/locales/bn/common.json";

i18n
.use(LanguageDetector)
.use(initReactI18next)
.init({
resources: {
en: {
translation: en,
},
hi: {
translation: hi,
},
bn: {
translation: bn,
},
},

fallbackLng: "en",
interpolation: {
escapeValue: false,
},
});

export default i18n;
```
---
### ๐Ÿ“Œ Step 3 โ€” Translation JSON Files

## locales/en/common.json
```
{
"About Us": "About Us",
"Contact": "Contact",
"Add To Cart": "Add To Cart"
}
```
## locales/hi/common.json
```
{
"About Us": "เคนเคฎเคพเคฐเฅ‡ เคฌเคพเคฐเฅ‡ เคฎเฅ‡เค‚",
"Contact": "เคธเค‚เคชเคฐเฅเค• เค•เคฐเฅ‡เค‚",
"Add To Cart": "เค•เคพเคฐเฅเคŸ เคฎเฅ‡เค‚ เคœเฅ‹เคกเคผเฅ‡เค‚"
}
```
## locales/bn/common.json
```
{
"About Us": "เฆ†เฆฎเฆพเฆฆเง‡เฆฐ เฆธเฆฎเงเฆชเฆฐเงเฆ•เง‡",
"Contact": "เฆฏเง‹เฆ—เฆพเฆฏเง‹เฆ—",
"Add To Cart": "เฆ•เฆพเฆฐเงเฆŸเง‡ เฆฏเง‹เฆ— เฆ•เฆฐเงเฆจ"
}
```
---
### ๐Ÿ“Œ Step 4 โ€” Why Static Translation Is Not Enough?
i18next works perfectly for static text.
But API product data comes dynamically:
```
title
description
category
```
These values are not stored in JSON files.
So we need:
โœ… Backend Translation API

---
### ๐Ÿ“Œ Step 5 โ€” Create Translation API Route

## Why API Route?
Because:
- Dynamic product data changes
- We cannot manually store all translations
- API translates text in real-time

## app/api/translate/route.ts
```
import { NextRequest, NextResponse } from "next/server";
import translate from "google-translate-api-x";

import {
RequestBody,
TranslationResponse,
} from "@/@type/product";

export async function POST(
req: NextRequest,
): Promise> {

let body: RequestBody | null = null;

try {
body = await req.json();

const result = await translate(body?.text || "", {
to: body?.target || "",
});

return NextResponse.json({
translatedText: result.text,
});

} catch (error) {

console.log(error);

return NextResponse.json(
{
translatedText: body?.text || "",
},
{
status: 500,
},
);
}
}
```
---
### ๐Ÿ“Œ Step 6 โ€” Why google-translate-api-x?
This package helps:
- Translate dynamic text
- No Google Cloud billing setup
- Easy integration
- Supports many languages

---
### ๐Ÿ“Œ Step 7 โ€” Create Translation Function
## api/api.function.ts
```
export const translateTextFns = async (
text: string,
target: string,
) => {
const response = await axios.post("/api/translate", {
text,
target,
});
return response.data.translatedText;
};
```

---
### ๐Ÿ“Œ Step 8 โ€” Why TanStack Query?
Without TanStack Query:
- Multiple API calls happen
- Performance becomes slow

TanStack Query:
- โœ… Caches translations
- โœ… Avoids duplicate requests
- โœ… Improves performance

---
### ๐Ÿ“Œ Step 9 โ€” Final Workflow
```
User changes language
โ†“
i18next updates static text
โ†“
React Query detects language change
โ†“
Translation hooks call API
โ†“
API translates product data
โ†“
UI updates dynamically
```
---
## ๐Ÿ™‹โ€โ™‚๏ธ Author

Made with โค๏ธ by Tanmay Shil
GitHub: [@TanmayShil](https://github.com/TanmayShil)