Google API có cho phương thức GET sử dụng FREE không phải trả phí.
const apiUrl = `https://translate.googleapis.com/translate_a/single?client=gtx&sl=${'ja'}&tl=${'en'}&dt=t&q=${content}`;
const { data: result } = await axios.get(apiUrl);
if (result?.[0]?.[0]?.[0]) {
textTranslate += `${result?.[0]?.[0]?.[0]}\n`;
} else {
textTranslate += "error\n";
}
Tham số sl => nguồn ngôn ngữ. Ex: vi = Việt Nam (các bạn có thể để auto để api tự động detect ngôn ngữ đầu vào)
Tham số tl => ngôn ngữ đích cần dịch. Ex: en = Tiếng Anh
Tham số q => (query) truyền vào đoạn văn bản cần dịch
Tham khảo: https://laptrinhvb.net/bai-viet/devexpress/---Csharp----Su-dung-Google-Translate-API-de-dich-van-ban-/c251d0c2ee8acb6c.html