If you know a thing or two about programming, you might already be familiar with Google Translate API. It’s a service from the search giant which allows programmers to translate text or HTML from one language to another. The other languages include PHP, cURL and JSON.
As indicated on the Google Developers site, the program makes it possible for users to dynamically translate text between thousands of language pairs (maybe even alien language one day!). It also lets websites and programs integrate with Google Translate programmatically.
Steps to Translate Text Using Google Translate API and PHP
Now that you already have a basic idea about Google’s Translate API, how can you actually translate text or HTML to PHP? Here are a few basic steps that you can follow:
- If you already have a Google account, go to Google API’s console.
The link should be something like this: https://code.google.com/apis/console/
Upon your arrival at the page, you can start using Google API’s console by clicking the Create Project button. It will show you the following options on what you can do after creating an APIs project:
- Use Google APIs beyond anonymous limits.
- Monitor API usage and control API access.
- Share API management with a team.
- Turn on the “Translate API” option.
From the Google APIs console, you will see the names of different APIs, the permissions that you will have, settings support, compute engine, cloud storage, cloud SQL, BigQuery and cloud development. Initially, the status of all the APIs names will be Off. Once you initiate a project, that is when the status will change.
This means that you simply need to choose the name of the Google API project that you would like to initiate and change the status to On. For example, if you would like to work on AdSense Host API, simply switch the Off button to On so that you can activate it.
- Enable billing in your project settings.
Next, enable billing in your project settings. Click the Billing option on the left menu of the Google APIs console. Click on Enable Billing.Key in your payment data and the additional personal information that will be asked. Credit card payments are accepted so it should not matter which country you are logging in from.
For more information on how Google bills for the service, visit this link:
- Get the API key.
There are apps which allow you to access the Translate API, but you would need an API key. This is connected to the created project in the Google APIs console. To get it, simply click on the API Access menu at the console page. The code is under “Simple API Access”. To access Translate API from your app, you can choose from these three options: translate, detect or languages.
- Get the translations.
Finally, get the translations. This is the core functionality of Google Translate API and can be accessed through:
The most important among the parameters are q for the input text; source for the source language which Google identifies automatically; and target which is the target language.
If your request cannot be processed, a corresponding error code would appear and suggestions on how the issue can be resolved will be indicated.
The Usefulness of Google Translate API
When is the Google Translate API most useful? If your site is already attracting online visitors from all parts of the world, the content may have already been translated to several languages. The one thing that might be skipped, however, is the user comments which are posted daily on site – along with the reviews, ratings and opinions. These all play a role in further promoting the popularity of your site, so they should also be translated to other languages and this is where Google Translate API proves to be most useful. I have used it in my blog and I can say that it’s really beneficial.
Sarah Del Rosario is a technology and lifestyle blogger and a mother of one bouncing 8 months old baby.