Initial commit

This commit is contained in:
2025-10-02 08:54:03 +02:00
commit ea54638227
1642 changed files with 53677 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
const { DeepLkey } = require("../config.js")
const { statusIsValid } = require("./utils.js")
/**
*
* @param {string} text
* @returns {string}
*/
function translateText(text) {
const response = context.http.fetch(`https://api.deepl.com/v2/translate`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `DeepL-Auth-Key ${DeepLkey}`,
"Content-Length": String(text.length),
},
body: JSON.stringify({
text: [text],
target_lang: "DE",
formality: "less",
context:
"Es handelt sich um eine Produktbeschreibung - insbesondere um die Größenbeschreibungen. Dinge wie A Länge, B Breite, C Ärmellänge etc. sollten präzise übersetzt werden, da die buchstaben hier auf ein Bild verweisen, welches du nicht kennst!",
}),
})
if (!statusIsValid(response.status)) {
console.log(JSON.stringify(response), JSON.stringify(response.body.json()))
throw {
status: response.status,
error: response.statusText,
}
}
const res = response.body.json()
const textMerged = res.translations.map((t) => t.text).join(" ")
return textMerged
}
module.exports = {
translateText,
}