Language I/O API (Salesforce Managed Package)
The Language I/O API managed package for Salesforce allows organizations to use a Detect and a Translate API call within Apex Code, Flows, and the Einstein Bot.
To use this, Language I/O must install a specific package. Contact your Customer Success Manager for more details, and to obtain the necessary credentials so that you can make requests via these API calls.
There are three ways you can use this package:
Installing the package
- Log in to the instance of SF where you want to install the package.
- Visit the relevant install link below in the same browser, and select "Install for all users":
- Sandbox Org: https://test.salesforce.com/packaging/installPackage.apexp?p0=04t1U000007U4TiQAK"
- Production Org: https://login.salesforce.com/packaging/installPackage.apexp?p0=04t1U000007U4TiQAK
Apex Code
The following examples show how to use the methods from the Language I/O API managed package to do on-demand Language Detection and Translation.
Language Detection
Lio.DetectionAPI.Request req = new Lio.DetectionAPI.Request(); // create new request
req.namedCredential = 'LIO'; // name of the named credential used for the connection to the LIO server
req.routableId = '123'; // unique identifier. For example, record Id
req.sContent = 'Bonjour'; // content for which the language needs to be detected
List<Lio.DetectionAPI.Result> resultList = Lio.DetectionAPI.detectLanguage(new List<Lio.DetectionAPI.Request>{req}); // make request
system.debug(resultList.get(0).sDetectedLanguage); // the result should be 'fr'
Translation
Here is a code example for a one time translation
Lio.TranslationAPI.Request req = new Lio.TranslationAPI.Request(); // create new request
req.namedCredential = 'LIO'; // name of the named credential used for the connection to the LIO server
req.routableId = '123'; // unique identifier. For example, record Id
req.sContent = 'Hello'; // content for which the language needs to be detected
req.sSourceLocale = 'en'; //source language. This is optional
req.sTargetLocale = 'fr'; // target language
List<Lio.TranslationAPI.Result> resultList = Lio.TranslationAPI.translate(new List<Lio.TranslationAPI.Request>{req}); // make request
system.debug(resultList.get(0).sTranslation); // the result should be 'Bonjour'
Flows
The Language Detection and Translation methods are "Invocable Methods". This means that you can use them in automation processes, such as Flows.
To call either the Language Detection or Translation functionalities in a Flow, add an Action element:
In the list of flow actions, find the LIO__DetectionAPI / LIO__TranslationAPI apex invocable methods:
Next fill in the parameters:
For Language Detection
(1) - Constant variable that contains the name of the named credential used to connect to the Language I/O server
(2) - Unique ID (This can be the record ID)
(3) - Text for which you want to determine the language
The output is called 'sDetectedLanguage'.
For Translation
(1) - Constant variable that contains the name of the named credential used to connect to the Language I/O server
(2) - Unique ID (This can be the record ID)
(3) - Text for which you want to determine the language
(4) - Target language
(5) - (Optional) Source language
The output is called ‘sTranslation’
Einstein Chat Bot
Similarly to the Flow, the Language Detection and Translation functions can be used with Einstein bots.
Language Detection
In the following example, you use Language detection to determine the visitor’s language from the pre-chat subject, and then potentially route the visitor to a bot configured with the necessary language.
(1) - Text for which you want to determine the language. In this example, this is the pre-chat Subject
(2) - Variable that contains the name of the named credential used to connect to the Language I/O server
(3) - Unique ID
(4) - Detected language
Translation
In the following example, you use the Translation functionality to translate an order status retrieved from Salesforce into the visitor’s language.
Apex Actions
Settings
(1) - Source language (In this example, the language of the retrieved order status)
(2) - Text to be translated (In this example, the order status)
(3) - Target language (In this example, the visitor’s language)
(4) - Variable that contains the name of the named credential used to connect to the Language I/O server
(5) - Unique ID
(6) - Translated text.
Comments
0 comments
Please sign in to leave a comment.