This is a test message to test the length of the message box.
Login
Photo by Joshua Hoehne on Unsplash

Google Translate API

344

In this article we look at activating and provisioning the Google Translate API to perform automated translations.



Since we also use the Google Translate API for the automatic translation of our articles, we wanted to take a closer look at the integration and use of the API in this article.

 

Introduction

If you want to translate texts from one language into another language, there are various services and websites available on the Internet today, such as Google Translate or DeepL Translator. But you don't always want to do the translations manually on the website; you might want to translate larger texts or even entire blogs automatically at the touch of a button. This makes sense especially if the text contains a lot of formatting that should be retained after translation. In this article we look at the Google Translate API in its simplest form and how you can use it for yourself.

 

Configuration

Before you can use the API, you need a Google account or, in effect, an API key to be able to call up the interface.

 

Google Cloud

For the Google Cloud you need an account in order to be able to consume APIs and other Google Cloud services. You can do this with your private Google account or register with a new account with Google. You then have to create a project to which you can later assign the service.

 

Cloud Translation API

After registering the account, you can log in and search for the API in the Cloud Marketplace. You can then provision the API using the "Activate" button. The project should have a payment method stored, even if using the API is free up to a certain number of characters.

 

API Key

Once you have activated the API in your project, you can choose the type of authentication. We would like to access the API via API key, as this is the easiest way. To do this, you can, for example, go to the API administration via the Marketplace.

 

In the "Login Details" area, you can select the appropriate method using the "Create Login Details" button.

 

After a short wait, the key has been created, which you can copy for further use. You can also use the settings to define whether the API key can only be used via a specific website, IP address or app. This also reduces the risk that if you lose the key, it will be misused and you will incur high costs.

 

Testing

In the next step, we want to test the API via POSTMAN to validate input, behavior and output for us. Since we are using an API key, we have to append it as a parameter to the URL for the call. The base URL therefore looks like this:

https://translation.googleapis.com/language/translate/v2?&key=<API-KEY>

 

In Postman we now configure a POST request to call the API. Don't forget to set the content type.

 

Finally, we give the request a payload that should be translated accordingly.

{
  "q": [
    "Test Artikel", 
    "Bitte diesen Text ins Englische übersetzen."
  ],
  "target": "en"
}

 

If we send the request to the API, we will receive an HTTP Code 200 if successful and will receive the translated texts back. You can find more information about the API in the official documentation from Google for the API. The various parameters are described there again.

 

Conclusion

After a little effort in the configuration, we quickly get a result when using the API and have the option of translating one or many texts at once. Please note the limits of the API, which are described in the documentation.


Included topics:
GoogleTranslatev2Web-API
Comments (0)



And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


RAP - Translation app (example)

Category - ABAP

Let's take a look at a practical example of developing a RAP application in the ABAP environment and how you can create an app with little effort.

08/02/2024

BTP - Google Translate Integration

Category - ABAP

How do you call an external API, such as Google Translate, from the ABAP environment and consume it in a local class? Read more in this article.

07/30/2024

App Update January 2020

Category - Apps

The updates for our apps are out, we will show you briefly what has changed in January.

01/31/2020

App Planner on GooglePlay

Category - Apps

Our latest app for planning further app projects is now in the Google Play Store and can also be used by you.

01/03/2020

Resource Monitor on GooglePlay

Category - Apps

The beta version of the Resource Monitor is now launched on Google Play, we'll show you our first impressions and the finalization of the app.

10/04/2019