The /whisk.system/watson-translator
package offers a convenient way to call Watson APIs to translate.
The package includes the following actions.
Entity | Type | Parameters | Description |
---|---|---|---|
/whisk.system/watson-translator | package | username, password | Package for text translation and language identification |
/whisk.system/watson-translator/translator | action | payload, translateFrom, translateTo, translateParam, username, password | Translate text |
/whisk.system/watson-translator/languageId | action | payload, username, password | Identify language |
Note: The package /whisk.system/watson
is deprecated including the actions /whisk.system/watson/translate
and /whisk.system/watson/languageId
.
If you're using OpenWhisk from Bluemix, OpenWhisk automatically creates package bindings for your Bluemix Watson service instances.
Be sure to remember the name of the service instance and the Bluemix organization and space you're in.
wsk package refresh
created bindings: Bluemix_Watson_Translator_Credentials-1
wsk package list
packages /myBluemixOrg_myBluemixSpace/Bluemix_Watson_Translator_Credentials-1 private
If you're not using OpenWhisk in Bluemix or if you want to set up your Watson Translator outside of Bluemix, you must manually create a package binding for your Watson Translator service. You need the Watson Translator service user name, and password.
Create a package binding that is configured for your Watson Translator service.
wsk package bind /whisk.system/watson-translator myWatsonTranslator -p username MYUSERNAME -p password MYPASSWORD
The /whisk.system/watson-translator/translator
action translates text from one language to another. The parameters are as follows:
username
: The Watson API user name.
password
: The Watson API password.
payload
: The text to be translated.
translateParam
: The input parameter indicating the text to translate. For example, if translateParam=payload
, then the value of the payload
parameter that is passed to the action is translated.
translateFrom
: A two-digit code of the source language.
translateTo
: A two-digit code of the target language.
Invoke the translator
action in your package binding to translate some text from English to French.
wsk action invoke myWatsonTranslator/translator \ --blocking --result \ --param payload "Blue skies ahead" --param translateFrom "en" \ --param translateTo "fr"
{ "payload": "Ciel bleu a venir" }
The /whisk.system/watson-translator/languageId
action identifies the language of some text. The parameters are as follows:
username
: The Watson API user name.
password
: The Watson API password.
payload
: The text to identify.
Invoke the languageId
action in your package binding to identify the language.
wsk action invoke myWatsonTranslator/languageId \ --blocking --result \ --param payload "Ciel bleu a venir"
{ "payload": "Ciel bleu a venir", "language": "fr", "confidence": 0.710906 }