<!--
{
  "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/Configuration",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Translation"
    ],
    "preciseIdentifier" : "s:11Translation0A7SessionC13ConfigurationV"
  },
  "title" : "TranslationSession.Configuration"
}
-->

# TranslationSession.Configuration

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

```
struct Configuration
```

## Overview

Specify the source and target languages to use in a translation session with this object.
Initialize an instance of this type using the [`init(source:target:)`](/documentation/Translation/TranslationSession/Configuration/init(source:target:)) and
passing in the `source` and `target` languages.
When you pass this configuration into the <doc://com.apple.documentation/documentation/SwiftUI/View/translationTask(_:action:)>  function,
the framework uses the languages you specify for translation.

To re-run a translation, store the configuration object as state in your SwiftUI view by using the `State` property wrapper.
Then change one of the configuration properties (such as the source or target language) to re-run
the translation on a new pair of languages.
You can also call [`invalidate()`](/documentation/Translation/TranslationSession/Configuration/invalidate()) on the configuration instance to re-run the translation using the same languages with new content to translate.
When you do, the action closure of <doc://com.apple.documentation/documentation/SwiftUI/View/translationTask(_:action:)>
runs and the framework translates the text.

The following example demonstrates how to initiate a new translation from a button press:

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

    @State private var targetText: String?
    @State private var configuration: TranslationSession.Configuration?

    var body: some View {
        VStack {
            Text(targetText ?? sourceText)
            Button("Translate") {
                guard configuration != nil else {
                    configuration = TranslationSession.Configuration(
                        source: sourceLanguage,
                        target: targetLanguage)
                    return
                }
                self.configuration.invalidate()
            }
        }
        .translationTask(configuration) { session in
            do {
                let response = try await session.translate(sourceText)
                targetText = response.targetText
            } catch {
                // Handle error.
            }
        }
    }
}
```

## Topics

### Creating a configuration

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

Creates a configuration from a source and target language.

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

Creates a configuration from a source and target language.

### Specifying translation languages

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

The language to translate content from.

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

The language to translate content into.

### Configuring translation behavior

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

The translation approach for this configuration.

### Updating the translation

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

Invalidate the current translation session and re-run it with new content.

### Comparing configurations

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

A value the equals function uses to represent change in the configuration instance.



---

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)