Back to Devexpress

ITranslationService Interface

xtrareports-js-devexpress-dot-reporting-dot-designer-dot-localization.md

latest3.1 KB
Original Source

ITranslationService Interface

Defines the interface used to access a remote translation service.

Declaration

ts
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.

js
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

ts
onRequest: (texts: string[], destinationLanguage: string, destinationLanguageText?: string) => JQueryAjaxSettings | DevExpress.Analytics.Internal.DxPromise

Property Value

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

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

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

Property Value

TypeDescription
(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.