The Google Translate API key allows you to connect with the same machine learning that Google uses in its search engine and in Gmail when it encounters text in another language than yours.
There’s a reason Tim Berners-Lee called his most important creation the “World Wide Web.” Everyone in the world could use it! Since we don’t all use the same language, it’s important that we can communicate with each other regardless of the language we each speak and write in.
If you use the Web to reach out to customers worldwide, the international student at the nearby college campus, or anyone who needs to access your content, make your website readable in other languages. Making your site accessible in other languages also improves the user experience for your site’s international guests.
Perhaps you have used Google Translate to read a page that came up in Google Search? You may not know that Google offers an Application Programming Interface (API) to allow anyone to access its Translate tool. While not perfect, it does pretty well for machine translation. For that reason, the Google Translate API is often seen as an easy choice to get this task done.
In this post, we’ll walk you through the setup process, and help you to turn your website into an international sensation with the Cloud Translation API.
Getting a Google Translate API Key
To use the Google API, you first need a Google Cloud account.
- Go to https://cloud.google.com/translate/docs/basic/setup-basic
- Click Set up a project.
- Name the new project in the Enable Cloud Translation API screen. Use this dialog to name your project
- They may ask you to create or connect to an existing billing account. Google gives you a $300 credit to use the Cloud Translation API over a year to try it out.
- Create a new service account.
- This screen will pop up with your new project name and the associated service account. Click Download Private Key. This API key (written in JSON) connects your site to the Google Cloud. To enable API, download the private key.
- Upload the Google Translate API key to your site. Check with your hosting company where on your system to place this key.
- When you’ve placed the Google API key on your site, tell your system where to find it. Set an environment variable. Again, check with your hosting company if you don’t know how to open a terminal.
On a Windows command prompt, enter:
On a Linux terminal, enter:
Installing the Google Cloud Tools
When the account is set up, and your API key is on your site, next up is installing the Cloud Tools. You will find installation information for Linux, Mac, and Windows here.
Run through the Google Cloud SDK Setup. This software development kit is written in the Python language (bundled in the software).
When the setup is complete, a command-line program will appear and run through the configuration routine. You’ll log in with your Google account and then select your project. The program kindly selects all the default options for you.
We’re almost done!
Sending text for Translation
To get a paragraph translated, open the Google Cloud Tools for Powershell (in Windows). Enter this command:
curl -s -X POST -H “Content-Type: application/json” \
-H “Authorization: Bearer “$(gcloud auth application-default print-access-token) \
‘q’: ‘The Great Pyramid of Giza (also known as the Pyramid of Khufu or the
Pyramid of Cheops) is the oldest and largest of the three pyramids in
the Giza pyramid complex.’,
You should see something like this translated text coming back.
“translatedText”: “La Gran Pirámide de Giza (también conocida como la
Pirámide de Khufu o la Pirámide de Keops) es la más antigua y más
grande de las tres pirámides en el complejo de la pirámide de Giza.”
You can now put this on your site. Whew!
Weglot Has a Better Way
There is an easier way to translate your website. The Weglot plugin is simple to integrate because it installs like any other WordPress plugin. From your admin page, go to Plugins > Add New. Search for Weglot. Install and activate.
Configuring Weglot is quick and easy too. Create your account at Weglot.com. Grab your API key from your email and paste it into the configuration screen:
Choose your destination languages in the Weglot configuration screen.
Choose your source language and target language from the list of over 100 supported languages. Click Save Changes and you’re ready to go.
When you publish a post on your site, Weglot uses content detection to create a separate site for each targeted language. It starts with Google-like machine learning, but humans review the work, so you don’t have to think constantly about how your idioms will translate.
At the bottom of every published post, readers will click this box to select their language:
Readers click this easy-to-use button to choose their language.
They will see something like this:
In addition, you get access to Weglot’s network of professional translators for your more complex tasks.
These are just a few of the reasons more than 50,000 website owners trust Weglot.
The Google Translate API key will help you to connect with readers of other languages, once you’ve completed the cumbersome installation process outlined here. If you’re using WordPress to build your website, Weglot can simplify the process.