-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Integrate Translation framework #25089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
8f8dc24 to
866bd15
Compare
| } | ||
| translationAvailabilityTask?.cancel() | ||
| translationAvailabilityTask = Task { @MainActor in | ||
| self.isTranslationAvailable = await self.checkIsTranslationAvailable() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It creates a little bit of a race condition, but in practice, it's extremely fast so it should not matter.
|
| App Name | WordPress | |
| Configuration | Release-Alpha | |
| Build Number | 30286 | |
| Version | PR #25089 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | 14cb490 | |
| Installation URL | 5l5l47t494ndg |
|
| App Name | Jetpack | |
| Configuration | Release-Alpha | |
| Build Number | 30286 | |
| Version | PR #25089 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | 14cb490 | |
| Installation URL | 749q3uftjths0 |
| } | ||
|
|
||
| private lazy var _translationViewModel: Any = { | ||
| guard #available(iOS 26, *) else { return {} } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how I feel about this pattern... I guess it's fine, since the else block is dead code because the caller only runs on iOS 26+. But maybe there is another better (in terms of readability) way to code this?
|
|
||
| // Use continuation to wait for translation result | ||
| return try await withCheckedThrowingContinuation { continuation in | ||
| self.continuation = continuation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems a bit risky to hold the continuation instances at the class level, instead of locally in the function.
|
I couldn't get the translation to work. I can see the UI from the Translation framework, but after selecting languages, the app shows an "Unable to translate" error message. There are 100+ repeating error messages in Xcode console: |
I forgot to mention that it requires a physical device. Have you tried on a physical one or a sim? |
|
@kean Yes, I used my iPhone 16. I also downloaded the Chinese and English languages in the Translate app, which I don't think is necessary, but just in case. |
…it never restarts the translation if already started
|
I've tested a few other scenarios and found and fixed some issues:
I also opened the following issue: CMM-1107: Post translation in Reader sometimes breaks the HTML tags. I don't think there is an easy fix, so I'm not planning to address it in the scope of the PR. I've tested a couple of posts in Mandarin, and it worked for me. Would you mind sharing a post for which the translation fails? ScreenRecording_01-05-2026.18-11-50_1.MP4 |
|
The translation works on my iPhone now. What do you think about adding a button to revert back to the original content? |
crazytonyli
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still feel like the indirection between setting the configuration property to trigger the translation process and getting the translated result can be improved.
| guard #available(iOS 26, *) else { | ||
| return | ||
| } | ||
| let hostingController = UIHostingController(rootView: translationHostView) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's annoying that the Translation framework does not support UIKit. What do you think about adding a comment here, saying this hidden UIHostingController view is used to present translation UI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It definitely is. I added a note.
| Color.clear | ||
| .frame(width: 0, height: 0) | ||
| .translationTask(viewModel.configuration) { session in | ||
| Task { @MainActor in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This Task is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|






Description
Closes CMM-745: On-device translation for posts.
Testing instructions
Recording
ScreenRecording_12-22-2025.16-58-08_1.MP4