Skip to content

Latest commit

 

History

History
19 lines (18 loc) · 488 Bytes

File metadata and controls

19 lines (18 loc) · 488 Bytes

google-translate

export async function translate(text, language, key) {
    const url = `https://translation.googleapis.com/language/translate/v2?key=${key}`;
    const response = await fetch(url, {
        method: 'POST',
        headers : {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            target: language,
            format: "text",
            q: text
        }),
    });
    return await response.json();
}