Skip to content

You'll need your own domain. Then, use Cloudflare's Worker service to reverse proxy the Google Translate API. This allows you to use the Google Translate API without needing extra tools.

Create a Cloudflare Worker to Proxy the API

Here are the detailed steps:

  1. Open the Cloudflare Dashboard: Go to https://dash.cloudflare.com/

  2. Create a Worker:

    After logging in, select "Workers" in the left panel, then click "Create a Worker" to create a new Worker service.

  3. Give your Worker a name and click Save.

    After saving, click "Finish" in the bottom right corner.

  1. Edit the code:

    After completing the above steps, click "Edit code" in the upper right corner to enter the code editing page. Delete the default code and replace it with the following code, then click the "Deploy" button in the upper right corner to deploy.

    This code has already parsed the translation result and will directly return the assembled result text.

    Successful code looks like this:

    Failure result:

export default {
  async fetch(request, env, ctx) {
    let url = new URL(request.url);
    if(url.pathname.startsWith('/')){
      url.hostname="translate.googleapis.com";
      let new_request = new Request(url, request)
      let response=await fetch(new_request)
      if(response.status!==200){
        return new Response(JSON.stringify({code:1,msg:response.text}), {
          status: 200,
          headers: {
            'content-type': 'application/json',
          },
        });
      }

      let jsonData = await response.json();
      let str=jsonData[0].map(it=>{
        return it[0]
      })

      let data={code:0,msg:"ok",text:str.join('')}

      return new Response(JSON.stringify(data), {
        status: 200,
        headers: {
          'content-type': 'application/json',
        },
      });
    }
    return await env.ASSETS.fetch(request);
  },
};
  1. Get the route URL:

    After successful deployment, click the back button on the left, and then click "Settings" - "Triggers" in sequence.

    Click "Add Custom Domain" above to bind your own domain. Highly recommended, because the workers.dev domain may be blocked and not directly accessible. By binding a custom domain, you can avoid needing extra tools.

Use in Video Translation Software

Open the settings menu in the upper left corner - Custom Translation API, fill in your API address and key (any value), and then test it.

If there are no problems, select "TransAPI" in the translation channel and you can happily use the free Google Translate API.