-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image translate #38
Comments
In theory, yes. However, I couldn't find a way to make it work. Here is the code I tested. It consistently responds with the same image data without any translation. import https from "node:https";
import fs from 'node:fs';
import path from 'node:path';
import zlib from 'node:zlib';
export function translate(filePath) {
const imagePath = path.resolve(__dirname, filePath);
const fileData = fs.readFileSync(imagePath);
const base64 = Buffer.from(fileData).toString('base64');
return new Promise((resolve, reject) => {
let body = encodeURIComponent(`[[["WqWDPb","[[\\"${base64}\\",\\"image/png\\"],\\"en\\",\\"es\\"]",null,"generic"]]]`);
body = `f.req=${body}&`;
const searchParams = new URLSearchParams({
rpcids: "WqWDPb",
"source-path": "/",
"bl": "boq_translate-webserver_20240220.05_p0",
hl: "en-US",
"soc-app": "1",
"soc-platform": "1",
"soc-device": "1",
rt: "c"
});
const url = `https://translate.google.com/_/TranslateWebserverUi/data/batchexecute?${searchParams}`;
const req = https
.request(
url,
{
method: "POST",
headers: {
"Accept-Encoding": "gzip, deflate, br",
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
"Content-Length": Buffer.byteLength(body),
}
},
(resp) => {
const gunzip = zlib.createGunzip();
resp.pipe(gunzip);
let data = "";
gunzip.on("data", (chunk) => {
data += chunk;
});
gunzip.on("end", () => {
resolve(data);
});
},
)
.on("error", reject);
req.write(body);
req.end();
});
}
translate("image.png").then((data) => {
console.log(data)
}) |
Anyway, did you manage to read the image? |
@cjvnjde Did you manage to get translated image? I am getting same Image I sent. |
no, most likely we need to pass the |
I tried passing it, but same response. Google is good at hiding stuffs, IG. Pls do let me know if you get some luck |
Thank you for the open source code, I have a question: can it be translated using an image?
The text was updated successfully, but these errors were encountered: