Language Detection

Language Detection identifies the language of a given text. This feature enhance global support and collaboration, enabling seamless communication between teams and customers.

Salesforce Translation Options:
  • Flow-Based Language Detection: It enables users to set up language detection through straightforward, declarative tools, making automation simple and code-free.
  • Apex-Based Language Detection: Provides developers with an easy method for detecting the language of the text.
APEX-Based Language Detection

To use the ST_DetectLanguageInvocable class and its st_getSourceLanguage method, create a list of ST_DetectLanguageWrapper with the required data.
For more information about the ST_DetectLanguageWrapper class, see the section below.

The code below provides an example of how to use the st_translate method:

//Created a list of strings in which we will add the texts we would like to detect the language of.
List<String> texts = new List<String>();
//Text added to the list.
texts.add('Hello');
texts.add('Help');
//Created the ST_DetectLanguageWrapper object, which will contain all the required data for the language detection callout.
simpleT.ST_DetectLanguageWrapper sourceLanguageWrapper = new simpleT.ST_DetectLanguageWrapper();
//Added the prepared list of texts to the wrapper object.
sourceLanguageWrapper.texts = texts;
//Selected engine for language detection.
sourceLanguageWrapper.engine = ‘Google Translate‘
//Created a list of ST_DetectLanguageWrapper objects because invocable methods must have parameters set up as a list.
List<simpleT.ST_DetectLanguageWrapper> detectLanguageWrappers = new List<simpleT.ST_DetectLanguageWrapper>();
//Added previously created wrapper to the list.
listWrappers.add(sourceLanguageWrapper);
//Called the ST_DetectLanguageInvocable st_getSourceLanguage invocable method and sent the created list of detectLanguageWrappers
List<simpleT.ST_DetectLanguageWrapper> detectLanguageWrappersRes = simpleT.ST_DetectLanguageInvocable.st_getSourceLanguage(detectLanguageWrappers);

The picture shows us the apex-based language detection class.
FLOW-Based Language Detection
  1. Navigate to "Salesforce Flows" to enable language detection.
  2. Create a new flow or modify an existing one.
  3. For record-triggered flows, select "Optimize the Flow for Actions and Related Records."
  4. Set the flow to run asynchronously.
  5. Use the language detection functionality in Flow Actions.
  6. In the Flow Action search bar, type "Simple Translate Source Language detection".
  7. "Simple Translate Source Language Detection" detects the language of the given text.
  8. The method takes a List<ST_DetectLanguageWrapper> parameter. See the "ST_DetectLanguageWrapper Class" section below for more details.
The picture shows us the flow-based language detection panel.
ST_DetectLanguageWrapper class
  • The ST_DetectLanguageWrapper class includes the attributes: detected_lan, engine, and texts.
  • Required attributes: engine and texts.
  • Detected_lan is a list of type ST_DetectLanguageResponseWrapper.Detected_lan, containing language detections with languageCode and a score indicating the probability of correct detection.
The picture shows us the detection Language Wrapper class.