1 | |
2 | type Deepl = { |
3 | apiKey: string; |
4 | baseUrl: string; |
5 | }; |
6 | |
7 | * Create a Glossary |
8 | * |
9 | */ |
10 | export async function main( |
11 | auth: Deepl, |
12 | body: { |
13 | name: string; |
14 | source_lang: |
15 | | "da" |
16 | | "de" |
17 | | "en" |
18 | | "es" |
19 | | "fr" |
20 | | "it" |
21 | | "ja" |
22 | | "ko" |
23 | | "nb" |
24 | | "nl" |
25 | | "pl" |
26 | | "pt" |
27 | | "ro" |
28 | | "ru" |
29 | | "sv" |
30 | | "zh"; |
31 | target_lang: |
32 | | "da" |
33 | | "de" |
34 | | "en" |
35 | | "es" |
36 | | "fr" |
37 | | "it" |
38 | | "ja" |
39 | | "ko" |
40 | | "nb" |
41 | | "nl" |
42 | | "pl" |
43 | | "pt" |
44 | | "ro" |
45 | | "ru" |
46 | | "sv" |
47 | | "zh"; |
48 | entries: string; |
49 | entries_format: "tsv" | "csv"; |
50 | }, |
51 | ) { |
52 | const url = new URL(`${auth.baseUrl}/v2/glossaries`); |
53 |
|
54 | const response = await fetch(url, { |
55 | method: "POST", |
56 | headers: { |
57 | "Content-Type": "application/json", |
58 | Authorization: "DeepL-Auth-Key " + auth.apiKey, |
59 | }, |
60 | body: JSON.stringify(body), |
61 | }); |
62 | if (!response.ok) { |
63 | const text = await response.text(); |
64 | throw new Error(`${response.status} ${text}`); |
65 | } |
66 | return await response.json(); |
67 | } |
68 |
|