Skip to content

Latest commit

ย 

History

38 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Polyglot ๐ŸŒ

Polyglot Branding

Polyglot is a lightweight AI-powered translation web app built with React, TypeScript, Express, and OpenAI.

Live Demo

โœจ Features

  • Welcome screen with Polyglot branding, tagline, and โ€œGet Startedโ€ entry point
  • Route-based flow between / (welcome) and /app (translator)
  • Translate text into English, Spanish, French, or Japanese
  • Chat-style translation history with per-message rendering
  • Inline loading animation while translations are in progress
  • Press Enter to submit and Shift + Enter for multiline input
  • Animated language greeting elements (โ€œHello,โ€ โ€œยกHola!,โ€ โ€œBonjour,โ€ and โ€œใ“ใ‚“ใซใกใฏโ€)
  • Auto-scroll to the newest message
  • Client-side validation for empty input
  • User-friendly error handling for failed translation requests
  • Home button to return to the welcome screen

๐Ÿง  How It Works

The frontend manages translation state through a custom hook and sends the user text and target language to the backend. The backend sanitizes input, applies rate limiting, forwards the request to OpenAI, and returns a normalized translation response for UI rendering.

๐Ÿ› ๏ธ Tech Stack

Frontend

  • React
  • TypeScript
  • Vite
  • React Router
  • Motion
  • CSS
  • Vitest + Testing Library + MSW

Backend

  • Node.js
  • Express
  • TypeScript
  • OpenAI API
  • CORS
  • Express Rate Limit

๐Ÿ”Œ API Endpoints

  • GET /health
  • POST /translate

POST /translate example request

{
  "userPrompt": "Hello, how are you today?",
  "targetLanguage": "Japanese"
}

POST /translate example response

{
  "message": {
    "input": "Hello, how are you today?",
    "output": "ใ“ใ‚“ใซใกใฏใ€ใŠๅ…ƒๆฐ—ใงใ™ใ‹๏ผŸ"
  }
}

๐Ÿ“ฆ Getting Started

Prerequisites

  • Node.js 18+
  • npm

Clone the repository

git clone <your-repository-url>
cd polyglot

Install frontend dependencies

cd frontend
npm install

Install backend dependencies

cd ../backend
npm install

๐Ÿ” Environment Variables

Create .env files in both backend and frontend directories.

Backend .env example

OPENAI_API_KEY=your_openai_api_key
PORT=5000
ALLOWED_ORIGINS=http://localhost:5173,https://polyglot-static.onrender.com

Frontend .env example

VITE_API_BASE_URL=http://localhost:5000

โ–ถ๏ธ Running Locally

Start backend

cd backend
npm run dev

Start frontend

cd frontend
npm run dev

โœ… Testing

Frontend tests

cd frontend
npm test

Frontend coverage

cd frontend
npm run test:coverage

๐Ÿ“ Project Structure

polyglot/
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ pages/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ App.tsx                # Translator page container
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ WelcomeScreen.tsx      # Landing page with branding and app entry
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ TranslationForm.tsx
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ TranslationMessages.tsx
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ hooks/
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ useTranslationChat.ts # Translation chat state, submit flow, and UI handlers
โ”‚   โ”‚   โ”œโ”€โ”€ config/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ deploy.config.ts       # Frontend deploy/runtime settings
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ endpoints.config.ts    # API endpoint definitions used by the client
โ”‚   โ”‚   โ”œโ”€โ”€ test/                       # UI and routing-focused component tests
โ”‚   โ”‚   โ”œโ”€โ”€ utils/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ requests.ts            # HTTP request helpers for backend communication
โ”‚   โ”‚   โ””โ”€โ”€ index.css                  # Global styles and Polyglot UI theme
โ”‚   โ”œโ”€โ”€ public/                        # Static assets served as-is
โ”‚   โ””โ”€โ”€ dist/                          # Production build output
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ app.ts                     # Express app setup, middleware, and route registration
โ”‚   โ”‚   โ”œโ”€โ”€ controllers/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ translate.controllers.ts # Translation endpoint logic and OpenAI integration
โ”‚   โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ translate.routes.ts    # Route registration for translate API
โ”‚   โ”‚   โ””โ”€โ”€ middleware/
โ”‚   โ”‚       โ”œโ”€โ”€ sanitize.middleware.ts # Request input sanitization and validation hardening
โ”‚   โ”‚       โ””โ”€โ”€ rateLimiter.middleware.ts # API rate limiting to protect backend resources
โ”‚   โ””โ”€โ”€ dist/                          # Compiled backend output
โ””โ”€โ”€ README.md

๐Ÿ›ก๏ธ Backend Protections

  • Request sanitization middleware
  • Rate limiting
  • CORS configuration
  • Error handling for missing input, unknown endpoints, and server failures

๐Ÿ”ฎ Future Improvements

  • Add support for more languages
  • Add copy-to-clipboard functionality
  • Save translation history
  • Add user authentication
  • Improve accessibility
  • Add backend integration tests

About

Polyglot is a lightweight, AI-powered full-stack translation app built with React, TypeScript, Express, and the OpenAI API. It helps users quickly translate text through a clean, interactive chat-style interface.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages