Platforms to show: All Mac Windows Linux Cross-Platform

Back to TranslationSessionMBS class.

TranslationSessionMBS.Cancel

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Translation MBS Swift Plugin 26.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Attempts to stop all ongoing work for the translation session.

Future requests will throw an error that the session is already cancelled.
Requires macOS 26.0 or iOS 26.0 or later.

TranslationSessionMBS.Constructor(fromLanguageIdentifier as String, toLanguageIdentifier as String = "")

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Translation MBS Swift Plugin 26.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates a translation session to translate between a given source and target language already installed on device.
Example
// translate from German to English
var session as new TranslationSessionMBS("de", "en")

if session.isReady then
messageBox "Ready to translate"
else
messageBox "Not ready. User may need to download languages."
end if

If one or both of the languages aren't installed on the device already, attempting to translate will throw errors.

toLanguageIdentifier is optional and if empty will default to the users current locale.

TranslationSessionMBS.isReady as Boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Translation MBS Swift Plugin 26.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Synchronous version of isReady.

Waits for callback and returns result.
Requires macOS 26.0 or iOS 26.0 or later.

See also:

TranslationSessionMBS.isReady(completed as TranslationReadyCompletedMBS, Tag as Variant = nil)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Translation MBS Swift Plugin 26.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Queries a boolean value that indicates whether the system has installed the source and target languages of the session and is ready to begin translation.
Example
// translate from German to English
var session as new TranslationSessionMBS("de", "en")

if session.isReady then
messageBox "Ready to translate"
else
messageBox "Not ready. User may need to download languages."
end if

Use this property to check whether a translation is likely to succeed. In a session that can request downloads, it prompts the person to approve downloads if languages aren't ready yet. In a session that can't request downloads, it will throw an error if the person calls any functions when languages aren't ready.

Note: This value returns whether the languages are currently installed. The person or system can still delete the downloaded languages after calling this, so make sure you handle the appropriate errors when calling one of the translate functions.

The tag value is passed through to the delegate.

Requires macOS 26.0 or iOS 26.0 or later.

See also:

TranslationSessionMBS.prepareTranslation(completed as TranslationPrepareTranslationCompletedMBS, Tag as Variant = nil)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Translation MBS Swift Plugin 26.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Asks for permission to download translation languages without doing any translations.

If you know ahead of time which languages the person needs to translate, you can prompt them to download those languages in advance by calling this method.

When you call this method, the framework asks the person for permission to download the sourceLanguage and targetLanguage. If the languages are already installed or in the middle of downloading, the function returnswithout prompting them.

If you call this function when the sourceLanguage is empty, it unableToIdentifyLanguage error, since there's no sample text to identify which source language to use for translation.

The tag value is passed through to the delegate.

TranslationSessionMBS.translateBatch(Requests() as TranslationRequestMBS, completedOne as TranslateStringCompletedMBS, completed as TranslationsCompletedMBS, Tag as Variant = nil)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Translation MBS Swift Plugin 26.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Translates multiple strings of text of the same language, returning a sequence of responses as they're available.

This function translates multiple strings of text incrementally and might display different UI depending on the state of the translation. The required languages for translation don't have to be installed before calling this method.

/ Pass in the strings of text you want to translate as an array of the Request type. Set the Request/clientIdentifier on each request so you can match the request with the response as the translations incrementally return.

If the required languages for translation have already downloaded and the source language is clear, this function returns results without showing any UI to the person.

If the source or target language aren't installed, the framework asks the person for permission to download the languages. During the download a progress indicator displays. After it completes, the framework performs the translation.

If the sourceLanguage is empty and the framework can't detect the source language from the content, the framework prompts the person to choose the source language.

The framework only supports string translations of the same language. The strings must either match the sourceLanguage you set in the configuration, or if the sourceLanguage is nil, be of the same language.

This function throws an Error if:

  • The person doesn't agree to downloading the languages
  • The person dismisses the progress view during language downloads
  • TranslationSession fails system validation
  • The session doesn't allow requesting downloads and languages aren't installed
  • You already cancelled the session
  • Something goes wrong during translation

If a person dismisses the progress view while the languages download, the system throws a usercancelled error, and the languages continue to download in the background.

Note: Calls to this function can take several minutes while languages download.

