Back to Devexpress

IAIDocProcessingService.TranslateAsync(Slide, CultureInfo, CancellationToken) Method

officefileapi-devexpress-dot-aiintegration-dot-docs-dot-iaidocprocessingservice-dot-translateasync-x28-devexpress-dot-docs-dot-presentation-dot-slide-system-dot-globalization-dot-cultureinfo-system-dot-threading-dot-cancellationtoken-x29.md

latest5.0 KB
Original Source

IAIDocProcessingService.TranslateAsync(Slide, CultureInfo, CancellationToken) Method

Translates slide content into a specific language with AI-powered translation services.

Namespace : DevExpress.AIIntegration.Docs

Assembly : DevExpress.AIIntegration.Docs.v25.2.dll

NuGet Package : DevExpress.AIIntegration.Docs

Declaration

csharp
Task TranslateAsync(
    Slide slide,
    CultureInfo culture,
    CancellationToken cancellationToken = default(CancellationToken)
)
vb
Function TranslateAsync(
    slide As Slide,
    culture As CultureInfo,
    cancellationToken As CancellationToken = Nothing
) As Task

Parameters

NameTypeDescription
slideSlide

The Slide instance which content should be translated.

| | culture | CultureInfo |

An object that specifies culture settings applied during translation.

|

Optional Parameters

NameTypeDefaultDescription
cancellationTokenCancellationTokennull

The token that cancels the task.

|

Returns

TypeDescription
Task

The response that contains AI-generated translation.’

|

Example

How to: Translate the First Slide in the Presentation

The following code snippet translates the first slide in a presentation:

csharp
using DevExpress.AIIntegration;
using DevExpress.AIIntegration.Docs;
using DevExpress.Docs.Presentation;
using Microsoft.Extensions.AI;

// See "Register AI extension service" section for implementation code
docProcessingService docProcessingService = 
        defaultAIExtensionsContainer.CreateAIDocProcessingService();

var presentation = 
        new Presentation(File.ReadAllBytes("Documents/Presentation.pptx"));

await docProcessingService.TranslateAsync(
        presentation.Slides[0], 
        new System.Globalization.CultureInfo("DE-DE"));

// Save the modified document
FileStream outputStream = File.OpenWrite(
        Path.Combine(
                Path.Combine(
                        Environment.CurrentDirectory, 
                        $"presentation_translated.pptx")));
presentation.SaveDocument(outputStream, DocumentFormat.Pptx);
outputStream.Close();
vb
Imports DevExpress.AIIntegration
Imports DevExpress.AIIntegration.Docs
Imports DevExpress.Docs.Presentation
Imports Microsoft.Extensions.AI
Imports System.Globalization
Imports System.IO

' See "Register AI extension service" section for implementation code
var docProcessingService = 
        defaultAIExtensionsContainer.CreateAIDocProcessingService()

Dim presentation As New Presentation(File.ReadAllBytes("Documents/Presentation.pptx"))

Await docProcessingService.TranslateAsync(
        presentation.Slides(0), 
        New CultureInfo("DE-DE"))

' Save the modified document
Dim outputStream As FileStream = File.OpenWrite(Path.Combine(Environment.CurrentDirectory, "presentation_translated.pptx"))
presentation.SaveDocument(outputStream, DocumentFormat.Pptx)
outputStream.Close()

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the TranslateAsync(Slide, CultureInfo, CancellationToken) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

office-file-api-ai-implementation/CS/Controllers/TranslateController.cs#L37

csharp
var slide = presentation.Slides[0];
await docProcessingService.TranslateAsync(slide, language);
break;

See Also

IAIDocProcessingService Interface

IAIDocProcessingService Members

DevExpress.AIIntegration.Docs Namespace