Skip to content

Commit 17a914d

Browse files
committed
docs: update readme with detailed content
1 parent d8a36bf commit 17a914d

File tree

1 file changed

+149
-18
lines changed

1 file changed

+149
-18
lines changed

README.md

Lines changed: 149 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,149 @@
1-
# CodeTranslateAI
2-
3-
CodeTranslateAI is a browser extension designed to help developers translate code snippets between different programming languages. It provides an easy-to-use interface for selecting target languages and enabling a code picker on web pages.
4-
5-
## Features
6-
7-
- **Language Selection**: Choose from a variety of programming languages to translate code snippets.
8-
- **Code Picker**: Enable a code picker that allows you to select code snippets directly from
9-
web pages.
10-
- **Real-time Translation**: Translate code snippets in real-time as you select them.
11-
- **User Preferences**: Save your preferred target language for quick access.
12-
- **Cross-Browser Support**: Compatible with major browsers like Chrome and Firefox.
13-
- **Open Source**: Contribute to the project on GitHub.
14-
- **Easy Installation**: Simple installation process for both development and production environments.
15-
- **Customizable**: Modify the extension to suit your coding style and preferences.
16-
- **Lightweight**: Minimal impact on browser performance.
17-
- **User-Friendly Interface**: Intuitive design for easy navigation and usage.
18-
- **Active Development**: Regular updates and improvements based on user feedback.
1+
# CodeTranslateAI 🚀
2+
3+
CodeTranslateAI is a powerful Chrome 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 injected into the page in a clean, tabbed interface.
4+
5+
## ✨ Key Features
6+
7+
- **On-the-Fly Translation:** Instantly translate code on platforms like Stack Overflow, Medium, and technical blogs.
8+
- **Secure Backend:** Uses a serverless Cloudflare Worker so your AI API key is never exposed on the frontend.
9+
- **Multi-Language Tabs:** Translate the same code block into multiple languages and switch between them easily.
10+
- **Smart Caching:** Translations are cached in your browser for 10 days to reduce API calls and provide instant results for previously translated code.
11+
- **Elegant UI:** A clean, non-intrusive UI that matches the width of the original code block and uses a tabbed layout for multiple translations.
12+
- **Powered by Gemini:** Leverages the power of Google's Gemini AI for high-quality code translations.
13+
14+
---
15+
16+
## 🔧 Tech Stack
17+
18+
- **Frontend:**
19+
- Plain JavaScript (ES6+)
20+
- HTML5 & CSS3
21+
- Chrome Extension APIs (`storage`, `runtime`, `scripting`)
22+
- Shadow DOM for style isolation.
23+
- **Backend:**
24+
- Cloudflare Workers
25+
- TypeScript
26+
- Wrangler CLI
27+
- Google Gemini API
28+
29+
---
30+
31+
## 📚 Getting Started & Installation Guide
32+
33+
To get a local copy up and running, follow these simple steps.
34+
35+
### Prerequisites
36+
37+
You must have Node.js and npm installed on your machine.
38+
39+
- [Download Node.js](https://nodejs.org/)
40+
41+
### ⚙️ Part 1: Backend Setup (Cloudflare Worker)
42+
43+
1. **Clone the Repository** (or set up your backend folder).
44+
45+
```sh
46+
git clone https://github.com/dineshsutihar/CodeTranslateAI.git
47+
cd CodeTranslateAI/backend
48+
```
49+
50+
2. **Install Dependencies**
51+
52+
```sh
53+
npm install
54+
```
55+
56+
3. **Login to Cloudflare**
57+
58+
```sh
59+
npx wrangler login
60+
```
61+
62+
4. **Get a Gemini API Key**
63+
64+
- Go to [Google AI Studio](https://aistudio.google.com/) to create your free API key.
65+
66+
5. **Set the Secret Key**
67+
68+
- Run the following command and paste your Gemini API key when prompted. This stores it securely on Cloudflare.
69+
70+
```sh
71+
npx wrangler secret put GEMINI_API_KEY
72+
```
73+
74+
6. **Deploy the Worker**
75+
76+
- Deploy the backend to make it live.
77+
78+
```sh
79+
npx wrangler deploy
80+
```
81+
82+
- After deployment, **copy the URL** that Wrangler provides. It will look like `https://backend.<your-worker-name>.dev`.
83+
84+
### 🖥️ Part 2: Frontend Setup (Chrome Extension)
85+
86+
1. **Configure the Backend URL**
87+
88+
- Navigate to your Chrome extension folder (e.g., `my-code-translator`).
89+
- Open the `background.js` file.
90+
- Find the `BACKEND_URL` constant and **paste the Cloudflare Worker URL** you copied in the previous step.
91+
92+
```javascript
93+
// background.js
94+
const BACKEND_URL = "https://backend.<your-worker-name>.dev"; // PASTE YOUR URL HERE
95+
```
96+
97+
2. **Load the Extension in Chrome**
98+
99+
- Open Google Chrome and navigate to `chrome://extensions`.
100+
- Enable **"Developer mode"** using the toggle in the top-right corner.
101+
- Click the **"Load unpacked"** button.
102+
- Select your Chrome extension folder (the one containing `manifest.json`).
103+
104+
The **CodeTranslateAI** icon should now appear in your Chrome toolbar, and the extension is ready to use\!
105+
106+
---
107+
108+
## 📖 How to Use
109+
110+
1. Click the extension icon in the Chrome toolbar.
111+
2. Select your desired target language from the dropdown menu.
112+
3. Click the **"Enable Code Selector"** button.
113+
4. Your cursor will change to a crosshair. Hover over any code block on a webpage and click on it.
114+
5. A "Translating..." message will appear, followed by a new UI element containing the translated code.
115+
6. If you translate the same block into another language, a new tab will be added to the UI.
116+
117+
---
118+
119+
## 🐛 Debugging the Backend
120+
121+
If you encounter errors or the translation isn't working, the first step is to check the live logs from your Cloudflare Worker. This allows you to see what's happening on the server in real-time.
122+
123+
1. **Navigate to your Backend Directory**
124+
125+
- Open your terminal and change into the directory where your Cloudflare Worker code is located (e.g., `CodeTranslateAI/backend`).
126+
127+
2. **Run the Tail Command**
128+
129+
- Execute the following command to start streaming the logs:
130+
131+
```sh
132+
npx wrangler tail
133+
```
134+
135+
- The terminal will connect and say `Connected to [worker-name], waiting for logs...`.
136+
137+
3. **Trigger the Error**
138+
139+
- With the log stream running, go to your browser and use the extension to perform an action that causes an error.
140+
141+
4. **Check the Terminal**
142+
143+
- Look back at your terminal. Any errors or log messages from your worker will appear instantly. Look for lines that start with `(error)`. This will give you the exact reason for the failure, such as an invalid API key or a quota issue.
144+
145+
---
146+
147+
## ⚖️ License
148+
149+
Distributed under the MIT License. See `LICENSE.txt` for more information.

0 commit comments

Comments
 (0)