Calls the completedOne delegate (if not nil) for each translation as they are ready in random order. Then later calls completed event (if not nil)

The tag value is passed through to the delegate.

TranslationSessionMBS.translateString(text as String) as TranslationResponseMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Translation MBS Swift Plugin 26.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Synchronous version of translateString.
Example
Var session as new TranslationSessionMBS("en", "de")
Var Translation as TranslationResponseMBS = session.translateString("Hello World")
MessageBox "Translation of Hello World to German: "+Translation.targetText

Waits for callback and returns result.

See also:

TranslationSessionMBS.translateString(text as String, completed as TranslateStringCompletedMBS, Tag as Variant = nil)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Translation MBS Swift Plugin 26.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Translates a single string of text.
Example
Var session as new TranslationSessionMBS("en", "de")
Var Translation as TranslationResponseMBS = session.translateString("Hello World")
MessageBox "Translation of Hello World to German: "+Translation.targetText

This function translates a single line of text and might display different UI depending on the state of the translation. The required languages for translation don't have to be installed before calling this method.

If the required languages for translation have already downloaded and the source language is clear, this function returns results without showing any UI to the person.

If the source or target language aren't installed, the framework asks the person for permission to download the languages. During the download a progress indicator displays. After it completes, the framework performs the translation.

If the sourceLanguage is empty and the framework can't detect the source language from the content, the framework prompts the person to choose the source language.

This function throws an Error if:

  • The person doesn't agree to downloading the languages
  • The person dismisses the progress view during language downloads
  • TranslationSession fails system validation - The session doesn't allow requesting downloads and languages aren't installed
  • You already cancelled the session - Something goes wrong during translation

If a person dismisses the progress view while the languages download, the system throws a usercancelled error, and the languages continue to download in the background.

Note: This function call can take several minutes while languages download.

The tag value is passed through to the delegate.

See also:

TranslationSessionMBS.translations(Requests() as TranslationRequestMBS) as TranslationResponseMBS()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Translation MBS Swift Plugin 26.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Synchronous version of translations.
Example
// we translate from English to German
var session as new TranslationSessionMBS("en", "de")

// build an array of requests
var r1 as new TranslationRequestMBS("Hello World", "1")
var r2 as new TranslationRequestMBS("Just a test", "2")
var requests() as TranslationRequestMBS = array(r1, r2)

// we ask for translation
var responses() as TranslationResponseMBS = session.translations(requests)

// collect result and show
var texts() as string
for each response as TranslationResponseMBS in responses
texts.add response.clientIdentifier + ": " + response.targetText
next
MessageBox string.FromArray(texts, EndOfLine)

Waits for callback and returns result.

See also:

TranslationSessionMBS.translations(Requests() as TranslationRequestMBS, completed as TranslationsCompletedMBS, Tag as Variant = nil)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Translation MBS Swift Plugin 26.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Translates multiple strings of text of the same language, returning the results all at once when complete.

This function translates multiple strings as a batch and might display different UI depending on the state of the translation. The languages the framework requires for the translation don't have to be installed before calling this method.

Pass in the strings of text you want to translate as an array of the Request type. This method takes longer to return than translateBatch, but it has the advantage of not having to map translation requests to responses. The responses return in the same order the requests are sent.

If the required languages for translation have already downloaded and the source language is clear, this function returns results without showing any further prompts to the person.

If the source or target language aren't installed, the framework asks the person for permission to download the languages. During download a progress indicator displays. After the download completes, the framework performs the translation.

If the sourceLanguage is empty and the framework can't detect the source language from the content, the framework prompts the person to choose the source language.

The framework only supports string translations of the same language. The strings must either match the sourceLanguage you set in the configuration, or if the sourceLanguage is empty, be of the same language.

This function throws an Error if: - The person doesn't agree to downloading the languages - The person dismisses the progress view during language downloads - TranslationSession fails system validation - The session doesn't allow requesting downloads and languages aren't installed - You already cancelled the session - Something goes wrong during translation

If a person dismisses the progress view while the languages download, the system throws a usercancelled error, and the languages continue to download in the background.

Note: Calls to this function can take several minutes while languages download.

The tag value is passed through to the delegate.

See also:

The items on this page are in the following plugins: MBS Swift Plugin.


The biggest plugin in space...