|
| 1 | +# Google Translate Page Translation |
| 2 | + |
| 3 | +> Use your own Google Cloud API key to enable page translation in BotBrowser. |
| 4 | +
|
| 5 | +--- |
| 6 | + |
| 7 | +<a id="requirements"></a> |
| 8 | + |
| 9 | +## Requirements |
| 10 | + |
| 11 | +- A BotBrowser release and a matching profile. |
| 12 | +- A Google Cloud project with billing enabled. |
| 13 | +- The Cloud Translation API enabled for that project. |
| 14 | +- An API key restricted to the Cloud Translation API. |
| 15 | + |
| 16 | +Google Cloud controls pricing and quotas. Check the [Cloud Translation pricing](https://cloud.google.com/translate/pricing) and [quotas](https://cloud.google.com/translate/quotas) pages before production use. |
| 17 | + |
| 18 | +<a id="what-it-enables"></a> |
| 19 | + |
| 20 | +## What this enables |
| 21 | + |
| 22 | +The key supplies the Google service used by the browser's built-in page translation flow. BotBrowser does not provide a shared translation key. Each deployment can use its own Google Cloud project, quota, and billing policy. |
| 23 | + |
| 24 | +The `hrefTranslate` page capability and the full translation service are separate. A page can expose the standard translation-related DOM surface while translation remains unavailable because the deployment has no usable key or network access. |
| 25 | + |
| 26 | +<a id="create-key"></a> |
| 27 | + |
| 28 | +## Create an API key |
| 29 | + |
| 30 | +1. Open the [Google Cloud Console](https://console.cloud.google.com/). |
| 31 | +2. Create or select a project for translation. |
| 32 | +3. Enable the [Cloud Translation API](https://console.cloud.google.com/apis/library/translate.googleapis.com). |
| 33 | +4. Link the project to a billing account. |
| 34 | +5. Open **APIs & Services** > **Credentials**, then create an API key. |
| 35 | +6. Edit the key and set **API restrictions** to **Cloud Translation API**. |
| 36 | +7. Add an application restriction that matches where BotBrowser runs. An IP restriction is suitable for a stable server egress. Review referrer restrictions carefully because translation requests are made by the browser session. |
| 37 | + |
| 38 | +Keep the key out of source control, profile files, screenshots, and shared logs. Rotate or revoke it from Google Cloud if it is exposed. |
| 39 | + |
| 40 | +<a id="launch"></a> |
| 41 | + |
| 42 | +## Launch BotBrowser |
| 43 | + |
| 44 | +Set `GOOGLE_API_KEY` in the environment of the BotBrowser process before launch: |
| 45 | + |
| 46 | +```bash |
| 47 | +GOOGLE_API_KEY='YOUR_API_KEY' \ |
| 48 | +chromium-browser \ |
| 49 | + --bot-profile='/absolute/path/to/profile.enc' \ |
| 50 | + --user-data-dir='/absolute/path/to/user-data' \ |
| 51 | + https://example.com |
| 52 | +``` |
| 53 | + |
| 54 | +The key is read when the browser process starts. Restart BotBrowser after changing the environment variable. Do not put the key in a page script or pass it only to an outer HTTP client. |
| 55 | + |
| 56 | +After opening a page in another language, use the browser's normal page-translation command. Translation availability depends on the key, billing account, quota, proxy, network access, and the source page. |
| 57 | + |
| 58 | +### macOS and Linux |
| 59 | + |
| 60 | +Export the variable in the same shell that starts BotBrowser: |
| 61 | + |
| 62 | +```bash |
| 63 | +export GOOGLE_API_KEY='YOUR_API_KEY' |
| 64 | +chromium-browser \ |
| 65 | + --bot-profile='/absolute/path/to/profile.enc' \ |
| 66 | + --user-data-dir='/absolute/path/to/user-data' |
| 67 | +``` |
| 68 | + |
| 69 | +### Windows PowerShell |
| 70 | + |
| 71 | +Set the variable for the process before launching the browser: |
| 72 | + |
| 73 | +```powershell |
| 74 | +$env:GOOGLE_API_KEY = 'YOUR_API_KEY' |
| 75 | +& 'C:\path\to\chromium.exe' ` |
| 76 | + '--bot-profile=C:\path\to\profile.enc' ` |
| 77 | + '--user-data-dir=C:\path\to\user-data' |
| 78 | +``` |
| 79 | + |
| 80 | +### Playwright and Puppeteer |
| 81 | + |
| 82 | +The environment must belong to the process that launches the browser. The browser arguments still carry the profile and user-data paths: |
| 83 | + |
| 84 | +```javascript |
| 85 | +const browser = await chromium.launch({ |
| 86 | + executablePath: process.env.BOTBROWSER_EXEC_PATH, |
| 87 | + env: { ...process.env, GOOGLE_API_KEY: process.env.GOOGLE_API_KEY }, |
| 88 | + args: [ |
| 89 | + '--bot-profile=/absolute/path/to/profile.enc', |
| 90 | + '--user-data-dir=/absolute/path/to/user-data', |
| 91 | + ], |
| 92 | +}); |
| 93 | +``` |
| 94 | + |
| 95 | +Do not place the key in a committed `.env` file. Use the deployment secret store or an interactive shell instead. |
| 96 | + |
| 97 | +<a id="verify"></a> |
| 98 | + |
| 99 | +## Verify the setup |
| 100 | + |
| 101 | +1. Confirm that the BotBrowser process was restarted after the key was set. |
| 102 | +2. Open a page whose main text is not in the browser's target language. |
| 103 | +3. Use the normal page-translation command from the browser menu or context menu. |
| 104 | +4. Confirm that the translated page is rendered and that the Google Cloud project shows the expected request usage. |
| 105 | + |
| 106 | +Run this check with the same profile, proxy, and launch method used by the deployment. A successful DOM capability check alone does not prove that the external translation service is available. |
| 107 | + |
| 108 | +<a id="troubleshooting"></a> |
| 109 | + |
| 110 | +## Troubleshooting |
| 111 | + |
| 112 | +| Symptom | Check | |
| 113 | +| --- | --- | |
| 114 | +| Translation is unavailable | Confirm that `GOOGLE_API_KEY` was set before the browser process started and that the Cloud Translation API is enabled. | |
| 115 | +| Permission denied | Check the key restrictions and confirm that the selected project has billing enabled. | |
| 116 | +| Quota or rate-limit errors | Review the project quotas and usage in Google Cloud Console. | |
| 117 | +| Requests fail through a proxy | Confirm that the proxy is configured in BotBrowser and that it permits the required Google services. | |
| 118 | +| The key was exposed | Revoke or rotate it in Google Cloud, then update the launch environment. | |
| 119 | + |
| 120 | +<a id="privacy-and-cost"></a> |
| 121 | + |
| 122 | +## Privacy and cost |
| 123 | + |
| 124 | +Page translation sends the text needed by the translation service to Google's service. Review your data-handling requirements before translating sensitive content. Set quotas and monitor usage so the project stays within the intended budget. |
| 125 | + |
| 126 | +## Related Documentation |
| 127 | + |
| 128 | +- [Profile Management](PROFILE_MANAGEMENT.md) - choose and launch a matching profile. |
| 129 | +- [Proxy Configuration](../network/PROXY_CONFIGURATION.md) - configure browser-level proxy routing. |
| 130 | +- [First Verification](FIRST_VERIFICATION.md) - verify a new BotBrowser launch. |
0 commit comments