Skip to content
This repository has been archived by the owner on Sep 4, 2023. It is now read-only.

Translate Selected Text #358

Closed
Miserlou opened this issue Jun 2, 2022 · 25 comments · Fixed by #615
Closed

Translate Selected Text #358

Miserlou opened this issue Jun 2, 2022 · 25 comments · Fixed by #615
Labels
enhancement New feature or request
Milestone

Comments

@Miserlou
Copy link

Miserlou commented Jun 2, 2022

I'd absolutely love it if I could highlight some text on a page, right click and translate it (see the translation and have that added to my pastebuffer when I click on it. Ideally, this would work both ways, to and from English/the system language.

@Miserlou
Copy link
Author

Miserlou commented Jun 2, 2022

Another user requests this here: https://news.ycombinator.com/item?id=31598074

@jelmervdl
Copy link
Contributor

Another HN user mentioned this extension which has such a user interface.

It might be tricky to do well with the current translation models: I'd expect users will select a single word, or just a couple of words, not a full sentence.

IIRC the training data used for the current translation models don't have much of that kind of input. It should be doable to augment the training data to add it, but it does entail retraining models.

@aspensmonster
Copy link

I'd love something like this. For my use-case, it doesn't have to replace the text in the DOM either. Popping a modal or new tab is perfectly fine. Presently, I've been using this add-on, which adds entries to the right-click context menu (as well as keyboard shortcuts/bindings) for sending selected text to Google Translate.

Also, my use-case involves translating entire posts across the fediverse, which can be anything from dozens to hundreds of words long (so typically, at least a few sentences, and not just a couple words). I have only a so-so grip on the Spanish language, and popping those posts into Google Translate to make sure I interpreted them accurately is quite helpful.

@woj-tek
Copy link

woj-tek commented Jun 6, 2022

I second @aggroskater comment and use the same extension currently. Most of the time I only need parts of the webpage translated (usually if I'm not sure about my own translation or it's something like a fediverse with really mixed bag of languages). I virtually never use whole page translation (most of the pages I need are either in my native tongue or English)

@andrenatal andrenatal added the enhancement New feature or request label Jun 7, 2022
@jelmervdl
Copy link
Contributor

@woj-tek in that case, would you also like it to be able to select/auto-detect the language of just the selection? Right now the add-on only identifies the language of the page, assuming its just all in the same language. And would you mostly want to translate that then to the same output language (e.g. the same language as your Browser is using, like the add-on assumes right now)?

@woj-tek
Copy link

woj-tek commented Jun 17, 2022

@jelmervdl I think something along the lines of:

  1. try to translate in the specified language of the page (overwhelming majority of cases)
  2. if (1) fails try to detect the language of the selection (assuming it would be possible)

As for the target language - I think it should be configurable but translating to browser language should be enough I think (sometimes I set my OS and thus browser to Spanish for immersion though when reading something online and trying to understand it better I would prefer to have it translated to English [still not my native but I think machine translation to to English would be better than to Polish :) ]).

@lonnen
Copy link
Contributor

lonnen commented Jul 2, 2022

It might be tricky to do well with the current translation models: I'd expect users will select a single word, or just a couple of words, not a full sentence.

Maybe do too much and throw some away, then optimize. Consider this straw proposal starting point:

User highlights a portion of text. We insert a non-functional custom markup tag around the highlight. It might look like:

<p>He heard the voice say, "<bergamot-translation-tag>El tiempo para su trabajo ha sido concedido</bergamot-translation-tag>.</p>

Then we walk the tree and chunk it like normal (or we get clever and only chunk until we queue a chunk with the closing tag, since that's all the context the engine would get anyhow. something like that). When the translated text is returned, instead of inserting it into the page we grab the inner text of the fake element and present that to the user or replace the fake tag contents with it. Finally, remove the fake tags from the page.

I'm probably missing a bunch of edge cases, here. For example, maybe we need to consider non-contiguous highlighting for some platform. How this is presented to the user is also critical. Translation in place seems to match what we already do but there are other options to consider, like a modal window injected into the page would also provide a convenient place for selecting the language.

@jelmervdl
Copy link
Contributor

In https://github.com/jelmervdl/firefox-translations I've implemented a basic version of this, which just shows a popup of the translated text you selected. It assumes the text is in the same language as the rest of the page. In theory, in my implementation, you can change the from/to language via the translate button popup in the browser UI, but that's unintuitive.

@lonnen oooh I like the idea of expanding the selection to also capture some context!

@lonnen
Copy link
Contributor

lonnen commented Jul 2, 2022

Thanks. No matter how we incorporate short strings into the training, the translation should always work a little better with some context to disambiguate words with multiple meanings

@ghost
Copy link

ghost commented Jul 18, 2022

This is a must-have. This open-source addon translates the selected text: https://simple-translate.sienori.com/

@320x200
Copy link

320x200 commented Sep 2, 2022

Also want to add a potentially positive use case of such feature request. I'm currently learning a language, and it would be very handy to read the page in its original language, and only highlight the words, sentences and paragraphs that I am not sure about.

@okias
Copy link

okias commented Sep 2, 2022

I would love that for messengers like Element (where web page translation currently doesn't work). This would help translate messages in international chats a lot.

@mildlyhuman
Copy link

mildlyhuman commented Sep 25, 2022

This would be great, especially for fediverse and twitter.

Functionality-wise I really like this add-on (disclaimer i am in no way related to the author). I do not know what's its backend, but at the front it seems to work fantastically: select text, select item in right click menu and it shows a in-page pop-up overlay box. It also does not require any permissions.

@kpu

This comment was marked as off-topic.

@mildlyhuman
Copy link

mildlyhuman commented Sep 25, 2022

@kpu my bad, thanks for mentioning! I (vaguely) remembered this, but did not think when google landed me here. Will lurk in that repo.

@kpu

This comment was marked as off-topic.

@woj-tek

This comment was marked as off-topic.

@okias
Copy link

okias commented Sep 26, 2022

What is also surprising is that it does add Chrome support together with manifest v3, which I recall Mozilla was strongly against.

@jelmervdl

This comment was marked as off-topic.

@kpu

This comment was marked as off-topic.

@kpu

This comment was marked as off-topic.

@j-sidd
Copy link

j-sidd commented Dec 12, 2022

This was also recently requested on Mozilla Connect: https://connect.mozilla.org/t5/ideas/translate-addon-highlight-to-translate/idi-p/20759

@unhammer
Copy link

My ideal flow would be:

  1. select a paragraph
  2. right click and hit Translate
  3. see a popup/modal with the text translated from Russian to Bulgarian
  4. click the little buttons in the popup to change the source and target language to Hungarian→English

It should probably remember the source/target language if overridden while on the same web page, but do langid if the user has navigated to a different page (just remembering target language), though having the above parts 1-4 are the most important.

@aspensmonster
Copy link

It seems like it's been several months since this was added into the add-on, but I only recently noticed it. And I just have to say... thank y'all so very much! The ability to select text, right-click, and hit "translate with Firefox Translations" is exactly the sort of thing I was looking for. I no longer have to send data to Google, I no longer have to pop into a new tab, I can translate just pieces of the page in my fediverse feeds... awesome :D

@andrenatal and team

@andrenatal
Copy link
Contributor

We're glad to help @aggroskater.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.