Using Translation API in Swift and SwiftUI

Simon Ng
AppCoda Tutorials
Published in
5 min readJul 1, 2024

--

iOS already includes a system-wide translation feature that allows users to easily translate text into various languages. With the release of iOS 17.4 (and iOS 18), you can now leverage the new Translation API to integrate this powerful translation capability into your apps.

Apple provides two options for developers to utilize the Translation API. The quickest and simplest method is to use the .translationPresentation modifier, which displays a translation overlay in your app. For a more flexible solution, you can directly call the Translation API to build a custom translation feature.

In this tutorial, we will explore both approaches and guide you through their implementation using a SwiftUI demo app. Please note that you will need Xcode 16 to follow along.

Using the translationPresentation Modifier

Let’s start with the straightforward approach: the .translationPresentation modifier. In Safari, users can highlight any text to access the translation option, which then displays a translation overlay with the translated text.

If you want to bring this translation overlay to your app, all you need is to import the Translation package and use the .translationPresentation modifier. Take a look at the following sample code:

--

--

Simon Ng
AppCoda Tutorials

Founder of AppCoda. iOS Developer and Indie Entrepreneur. Love coffee, food and travel. http://www.appcoda.com