DynamicTranslation - Client
-
- UpdatedJan 30, 2025
- 19 minutes to read
- Yokohama
- API reference
The DynamicTranslation API provides methods that translate text, in real time, into multiple languages using translation service providers. This API is available for both standard clients and Angular-based Service Portal clients.
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.
To use this API you must activate the Dynamic Translation plugin. For information on this plugin and additional information on Dynamic Translation, refer to Dynamic translation overview. Also, to use this API in a Service Portal widget, you must inject the dynamicTranslation service into the widget client script function.
DynamicTranslation - getDetectedLanguage(String text, Object parms)
Detects the language of the passed in text.
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 | 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:
Note: To use custom translation services you must first configure the translation service in your instance. For details, see Integrate with a translation service provider. Default: Translation service configured in the Translator Configuration [sn_dt_translator_configuration] table. Table: Translator Configuration [sn_dt_translator_configuration] |
Example
This example shows code that detects a string in English using IBM's translation service in a standard client script.
Output:
Example
This example shows a client script that throws an error when an invalid translation service is passed in.
Output:Example
This example shows code that detects a string in English using IBM's translation
service in a Service Portal
widget client script. Note that the name of the class is dynamicTranslation
not
DynamicTranslation
.
Example
This example shows a Service Portal widget client script that throws an error when an invalid translation service is passed in.
Output:DynamicTranslation - getDetectedLanguages(Array texts, Object parms)
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.
When calling this method from a portal client script, use the class name dynamicTranslation; such as dynamicTranslation.getTranslations(). When calling it from a platform client script, use the class name DynamicTranslation; such as DynamicTranslation.getTranslations().
Name | Type | Description |
---|---|---|
parms | Object | Optional. JSON object that contains additional translation parameters. |
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:
Note: To use custom translation services you must first configure the translation service in your instance. For details, see Integrate with a translation service provider. Default: Translation service configured in the Translator Configuration [sn_dt_translator_configuration] table. Table: Translator Configuration [sn_dt_translator_configuration] |
texts | Array | List of text strings to use to detect the language(s). |
Example
This example shows code from a portal client script that detects English as the language of the passed-in strings using the Microsoft translation service.
Output
Example
This example shows code in a portal client script that returns a Partial status when two
text strings are passed in and one of them is invalid. To use this code example in a
platform client script, change dynamicTranslation.getDetectedLanguages
to
DynamicTranslation.getDetectedLanguages
.
Output
Example
This example shows code from a portal client script that throws an error when an invalid
translation service is passed in. To use this code example for a platform client script,
change dynamicTranslation.getDetectedLanguages
to
DynamicTranslation.getDetectedLanguages
.
Output
DynamicTranslation - getTranslation(String textToTranslate, Object parms)
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.
Example
This example shows the translation of plain text content from English (detected) into French and Italian using Microsoft's translation service in a standard client script.
Response:
Example
This example shows a client script that throws an error when an invalid target language is passed in.
Response:
Example
This example shows the translation of plain text content from English (detected) into
French and Italian using Microsoft's translation service in a Service Portal widget client
script. Note that the name of the class is dynamicTranslation
not
DynamicTranslation
.
Response:
Example
This example shows a Service Portal widget client script that throws an error when an invalid target language is passed in
Response:
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.
When calling this method from a portal client script, use the class name dynamicTranslation; such as dynamicTranslation.getTranslations(). When calling it from a platform client script, use the class name DynamicTranslation; such as DynamicTranslation.getTranslations().
Example
This example shows code in a portal client script that translates a list of text strings into French and Italian using the Microsoft translation service.
Response:
Example
This example shows a portal client script that returns a Partial status when one of the two
passed in text strings is invalid. To use this code example for a platform client script,
change dynamicTranslation.getTranslations
to
DynamicTranslation.getTranslations
.
Response:
Example
This example shows a portal client script that throws an error when an invalid translation
service is passed in. To use this code example for a platform client script, change
dynamicTranslation.getTranslations
to
DynamicTranslation.getTranslations
.
Response:
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.
When calling this method from a portal client script, use the class name dynamicTranslation; such as dynamicTranslation.isEnabled(). When calling it from a platform client script, use the class name DynamicTranslation; such as DynamicTranslation.isEnabled().
Name | Type | Description |
---|---|---|
translator | String | 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:
Note: To use custom translation services you must first configure the translation service in your instance. For details, see Integrate with a translation service provider. Default: Default translation service. |
Example
This example shows a client script that checks whether the
DynamicTranslation methods are enabled for the Microsoft translation
service. To use this code example for a platform client script, change
DynamicTranslation.getTranslations
to
dynamicTranslation.getTranslations
.
Output:
Example
This example shows a client script that throws an error when an invalid translation service
is passed in. To use this code example for a platform client script, change
DynamicTranslation.getTranslations
to
dynamicTranslation.getTranslations
.
Output:
On this page
- DynamicTranslation - getDetectedLanguage(String text, Object parms)
- DynamicTranslation - getDetectedLanguages(Array texts, Object parms)
- DynamicTranslation - getTranslation(String textToTranslate, Object parms)
- DynamicTranslation - getTranslations(Array texts, Object parms)
- DynamicTranslation - isEnabled(String translator)