How to get started with the Google Translate API – TechTalks

By Richard Koret

Even though most of us can’t travel the way we used to, the world is a more accessible place, at least online. Business people may not attend international conferences or travel around the world for meetings as much. But in many ways, companies are finding that they can access and develop foreign markets by localizing their websites and apps to speak the language of locals and adapt to their standards. Developers can play a vital role in the localization process.

How localization tools are driving innovation in AI-powered APIs

Developers can take advantage of this trend, increase the value of their software and expand the capabilities of their applications online. Google has emerged as a leader in translation algorithms over the past decade, taking advantage of advances in AI-driven neural network technology. This powers Google Translate, which is well known to businesses for their businesses or customers. They can do this easily by adding Google Translate machine translators, well known to businesses and consumers, an application that has had an impact on the translation profession as we know it. Here we’ll explore how developers can add Google-based translations to their applications by leveraging the powers of the Enterprise Translate API. Localization tools, which greater precision in translation mechanics, is also necessary for the translator to work more efficiently.

Before we dive into the software weeds, it’s worth noting the alternatives to the Google Translate API route. Third-party conversion tools like Zapier and IFTTT allow you to link your software workflow to machine translation modules through webhooks and web services, with minimal coding. Even a savvy non-programmer should be able to implement these solutions. The main downside, however, is that you might end up settling for a lower translation engine than Google offers.

What does Google offer for translation?

Google is a pioneer in both machine language and machine learning, with the two L words representing two sides of the same coin. The language must be learned, and this learning is achievable by mastering a natural language. Today’s AI Driven Mastery is Neural Machine Driven or NMT in 2016, bringing a ‘paradigm shift’ in translation technology. Since that year, NMT has been the preferred translation method.

In 2006, Google began training its translation algorithm by digesting tens of millions of words taken from translated documents from the European Union and United Nations Parliament. Today, Google faces competition from Facebook, which leverages lessons learned from the comments and posts of its 2 billion users to translate more informal conversations, including rendering LOL and WTF in dozens of languages. NMT continues to be a way forward.

Fortunately, the language learning process didn’t stop with the bureaucrats and Emoji. Google Translate now supports more than 100 languages, several dozen of which have voice support. You can speak in one language and have the translation vocalized in another, usually with a choice of voices. And, as we’ll see, machine learning has been produced so that you can effectively translate your own domain-specific language.

Getting started with the Google Translate API

Google promotes its API as fast and dynamic, adaptable to a variety of content needs. The company not only markets to professional coders, but also to a wider range of users, including those with “limited machine learning expertise” who can quickly “create high quality production ready models.” .

For the latter, you can simply upload translated language pairs (a structured list of words / phrases with their translations) and AutoML Translation will form a custom translation template. The workflow allows for inputs personalized by the customer or pre-trained (by Google). To translate an English product description into French, Korean, and Portuguese, for example, you can customize a Google AutoML template for French and rely on a pre-trained template for Korean and Portuguese. Then you just need to upload your English HTML file to Google Cloud Storage and send a batch request to the Translation API pointing to your AutoML and pre-trained models. Google’s AutoML translation will then generate your HTML code in three separate language files on your cloud storage.

Training is essential, but the initial model is pre-trained to render over 100 languages. And if you have a domain-specific lexicon (medical or legal terms, for example), these just require a bit more training and basic API tweaking, if they don’t already exist. A glossary allows users to “wrap” proprietary non-translatable terminology (such as brand and product names) to ensure they remain intact during translation. There is also built-in support for the Media Translation API, which handles real-time, low-latency streaming of audio translations.

The process basically consists of three steps: Download a language pair. Train AutoML. Assess.

This translation power is not free, but the price is fair. Typically, you’ll use Google’s Translate API and its Media Translation API (if you need voice assistance). You will only need the AutoML service if you need to train other language pairs.

The charge for the Translate API is $ 20 per million characters. The Media Translation API will cost you from $ 0.068 to $ 0.084 per minute. AutoML is a bit more expensive, it costs $ 45 per hour to train a language pair, up to a maximum of $ 300 / pair. Pay only for what you use, as you use it. (Google is patient: it wants to get you hooked, so it’s rolling out free treatment as you get used to speed, with a full year to practice before you have to pay.)

Setup for your first translation

The RESTful Translate API is the easiest way to get started. Google offers basic and advanced configuration. You can do this with localization tools, but you can also do it manually. If you’ve set up a Google API service, you’re probably comfortable with the exercise and may already have a Cloud Console account. Assuming this to be true, the next things you need to do, if you haven’t already, are:

  • Create or select your project.
  • Activate the Cloud Translation API.
  • Create a service account.
  • Download your private key in JSON format. Keep the full path to this file for the next step.

Go to the shell prompt on your Mac OS X, Linux, or Windows (Powershell) system and set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path of your JSON service account key using the following commands. This variable only applies to the current shell session. If you open a new session, you will need to reset this variable by replacing [PATH] with the path of the JSON file with your key.

If you are using Linux or macOS:


For Windows, in PowerShell:


Or, from a command prompt:


Next, install and initialize the Google Cloud SDK. Depending on the operating system you are using, the Cloud SDK may depend on a version of Python that is not installed on your system. So be sure to double-check the Cloud SDK documentation to make sure the correct version of Python is installed.

Perform your first translation

Make a translation API request with a REST call using the v2 translation method.

Use loop make your request to period.

The command includes JSON with (1) the text to translate (q), (2) the language to translate from (source) and (3) the language to translate to (target).

Source and target languages ​​are identified by ISO-639-1 codes. In this example, the source language is English (en), the target is French (fr). The format of the query is plain “text”.

Sample loop command uses the gcloud auth application-default print-access-token command to get an authentication token.

curl -s -X POST -H "Content-Type: application/json" 
    -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) 
    --data "{
  'q': 'The quick brown fox jumps over the lazy dog',
  'source': 'en',
  'target': 'fr',
  'format': 'text'
}" ""

The answer should look like the following:

  "data": {
    "translations": [
        "translatedText": "Le renard brun rapide saute par-dessus le chien paresseux"

Congratulations! You’ve submitted your first request to the Cloud Translation API!

Next steps in the translation process

For most applications, you can count on one of the more than 100 language pairs already trained and tested. (If the pair you need is not available or you need a custom translation with the AutoML training module.) The complete process is as follows:

  1. Create a file containing the desired language pairs, using the CURL example above. Choose source and target languages ​​from the list here (for example, “en” or “fr”).
  2. Write code that reads your website content and makes a REST call to the Cloud Translation API (including a parameter pointing to your model, and then producing a translated version of that text).
  3. Create a new page in your content management system to contain and then display the translated text. Better yet, if your CMS is programmable (either directly or via API), improve the code by automating this step.
  4. Configure your CMS and website to display the appropriate pages when a specific language is selected by end users of your site.

Client libraries are currently available for seven popular programming languages: C #, Go, Java, Node.js, PHP, Python, and Ruby. Just install the library of your choice. Go to the translation client libraries for installation instructions.

About the Author

richard koret

Richard Koret writes on technology, language and culture.

About Jon Moses

Check Also

Upcoming Amateur Radio Conventions Focus on Learning and Youth

08/12/2022 Two major amateur radio events in August will host divisional conventions for the ARRL, …

Leave a Reply

Your email address will not be published.