{"id":43958,"date":"2024-07-04T16:07:17","date_gmt":"2024-07-04T20:07:17","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=43958"},"modified":"2024-10-07T13:22:58","modified_gmt":"2024-10-07T17:22:58","slug":"translation-api-in-ios-17-and-macos-sequoia","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2024\/07\/04\/translation-api-in-ios-17-and-macos-sequoia\/","title":{"rendered":"Translation API in iOS 18 and macOS Sequoia"},"content":{"rendered":"<p><a href=\"https:\/\/www.macrumors.com\/2024\/06\/20\/apple-translation-framework\/\">Joe Rossignol<\/a>:<\/p>\n<blockquote cite=\"https:\/\/www.macrumors.com\/2024\/06\/20\/apple-translation-framework\/\">\n<p>In a WWDC 2024 coding video last week, Apple highlighted a recently-introduced API that allows developers to offer built-in Translate app capabilities in their own apps on iOS 17.4, iPadOS 17.4, macOS Sonoma, and later.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/developer.apple.com\/videos\/play\/wwdc2024\/10117\/\">Apple<\/a>:<\/p>\n<blockquote cite=\"https:\/\/developer.apple.com\/videos\/play\/wwdc2024\/10117\/\"><p>Discover how you can translate text across different languages in your app using the new Translation framework. We&rsquo;ll show you how to quickly display translations in the system UI, and how to translate larger batches of text for your app&rsquo;s UI.<\/p><\/blockquote>\n\n<p>Sequoia still doesn&rsquo;t bring the Translate app to the Mac, so I&rsquo;m hoping someone will use this to make  a standalone app so that I don&rsquo;t need to read translations within a tiny popover.<\/p>\n\n<p><a href=\"https:\/\/mastodon.social\/@iKyle\/112607672392333097\">Kyle Howells<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@iKyle\/112607672392333097\"><p>The new Translation API is such a massive disappointment.<\/p><p>It&rsquo;s a purely SwiftUI API.<\/p><p>Even the programatic API to get back Strings from Strings (no UI) requires you to get a session object via SwiftUI to do so.<\/p><p>[&#8230;]<\/p><p>Really hope this isn&rsquo;t a pattern Apple is going to use going forward in the future.<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/developer.apple.com\/documentation\/translation\/translationsession\">TranslationSession<\/a>:<\/p>\n<blockquote cite=\"https:\/\/developer.apple.com\/documentation\/translation\/translationsession\"><p>You don&rsquo;t instantiate this class directly. Instead, you obtain an instance of it by adding a <a href=\"https:\/\/developer.apple.com\/documentation\/SwiftUI\/View\/translationTask(_:action:)\"><code>translationTask(_:action:)<\/code><\/a> or <a href=\"https:\/\/developer.apple.com\/documentation\/SwiftUI\/View\/translationTask(source:target:action:)\"><code>translationTask(source:target:action:)<\/code><\/a> function to the SwiftUI view containing the content you want to translate, such as a <code>Text<\/code> view. When you do, the function passes you an instance of a translation session in its <code>action<\/code> closure which triggers as soon as the view appears. After you receive this instance, use one of the translate functions to translate one or more strings of text.<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/mastodon.social\/@iKyle\/112607698135869347\">Kyle Howells<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@iKyle\/112607698135869347\"><p>I wonder if these sort of horrible API designs are a consequence of Apple building features with SwiftUI natively now?<\/p><p>UIKit allows UI to be presented fairly freely from around your code, due to the view controller hierarchy being easily accessed.<\/p><p>SwiftUI needs an element anchored to a View to do anything.<\/p><p>If that&rsquo;s true, eventually virtually all APIs will need to be invoked via a method on View and I&rsquo;m going to really hate the next few years of Apple API releases.<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/10\/25\/translate-in-ios-17-and-macos-sonoma\/\">Translate in iOS 17 and macOS Sonoma<\/a><\/li>\n<\/ul>\n\n<p id=\"translation-api-in-ios-17-and-macos-sequoia-update-2024-10-07\">Update (2024-10-07): <a href=\"https:\/\/captainswiftui.substack.com\/p\/translations-concurrency-pattern\">Danny Bolella<\/a>:<\/p>\n<blockquote cite=\"https:\/\/captainswiftui.substack.com\/p\/translations-concurrency-pattern\"><p>Curiously, the manner in which Apple forces developers to use Translation is strikingly passive aggressive: it can be accessed by SwiftUI <strong>only<\/strong>. This has been confirmed by an <a href=\"https:\/\/developer.apple.com\/forums\/thread\/756837?answerId=791116022#791116022\">Apple Engineer<\/a> who suggests UIKit apps would need to host a SwiftUI View if it would like to access Translation.<\/p><p>[&#8230;]<\/p><p>There are <em>strong<\/em> implications and signals to take from all this, even if a translation feature doesn&rsquo;t apply to you. In fact, it has some of the strongest messaging regarding Apple&rsquo;s recent stance on UIKit and SwiftUI.<\/p><p>[&#8230;]<\/p><p>There&rsquo;s no doubt that UIKit and AppKit are not to be deprecated any time soon (or ever). But Apple has made it <em>abundantly<\/em> clear the tide will eventually turn towards SwiftUI, and they will make it so.<\/p><p>[&#8230;]<\/p><p>Translation also offers a glimpse into how Apple wants developers to view the relationship between concurrency and SwiftUI. When we obtain a TranslationSession through the programmatic route, it&rsquo;s done so through a translationTask and offers function calls that are all async.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Joe Rossignol: In a WWDC 2024 coding video last week, Apple highlighted a recently-introduced API that allows developers to offer built-in Translate app capabilities in their own apps on iOS 17.4, iPadOS 17.4, macOS Sonoma, and later. Apple: Discover how you can translate text across different languages in your app using the new Translation framework. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2024-07-04T20:07:21Z","apple_news_api_id":"d1c9d9c5-9fb9-4291-b307-0261300e9076","apple_news_api_modified_at":"2024-10-07T17:23:01Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAQ==","apple_news_api_share_url":"https:\/\/apple.news\/A0cnZxZ-5QpGzBwJhMA6Qdg","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[31,2586,865,30,2598,71,1812,2216],"class_list":["post-43958","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-ios","tag-ios-18","tag-language-translation","tag-mac","tag-macos-15-sequoia","tag-programming","tag-swiftui","tag-translate-app"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/43958","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=43958"}],"version-history":[{"count":3,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/43958\/revisions"}],"predecessor-version":[{"id":45263,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/43958\/revisions\/45263"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=43958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=43958"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=43958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}