The DynamicTranslation API provides methods that translate text, in real time, into multiple languages using translation service providers.
In addition, you can use this API to detect the language of a specific string and check whether the DynamicTranslation methods are enabled for a translation service. Use this API to create a seamless localization experience for your user interface, enabling one interface to service multiple countries.
Currently this API supports two translation service providers: Microsoft Azure Translator Service and Google Cloud Translator Service. You can also configure other translation services within your instance and then use the DynamicTranslation API to translate your text.
When using these methods in a server-side script, use the sn_dt_api namespace identifier. Before you are able to use this API, you must activate the DynamicTranslation (com.glide.dynamic_translation) plugin. For information on this plugin and additional information on Dynamic Translation, refer to Dynamic translation overview.
If you pass in a translator, the method uses that translation service to detect the source language. Otherwise, the detection is performed by the default translation service. Ensure that the text strings that you provide contain enough verbiage to enable proper language detection.
In addition to the detected language, the response contains a confidence level of the detection, along with other possible language alternatives. If a translator is not passed in, the method also returns the default translation service used to detect the language.
Name
Type
Description
text
String
Text to use to detect the language.
parms
Object
Optional. JSON object that contains additional translation parameters.
parms.translator
String
Optional. Translation service to use to translate the text (not case-sensitive).Valid values:
Default: Translation service configured in the Translator Configuration [sn_dt_translator_configuration] table.
Type
Description
alternatives
Array of objects that describe other languages that also may be a match.Data type: Array ``` "alternatives": [ { "code": "String", "confidence": "String", "name": "String" } ]
</td></tr><tr id="detections_alternatives_code-row-dynTran"><td>
alternatives.code
</td><td>
Language code of the alternative language.Data type: String
</td></tr><tr id="detections_alternatives_conf-row-dynTran"><td>
alternatives.confidence
</td><td>
Float value indicating the confidence level of the alternative language. Value is between zero and one. The lower the value, the lower the confidence level.Data type: String
</td></tr><tr id="detections_alternatives_name-row-dynTran"><td>
alternatives.name
</td><td>
Language code of the alternative language.Data type: String
</td></tr><tr id="detections_detectedLanguage-row-dynTran"><td>
detectedLanguage
</td><td>
Description of the detected language.Data type: Object
```
"detectedLanguage": {
"code": "String",
"confidence": "String",
"name": "String"
}
detectedLanguage.code
Language code of the detected language.Data type: String
detectedLanguage.confidence
Float value indicating the confidence level of the alternative language. Value is between zero and one. The lower the value, the lower the confidence level.Data type: String
detectedLanguage.name
Language code of the detected language.Data type: String
translator
Translation service used to detect the language.Data type: String
Error messages
The following are error messages that the method may return and indications as to the error's root cause. - Text ("text" field) is missing or invalid. (40000): The text to translate is either missing or not a string. - Dynamic Translation plugin is not installed. (40001): The Dynamic Translation API was invoked without activating the com.glide.dynamic_translation plugin. For information on activating this plugin, see Dynamic translation overview. - Translator ("translator" field) is invalid. (40003): The passed in translator parameter is not a string. - <translator> translator is not configured. (40004): The specified translation service is not configured in the Translator Configuration. For information on creating/modifying a translator configuration, see Create a translator configuration. - <translator> translator is inactive. (40005): The specified translation service is not set to Active in the Translator Configuration. For information on creating/modifying a translator configuration, see Create a translator configuration. - Additional parameters are invalid. (40006): The additional parameters that were passed are not an object. - Maximum time limit has been exceeded. (40009): The operation took longer than the defined timeout value specified in the Translation Configuration. Default: 40 seconds - Default translator is not configured for detection. (40011): The default translation service has not been specified for language detection in the Translator Configuration. For information on creating/modifying a translator configuration, see Create a translator configuration. - <translator> translator is not configured for detection. (40013): The specified translation service is not configured for language detection in the Translator Configuration. For information on creating/modifying a translator configuration, see Create a translator configuration. - Unknown error occurred. (40051): Default error thrown when the error doesn't fall in to any other category. - Text ("text" field) has exceeded its maximum length. (40052): The text that was passed in to translate exceeds the maximum length supported by the corresponding translation service. - Request is not authorized because credentials are missing or invalid (40055): The credentials configured for the translation service in Connections & Credentials are not valid. For information on connections and credentials, see Dynamic translation overview.
This example shows code in a server-side script that detects a string in English using IBM's translation service.
var detectedResponse = sn_dt_api.DynamicTranslation.getDetectedLanguage('Please detect the language of this text', {"translator":'IBM'});
gs.info(JSON.stringify(detectedResponse));
This example shows a server script that throws an error when an invalid translation service is passed in.
var detectedResponse = sn_dt_api.DynamicTranslation.getDetectedLanguage('Please detect the language of this text', {"translator":123});
gs.info(JSON.stringify(detectedResponse));
Output:
{"code":"40003","message":"Translator (\"translator\" field) is invalid"}
Detects the languages of the passed in text strings.
If you pass in a translator, the method uses that translation service to detect the source language. Otherwise, the detection is performed by the default translation service. Ensure that the text strings that you provide contain enough verbiage to enable proper language detection.
In addition to the detected language, the response contains a confidence level of the detection, along with other possible language alternatives. If a translator is not passed in, the method also returns the default translation service used to detect the language.
Name
Type
Description
texts
Array
List of text strings to use to detect the language\(s\).
parms
Object
Optional. JSON object that contains additional translation parameters.
"parms": {
"translator": "String"
}
parms.translator
String
Translation service to use to detect the language of a string. Translation services are configured under the Translator Configuration menu.Possible values - not case-sensitive:
Array of objects that describe other languages that might also be a match.Data type: Array ``` "alternatives": [ { "code": "String", "confidence": "String", "name": "String" } ]
</td></tr><tr><td>
detections.alternatives.code
</td><td>
Language code of the alternative language.Data type: String
</td></tr><tr><td>
detections.alternatives.confidence
</td><td>
Float value indicating the confidence level of the alternative language. Value is between zero and one. The lower the value, the lower the confidence level.Data type: String
</td></tr><tr><td>
detections.alternatives.name
</td><td>
Language code of the alternative language.Data type: String
</td></tr><tr><td>
detections.detectedLanguage
</td><td>
Description of the detected language.Data type: Object
```
"detectedLanguage": {
"code": "String",
"confidence": "String",
"name": "String"
}
detections.detectedLanguage.code
Language code of the detected language.Data type: String
detections.detectedLanguage.confidence
Float value indicating the confidence level of the alternative language. Value is between zero and one. The lower the value, the lower the confidence level.Data type: String
detections.detectedLanguage.name
Language code of the detected language.Data type: String
detections.isError
Flag that indicates whether the detection of language for the text resulted in an error.Valid values: - true: Error encountered. - false: Language detection was successful. Data type: Boolean
status
Status of the response to the method call.Possible values: - Error - Partial - Success Data type: String
translator
Translation service used to detect the language.Data type: String
Error messages
The following are error messages that the method may return and indications as to the error's root cause. - Text ("text" field) is missing or invalid. (40000): The text to translate is either missing or not a string. - Dynamic Translation plugin is not installed. (40001): The Dynamic Translation API was invoked without activating the com.glide.dynamic_translation plugin. For information on activating this plugin, see Dynamic translation overview. - Translator ("translator" field) is invalid. (40003): The passed in translator parameter is not a string. - <translator> translator is not configured. (40004): The specified translation service is not configured in the Translator Configuration. For information on creating/modifying a translator configuration, see Create a translator configuration. - <translator> translator is inactive. (40005): The specified translation service is not set to Active in the Translator Configuration. For information on creating/modifying a translator configuration, see Create a translator configuration. - Additional parameters are invalid. (40006): The additional parameters that were passed are not an object. - Maximum time limit has been exceeded. (40009): The operation took longer than the defined timeout value specified in the Translation Configuration. Default: 40 seconds - Request failed with multiple errors. (40010): Multiple errors occurred in the language detection call. For more information, refer to the response for each individual text string. - Default translator is not configured for detection. (40011): The default translation service has not been specified for language detection in the Translator Configuration. For information on creating/modifying a translator configuration, see Create a translator configuration. - <translator> translator is not configured for detection. (40013): The specified translation service is not configured for language detection in the Translator Configuration. For information on creating/modifying a translator configuration, see Create a translator configuration. - Translator configuration version is invalid. Migrate to v3. (40014): The associated version of the Translator Configuration for the specified translation service does not support the specified text translation method. For more information, see Migrate to version v3 of a translator configuration. - Unknown error occurred. (40051): Default error thrown when the error doesn't fall in to any other category. - Text ("text" field) has exceeded its maximum length. (40052): The text that was passed in to translate exceeds the maximum length supported by the corresponding translation service. - Request is not authorized because credentials are missing or invalid (40055): The credentials configured for the translation service in Connections & Credentials are not valid. For information on connections and credentials, see Dynamic translation overview.
This example shows code in a server script that detects English as the language of the passed-in strings using the Microsoft translation service.
var detectedResponse = sn_dt_api.DynamicTranslation.getDetectedLanguages(["First text string language to detect", "Second text string language to detect"], {"translator": "Microsoft"});
gs.info(JSON.stringify(detectedResponse));
This example shows code in a server script that returns a Partial status when two text strings are passed in and one of them is invalid.
var detectedResponse = sn_dt_api.DynamicTranslation.getDetectedLanguages(["First text string language to detect", ""], {"translator": "Microsoft"});
gs.info(JSON.stringify(detectedResponse));
This example shows code in a server script that throws an error when an invalid translation service is passed in.
var detectedResponse = sn_dt_api.DynamicTranslation.getDetectedLanguages(["First text string language to detect", "Second text string language to detect"], {"translator": "123"});
gs.info(JSON.stringify(detectedResponse));
Output
{"code":"40003","message":"Translator (\"translator\" field) is invalid","status":"Error"}
Translates the passed in text to one or more languages.
The method uses translation services, such as Microsoft Azure Translator Service and Google Cloud Translator Service, to perform the translation. If you do not pass in translation parameters, the method uses the system default.
Name
Type
Description
textToTranslate
String
Text to translate.
parms
Object
Optional. JSON object that contains additional translation parameters.
Optional. Key name.Valid values: textype: Type of text to translate. For Microsoft Azure Translator Service only.
parms.additionalParameters.parameterValue
String
Optional. Value of the associated key.Valid values: - html: HTML text string - plain: Standard text string Default: plain
parms.sourceLanguage
String
Optional. Language code of the source text.Default: Translation service detects the source language.
parms.targetLanguages
Array
Optional. List of language codes to use to translate the text. The method returns translated text for each language code.Default: User preferred language.
parms.translator
String
Optional. Translation service to use to translate the text (not case-sensitive).Valid values:
Default: Translation service configured in the Translator Configuration [sn_dt_translator_configuration] table.
Type
Description
detectedLanguage
Description of the detected language.Data type: Object ``` "detectedLanguage": { "code": "String", "name": "String" }
</td></tr><tr id="detections_detectedLanguage_code-row-dynTran"><td>
detectedLanguage.code
</td><td>
Language code of the detected language.Data type: String
</td></tr><tr id="detections_detectedLanguage_name-row-dynTran"><td>
detectedLanguage.name
</td><td>
Language code of the detected language.Data type: String
</td></tr><tr><td>
translations
</td><td id="translations-trans-entry-dynTrans">
List that describe the language translations.Data type: Array of Objects
</td></tr><tr><td>
translations.targetLanguage
</td><td id="trans_trg_lang-trans-entry-dynTrans">
Language code to which the source text was translated.Data type: String
</td></tr><tr><td>
translations.translatedText
</td><td id="trans_transText-trans-entry-dynTrans">
Translated text.Data type: String
</td></tr><tr id="translator-row-dynTran"><td>
translator
</td><td>
Translation service used to detect the language.Data type: String
</td></tr><tr><td>
Error messages
</td><td><p>The following are error messages that the method may return and indications as to their root cause. - Text ("text" field) is missing or invalid. (40000): The text to translate is either missing or not a string.
- Dynamic Translation plugin is not installed. (40001): The Dynamic Translation API was invoked without activating the com.glide.dynamic_translation plugin. For information on activating this plugin, see <a href="../../../platform-administration/dynamic-translation/">Dynamic translation overview</a>.
- Default translator is not configured for translation. (40002): No translation service is selected as the default translation service in the Translator Configurations. For information on creating/modifying a translator configuration, see <a href="../../../platform-administration/dynamic-translation/create-custom-translator/">Create a translator configuration</a>.
- Translator ("translator" field) is invalid. (40003): The passed in <strong>translator</strong> parameter is not a string.
- <translator> translator is not configured. (40004): The specified translation service is not configured in the Translator Configuration. For information on creating/modifying a translator configuration, see <a href="../../../platform-administration/dynamic-translation/create-custom-translator/">Create a translator configuration</a>.
- <translator> translator is inactive. (40005): The specified translation service is not set to <strong>Active</strong> in the Translator Configuration. For information on creating/modifying a translator configuration, see <a href="../../../platform-administration/dynamic-translation/create-custom-translator/">Create a translator configuration</a>.
- Additional parameters are invalid. (40006): The additional parameters that were passed are not an object.
- Target languages ("targetLanguages" field) are invalid. (40007): The <strong>targetLanguages</strong> parameter is passed in the call but is not valid for one of the following reasons:</p>
<ul>
<li>Value isn't an array</li>
<li>Array is empty</li>
<li>One or multiple of the entries is not a string</li>
<li>Source language ("sourceLanguage" field) is invalid. (40008): The <strong>sourceLanguage</strong> parameter is passed in the call but the value is not a String.</li>
<li>Maximum time limit has been exceeded. (40009): The operation took longer than the defined timeout value specified in the Translation Configuration. Default: 40 seconds</li>
<li><translator> translator is not configured for translation. (40012): The specified translation service is not configured for text translation in the Translator Configuration. For information on creating/modifying a translator configuration, see <a href="../../../platform-administration/dynamic-translation/create-custom-translator/">Create a translator configuration</a>.</li>
<li>Unknown error occurred. (40051): Default error thrown when the error doesn't fall in to any other category.</li>
<li>Text ("text" field) has exceeded its maximum length. (40052): The text that was passed in to translate exceeds the maximum length supported by the corresponding translation service.</li>
<li>Source language is invalid. (40053): The passed in <strong>sourceLanguage</strong> parameter contains a language code that is not supported by the corresponding translation service.</li>
<li>Target language is invalid. (40054): One or more of the language codes passed in the <strong>targetLanguages</strong> parameter is not supported by the corresponding translation service.</li>
<li>Request is not authorized because credentials are missing or invalid (40055): The credentials configured for the translation service in Connections & Credentials are not valid. For information on connections and credentials, see <a href="../../../platform-administration/dynamic-translation/">Dynamic translation overview</a>.</li>
<li>Text cannot be translated to target languages. (40056): The specified translation service is not able to translate the passed in text into the specified target languages.</li>
</ul></td></tr></tbody>
</table>
This example shows a server script translating plain text from English \(detected\) into French and Italian using Microsoft's translation service.
try { gs.info(JSON.stringify(sn_dt_api.DynamicTranslation.getTranslation("Translate this text using platform from server", { "targetLanguages": ["fr", "it"], "additionalParameters": [{ "parameterName": "texttype", "parameterValue": "plain" }], "translator": "Microsoft" }))); } catch (error) { gs.info(error.message); }
Response:
{"translations":[ { "targetLanguage":"it", "translatedText":"Tradurre questo testo utilizzando la piattaforma dal server" }, { "targetLanguage":"fr", "translatedText":"Traduire ce texte en utilisant la plate-forme à partir du serveur" } ], "translator":"Microsoft", "detectedLanguage":{"code":"en","name":"en"} }
This example shows a server script that throws an error when an invalid target language is passed in.
try { gs.info(JSON.stringify(sn_dt_api.DynamicTranslation.getTranslation("Translate this text using platform from server", { "targetLanguages": ["123"], "additionalParameters": [{ "parameterName": "texttype", "parameterValue": "plain" }], "translator": "Microsoft" }))); } catch (error) { gs.info(error.message); }
Response:
{"code":"40054","message":"Target language is invalid"}
## DynamicTranslation - getTranslations\(Array texts, Object parms\)
Translates the passed in text strings to one or more languages.
The method uses translation services, such as Microsoft Azure Translator Service and Google Cloud Translator Service, to perform the translation. If you do not pass in translation parameters, the method uses the system default.
<table id="table_bzb_4zk_thb" class="parameters"><thead><tr><th>
Name
</th><th>
Type
</th><th>
Description
</th></tr></thead><tbody><tr><td>
texts
</td><td>
Array
</td><td>
List of text stings to translate.
</td></tr><tr><td>
parms
</td><td>
Object
</td><td>
Optional. JSON object that contains additional translation parameters.
</td></tr><tr><td>
parms.additionalParameters
</td><td>
Object
</td><td>
Optional. Array of JSON objects. Each object contains key-value pairs that provide additional information for performing the translation.
</td></tr><tr><td>
parms.additionalParameters.parameterName
</td><td>
String
</td><td>
Optional. Key name.Valid values:
textype: Type of text to translate. For Microsoft Azure Translator Service only.
</td></tr><tr><td>
parms.additionalParameters.parameterValue
</td><td>
String
</td><td>
Optional. Value of the associated key.Valid values:
- html: HTML text string
- plain: Standard text string
Default: plain
</td></tr><tr><td>
parms.sourceLanguage
</td><td>
String
</td><td>
Optional. Language code of the source text.Default: Translation service detects the source language.
</td></tr><tr><td>
parms.targetLanguages
</td><td>
Array
</td><td>
Optional. List of language codes to use to translate the text. The method returns translated text for each language code.Default: User preferred language.
</td></tr><tr><td>
parms.translator
</td><td>
String
</td><td><p>Optional. Translation service to use to translate the text (not case-sensitive).Valid values:</p>
<ul>
<li>Google</li>
<li>Microsoft</li>
<li>IBM</li>
<li><custom></li>
</ul>
<p><strong>Note:</strong> To use custom translation services you must first configure the translation service in your instance. For details, see <a href="../../../platform-administration/dynamic-translation/integrate-translation-service-provider/">Integrate with a translation service provider</a>.</p>
<p>Default: Translation service configured in the Translator Configuration [sn_dt_translator_configuration] table.</p></td></tr></tbody>
</table>
<table id="table_czb_4zk_thb" class="returns"><thead><tr><th>
Type
</th><th>
Description
</th></tr></thead><tbody><tr><td>
status
</td><td id="status-entry-dynTran">
Status of the response to the method call.Possible values:
- Error
- Partial
- Success
Data type: String
</td></tr><tr><td>
translations
</td><td>
List that describe the language translations.Data type: Array
</td></tr><tr><td>
translations.isError
</td><td>
Flag that indicates whether the translation of the text resulted in an error.Valid values:
- true: Error encountered.
- false: Text translation was successful.
Data type: Boolean
</td></tr><tr id="detections_detectedLanguage-row-dynTran"><td>
translations.detectedLanguage
</td><td>
Description of the detected language.Data type: Object
</td></tr><tr id="detections_detectedLanguage_code-row-dynTran"><td>
translations.detectedLanguage.code
</td><td>
Language code of the detected language.Data type: String
</td></tr><tr id="detections_detectedLanguage_name-row-dynTran"><td>
translations.detectedLanguage.name
</td><td>
Language code of the detected language.Data type: String
</td></tr><tr><td>
textTranlations
</td><td>
Description of the language used to translate the text string.Data type: Array of Objects
</td></tr><tr><td>
textTranslations.targetLanguage
</td><td>
Language code to which the source text was translated.Data type: String
</td></tr><tr><td>
textTranslations.translatedText
</td><td>
Translated text.Data type: String
</td></tr><tr id="translator-row-dynTran"><td>
translator
</td><td>
Translation service used to translate the text.Data type: String
</td></tr><tr><td>
Error messages
</td><td><p>The following are error messages that the method may return and indications as to their root cause. - Text ("text" field) is missing or invalid. (40000): The text to translate is either missing or not a string.
- Dynamic Translation plugin is not installed. (40001): The Dynamic Translation API was invoked without activating the com.glide.dynamic_translation plugin. For information on activating this plugin, see <a href="../../../platform-administration/dynamic-translation/">Dynamic translation overview</a>.
- Default translator is not configured for translation. (40002): No translation service is selected as the default translation service in the Translator Configurations. For information on creating/modifying a translator configuration, see <a href="../../../platform-administration/dynamic-translation/create-custom-translator/">Create a translator configuration</a>.
- Translator ("translator" field) is invalid. (40003): The passed in <strong>translator</strong> parameter is not a string.
- <translator> translator is not configured. (40004): The specified translation service is not configured in the Translator Configuration. For information on creating/modifying a translator configuration, see <a href="../../../platform-administration/dynamic-translation/create-custom-translator/">Create a translator configuration</a>.
- <translator> translator is inactive. (40005): The specified translation service is not set to <strong>Active</strong> in the Translator Configuration. For information on creating/modifying a translator configuration, see <a href="../../../platform-administration/dynamic-translation/create-custom-translator/">Create a translator configuration</a>.
- Additional parameters are invalid. (40006): The additional parameters that were passed are not an object.
- Target languages ("targetLanguages" field) are invalid. (40007): The <strong>targetLanguages</strong> parameter is passed in the call but is not valid for one of the following reasons:</p>
<ul>
<li>Value isn't an array</li>
<li>Array is empty</li>
<li>One or multiple of the entries is not a string</li>
<li>Source language ("sourceLanguage" field) is invalid. (40008): The <strong>sourceLanguage</strong> parameter is passed in the call but the value is not a String.</li>
<li>Maximum time limit has been exceeded. (40009): The operation took longer than the defined timeout value specified in the Translation Configuration. Default: 40 seconds</li>
<li>Request failed with multiple errors. (40010): Multiple errors occurred in the language detection call. For more information, refer to the response for each individual text string.</li>
<li><translator> translator is not configured for translation. (40012): The specified translation service is not configured for text translation in the Translator Configuration. For information on creating/modifying a translator configuration, see <a href="../../../platform-administration/dynamic-translation/create-custom-translator/">Create a translator configuration</a>.</li>
<li>Translator configuration version is invalid. Migrate to v3. (40014): The associated version of the Translator Configuration for the specified translation service does not support the specified text translation method. For more information, see <a href="../../../platform-administration/dynamic-translation/migrate-v3-dynamic-translation/">Migrate to version v3 of a translator configuration</a>.</li>
<li>Unknown error occurred. (40051): Default error thrown when the error doesn't fall in to any other category.</li>
<li>Text ("text" field) has exceeded its maximum length. (40052): The text that was passed in to translate exceeds the maximum length supported by the corresponding translation service.</li>
<li>Source language is invalid. (40053): The passed in <strong>sourceLanguage</strong> parameter contains a language code that is not supported by the corresponding translation service.</li>
<li>Target language is invalid. (40054): One or more of the language codes passed in the <strong>targetLanguages</strong> parameter is not supported by the corresponding translation service.</li>
<li>Request is not authorized because credentials are missing or invalid (40055): The credentials configured for the translation service in Connections & Credentials are not valid. For information on connections and credentials, see <a href="../../../platform-administration/dynamic-translation/">Dynamic translation overview</a>.</li>
<li>Text cannot be translated to target languages. (40056): The specified translation service is not able to translate the passed in text into the specified target languages.</li>
</ul></td></tr></tbody>
</table>
This example shows code in a server-side script that translates a list of text strings into French and Italian using the Microsoft translation service.
try { gs.info(JSON.stringify(sn_dt_api.DynamicTranslation.getTranslations(["Translate first text using platform from server", "Translate second text using platform from server"], { "targetLanguages": ["fr", "it"], "additionalParameters": [{"parameterName": "texttype", "parameterValue": "plain"}], "translator": "Microsoft" }))); } catch (error) { gs.error(error.message); }
Response:
{ "translations":[ { "isError":false, "textTranslations":[ { "targetLanguage":"it", "translatedText":"Traduci il primo testo utilizzando la piattaforma dal server" }, { "targetLanguage":"fr", "translatedText":"Traduire le premier texte à l'aide de la plate-forme à partir du serveur" } ], "detectedLanguage": {"name":"en", "code":"en"} }, { "isError":false, "textTranslations":[ { "targetLanguage":"it", "translatedText":"Traduci il secondo testo utilizzando la piattaforma dal server" }, { "targetLanguage":"fr", "translatedText":"Traduire le deuxième texte à l'aide de la plate-forme à partir du serveur" } ], "detectedLanguage": {"name":"en", "code":"en"} } ], "translator":"Microsoft", "status":"Success" }
This example shows a server script that returns a Partial status when one of the two passed in text strings is invalid.
try { gs.info(JSON.stringify(sn_dt_api.DynamicTranslation.getTranslations(["Translate first text using platform from server", ""], { "targetLanguages": ["fr", "it"], "additionalParameters": [{"parameterName": "texttype", "parameterValue": "plain"}], "translator": "Microsoft" }))); } catch (error) { gs.error(error.message); }
Response:
{ "translations":[ { "isError":false, "textTranslations":[ { "targetLanguage":"it", "translatedText":"Traduci il primo testo utilizzando la piattaforma dal server" }, { "targetLanguage":"fr", "translatedText":"Traduire le premier texte à l'aide de la plate-forme à partir du serveur" } ], "detectedLanguage":{"name":"en", "code":"en"} }, { "isError":true, "code":"40000", "message":"Text is missing or invalid" } ], "translator":"Microsoft", "status":"Partial" }
This example shows a server script that throws an error when an invalid translation service is passed in.
try { gs.info(JSON.stringify(sn_dt_api.DynamicTranslation.getTranslations(["Translate first text using platform from server", "Translate second text using platform from server"], { "targetLanguages": ["fr", "it"], "additionalParameters": [{"parameterName": "texttype", "parameterValue": "plain"}], "translator": 123 }))); } catch (error) { gs.error(error.message); }
Response:
{"code":"40003","message":"Translator (\"translator\" field) is invalid","status":"Error"}
## DynamicTranslation - isEnabled\(String translator\)
Determines whether the various methods in the DynamicTranslation API are enabled for a translation service.
If you pass in a specific translation service, the method checks the method activation for that translation service; otherwise the method checks the default translation service.
<table id="table_qx5_nwl_thb" class="parameters"><thead><tr><th>
Name
</th><th>
Type
</th><th>
Description
</th></tr></thead><tbody><tr><td>
translator
</td><td>
String
</td><td><p>Optional. Translation service to use to verify whether the methods are active. Translation services are configured under the Translator Configuration menu.Possible values - not case-sensitive:</p>
<ul>
<li>Google</li>
<li>Microsoft</li>
<li>IBM</li>
<li><custom></li>
</ul>
<p><strong>Note:</strong> To use custom translation services you must first configure the translation service in your instance. For details, see <a href="../../../platform-administration/dynamic-translation/integrate-translation-service-provider/">Integrate with a translation service provider</a>.</p>
<p>Default: Default translation service.</p></td></tr></tbody>
</table>
<table id="table_rx5_nwl_thb" class="returns"><thead><tr><th>
Type
</th><th>
Description
</th></tr></thead><tbody><tr><td>
batchDetection
</td><td>
Flag that indicates whether the getDetectedLanguages\(\) method is enabled.Possible values:
- false: Disabled
- true: Enabled
Data type: Boolean
</td></tr><tr><td>
batchTranslation
</td><td>
Flag that indicates whether the getTranslations\(\) method is enabled.Possible values:
- false: Disabled
- true: Enabled
Data type: Boolean
</td></tr><tr><td>
detection
</td><td>
Flag that indicates whether the getDetectedLanguage\(\) method is enabled.Possible values:
- false: Disabled
- true: Enabled
Data type: Boolean
</td></tr><tr><td>
translation
</td><td>
Flag that indicates whether the getTranslation\(\) method is enabled.Possible values:
- false: Disabled
- true: Enabled
Data type: Boolean
</td></tr><tr><td>
Error messages
</td><td>The following are error messages that the API may return and indications as to their root cause.- Translator ("translator" field) is invalid. (40003): The passed in <strong>translator</strong> parameter is not a string.</td></tr></tbody>
</table>
This example shows a server script that checks whether the DynamicTranslation methods are active for the Microsoft translator.