//native
type Deepl = {
apiKey: string;
baseUrl: string;
};
/**
* Request Translation
* The translate function.
The total request body size must not exceed 128 KiB (128 · 1024 bytes). Please split up your text into multiple
calls if it exceeds this limit.
*/
export async function main(
auth: Deepl,
body: {
text: string[];
source_lang?:
| "AR"
| "BG"
| "CS"
| "DA"
| "DE"
| "EL"
| "EN"
| "ES"
| "ET"
| "FI"
| "FR"
| "HU"
| "ID"
| "IT"
| "JA"
| "KO"
| "LT"
| "LV"
| "NB"
| "NL"
| "PL"
| "PT"
| "RO"
| "RU"
| "SK"
| "SL"
| "SV"
| "TR"
| "UK"
| "ZH";
target_lang:
| "AR"
| "BG"
| "CS"
| "DA"
| "DE"
| "EL"
| "ES"
| "ET"
| "FI"
| "FR"
| "HU"
| "ID"
| "IT"
| "JA"
| "KO"
| "LT"
| "LV"
| "NB"
| "NL"
| "PL"
| "RO"
| "RU"
| "SK"
| "SL"
| "SV"
| "TR"
| "UK"
| "ZH"
| "EN-GB"
| "EN-US"
| "PT-BR"
| "PT-PT"
| "ZH-HANS"
| "ZH-HANT";
context?: string;
show_billed_characters?: false | true;
split_sentences?: "0" | "1" | "nonewlines";
preserve_formatting?: false | true;
formality?: "default" | "more" | "less" | "prefer_more" | "prefer_less";
model_type?:
| "quality_optimized"
| "prefer_quality_optimized"
| "latency_optimized";
glossary_id?: string;
tag_handling?: "xml" | "html";
outline_detection?: false | true;
non_splitting_tags?: string[];
splitting_tags?: string[];
ignore_tags?: string[];
},
) {
const url = new URL(`${auth.baseUrl}/v2/translate`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "DeepL-Auth-Key " + auth.apiKey,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago