Comments (4)
Sounds good. I would implement it as another popup, not as a "selected text translation" feature.
How this feature can be implemented technically?
If you need to translate one word, we have to detect what word user hover on. We can track hovered element with pointeover event, but how to detect exact word? Have you some ideas?
from linguist.
How this feature can be implemented technically?
The extension that I mentioned appears to be doing some funky markup manipulation: https://github.com/artemave/translate_onhover/blob/12aab5217677b0ba3579106c1200443454c87a16/contentscript.js#L166, I'm not sure what's exactly going on there, maybe it transforms a text node into a bunch of text nodes each containing one word (which, I assume, may be the reason for some bugs like this one).
Another possible implementation would be to determine the word being hovered over by looking at the position of the cursor relative to the text node's rectangle. E.g. if a text node has two equally long words, we check whether the cursor is on the right or on the left side of the text element. But yeah, it's gonna be pretty inaccurate, at least for a very basic implementation. I'm sure this algorithm is implemented in some very low-level things like OS or some rendering engines (LibreOffice, game engines, text editors).
It makes sense to search for another solution.
from linguist.
@WofWca nothing to add, all your points are right. 1st solution unacceptable, because Linguist must never change original DOM structure, 2nd solution may be inaccurate by many reasons and we cannot to ensure nothing with this way.
But i like your idea, so i will keep it in mind, if you will find a possible solution, please return back here and add a new information
from linguist.
We could potentially clone hovered element to shadowRoot and split nodes there to calculate position, but this approach are not trivial, hard to maintain and may generate a lot of bugs like "texts styles are different in virtual element".
I imagine an ideal solution as some intersection API for chars - we detect hovered char and get chars around. Maybe we could hack text selection API.
But if such API does not exist, we could think how to simplify solution above
from linguist.
Related Issues (20)
- (Android) none of the drop down box clickable
- Google translator incorrect translate HTML chars (like `<` and `>`)
- Incorrect Linguist name for Korean language
- "Selected text translation" should not reset selection (Gecko) HOT 7
- "Translate page" context menu item doesn't show up until the page is loaded HOT 2
- [Feature request] Use multiple translators with different priorities HOT 7
- Add Safari support HOT 1
- Modal window for custom translators code have too small height
- Move custom translators to other repository
- Allow to choose different translators for page translation and text translation
- "Page translation" tab doesn't show up when the page finishes loading HOT 1
- Incorrect translation on Reddit and some websites. HOT 5
- Use domtranslator library
- Show words defenitions
- Add translation controls on page for mobile
- Can't click button to translate selected text
- Divide the history to a sections by date
- Not able to register Ctrl/Alt/Shift as keybindings when RFP on firefox is set to True HOT 4
- Open links from addon popup in a current tab
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from linguist.