<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 15.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Translation",
  "identifier" : "/documentation/Translation/TranslationSession",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Translation"
    ],
    "preciseIdentifier" : "s:11Translation0A7SessionC"
  },
  "title" : "TranslationSession"
}
-->

# TranslationSession

A class that performs translations between a pair of languages.

```
class TranslationSession
```

## Overview

This class provides a flexible way for you to translate one or more lines of text at a time.
There are two ways in which you can initialize a `TranslationSession`.
One way you can obtain an instance of this class is by adding a `.translationTask()` to a SwiftUI view within your app.
You can either add a <doc://com.apple.documentation/documentation/SwiftUI/View/translationTask(_:action:)> or a <doc://com.apple.documentation/documentation/SwiftUI/View/translationTask(source:target:action:)>
function to the SwiftUI view containing the content you want to translate, like a <doc://com.apple.documentation/documentation/SwiftUI/Text> view.
After adding the task, the function passes you an instance of a translation session in its `action` closure.
With this instance, you can use one or more of the translate functions to translate a single string or multiple strings of text.

Another way for contexts where there’s no UI, you can directly initialize the TranslationSession using [`init(installedSource:target:)`](/documentation/Translation/TranslationSession/init(installedSource:target:)) to translate between languages.
This initializer requires that you specify which source language you use and throws an error if the languages aren’t already installed on the person’s device.

The following example demonstrates how to translate a single string of text within a SwiftUI view:

```
struct TranslationExample: View {
    var sourceText: String
    var sourceLanguage: Locale.Language?
    var targetLanguage: Locale.Language?

    @State private var targetText: String?

    var body: some View {
        Text(targetText ?? sourceText)
            .translationTask(
                source: sourceLanguage,
                target: targetLanguage
            ) { session in
                do {
                    let response = try await session.translate(sourceText)
                    targetText = response.targetText
                } catch {
                    // Handle error.
                }
            }
    }
}
```

> Note: All translations using the `TranslationSession` class are processed on the user’s device. Apple
> may collect API usage and performance metrics including the app bundle ID and the original and translated
> language, but this data does not include the original or translated content.

## Topics

### Initalizing a translation session

[`init(installedSource:target:)`](/documentation/Translation/TranslationSession/init(installedSource:target:))

Creates a translation session to translate between a given source and target language already installed on device.

[`init(installedSource:target:preferredStrategy:)`](/documentation/Translation/TranslationSession/init(installedSource:target:preferredStrategy:))

Creates a translation session to translate between a given source and target language already
installed on device.

### Preparing for translation

[`TranslationSession.Configuration`](/documentation/Translation/TranslationSession/Configuration)

A type containing the information to use when performing a translation.

[`prepareTranslation()`](/documentation/Translation/TranslationSession/prepareTranslation())

Asks for permission to download translation languages without doing any translations.

### Getting the language configuration

[`sourceLanguage`](/documentation/Translation/TranslationSession/sourceLanguage)

The input language to translate from.

[`targetLanguage`](/documentation/Translation/TranslationSession/targetLanguage)

The output language to translate into.

### Translating the text

[`translate(_:)`](/documentation/Translation/TranslationSession/translate(_:)-59zi2)

Translates a formatted string of text, preserving formatting in the translation.

[`translate(_:)`](/documentation/Translation/TranslationSession/translate(_:)-4m20l)

Translates a single string of text.

[`translate(batch:)`](/documentation/Translation/TranslationSession/translate(batch:))

Translates multiple strings of text of the same language, returning a sequence of responses as they’re available.

[`translations(from:)`](/documentation/Translation/TranslationSession/translations(from:))

Translates multiple strings of text of the same language, returning the results all at once when complete.

[`TranslationSession.Request`](/documentation/Translation/TranslationSession/Request)

A translation request containing a single item of text to translate.

[`TranslationSession.Response`](/documentation/Translation/TranslationSession/Response)

The response to a translation request.

[`TranslationSession.BatchResponse`](/documentation/Translation/TranslationSession/BatchResponse)

A type that provides asynchronous access to translation responses.

### Accessing the session properties

[`canRequestDownloads`](/documentation/Translation/TranslationSession/canRequestDownloads)

A boolean value that indicates whether a translation session can request language downloads.

[`isReady`](/documentation/Translation/TranslationSession/isReady)

A boolean value that indicates whether the system has installed the source and target languages of the session and is ready to begin translation.

[`preferredStrategy`](/documentation/Translation/TranslationSession/preferredStrategy)

The preferred translation strategy configured for the session.

### Canceling a translation session

[`cancel()`](/documentation/Translation/TranslationSession/cancel())

Attempts to stop all ongoing work for the translation session.

### Configuring translation strategy

[`TranslationSession.Strategy`](/documentation/Translation/TranslationSession/Strategy)

The preferred model to handle translations in your app.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)