MCPcopy Create free account
hub / github.com/Bistutu/FluentRead / google

Function google

entrypoints/service/google.ts:4–24  ·  view source on GitHub ↗
(message: any)

Source from the content-addressed store, hash-verified

2import {config} from "@/entrypoints/utils/config";
3
4async function google(message: any) {
5 let params: any = {
6 client: 'gtx', sl: config.from, tl: config.to, dt: 't', strip: 1, nonced: 1,
7 'q': encodeURIComponent(message.origin),
8 };
9 let queryString = Object.keys(params).map((key: string) => key + '=' + params[key]).join('&');
10
11 const resp = await fetch('https://translate.googleapis.com/translate_a/single?' + queryString, {
12 method: method.GET,
13 });
14
15 if (resp.ok) {
16 let result = await resp.json();
17 let sentence = '';
18 result[0].forEach((e: any) => sentence += e[0]);
19 return sentence;
20 } else {
21 console.log(resp);
22 throw new Error(`翻译失败: ${resp.status} ${resp.statusText} body: ${await resp.text()}`);
23 }
24}
25
26export default google;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected