Translation API Test Drive¶
Objective¶
IBM Watson™ Language Translator allows you to translate text programmatically from one language into another language.
You call Translator API to translate sample text in this section.
Tools Used¶
- Watson Language Translator
Requirements¶
Steps¶
To test drive Translator API,
-
Go to the terminal window that you have configured in the previous section.
-
The terminal window should have been ready for making API calls. If not, execute command
export apikey=<your API key> export url=<your url> -
Translate
Hello, world!to Spanish by callingTranslatorAPI.curl -X POST -u "apikey:$apikey" --header "Content-Type: application/json" --data "{\"text\": [\"Hello, world! \", \"How are you?\"], \"model_id\":\"en-es\"}" "$url/v3/translate?version=2018-05-01"The command uses
apikeyfor API access credential. It returns the translation result in JSON format. It usesen-estranslation model to translateHello, World!andHow are you?to Spanish. -
It returns
{ "translations" : [ { "translation" : "¡Hola, mundo! " }, { "translation" : "¿Cómo estás?" } ], "word_count" : 5, "character_count" : 26 } -
Translate
Hello, world!to Chinese by callingTranslatorAPI.```bash curl -X POST -u "apikey:\(apikey" --header "Content-Type: application/json" --data "{\"text\": [\"Hello, world! \", \"How are you?\"], \"model_id\":\"en-zh\"}" "\)url/v3/translate?version=2018-05-01"
The command uses
apikeyfor API access credential. It returns the translation result in JSON format. It usesen-zhtranslation model to translateHello, World!andHow are you?to Chinese. -
It returns
{ "translations" : [ { "translation" : "你好世界 " }, { "translation" : "你怎么样" } ], "word_count" : 5, "character_count" : 26 } -
Optionally, translate
Hello, world!to your prefered lanaguage. To retrieve a list ofTranslator model_id,curl --user apikey:$apikey "$url/v3/models?version=2018-05-01" -
Identify language of a text by calling
TranslatorAPI.curl -X POST -u "apikey:$apikey" --header "Content-Type: text/plain" --data "Language Translator translates text from one language to another" "$url/v3/identify?version=2018-05-01"The command uses
apikeyfor API access credential. It returns the translation result inPLAIN TEXTformat. It identifies the language of textLanguage Translator translates text from one language to another. -
It returns a list of possible languages with different confidence.
{ "languages" : [ { "language" : "en", "confidence" : 0.9999979447464287 }, ......] }
Related Links¶
There is lots of great information, tutorials, articles, etc on the IBM Developer site as well as broader web. Here are a subset of good examples related to data understanding, visualization and processing: