A set of functions that use AI services, such as the machine translation service for translating text and large language models for computer vision and natural language processing. The use of AI services may not be allowed in your organization. You can view and change this in the AI Assistants section of the Organization settings page. AI functions are currently in beta. While in beta, AI functions do not consume credits.
TranslateText
TranslateText(inputText, toLanguages, fromLanguage?) -> Dictionary
Function bundle: AI
This function is currently in beta. While in beta, AI functions do not consume credits. The use of AI services may not be allowed in your organization. You can view and change this in the AI Assistants section of the Organization settings page.
Translates input text from a source language into one or more target languages. Language codes (e.g. "en" for English, "es" for Spanish) specify the languages involved. The underlying machine translation service uses AI to generate the translated output.
Parameters
- inputText: Text | Array<Text> - The text to translate. This can be a single text value or an array of text values.
- toLanguages: Text | Array<Text> - The target language(s) to translate to. This can be a single language code or an array of language codes.
- fromLanguage (Optional): Text - The source language of the input text. If not specified, the service will attempt to auto-detect the source language.
Return value: Dictionary
A dictionary containing the translated text.
-
success: Boolean - Indicates whether the translation was successful. This value will be
false
if the use of AI services is not allowed in your organization. You can view and change this in the AI Assistants section of the Organization settings page. -
results: Array<Dictionary> - An array of dictionaries containing the translation results for each
input
value.Text -
key: Text - The index of the input text in the original array.
-
text: Text - The input text that was translated.
-
detectedLanguage: Dictionary - The detected language of the input text, if applicable.
-
translation: Dictionary - A dictionary of translated values where the key is the language code and the value is the translation.
-
Additional resources
Example
Translates the text 'Hello world' to the locale of the client or system.
var locale = GetEnvironment().locale;
var result = TranslateText('Hello world', locale);
// result will be a dictionary with the translated text
if (result.success){
if(HasValue(result, ["results", 0, "translation"])){
// returns "Hola mundo" if the device locale is 'es'
return result.results[0].translation[locale];
}
if (HasValue(result, ["results", 0, "text"])){
// returns "Hello world" if translation could not be performed
return result.results[0].text;
}
}
return "Translation not successful";