0

Retrieve Supported Languages

by
Published Apr 8, 2025

Retrieve the list of languages that are currently supported for translation, either as source or target language, respectively. As of January 2024, Arabic (AR) is supported as a source and target language for text translation, but it is not yet supported for document translation. Therefore, Arabic has not yet been added to the `/languages` endpoint. We will add Arabic to the `/languages` endpoint after document translation support is added.

Script deepl Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Deepl = {
3
  apiKey: string;
4
  baseUrl: string;
5
};
6
/**
7
 * Retrieve Supported Languages
8
 * Retrieve the list of languages that are currently supported for translation, either as source or target language, respectively.
9

10
As of January 2024, Arabic (AR) is supported as a source and target language for text translation, 
11
but it is not yet supported for document translation. Therefore, Arabic has not yet been added to 
12
the `/languages` endpoint. We will add Arabic to the `/languages` endpoint after document translation 
13
support is added.
14
 */
15
export async function main(auth: Deepl, type: "source" | "target" | undefined) {
16
  const url = new URL(`${auth.baseUrl}/v2/languages`);
17
  for (const [k, v] of [["type", type]]) {
18
    if (v !== undefined && v !== "" && k !== undefined) {
19
      url.searchParams.append(k, v);
20
    }
21
  }
22
  const response = await fetch(url, {
23
    method: "GET",
24
    headers: {
25
      Authorization: "DeepL-Auth-Key " + auth.apiKey,
26
    },
27
    body: undefined,
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35