iOS 18 Translation API availability for UIKit

After reading the documentation for TranslationSession and other API methods I got an impression that it will not be possible to use the Translation API with UI elements built with UIKit.

You don’t instantiate this class directly. Instead, you obtain an instance of it by adding a translationTask(_:action:) or translationTask(source:target:action:) function to the SwiftUI view containing the content you want to translate

So the main question I have to the engineers of mentioned framework is will there be any support for UIKit or app developers will have to rewrite their apps in SwiftUI just to be able to use the Translation API?

Answered by Engineer in 793840022

Hello and thanks for your question and interest in the Translation API.

These APIs do only work from SwiftUI, but it's not necessary to rewrite your app if you're using UIKit or AppKit. You can use a UIHostingController in the spot where you want to trigger translation, and keep the rest of your app as-is.

There's a bit more detail in this reply on another post: https://developer.apple.com/forums/thread/756837?answerId=791116022#791116022

Accepted Answer

Hello and thanks for your question and interest in the Translation API.

These APIs do only work from SwiftUI, but it's not necessary to rewrite your app if you're using UIKit or AppKit. You can use a UIHostingController in the spot where you want to trigger translation, and keep the rest of your app as-is.

There's a bit more detail in this reply on another post: https://developer.apple.com/forums/thread/756837?answerId=791116022#791116022

iOS 18 Translation API availability for UIKit
 
 
Q