In a globalized economy, language translation becomes an important aspect of day to day business transactions with customers and partners from across the world. In the old world, you would have sought the services of a human translator while visiting a foreign country. However, now with the help of artificial intelligence, this job can be easily performed by machines.
Thanks to the power of the Microsoft Text Translation API, you can perform common language conversion tasks like translation, transliteration, and language detection with ease. In this blog post, we will show you how to leverage the Microsoft Text Translation API (v3.0) to build some compelling use cases around language text translation.
At Rakuten RapidAPI, we host thousands of APIs for helping developers build their apps rapidly. We are pleased to announce that the new version 3.0 of Microsoft Text Translation API is now fully integrated into our platform. So, log in to your Rakuten Rapid API account and head over to the API console.
In case you don’t have an account on Rakuten Rapid API, sign up now and get your universal API key to access the Microsoft Text Translation API and thousands of other APIs hosted on Rakuten Rapid API.
Use Cases of Text Translation
Text translation has become a de-facto feature in all the virtual assistants and bot platforms that offer various types of services to users.
If you are building a similar platform and want to add translation features, then your requirement would fall under one of these top-level text translation use cases.
All of us have faced this situation. You read a label on a package arriving from a different country or struggling to find your way through the road signboards in a foreign country. Whatever may be the case, you feel an instant need to translate it into your native language.
The iTranslate app, available for the Apple app store is one of the popular language translation apps out there. It supports over 100 languages and also does voice translation.
If you have been living in a foreign country for some time, then you would feel the urge to learn their language. By transliterating the foreign language text into your own language, you can take some baby steps and learn to pronounce simple words in that language.
Language Feature Detection
If you are building a bot to interact with users, then you need certain language features to be detected to make sense of conversation. This is also a prerequisite for building NLP (Natural Language Translation) based services.
Let’s explore the Microsoft Text Translation API to realize these use cases.
Overview of the Microsoft Text Translation API
The Microsoft Text Translation API mainly supports translation and transliteration along with a few more endpoints for utility purposes. Take a look at the API Console.
Note: If you are searching for this API then make sure that you choose the Microsoft Text Translation V3.0 API and not the older deprecated API.
Here are the endpoints supported by this API.
1. GET Languages
This endpoint returns the languages supported by the API for translation, transliteration and dictionary operations.
2. POST Translate
This endpoint performs the translation of text from one language to another language. It can accept multiple sentences and is capable of detecting the input language.
3. POST Transliterate
This endpoint performs the script translation from one language to another. It also accepts multiple sentences, but the input language and script have to be explicitly mentioned as mandatory parameters.
4. POST Detect
As the name suggests, this endpoint can be used to detect the language of the input text passed to it.
5. POST BreakSentence
Sometimes there is a need to break a long string of text into its constituent sentences. This endpoint can do that.
6. POST Dictionary Examples
This endpoint can look up a dictionary and dig out usage examples and phrases for a word and display them in a target language.
The Microsoft Text Translation API is available under a freemium pricing model. You can subscribe to the basic plan at zero cost and get 2500 API calls per month.
Microsoft Text Translation API in Action
Now for some translation fun. But before you test the Microsoft Text Translation API, it’s worthwhile to call the “Languages” endpoint to get the capabilities of the API. Here is a snippet from the API response.
Expanding it further will list the supported languages for specific operations. For instance, expanding the “translation” key will list all the languages that the API can translate to and from.
Similarly, expanding the “transliteration” key will list all the languages and their scripts along with the scripts to which they can be converted to.
This information is helpful while passing parameters for the API. Here’s how you can make use of Microsoft Text Translation API endpoints to build translation features in your app.
Translating Language Text
Fire up the API console, and select the “Translate” endpoint to pop in the required parameters as shown.
The ‘to’ refers to the language that you want to translate to and the value ‘hi’ is the shortcode for Hindi. The ‘Text’ contains the JSON array containing the sentence to be translated, as shown.
Hit the “Test Endpoint” button and you should get the translated text in the Hindi language.
You can try this endpoint by keying in the language of your choice. Check out the supported language shortcodes listed under the “translation” key in the response of the “Language” endpoint.
Transliterating Language Text
Transliteration also means to translate literally. By transliterating a text in a foreign language, you can spell it in your language. This way, you can pronounce it in the way it is done in a foreign language.
Select the “Transliterate” endpoint and enter the same text in Hindi that we tried translating to.
In this case, you have to also choose the ‘fromscript’ which is deva, meaning Devanagari script, and “toScript”which is latn meaning Latin script. The API response is
In this way, you have transliterated a sentence in Hindi to English so that you can pronounce it exactly the way it is supposed to be done in Hindi.
Check out the supported language shortcodes listed under the “transliteration” key in the response of the “Language” endpoint to try out more languages and scripts.
Performing Utility Language Operations on Text
When you are building a bot platform to interact with users through a chatbot interface then, there are several trivial challenges. For example, before the bot can even process the text, it needs to detect the language and split the text into reasonable chunks.
Microsoft Text Translation API offers a utility API endpoint “BreakSentence” which can detect the language of the input text as well as provide information about the sentences.
Select the “BreakSentence” endpoint and test it.
You will see the API response.
The first highlighted portion indicates the detected language, which is English in this case.
The second highlighted portion lists the length value of each sentence detected in the text entered in ‘Break Sentence’ parameter during API call. The API response reports three sentences in the text, each with a length of 13, 11 and 22 characters.
With this information, your bot can process the split the input text into its constituent sentences and process them sequentially. This is also a very handy tool when processing bulk input text for analysis purposes.
Apart from bots and the usual text analysis apps, this API also finds application in social media analysis which is a huge source of textual and conversational data from all across the world.
You must check out our Top 10 Translation APIs to know more about similar APIs hosted in Rakuten RapidAPI. You can also check out our translation API collection and see if it suffices your requirements for text translation and related operations.
Signing off now, until we are back in a few days with another API tutorial.