One Logo Pool Ball
Translation · IOS API REFERENCE

TranslationSession.Response

struct · iOS 18.0+ · SDK 27.1

struct Response

The response to a translation request. You get a single response structure after you translate a string, or when you call one of the batch translation methods passing in an array of translation requests. When the translation completes, a response instance returns with the translation result along with properties the framework used to perform the translation.

Members (9)

get · iOS 18.0+

sourceText

TypeScript
get sourceText(): string
Swift declaration
let sourceText: String

The original text to translate from.

get · iOS 18.0+

targetText

TypeScript
get targetText(): string
Swift declaration
let targetText: String

The translated text.

init · iOS 26.4+

init

TypeScript
static initSourceLanguageTargetLanguageSourceAttributedTextTargetAttributedTextClientIdentifier(sourceLanguage: _Foundation_Locale_Language, targetLanguage: _Foundation_Locale_Language, sourceAttributedText: _Foundation_AttributedString, targetAttributedText: _Foundation_AttributedString, clientIdentifier?: (string) | null): TranslationSession_Response
Swift declaration
init(sourceLanguage: Locale.Language, targetLanguage: Locale.Language, sourceAttributedText: AttributedString, targetAttributedText: AttributedString, clientIdentifier: String? = nil)

Creates an instance of a translation response with formatted text. You don't normally use this initializer directly. Instead, let the translation functions create instances of this type for you. Use this initializer when you want to create sample response for a test, for example in a SwiftUI preview.

init · iOS 18.0+

init

TypeScript
static initSourceLanguageTargetLanguageSourceTextTargetTextClientIdentifier(sourceLanguage: _Foundation_Locale_Language, targetLanguage: _Foundation_Locale_Language, sourceText: string, targetText: string, clientIdentifier?: (string) | null): TranslationSession_Response
Swift declaration
init(sourceLanguage: Locale.Language, targetLanguage: Locale.Language, sourceText: String, targetText: String, clientIdentifier: String? = nil)

Creates an instance of a translation response. You don't normally use this initializer directly. Instead, let the translation functions create instances of this type for you. Use this initializer when you want to create sample response for a test, for example in a SwiftUI preview.

get · iOS 18.0+

sourceLanguage

TypeScript
get sourceLanguage(): _Foundation_Locale_Language
Swift declaration
let sourceLanguage: Locale.Language

The language that the framework translated the text from.

get · iOS 18.0+

targetLanguage

TypeScript
get targetLanguage(): _Foundation_Locale_Language
Swift declaration
let targetLanguage: Locale.Language

The language that the framework translated the text into.

get · iOS 18.0+

clientIdentifier

TypeScript
get clientIdentifier(): (string) | null
Swift declaration
let clientIdentifier: String?

The unique identifier matching the client identifier set in the translation request. Use this identifier to associate a translation request with its response. If you set a client identifier in the translation request, that same identifier returns in the response. If the request contained no identifier, this value is `nil`.

get · iOS 26.4+

attributedSourceText

TypeScript
get attributedSourceText(): (_Foundation_AttributedString) | null
Swift declaration
let attributedSourceText: AttributedString?

The original translated text, including style formatting and links. When translating attributed strings using any translation method, the framework makes a best effort to preserve both visual formatting and defined attributes. This enables use cases like timestamp synchronization for captions or lyrics. For examples of translating text with preserved attributes, see ``TranslationSession/Request/attributedSourceText``.

get · iOS 26.4+

attributedTargetText

TypeScript
get attributedTargetText(): (_Foundation_AttributedString) | null
Swift declaration
let attributedTargetText: AttributedString?

The translated formatted text. This property contains the translated text with formatting and defined attributes preserved and aligned from the source text. The framework makes a best effort to preserve attributes like accessibility instructions and time ranges, aligning them to the corresponding words in the target language. > Note: The framework preserves but doesn't modify attributes. To use the correct language after translation, update any attributes that need to reflect the target language, such as the language modifier for VoiceOver. For examples of translating attributed source text, see ``TranslationSession/Request/attributedSourceText``.

Skipped declarations

No declarations were skipped in this snapshot.

All Translation types →