Table of Contents►
There are thousands of languages around the world. In addition, Internet users are more comfortable with content written in a language that is familiar to them. Therefore, in order to reach a wider target, website content translated into multiple languages comes in handy. Do you want to reach a wider audience with a multilingual site? Know that Google provides you with effective means for the translation of your website into several languages. In this guide, we'll walk you through two approaches to getting your site translated by Google. We will also detail the advantages and limitations of each of them, in order to help you in your choice.
The two approaches of Google Translate to offer content in different languages
Google offers two options for users to translate their content:
- The Google Translate API.
In the first case, your website will be displayed in any language offered by Google. However, in the second case, you have more flexibility in what you want to display as the language. We detail and compare these two possibilities below.
Your website can be easily accessible in several languages
Concretely, with very little effort, you can allow any visitor around the world to read your content.
Very easy integration.
To add such functionality to your website, you only need a few HTML skills. Even if you're not a computer person, you'll just have to copy and paste.
It's 100% free
We will talk later about the option with API. But, what we can see is that integrating the language module on its website is free. Indeed, the code is free and you do not pay any user fees.
The lack of flexibility
The obligation to use the Google logo on your translated pages
The Google logo is displayed to indicate that the translated text is provided by the Google translator. Which in some (cases) is not always professional. If you want advice on choosing an effective translation module for your website, contact us .
Poor SEO fit for search engines
2 – Use of Google Translate API
- A web server with command line access
- Knowledge of PHP
- A Google Cloud Console account
- Some notions in MySQL database management
Before embarking on this approach, it is important to note that the Google Translate API is not always free. The cost depends on the usage rate. Therefore, when using, you should be sure to pay close attention to queries.
Steps to use Google Translate api
The procedure includes steps to be followed carefully. For the use of the API to be effective, you will need to:
- Create the API for translation through your Google Cloud Platform account.
- Download the SDKs (PHP) on GitHub
- Use the example provided in the README file to see how to apply the translation.
For optimization purposes, you can create a database to save the texts you have translated. This will allow you to reduce the number of requests for the same result. Therefore, you will save in usage costs.
Create your API key for Google translation
To create your API key, go to the Google Cloud IA website for translation . Then log in to your account. If you don't have one, you can create one. Basically, if you have a Gmail account, you can use it to access the Google Cloud account. First, you will need to configure a payment method. Trials are free for a certain period. You should refer to Google's terms and conditions to learn more. Once your account is created, you will have access to a screen similar to this: You must then click on the icon right next to the logo to create a project. To do this, you will simply click on "New project" and then you will have to provide:
- A name for your project,
- A billing account
- your organization
- your area
Field 3 and 4 are usually automatically filled in with data you provided when creating your account. When you click on the "Create" button, the platform will configure your new project. After that, you will be able to generate your API key.
Generate the API key.
To generate the API key, click on the three horizontal bars to the left of the logo and then on the Marketplace tab. The Google platform will redirect you to the list of Google APIs. Search the bar for the translation API with the keyword “translate”. You will see it appear in the “Cloud Translation API” list. For the rest, you must click on this API and activate it.
Choose the type of key and make a restriction
Once you have created and activated the key, you will have to choose the type of key and restrict it. In this part, just go to the APIs and services tab, and create the identifier you want to use for your project. However, before doing so, make sure you have selected your new project (check in the top-right tab of the Google Cloud logo). To generate a type of key,
- click on the three bars at the top (left of the logo),
- and select APIs and Services.
- Next, click on the "Credentials" tab.
The Google Cloud Platform generally offers you 3 types of credentials:
- The API key
- The OAuth Client ID
- The service account
In the case of the Google Translate AI, you will need the API key. Depending on the approach you take, you could also use the OAuth Client ID. Click on the "CREATE CREDENTIALS" button. A drop-down menu will appear. Select "API key" in the latter. The platform will then generate a key that you will use for your project.
To make the key functional, you must:
- Configure the OAuth authorization screen with information about your application (You will see the notice at the top of your page). You must click on the button on the right and follow the instructions
- Next, you will need to restrict the key and protect it from possible out-of-context use. In this case, you just have to click on your new key, add your URL or the IP of the website.
Finally, select “Restrict Key” at the bottom of the page. In the restriction options, choose the options that suit you. Indeed, with an API key, it is possible to use it on different websites. Therefore, someone who comes across this key can use it in their project. Thus, it is important to restrict its use to avoid abusive charges. Likewise, you can use your key for different types of projects (Adding a map to your website, authentication or translation). It is also for this reason that you must limit it in the configuration. A restriction will help you, for example, to better assess the usage quota.
Use of the Google API translator on its website.
We are now going to show how to add the API key to your web project. Indeed, to be able to integrate Google Translate API into a web project, it is imperative to create the key as we saw above. For what follows, here are the steps to follow:
- Download Google Translate source codes (SDK) on GitHub
- Follow the documentation to see how to implement it in your web project
- Add the API key to activate the possibility of doing the translation.
Let's see together how to proceed.
Download Google Translate source codes (SDK) on GitHub
For this part, you must have access to the command lines to do the configuration and download all the components. Indeed, the GitHub code allows you to have the basics. Also, when you run the queries in your command line, you can easily download the items to finalize your project. You can, for example, use puTTY to connect to your server via the command lines. It is also important to say that to easily manipulate the codes, you must install the Composer command on your web server. In addition, you will find via this link a documentation to help you in this process.
Installing and Configuring Google Cloud PHP Translate
- Visit the GitHub website where the Google Cloud PHP translate code is located
- See the instructions for installing the codes in the README.md documentation.
A summary below:
- Install Composer to manage dependencies (resources you need for the project)
- Install Cloud Translate components
$ composer require google/cloud-translate
The site also recommends that you install the entire suite if you wish.
$ composer require google/cloud
If you have Composer installed on your server, you will normally have no problem running these queries.
Create sample code to use Google Cloud Translate
When you have installed the components on your website, you can then include them in your project. To do this, simply use a "require" from PHP to call the autoload.php file. Here is an example.
require 'vendor/autoload.php' ;
The translation code could be similar to what you have below. You must replace "your_key" in the expression below with your API key that you created above.
$translate = new TranslateClient ( [ 'key' => 'your_key' ] ) ;
- In order to use the resources optimally, you can, for example, do the translation and insert the data into a database. This will help you save in queries and consequently costs.
- You can also extend the use of the API to several types of applications. Among other things, you can use it to create a WordPress, Joomla or Magento extension.
- Keep in mind that using the Google Translate API becomes chargeable if you exceed the free query limit. So, when programming, you need to take this into consideration.
Some alternatives the Google API translation.
Using a development approach can be worthwhile if you are doing custom development. Indeed, several content managers like WordPress, Magento or Shopify already offer the possibility of integrating third-party resources to do the translation. To this end, before embarking on development, you must go to the market to see if there are any solutions that meet your needs. You will probably need to weigh the pros and cons before making a decision. To help you, we have listed some examples of alternative solutions.
The WMPL extension is a translation tool for WordPress websites. It is a solution to which you can subscribe to translate your website in WordPress. This solution has its advantages and disadvantages. However, it can help you focus better on your business.
It is also another WordPress website translation tool.
Translating a website can be relatively easy if you have the right tools. Indeed, several solutions are at your disposal to assist you in your process. If you want to work with subject matter experts to get quality work done, contact us today.