很多人不习惯必应、百度这些翻译服务,而是偏向谷歌翻译,但又碍于大陆不能直接使用,每次使用都要挂代理。现在可以使用cloudflare workers搭建谷歌翻译镜像站,可以免代理在浏览器使用,或者在idea、vscode等等开发工具上使用。

如果你有一个国外鸡的话也可以安装nginx来反代,不想的话就直接用cf来搭建

准备:一个cloudflare账号,一个域名(托管到cf)

搭建镜像站

直接登录来到首页:https://dash.cloudflare.com

点击Workers -> Workers 和 Pages -> 创建 -> 从Hello World 开始 -> 随便命名后部署 -> 编辑代码

把下面代码粘贴进去,部署

export default {
  async fetch(request, env, ctx) {
    let url = new URL(request.url);

    // Modify the hostname based on the path
    if (url.pathname.startsWith('/translate_a/') || url.pathname.startsWith('/translate_tts') || url.pathname.startsWith('/translate')) {
      url.hostname = "translate.googleapis.com";
    } else {
      url.hostname = "translate.google.com";
    }

    // Create a new request with the modified URL and original request options
    let new_request = new Request(url.toString(), {
      method: request.method,
      headers: request.headers,
      body: request.body,
      redirect: 'follow'
    });

    // Fetch the modified request
    let response = await fetch(new_request);

    // Create a new response to handle content
    let new_response = new Response(response.body, response);

    // Add CORS headers if necessary
    new_response.headers.set("Access-Control-Allow-Origin", "*");
    new_response.headers.set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
    new_response.headers.set("Access-Control-Allow-Headers", "Content-Type, Authorization");

    return new_response;
  }
};

来到你的域名管理页面,添加一条解析,为谷歌镜像站,记录值随便填,然后开启代理状态

还是域名管理页这里,左边点击路由 -> 添加路由 -> 保存

路由填刚刚解析的域名:域名/* (后面要有斜杠和一个星号),worker选择刚刚部署代码的那个worker

接下来就直接打开域名测试一下

现在就已经是大功告成了

还有就是不建议用已经搭建好的公布出去,自己用就好了

浏览器使用

接下来就是怎么在chrome上使用了。这里演示 安装第三方扩展来使用谷歌翻译,这样的好处是可以划词翻译,并且还能使用必应,百度等等来对比。

划词翻译扩展:https://chromewebstore.google.com/detail/%E5%88%92%E8%AF%8D%E7%BF%BB%E8%AF%91/ikhdkkncnoglghljlkmcimlnlhkeamad

安装完扩展打开设置-第三方服务:chrome-extension://ikhdkkncnoglghljlkmcimlnlhkeamad/settings.html#/services-options

把镜像站地址填进去就行了

重启浏览器就可以用了

划词翻译效果

整站翻译效果

vscode使用

vsc直接安装这个插件:Comment Translate

进入插件设置,搜索google,把镜像站地址填进去即可

测试一下

这样就已经成功应用上谷歌翻译了

  • alipay_img
  • wechat_img
此作者没有提供个人介绍
最后更新于 2025-07-06