Setting up the DeepL API in Google Sheets involves several steps, including obtaining a DeepL API key, writing a Google Apps Script, and configuring the script to use the API. Here's a detailed guide:
Step 1: Obtain a DeepL API Key
1. Create a DeepL API Account: Go to the DeepL website and create an account specifically for the DeepL API. This is different from a regular DeepL account, so ensure you sign up for the API account.
2. Get Your API Key: Once logged into your DeepL API account, navigate to the account settings to find your authentication key. This key is crucial for using the API.
Step 2: Set Up Google Apps Script
1. Open Google Sheets: Start by opening your Google Sheet.
2. Access Apps Script: From the menu, go to Extensions > Apps Script. This will open the Apps Script editor.
3. Create a New Script File: If you have an existing script, you can add a new file. Otherwise, you can use the default script file named "Code.gs".
4. Delete Default Code: Remove any default code in the script file, such as the `myFunction()` placeholder.
Step 3: Paste the DeepL API Script
1. Get the Script Code: You can use the example script provided by DeepL or similar scripts available online. For instance, you can use the script from GitHub's DeepL example repository[2].
2. Paste the Script: Copy the contents of the DeepL script and paste it into your Apps Script file. Make sure to replace the placeholder for the authentication key with your actual DeepL API key.
Step 4: Configure the Script
1. Modify the Script: In the script, locate the line where you need to enter your DeepL API key. It should look something like `const authKey = "your_api_key_here";`. Replace `"your_api_key_here"` with your actual API key.
2. Save the Script: After pasting and configuring your API key, save the script by clicking the floppy disk icon or pressing `Ctrl+S` (or `Cmd+S` on a Mac).
Step 5: Use the DeepL Function in Google Sheets
1. Return to Your Sheet: Close the Apps Script editor and go back to your Google Sheet.
2. Use the DeepL Function: You can now use the DeepL translation function in your sheet. For example, if you've set up a function named `DeepLTranslate`, you can use it like this: `=DeepLTranslate(A1, "auto", "DE")`. This translates the text in cell A1 from an automatically detected language to German.
Additional Tips
- Re-translation Issue: Be aware that formulas using the DeepL API can re-translate text every time the sheet is opened, which can consume your API quota quickly. Consider implementing workarounds to prevent unnecessary re-translations[2].
- API Quota: The free DeepL API account allows up to 500,000 characters per month. Monitor your usage to avoid exceeding this limit[2][4].
By following these steps, you can effectively integrate the DeepL API with Google Sheets to leverage DeepL's high-quality translation capabilities directly within your spreadsheets.
Citations:
[1] https://webapps.stackexchange.com/questions/149026/integrate-deepl-with-google-sheets
[2] https://github.com/DeepLcom/google-sheets-example
[3] https://www.scriptable-assets.page/add-ons/sheetsl/
[4] https://84office.jp/en/googlesheet-deepl-api-translation/
[5] https://developers.deepl.com/docs
[6] https://developers.deepl.com/docs/api-reference/document
[7] https://www.linkedin.com/pulse/deepl-function-google-sheets-andr%C3%A9-piti%C3%A9
[8] https://www.youtube.com/watch?v=Kxndko2rIqE
[9] https://n8n.io/integrations/deepl/and/google-sheets/