You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+65-40Lines changed: 65 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,20 +5,21 @@ CodeTranslateAI is a powerful Chrome extension that allows you to translate code
5
5
## ✨ Key Features
6
6
7
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.
8
+
-**Secure Serverless Backend:** Uses a Cloudflare Worker so your AI API key is never exposed on the frontend.
9
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.
10
+
-**Smart Caching:** Translations are cached in your browser for 10 days to reduce API calls and provide instant results.
11
+
-**Elegant & Isolated UI:** A cleanUI that matches the width of the original code block and uses a Shadow DOM to prevent any style conflicts with the host page.
12
+
-**Powered by Gemini:** Leverages Google's Gemini AI for high-quality code translations with syntax highlighting.
@@ -65,7 +66,9 @@ You must have Node.js and npm installed on your machine.
65
66
66
67
5. **Set the Secret Key**
67
68
68
-
- Run the following command and paste your Gemini API key when prompted. This stores it securely on Cloudflare.
69
+
- Run the following command and paste your Gemini API key when prompted.
70
+
71
+
<!-- end list -->
69
72
70
73
```sh
71
74
npx wrangler secret put GEMINI_API_KEY
@@ -75,33 +78,71 @@ You must have Node.js and npm installed on your machine.
75
78
76
79
- Deploy the backend to make it live.
77
80
81
+
<!-- end list -->
82
+
78
83
```sh
79
84
npx wrangler deploy
80
85
```
81
86
82
-
- After deployment, **copy the URL** that Wrangler provides. It will look like `https://backend.<your-worker-name>.dev`.
87
+
- After deployment, **copy the URL** that Wrangler provides.
83
88
84
89
### 🖥️ Part 2: Frontend Setup (Chrome Extension)
85
90
86
-
1. **Configure the Backend URL**
91
+
1. **Navigate to the Frontend Directory**
92
+
93
+
```sh
94
+
cd ../frontend
95
+
```
96
+
97
+
2. **Install Dependencies**
98
+
99
+
```sh
100
+
npm install
101
+
```
102
+
103
+
3. **Configure the Backend URL**
87
104
88
-
- Navigate to your Chrome extension folder (e.g., `my-code-translator`).
89
105
- Open the `background.js` file.
90
106
- Find the `BACKEND_URL` constant and **paste the Cloudflare Worker URL** you copied in the previous step.
91
107
92
108
```javascript
93
109
// background.js
94
-
const BACKEND_URL = "https://backend.<your-worker-name>.dev"; // PASTE YOUR URL HERE
110
+
const BACKEND_URL = "https://backend.exampledinesh.workers.dev"; // PASTE YOUR URL HERE
111
+
```
112
+
113
+
4. **Build the Extension**
114
+
115
+
- You must run the build command to bundle the modular JavaScript files.
116
+
117
+
<!-- end list -->
118
+
119
+
```sh
120
+
npm run build
95
121
```
96
122
97
-
2. **Load the Extension in Chrome**
123
+
This will create a `dist` folder containing the `content.bundle.js` file.
124
+
125
+
5. **Load the Extension in Chrome**
98
126
99
127
- Open Google Chrome and navigate to `chrome://extensions`.
100
-
- Enable **"Developer mode"** using the toggle in the top-right corner.
128
+
- Enable **"Developer mode"**.
101
129
- Click the **"Load unpacked"** button.
102
-
- Select your Chrome extension folder (the one containing`manifest.json`).
130
+
- Select your Chrome extension folder (the `frontend` folder that contains`manifest.json`).
103
131
104
-
The **CodeTranslateAI** icon should now appear in your Chrome toolbar, and the extension is ready to use\!
132
+
The **CodeTranslateAI** icon should now appear in your Chrome toolbar\!
133
+
134
+
---
135
+
136
+
## 💻 Development Workflow
137
+
138
+
When you make changes to the frontend JavaScript files in the `scripts/` folder, you must re-bundle them before you can see the changes.
139
+
140
+
1. Save your changes in any `.js` file inside the `scripts/` folder.
141
+
2. Run the build commandin your terminal:
142
+
```sh
143
+
npm run build
144
+
```
145
+
3. Go to `chrome://extensions` and click the **reload** button for the CodeTranslateAI extension.
105
146
106
147
---
107
148
@@ -110,40 +151,24 @@ The **CodeTranslateAI** icon should now appear in your Chrome toolbar, and the e
110
151
1. Click the extension icon in the Chrome toolbar.
111
152
2. Select your desired target language from the dropdown menu.
112
153
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.
154
+
4. Your cursor will change to a crosshair. Click on any code block on a webpage.
155
+
5. A "Translating..." message will appear, followed by the translated code in a new UI.
116
156
117
157
---
118
158
119
159
## 🐛 Debugging the Backend
120
160
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:
161
+
If you encounter errors, check the live logs from your Cloudflare Worker.
130
162
163
+
1. **Navigate to your Backend Directory**.
164
+
2. **Run the Tail Command**:
131
165
```sh
132
166
npx wrangler tail
133
167
```
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.
168
+
3. **Trigger the Error** by using the extension in your browser and check the terminal for error messages.
144
169
145
170
---
146
171
147
172
## ⚖️ License
148
173
149
-
Distributed under the MIT License. See `LICENSE.txt`for more information.
0 commit comments