Skip to content

Use your own domain and Cloudflare's Worker service to reverse proxy the Google Translate API, enabling access without needing special tools.

Create a Worker in Cloudflare to Reverse Proxy the API

Here are the detailed steps:

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

  2. Create a Worker:

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

  3. Name Your Worker, then 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 top right to enter the code editor. Delete the default code, replace it with the following code, and then click the "Deploy" button in the top right to deploy.

    This code parses the translation result and directly returns the assembled text.

    Success response example:

    Failure response example:

   
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 back on the left, then go to "Settings" → "Triggers".

    Click "Add Custom Domain" at the top to bind your own domain. This is highly recommended because the workers.dev domain is blocked in some regions and cannot be used directly. By using a custom domain, you can avoid the need for special tools.

Using It in Video Translation Software

Open the settings menu in the top left → Custom Translation API, enter your API URL and key (any value is fine), then test it.

Once it works, select "TransAPI" in the translation options to enjoy free use of the Google Translate API.