Localizing an application opens your reachable market to additional audiences on the other side of current language barriers. We’ll show you how to get started with Google API tools so you can add language auto-translation capabilities to apps and websites. Our survey will consider various translation tools that help us translate faster and more efficiently. We’ll also consider how machine translation quality stacks up against professional language services and freelancers.
Programmable Web Options for Language Translation and Google Supremacy
Translating from one language to another is a fundamental requirement for any website or app seeking global reach. Web services like Zapier or IFTTT will let you connect various web service pipes, creating workflows and webhooks to connect one app to another. But if you are a purist, working with APIs is the royal road to get the job done.
We’ll focus on Google’s Translate APITrack this API. Not surprisingly, Google is a pioneer in machine language and machine learning – the two L-words being two sides of the same coin. Language is learned, and learning is achieved through mastery of natural language. Launched in 2006, Google trained its translation engine at the outset by digesting tens of millions of words found in translated European Union parliaments and United Nations documents. That’s a scary thought if you fear language evolving into bureaucratese.
Happily, the learning process didn’t stop there. Now Google Translate supports more than 100 languages, including dozens with full voice support. The underlying technology, continually evolving, is based on the AI neural networks. Neural machine translation (NMT) was introduced by the QT21 European research consortium at the prestigious WMT (Workshop on Machine Translation) 2016 in what was considered a “paradigm shift” in automated translation tech, besting large tech companies that year. Google and other tech leaders adopted NMT soon after.
An article in Wired tells how Google’s AI innovations caused a breakthrough in machine translation. Today Google confronts competition from Facebook, which is leveraging the learnings from comments and posts by its 2 billion users to do some learning of its own. But neural translation continues to be the way to go for all machine translation players.
Getting Started with Google’s Translate API
Google promotes its API as fast and dynamic, adaptable to diverse content needs. The company markets not just to heavy duty coders but to a broad spectrum of users, including those with “limited machine learning expertise” who can quickly “create high-quality, production-ready models.” Maybe not your grandma, but perhaps her granddaughter.
The promise is straightforward: just upload translated language pairs and AutoML Translation will train a custom model” for you. As previously reported in ProgrammableWeb, the workflow allows for either customized or pre-trained (by Google) inputs. To translate an English product description into Spanish, Japanese, and Russian, you could customize a Google AutoML model for Spanish and rely on an off-the-shelf pre-trained model for Japanese and Russian. Then just 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 then outputs your HTML in three separate language files to Cloud Storage.
Training is key, but no need for diapers and baby-steps. This toddler comes pre-trained to translate 100+ languages for websites and apps. And if you have a specialized lexicon – medical or legal terms, for example – these just require a little more training and customization of the basic API. A Glossary feature lets users define specific terminology (e.g. brand names, product names, street names) to make sure they are kept intact during translation. Built-in is support for a Media Translation API, which handles real-time, low latency streaming of audio translations.
The process is just 3 steps: Upload a Language Pair. Train AutoML. Evaluate.
Before getting our hands dirty with samples, a word about price tags. You will be using Google’s Translate API and, optionally, the Media Translation API (if you need to support audio), and the AutoML service (if you need to train for additional language pairs). The fee for the Translate API is $20 per million characters processed. The Media Translation API will run you $0.068 to $0.084 per minute. AutoML costs $45 per hour for training a language pair, to a max of $300/pair. There’s no minimum: pay for what you use, as you use it. Google throws in free processing as you get up to speed, with a year to practice before paying.
Setting up for Your First Translation
Let’s focus on the RESTful Translate API as the easiest way to get started. Google offers two ways to get set up, basic and advanced. For the benefit of grandma, or her granddaughter, we’ll start with the basic one. If you’ve set up for any Google API, you probably know the drill, more or less, and may already have a Cloud Console Account. Assuming this is true, the next things you need to do, if you haven’t done them already, are:
- Create or select your project.
- Enable the Cloud Translation API.
- Create a service account.
- Download your private key in JSON format. You’ll need 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’ll need to reset this variable, replacing [PATH] with the path of the JSON file containing your key.
If you’re using Linux or macOS:
For Windows, in PowerShell:
Or, from a command prompt, simply:
Then install and initialize Google’s Cloud SDK. Depending on which specific operating system you’re using, the Cloud SDK may have a dependency on a version of Python that isn’t already installed on your system. So, be sure to double-check the Cloud SDK documentation and make sure that the appropriate version of Python is installed. You’re rolling!
Executing Your First Translation
Make a Translation API Request with a REST call using the v2 translate method.
Use curl to make your request to the https://translation.googleapis.com/language/translate/v2 endpoint. The command includes JSON with (1) the text to be translated (q), (2) the language to translate from (source), and (3) the language to translate to (target).
Source and target languages are identified with ISO-639-1 codes. In our example, source language is English (en) and target is French (fr). The query format is plain “text”.
The sample curl 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)
'q': 'The quick brown fox jumps over the lazy dog',
The response should resemble the following:
"translatedText": "Le renard brun rapide saute par-dessus le chien paresseux"
Congratulations, you fox! You’ve sent your first request to the Cloud Translation API! Next Steps
For most applications, you can rely on one of the more than 100 language pairs already trained and tested. (If the pair you need is not available, or you require a custom translation, you can resort to the AutoML training module.) The full process is as follows:
- Create a file containing the desired language pairs, using the CURL command example above. Choose source and target languages from the list here such as “en” and “fr”.
- Write code that reads the content of your Web site 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).
- Create a new page in your content management system to contain and then display the translated text. Even better, if your content management system is programmable (either directly or by way of API), improve the code you’ve written by automating this part of the process.
- Set your content management system and Web site to display the appropriate pages when a specific language is selected by your site’s end users.
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 Translation Client Libraries for installation instructions.
Want more variety? ProgrammableWeb has assembled a great collection of Translation APIs from various sources.
If you’re in the mood for some bawdy fun before getting down to business, why not roll up your pantaloons and try a Shakespearean translator API, which converts plain English text to invented Shakespearean style English. To quote the Bard: “Hide, fox, and all after!”
OK, enough foxy fun. you’re set up. Now the real work begins!
Translation Quality: Software vs. Freelancers vs. Agencies
Let’s not kid ourselves. Machines are far from matching a skilled human translator in terms of quality for most languages and tasks. But software is far more efficient for routine, highly structured, and repetitive language like weather reports, sports results, routine financial reports, or standard legal expressions. But for anything requiring creativity and persuasion? Forget it.
Still, for websites and apps, let’s face it: no one is expecting perfection from a machine translation. As long as there’s nothing too embarrassing, or downright stupid in the results, readers are likely to shrug it off and not get too confused. They may even chuckle. In short, investing in localizing your site with a custom API and auto-translation can be an excellent investment to add functionality and extend the reach of your digital content.
To ensure the best quality however, you should consider augmenting any programmatic translations with reviews by language professionals. They come into play when preparing the language pairs and evaluating the results. If you support just one or two foreign languages, a cost-effective approach is to hire a freelancer from a marketplace like Upwork or freelancer.com. Make sure you search for someone with technical skills and experience in localization because that person will be interfacing with developers and dealing with technical material.
The more expensive professional option is to hire an agency that specializes in localization, which is the catch-phrase for the processes we’ve been describing here: preparing your website or app to support multiple languages and to translate language, formats and measurement units automatically. Once you get beyond a couple of languages, the freelancer approach could involve burdensome overhead. A good localization company will have multi-lingual teams to evaluate the results of your API and machine language training without involving you in the nitty-gritty.
About the Writer
Ofer Tirosh is founder and CEO of Tomedes, a professional language service provider specializing in translation and localization.
Go to Source
Author: <a href="https://www.programmableweb.com/user/%5Buid%5D">ofertirosh</a>