CodeTranslateAI is a powerful browser extension that allows you to translate code snippets on any webpage in real-time. Simply select a block of code, choose your target language, and get an AI-powered translation instantly.
Choose your browser and click the button above to download and install CodeTranslateAI instantly!
See CodeTranslateAI work seamlessly on any webpage. Select code, and the translated version appears right beside it in a clean, tabbed interface with syntax highlighting.
- Frontend:
- Modular JavaScript (ES6+)
- esbuild & dotenv (for bundling and environment variables)
- HTML5 & CSS3
- Chrome Extension APIs (
storage
,activeTab
) - Shadow DOM for style isolation.
- Backend:
- Cloudflare Workers
- TypeScript
- Wrangler CLI
- Google Gemini API
To get a local copy up and running, follow these simple steps.
You must have Node.js and npm installed on your machine.
-
Clone the Repository
git clone https://github.com/dineshsutihar/CodeTranslateAI.git cd CodeTranslateAI/backend
-
Install Dependencies
npm install
-
Login to Cloudflare
npx wrangler login
-
Get a Gemini API Key
- Go to Google AI Studio to create your free API key.
-
Set the Secret Key
- Run the following command and paste your Gemini API key when prompted.
npx wrangler secret put GEMINI_API_KEY
-
Deploy the Worker
- Deploy the backend to make it live.
npx wrangler deploy
- After deployment, copy the URL that Wrangler provides.
-
Navigate to the Frontend Directory
cd ../frontend
-
Install Dependencies
npm install
-
Configure the Backend URL
- In the
frontend
folder, create a new file named.env
. - Add the Cloudflare Worker URL you copied in the previous step to this file:
# .env file BACKEND_URL="https://your-worker-url.workers.dev"
- In the
-
Create the Build Configuration
- In the
frontend
folder, create a file namedbuild.js
and add the following content. This file tells our build script how to use the.env
variable.
// build.js import esbuild from "esbuild"; import "dotenv/config"; const define = {}; for (const k in process.env) { define[`process.env.${k}`] = JSON.stringify(process.env[k]); } esbuild .build({ entryPoints: ["scripts/content.js", "background.js"], bundle: true, outdir: "dist", define: define, }) .catch(() => process.exit(1));
- In the
-
Build the Extension
- Run the build command to bundle your scripts and inject the environment variable.
npm run build
This will create a
dist
folder containing your finalcontent.js
andbackground.js
files. -
Load the Extension in Chrome
- Open Google Chrome and navigate to
chrome://extensions
. - Enable "Developer mode".
- Click the "Load unpacked" button.
- Select your Chrome extension folder (the
frontend
folder that containsmanifest.json
).
- Open Google Chrome and navigate to
The CodeTranslateAI icon should now appear in your Chrome toolbar!
- Make any changes to your JavaScript files in the
scripts/
folder orbackground.js
. - Run the build command in your terminal:
npm run build
- Go to
chrome://extensions
and click the reload button for the CodeTranslateAI extension.
- Click the extension icon in the Chrome toolbar.
- Select your desired target language from the dropdown menu.
- Click the "Enable Code Selector" button.
- Your cursor will change to a crosshair. Click on any code block on a webpage.
- A "Translating..." message will appear, followed by the translated code in a new UI.
If you encounter errors, check the live logs from your Cloudflare Worker.
- Navigate to your Backend Directory.
- Run the Tail Command:
npx wrangler tail
- Trigger the Error by using the extension in your browser and check the terminal for error messages.
Distributed under the MIT License.