mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-20 11:57:02 -04:00
Translate: Add DeepL support (#2721)
Co-authored-by: v <vendicated@riseup.net>
This commit is contained in:
parent
2382294e8b
commit
f8b01c1a31
9 changed files with 277 additions and 37 deletions
29
src/plugins/translate/native.ts
Normal file
29
src/plugins/translate/native.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2024 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { IpcMainInvokeEvent } from "electron";
|
||||
|
||||
export async function makeDeeplTranslateRequest(_: IpcMainInvokeEvent, pro: boolean, apiKey: string, payload: string) {
|
||||
const url = pro
|
||||
? "https://api.deepl.com/v2/translate"
|
||||
: "https://api-free.deepl.com/v2/translate";
|
||||
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `DeepL-Auth-Key ${apiKey}`
|
||||
},
|
||||
body: payload
|
||||
});
|
||||
|
||||
const data = await res.text();
|
||||
return { status: res.status, data };
|
||||
} catch (e) {
|
||||
return { status: -1, data: String(e) };
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue