AlexSJC
发布于 2023-04-11 / 8 阅读
0
0

JavaScript 调用谷歌翻译

let text = 'Hello, World!';
let source = 'en';
let target = 'zh-CN';

fetch(`https://translate.googleapis.com/translate_a/single?client=gtx&sl=${source}&tl=${target}&dt=t&q=${text}`)
    .then(response => response.json())
    .then(data => {
        let result = data[0][0][0];
        console.log(result);
    });


评论