Skip to main content
All docs
V25.1
  • ITranslationService Interface

    Defines the interface used to access a remote translation service.

    Declaration

    export interface ITranslationService

    Remarks

    Tip

    You can activate the built-in AI-powered Localization functionality in your ASP.NET Core and Blazor applications.

    Refer to the following help topic for more information: Localize Reports in the Web Report Designer.

    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, destinationLanguageText?: string) => JQueryAjaxSettings | DevExpress.Analytics.Internal.DxPromise

    Property Value

    Type
    (texts: string[], destinationLanguage: string, destinationLanguageText?: string) => JQueryAjaxSettings | DxPromise<any>

    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.