Skip to main content

ITranslationService Interface

Defines the interface used to access a remote translation service.

Declaration

export interface ITranslationService

Remarks

The following code snippet demonstrates how to implement the ITranslationService interface and pass it as a parameter to the registerTranslationService function:

Note

The complete sample project How to Use the Microsoft Azure Translator Text API in Report Localization is available in the DevExpress Examples repository.

function BeforeDesignerRender(s, e) {
    DevExpress.Reporting.Designer.Localization.registerTranslationService("AzureCognitiveService", {
        onRequest: (texts, language) => {
            var data = { 'Texts': texts.map(text => ({ 'Text': text })), 'Language': language };
            return {
                type: "POST",
                url: '/Home/GetAzureTranslationService',
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                processData: true,
                data: JSON.stringify(data),
                error: function (xhr) {
                    DevExpress.ui.notify(xhr.statusText, "error", 500);
                }
            };
        },
        onResponse: (data) => {
            if (data.error && data.error.message) {
                DevExpress.ui.notify(data.error.message, "warning", 500);
                return [];
            }
            return data.map(function (item) {
                return item.translations[0].text
            });
        }
    });
}

Properties

onRequest Property

Specifies a function that is called before a HTTP request is sent.

Declaration

onRequest: (texts: string[], destinationLanguage: string) => JQueryAjaxSettings

Property Value

Type Description
(texts: string[], destinationLanguage: string) => JQueryAjaxSettings

Specifies a function that takes an array of strings and a string and returns a JQueryAjaxSettings object that is a set of key/value pairs that configure the Ajax request.

Remarks

The specified function should construct an Ajax request for a remote translation service.

onResponse Property

Specifies a function that is called when a HTTP response is received.

Declaration

onResponse: (result: any) => string[]

Property Value

Type Description
(result: any) => string[]

A function that takes a response result value and converts it to an array of strings.

Remarks

The specified function should convert information received from a remote translation service to an array of text strings.