Skip to content

Commit 66ccdfb

Browse files
committed
docs: update docs
1 parent 64481d3 commit 66ccdfb

File tree

1 file changed

+39
-14
lines changed

1 file changed

+39
-14
lines changed

README.md

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ CodeTranslateAI is a powerful Chrome extension that allows you to translate code
55
## ✨ Key Features
66

77
- **On-the-Fly Translation:** Instantly translate code on platforms like Stack Overflow, Medium, and technical blogs.
8-
- **Secure Serverless Backend:** Uses a Cloudflare Worker so your AI API key is never exposed on the frontend.
8+
- **Secure Serverless Backend:** Uses a Cloudflare Worker.
99
- **Multi-Language Tabs:** Translate the same code block into multiple languages and switch between them easily.
1010
- **Smart Caching:** Translations are cached in your browser for 10 days to reduce API calls and provide instant results.
11-
- **Elegant & Isolated UI:** A clean UI that matches the width of the original code block and uses a Shadow DOM to prevent any style conflicts with the host page.
1211
- **Powered by Gemini:** Leverages Google's Gemini AI for high-quality code translations with syntax highlighting.
1312

1413
---
@@ -17,7 +16,7 @@ CodeTranslateAI is a powerful Chrome extension that allows you to translate code
1716

1817
- **Frontend:**
1918
- Modular JavaScript (ES6+)
20-
- **esbuild** (for bundling)
19+
- **esbuild** & **dotenv** (for bundling and environment variables)
2120
- HTML5 & CSS3
2221
- Chrome Extension APIs (`storage`, `activeTab`)
2322
- Shadow DOM for style isolation.
@@ -102,27 +101,55 @@ You must have **Node.js** and **npm** installed on your machine.
102101

103102
3. **Configure the Backend URL**
104103

105-
- Open the `background.js` file.
106-
- Find the `BACKEND_URL` constant and **paste the Cloudflare Worker URL** you copied in the previous step.
104+
- In the `frontend` folder, create a new file named `.env`.
105+
- Add the Cloudflare Worker URL you copied in the previous step to this file:
106+
107+
<!-- end list -->
108+
109+
```
110+
# .env file
111+
BACKEND_URL="https://your-worker-url.workers.dev"
112+
```
113+
114+
4. **Create the Build Configuration**
115+
116+
- In the `frontend` folder, create a file named `build.js` and add the following content. This file tells our build script how to use the `.env` variable.
117+
118+
<!-- end list -->
107119

108120
```javascript
109-
// background.js
110-
const BACKEND_URL = "https://backend.exampledinesh.workers.dev"; // PASTE YOUR URL HERE
121+
// build.js
122+
import esbuild from "esbuild";
123+
import "dotenv/config";
124+
125+
const define = {};
126+
for (const k in process.env) {
127+
define[`process.env.${k}`] = JSON.stringify(process.env[k]);
128+
}
129+
130+
esbuild
131+
.build({
132+
entryPoints: ["scripts/content.js", "background.js"],
133+
bundle: true,
134+
outdir: "dist",
135+
define: define,
136+
})
137+
.catch(() => process.exit(1));
111138
```
112139
113-
4. **Build the Extension**
140+
5. **Build the Extension**
114141
115-
- You must run the build command to bundle the modular JavaScript files.
142+
- Run the build command to bundle your scripts and inject the environment variable.
116143
117144
<!-- end list -->
118145
119146
```sh
120147
npm run build
121148
```
122149
123-
This will create a `dist` folder containing the `content.bundle.js` file.
150+
This will create a `dist` folder containing your final `content.js` and `background.js` files.
124151
125-
5. **Load the Extension in Chrome**
152+
6. **Load the Extension in Chrome**
126153
127154
- Open Google Chrome and navigate to `chrome://extensions`.
128155
- Enable **"Developer mode"**.
@@ -135,9 +162,7 @@ The **CodeTranslateAI** icon should now appear in your Chrome toolbar\!
135162
136163
## 💻 Development Workflow
137164
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.
165+
1. Make any changes to your JavaScript files in the `scripts/` folder or `background.js`.
141166
2. Run the build command in your terminal:
142167
```sh
143168
npm run build

0 commit comments

Comments
 (0)