Facebook Pixel

How to make your site multilingual using Google translation tools - The detailed guide

How to make your site multilingual using Google translation tools – The detailed guide

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 use of the JavaScript library which allows you to add a translation button to your website
  • 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.

1 – Using the JavaScript library

To translate on your website using the JavaScript library, you simply need to include JavaScript code in your website. Then, still with a line of JavaScript code, you will bring up a language selection option. Users will be able to choose a language to see your website translated into it.

Sample JavaScript Library Code for Google Translate

In the example above, we use the Google translation library to include the translation on the website (//translate.google.com/translate_a/element.js). Next, we create a JavaScript function that will initialize the “ my translation ” language selection form. In this initialization function, the identifier which will be used as the “translation_site_web” selection is transmitted. The code above is more than enough to translate your website with Google's JavaScript library. [voir_demo title="See an example of using the Google library or download" demo="googletranslationjs.php"]

Some Benefits of Google's JavaScript Library

The Google translate JavaScript library can have several benefits. We will list them 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.

Some Disadvantages of the JavaScript Translation Library

Although the use of the JavaScript library offers interesting advantages, it is however not devoid of disadvantages.

The lack of flexibility

Using Google to do the translation requires doing further editing. However, when you use the JavaScript library, it is impossible to modify the translated text that is displayed on the visitors' screen. In addition, the translation that Google's solution offers is not always accurate and may be out of context. You therefore risk ending up with a loss of the relevance of your content.

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

Usually, companies want to have page links specific to each language. However, with Google's JavaScript translation, content is displayed with different languages on the same page. In addition, unless you make relatively advanced adjustments to the programming, the content you offer may not be easily indexed by search engines.

2 – Use of Google Translate API

Google Translate API gives you a lot more options than the JavaScript library. In particular, you can use it to integrate the translation module. Even better, you will be able to edit the translated content of your website. It is therefore the ideal option if you want to maintain a professional posture and better control what your customers read. In this section, we are going to explain how to integrate Google Translate api into its web project. Where appropriate, we will focus in particular on websites that use PHP. To be able to use this approach, the prerequisites are:

  1. A web server with command line access
  2. Knowledge of PHP
  3. A Google Cloud Console account
  4. 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

Account creation.

To create your API key, go to the Google Cloud IA website for translation . How to translate your website with Google Translation API or Google 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: Sample screen of Google Cloud 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:

  1. A name for your project,
  2. A billing account
  3. your organization
  4. your area

Field 3 and 4 are usually automatically filled in with data you provided when creating your account. Create a google cloud 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. Google Cloud Marketplace 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. Google translation API key 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.

API Setup

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. [the_call_to_action title="Do you need a professional web service for your multilingual site?" action_text="Contact us" action_type="modal" action_link="exampleModal" data_title="Get the extension download link directly in your email " data_action ="download" data_link="prositeweb_paiement"]

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' ] ) ;

Some recommendations

  • 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.

WPML

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.

Weglot

It is also another WordPress website translation tool.

Conclusion

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.

Gilblas Ngunte Possi

Gilblas Ngunte Possi

Founder and Full-Stack Developer at Prositeweb.

My proficiency with modern tools and a keen analytical sense regarding information technology enable me to provide superior guidance in the development and implementation of your web solutions.

Leave a Reply

Your email address will not be published. Required fields are marked *

Gilblas Ngunte Possi

Gilblas
Typically replies within an hour

Gilblas
Hi there👋

How can I help you?
1:40
Chat with Us