If you've ever wanted a simple, free translator using Google Sheets, you're in the right place. In this post, I'll walk you through creating a multilingual translator using Google Sheets, Google Apps Script, and the Google Translate formula. Let's dive in!
What We’re Building
Today’s project involves setting up a translator in Google Sheets that supports multiple languages. Here's a brief overview of what we’ll accomplish:
- Fetch language codes and names from a free API.
- Utilize Google Apps Script to handle these codes.
- Use the Google Translate formula to translate content in your Google Sheets.
Getting Started
1. Setting Up Your Spreadsheet
Create a New Spreadsheet:
- Open Google Sheets and create a new spreadsheet.
- Rename the sheet to “Translator”.
2. Fetching Language Codes
Using the LibreTranslate API:
- LibreTranslate offers a free API to get language codes and names. You’ll need this to get a list of all supported languages.
- The API URL is available for free, and it provides standardized language codes compatible with Google Translate.
Implement Google Apps Script:
- Go to Extensions > Apps Script in your Google Sheet.
- You’ll need to write a script to fetch and handle the language data.
3. Writing the Script
Fetching Data:
- Create a variable for the API URL and fetch the data using HTTP requests.
- Parse the JSON response to extract language codes and names.
Populating the Sheet:
- Insert the language names into the first row and the language codes into the second row of your sheet.
- Format the cells: make text bold and set a background color for better readability.
4. Setting Up Translation
Using Google Translate Formula:
- In your sheet, use the
GOOGLETRANSLATE
formula to translate text from English to other languages.
- In your sheet, use the
Automating with a Script:
- Write a script function called
onEdit
that triggers whenever a cell is edited. - This function will check for edits in the English column and automatically apply the Google Translate formula to translate text into all supported languages.
5. Testing and Troubleshooting
Testing:
- Enter text in the English column and see if it translates automatically.
- Ensure that the translations update correctly and check for any issues with the script, such as incorrect column references or syntax errors.
Handling Errors:
- If the script doesn’t work as expected, verify syntax and column references.
- Ensure the formula and script are correctly set up to handle different languages and updates.
6. Extending the Functionality
Future Enhancements:
- Consider creating a REST API for your Google Sheet in future projects. This would allow you to filter translations for specific languages and integrate with other applications.
Feedback and Community:
- If you have suggestions or want to learn more, let us know in the comments! We’re here to help and might create a video on building a REST API for this sheet based on your feedback.
Conclusion
And that’s it! You've just created a free translator using Google Sheets. With this setup, you can translate text into multiple languages effortlessly. If you need a copy of the sheet or have any questions, feel free to ask in the comments.
Thank you for reading, and happy translating!
Don't forget to check out the detailed Apps Script tutorial linked below