A beautiful, responsive AI translation interface built with Next.js 15, TypeScript, and shadcn/ui. Features Google Translate-like design with Cloudflare Turnstile integration, multi-language support, and dark/light theme switching.
Experience the AI Translator in action: https://translate.english-dictionary.app/
π― Try the live demo to see all features including multi-language support, dark/light themes, and seamless translation experience.
- π Multi-language Support - Interface available in 10 languages with automatic system language detection
- π¨ Beautiful UI - Google Translate-inspired design with responsive layout
- π Theme Switching - Dark/light mode toggle with system preference detection
- π Cloudflare Turnstile - Secure verification with pass-based authentication
- π± Responsive Design - Optimized for desktop and mobile devices
- β‘ Auto-resize TextArea - Dynamic text input with character counting
- π Copy/Paste/Clear - Quick action buttons for better UX
- π Modern Stack - Next.js 15 App Router, TypeScript, Tailwind CSS
- Framework: Next.js 15 (App Router)
- Language: TypeScript
- Styling: Tailwind CSS v4
- UI Components: shadcn/ui
- Package Manager: pnpm
- Theme: next-themes
- Icons: Lucide React
- Security: Cloudflare Turnstile
- Node.js 18+
- pnpm (recommended) or npm/yarn
- A running AI Translator backend API
# Clone the repository
git clone [email protected]:chismo950/ai-translator-nextjs.git
cd ai-translator-nextjs-cursor
# Install dependencies
pnpm installThe application uses a centralized configuration system in src/lib/config.ts. Update the API base URL:
// src/lib/config.ts
export const API_CONFIG = {
// Update this URL to your backend API
BASE_URL: "https://your-api-domain.com",
// ... other settings
} as const;Key Configuration Options:
API_CONFIG.BASE_URL: Your backend API URL- Local development:
http://localhost:8080 - Production: Your deployed API URL
- Local development:
TRANSLATION_CONFIG.MAX_CHARACTERS: Character limit for translationsTRANSLATION_CONFIG.TEXTAREA: Text area rows configurationTURNSTILE_CONFIG: Cloudflare Turnstile widget settings
Your backend API must provide these endpoints:
GET /_turnstile/sitekey # Returns Turnstile configuration
POST /v1/translate # Translation endpoint
Expected API responses:
GET /_turnstile/sitekey:
{
"siteKey": "your-turnstile-site-key",
"headerName": "CF-Turnstile-Token"
}POST /v1/translate:
{
"sourceLang": "auto",
"targetLang": "en",
"translatedText": "Hello everyone!"
}# Start the development server
pnpm dev
# Or with npm
npm run devOpen http://localhost:3000 in your browser.
Edit character limits in src/lib/config.ts:
export const TRANSLATION_CONFIG = {
MAX_CHARACTERS: 5000, // Hard limit
SOFT_LIMIT: 4000, // Warning threshold
TEXTAREA: {
MIN_ROWS: 4,
MAX_ROWS: 15,
},
} as const;Add or modify languages in src/lib/i18n.ts:
export const languages: Record<SupportedLanguage, string> = {
en: "English",
zh: "δΈζ",
// Add more languages...
};Theme settings are in src/app/layout.tsx:
<ThemeProvider
attribute="class"
defaultTheme="system" // 'light' | 'dark' | 'system'
enableSystem
disableTransitionOnChange
>- Select Languages: Choose source and target languages
- Enter Text: Type or paste text in the source textarea
- Verify: Complete Turnstile challenge if prompted
- Translate: Click the translate button
- Copy Result: Use the copy button to copy the translation
- Auto-detect: Source language can be set to "Detect language"
- Swap Languages: Click the swap button to reverse source/target
- Character Counter: Shows usage against limits
- Responsive Design: Works on mobile and desktop
- Theme Toggle: Switch between light/dark themes
- Multi-language UI: Interface adapts to user's system language
- First Use: Turnstile widget appears for verification
- Verification: User completes the challenge
- Pass Issued: Server provides a short-lived pass
- Subsequent Requests: Pass allows multiple translations
- Pass Expiry: Widget reappears when pass expires
src/
βββ app/
β βββ layout.tsx # Root layout with providers
β βββ page.tsx # Main page
β βββ globals.css # Global styles
βββ components/
β βββ ui/ # shadcn/ui components
β βββ auto-resize-textarea.tsx
β βββ character-counter.tsx
β βββ header.tsx
β βββ language-selector.tsx
β βββ theme-provider.tsx
β βββ theme-toggle.tsx
β βββ translator.tsx # Main translation component
βββ hooks/
β βββ use-language.ts # Language switching hook
β βββ use-toast.tsx # Toast notifications
β βββ useTurnstile.tsx # Turnstile widget management
βββ lib/
βββ apiClient.ts # API client with pass management
βββ i18n.ts # Internationalization
βββ utils.ts # Utility functions
# Create production build
pnpm build
# Start production server
pnpm startUpdate src/lib/config.ts with your production settings:
export const API_CONFIG = {
BASE_URL: "https://your-production-api.com",
// ... other production settings
} as const;Vercel:
# Deploy to Vercel
npx vercel --prodExample Deployment: See the live production deployment at https://translate.english-dictionary.app/ for reference.
Netlify:
# Build command
pnpm build
# Publish directory
outDocker:
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]- Turnstile Keys: Keep your secret key on the backend only
- API Endpoints: Ensure proper CORS configuration
- Rate Limiting: Implement backend rate limiting
- Pass Storage: Passes are stored in memory only (not localStorage)
Turnstile not loading:
- Check console for script loading errors
- Verify site key configuration
- Ensure proper CORS headers
Translation failures:
- Verify API base URL in environment
- Check backend CORS configuration
- Ensure proper request headers
Theme not working:
- Verify ThemeProvider wraps your app
- Check CSS custom properties
- Ensure suppressHydrationWarning is set
Enable detailed logging by adding to your environment:
NODE_ENV=developmentimport { postTranslate, getTurnstileSiteKey } from "@/lib/apiClient";
// Get Turnstile configuration
const config = await getTurnstileSiteKey();
// Translate text
const result = await postTranslate(
{
text: "Hello world",
sourceLang: null, // auto-detect
targetLang: "es",
},
{
turnstileHeaderName: "CF-Turnstile-Token",
getTurnstileToken: () => "turnstile-token",
}
);// Language switching
const { currentLanguage, setCurrentLanguage, t } = useLanguage();
// Turnstile management
const { containerRef, render, refresh, token, isVerified } = useTurnstile();
// Toast notifications
const { toast } = useToast();- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Check out the fully functional demo at https://translate.english-dictionary.app/ to experience:
- Real-time Translation: Powered by advanced AI models
- Multi-language Interface: Automatic system language detection
- Responsive Design: Seamless experience across devices
- Theme Switching: Dark/light mode with system preference
- Cloudflare Turnstile: Security verification in action
This demo showcases all the features implemented in this repository and serves as a reference for successful deployment.
This project is licensed under the MIT License - see the LICENSE file for details.
- Next.js - React framework
- shadcn/ui - UI components
- Tailwind CSS - Styling
- Cloudflare Turnstile - Security
- Lucide - Icons