🥹Hãy triển khai sử dụng đã ngôn ngữ nextjs, wordpress sử dụng plugin polylang
1. Triển khai đã ngôn ngữ cho bài viết
{
"name": "langw",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev --turbopack",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@apollo/client": "^3.13.8",
"graphql": "^16.11.0",
"next": "15.3.2",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@tailwindcss/postcss": "^4",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"tailwindcss": "^4",
"typescript": "^5"
}
}


Home Page
Layout
Page Detail
Post Details
Show Category In Home Page
Get Posts By Category


Tiếp tục triển khai gói i18next
🧩 Công nghệ sử dụng:
✅ Cài đặt bên WordPress
🚀 Next.js – Thiết lập fetch dữ liệu đa ngôn ngữ
1. Cài thư viện
2. Cấu hình Apollo Client
3. Truy vấn GraphQL có đa ngôn ngữ
🌐 Next.js – Cấu trúc thư mục đa ngôn ngữ
Ví dụ app/[lang]/post/[slug]/page.tsx
app/[lang]/post/[slug]/page.tsx🌍 Chuyển đổi ngôn ngữ
📌 Gợi ý nâng cao
🧩 Cấu trúc thư mục app/
app/📁 app/[lang]/layout.tsx – Layout đa ngôn ngữ
app/[lang]/layout.tsx – Layout đa ngôn ngữ🏠 app/[lang]/page.tsx – Trang chủ theo ngôn ngữ
app/[lang]/page.tsx – Trang chủ theo ngôn ngữ✨ Tự động chuyển đổi ngôn ngữ (Language Switcher)
🧠 Middleware (tùy chọn) – Redirect / → /vi hoặc /en
/ → /vi hoặc /en🔧 1. Cấu trúc thư mục
📦 2. Cài đặt thư viện
🧠 3. File lib/apollo.ts
lib/apollo.ts📁 4. graphql/queries.ts
graphql/queries.ts🌍 5. app/[lang]/layout.tsx
app/[lang]/layout.tsx🏠 6. app/[lang]/page.tsx
app/[lang]/page.tsx📝 7. app/[lang]/post/[slug]/page.tsx
app/[lang]/post/[slug]/page.tsx🌐 8. middleware.ts
middleware.ts⚙️ 9. next.config.js
next.config.js🚀 Sử dụng
👉 Muốn clone nhanh?
🧩 Bước 1: Tạo components/LanguageSwitcher.tsx
components/LanguageSwitcher.tsx🛠 Bước 2: Gọi LanguageSwitcher trong post page
LanguageSwitcher trong post page🎁 Tuỳ chọn: Đặt vào layout.tsx nếu muốn luôn hiển thị trên header
layout.tsx nếu muốn luôn hiển thị trên headerTóm tắt thay đổi:
PreviousSử dụng next.config chuyển localhost:3000 sang http://localhost:3000/en cách hay nhất (ok)NextLỗi hydrat hóa xảy ra vì HTML được hiển thị trên máy chủ không khớp với HTML được hiển thị trên máy
Last updated