damus icon indicating copy to clipboard operation
damus copied to clipboard

Automatic offline machine translation

Open badonyx opened this issue 1 year ago • 23 comments

user story

As a Damus user who would like to read notes in foreign languages, I would like my local device to translate notes for me automatically, so that I can seamlessly enjoy reaading notes in foreign languages on my device translated to my preferred language.

acceptance criteria

  1. there is a method to enable offline local device auto translation (i.e. no need to tap "translate note")
  2. there is a way to disable
  3. User is warned if there is a need to download offline language packs
  4. data size download MB/GB is displayed
  5. If not on wifi warn user about mobile network bandwidth

Machine translation of notes could be done on-device or otherwise using the language API provided by Apple (which can do offline translations if you download additional data in system settings). ~~Unfortunately Apple does not seem to allow access to their translation API?~~ (Edit: I have seen some activitypub app do this with a button that calls the system translation UI on the note contents, so it seems that is possible at least.)

A nice alternative I found is Google's ML Kit. It is used in another nostr client nostrmo. The translation quality is good and the downloaded models are not very large -- on nostrmo I have loaded 6 languages for translation to English and the app's total documents & data size is still only ~300 MB.

badonyx avatar Aug 14 '23 20:08 badonyx

Have you tried the current translation options?

cc @tyiu

alltheseas avatar Aug 14 '23 20:08 alltheseas

I would love to have offline translations and have spent a significant amount of time investigating. However,

  1. Apple has not opened up their translation APIs.
  2. Google's ML Kit for iOS is poorly maintained and does not work for modern development environments. They require Pods but the industry standard is to use Swift Package Manager. It also doesn't work natively for the new Apple M* processors.

I hope things will develop over the next year or so, but nothing is ready at the moment.

tyiu avatar Jan 18 '24 12:01 tyiu

On Thu, Jan 18, 2024 at 04:33:00AM -0800, Terry Yiu wrote:

It also doesn't work natively for the new Apple M* processors.

surprised to hear this! that's kind of a deal breaker isn't it.

jb55 avatar Jan 18 '24 17:01 jb55

Let's keep this open, maybe a solution will crop up eventually

jb55 avatar Jan 18 '24 17:01 jb55

some activitypub app do this with a button that calls the system translation UI on the note contents

I have no idea how this was implemented, but it would be a great alternative.

I will try to find the app again if it helps.

badonyx avatar Jan 18 '24 18:01 badonyx

I will try to find the app again if it helps.

It is Radiant.

image

image

badonyx avatar Jan 18 '24 18:01 badonyx

@badstacker is radiant FOSS?

alltheseas avatar Jan 18 '24 18:01 alltheseas

I do not think it is FOSS.

badonyx avatar Jan 18 '24 18:01 badonyx

@alexgleason any idea how Radiant mastodon client does iOS translations?

alltheseas avatar Jan 18 '24 18:01 alltheseas

Whoa, that's definitely Apple native translations. I wonder if they're somehow hacking together some UIKit functionality to get that to work. I'll dig around a bit.

tyiu avatar Jan 18 '24 19:01 tyiu

@tyiu just found this on iOS. Have you explored?

image

alltheseas avatar Jan 18 '24 19:01 alltheseas

@tyiu just found this on iOS. Have you explored?

I've seen that but I don't think that has anything to do with what Radiant does to expose the Translate sheet.

@bryanmontz do you know how Radiant might be accessing Apple's native translate sheet in-app? Is there some UIKit or accessibility magic going on? I don't think there's an API for it at the moment.

tyiu avatar Jan 18 '24 21:01 tyiu

No, I'm not sure how they're triggering Apple's translate sheet, if that's what's happening. I googled around for a minute and didn't see a way to do it.

bryanmontz avatar Jan 18 '24 22:01 bryanmontz

[email protected]

Jake is the dev name. Maybe you could ask him @tyiu

alltheseas avatar Jan 18 '24 22:01 alltheseas

I wonder if they're somehow hacking together some UIKit functionality to get that to work.

@tyiu I think you are on the right track here. Notice in my screenshot those two big dots at the beginning of the text -- those only appear after translation, and they sort of look like a collapsed form of the text selection cursors. Suggests they are doing some trickery to select the text and then trigger the native translation somehow.

badonyx avatar Jan 18 '24 23:01 badonyx

[email protected]

Jake is the dev name. Maybe you could ask him @tyiu

Seems like @jknlsn might be the developer. I've privately messaged him on Mastodon to see if he'd be willing to offer insights.

tyiu avatar Jan 19 '24 00:01 tyiu

I wonder if they're somehow hacking together some UIKit functionality to get that to work.

@tyiu I think you are on the right track here. Notice in my screenshot those two big dots at the beginning of the text -- those only appear after translation, and they sort of look like a collapsed form of the text selection cursors. Suggests they are doing some trickery to select the text and then trigger the native translation somehow.

Interesting approach!

Here is the manual flow Screenshot 2024-01-18 at 6 36 23 PM

Screenshots:

image

image

image

image

image

alltheseas avatar Jan 19 '24 00:01 alltheseas

Here is the suggested auto-translate workflow, given you can simulate the manual actions @tyiu

Screenshot 2024-01-18 at 6 38 13 PM

alltheseas avatar Jan 19 '24 00:01 alltheseas

Changing name to automatic offline machine translation

@tyiu solved the underlying technical challenge with new iOS translate API

https://github.com/damus-io/damus/issues/2302

alltheseas avatar Jun 21 '24 04:06 alltheseas

added user story to OP's top entry on this issue. looks like iOS 18 is required for this.

alltheseas avatar Jun 21 '24 04:06 alltheseas

pending #2332 fix

alltheseas avatar Jul 14 '24 22:07 alltheseas

This will be a very interesting feature. iOS18.1 should enable this feature.

tkhumush avatar Sep 10 '24 02:09 tkhumush

@tyiu any idea if iOS 18 introduced iOS translation regression?

image

alltheseas avatar Sep 19 '24 10:09 alltheseas