A simple AI-powered text translator built with Google Gemini 2.5 Flash Lite, Cloudflare Workers and deployed on Cloudflare Pages.
Translates text from English to 3 languages like
- French
- Spanish
- Japanese
Built with simple HTML5, CSS3, JavaScript, Gemini API and Cloudflare Worker & pages.
ai-translator.mov
-
Uses Google Gemini 2.5 Flash Lite API.
-
Runs on Cloudflare's global network—low latency worldwide.
-
Real-time translation without page reloads.
-
Simple UI - Input text, select target languages, click translate.
-
Responsive Design - Works seamlessly on desktop, tablet, and mobile.
-
Modern UI - Clean and intuitive user interface.
-
No Backend Server - Serverless Worker handles API calls securely.
-
Learned how to setup Worker to protect API Keys.
-
Learned how to deploy to Cloudflare pages.
-
Learned about CORS (Cross Origin Resource Sharing).
-
Practiced Error handling if incase any error occurs during API Calls.
-
Practiced fetching data from APIs and rendering it dynamically on the DOM.
-
Practiced more CSS flexbox.
Before you begin, ensure you have the following installed:
- Node.js (v16 or higher)
- npm or yarn
- An API key for AI translation service (e.g., OpenAI, Google Gemini API)
-
Clone the repository
git clone https://github.com/yourusername/ai-translator.git cd ai-translator -
Install dependencies
npm install # or yarn install -
Set up secret key
npx wrangler secret put GEMINI_API_KEY
-
Run the development server
npx wrangler dev # or yarn devOpen http://localhost:3000 to view it in your browser.
This project is deployed on Cloudflare Pages. To deploy your own instance:
-
Connect your repository to Cloudflare Pages
- Log in to Cloudflare Dashboard
- Navigate to Pages
- Click "Create a project"
- Connect your Git repository
-
Configure build settings
- Build command: ''
- Build output directory: ''
-
Deploy
- Push to your main branch to trigger automatic deployment
Frontend - HTML5 + Vanilla JavaScript + CSS (Cloudflare Pages)
Backend - Cloudflare Workers + @google/genai SDK
AI Model - Google Gemini 2.5 Flash Lite
Deployment - Wrangler CLI + Cloudflare Pages
Secrets - Cloudflare Worker Secrets (GEMINI_API_KEY)
- Google Studio API.
- Cloudflare Worker and pages.


