Git Product home page Git Product logo

Comments (20)

uetchy avatar uetchy commented on May 25, 2024 1

Thank you for the detailed survey!

I think this feature could be shipped if the following issues were solved.

  • For English speakers, they may have a problem with translating Chinese contents in GitHub because lang in their page indicates 'en' and thus Polyglot won't reveal a translation.
  • Relating to the above, all web service which provides user-generated contents have a similar issue. so at least we should make this feature optional.

Consider filing PR for this feature! so we can test it in the real world whether it works well 👍

from polyglot.

gingerbeardman avatar gingerbeardman commented on May 25, 2024 1

This issue still annoys me every day.

How about disabling Polyglot for certain domains? For me that would be English Wikipedia for example.

from polyglot.

uetchy avatar uetchy commented on May 25, 2024 1

doing quick experiment. mostly working fine though.

Screen Shot 2021-01-25 at 2 17 32 PM

from polyglot.

devemio avatar devemio commented on May 25, 2024

To implement this we can retrieve the detected language from Google API and check with our targetLanguage. But in this case we shouldn't dispatch message showPanel with loading icon first. In other words, we first need to translate the text and then decide whether to show the panel or not. Perhaps there is another good solution to determine the language of the selected text on the extension side.

from polyglot.

gingerbeardman avatar gingerbeardman commented on May 25, 2024

To get the language of the page we have the following:

  1. HTML lang (cf HTML spec)
    <html lang="ja-JP"...
  2. META charset (cf HTML spec)
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"...
  3. META locale (cf Facebook)
    <meta property="og:locale" content="ja_JP"...

If testing those disables and the user still wants to translate they can use the context menu.

To detect user language:

  1. navigator.language (language of browser app?)
  2. navigator.languages (users preferred languages?)
    (these are sometimes the same but not always)

There's also Window.onlanguagechange to take care of.

from polyglot.

uetchy avatar uetchy commented on May 25, 2024

Yes. We need to do something for this.

However, language detection is inefficient because ...

  • Not all site admins follow the rule (some site mistakenly points to inappropriate language)
  • Detecting a language using APIs takes a large amount of network requests
  • Doing language detection without showing loading indicator bring it with the loss of UX.

Instead of those, how about we'd offer a toolbar button (and key shortcut) for switching instant translation feature?

from polyglot.

gingerbeardman avatar gingerbeardman commented on May 25, 2024

That doesn't solve the problem IMHO.

Maybe an option to switch off language detection for Instant Translation?

from polyglot.

devemio avatar devemio commented on May 25, 2024

Using the API to define the language brings a lot of extra network requests.

I think that some kind of shortcut would be a good idea to switch instant translation feature.

from polyglot.

gingerbeardman avatar gingerbeardman commented on May 25, 2024

I'm working on this one :)

from polyglot.

gingerbeardman avatar gingerbeardman commented on May 25, 2024

Just putting some thoughts down...

If we try to simplify the goal: what do we really want to do?

Check if the language of the text/page is the same as the target language.
We don't actually need to know what it is, Google Translate can figure that out.

function getPageLanguage() {
  var langHTML = document.documentElement.lang

  var langCharSet = document.characterSet

  var x = document.getElementsByTagName("META")
  for (var i = 0; i < x.length; i++) {
    if (x[i].getAttribute('property') == 'og:locale')
      var langOgLocale = x[i].getAttribute('content')
  }

  if (langHTML != null) console.log(langHTML)
  if (langCharSet != null) console.log(langCharSet)
  if (langOgLocale != null) console.log(langOgLocale)
  if (langClosest != null) console.log(langClosest)

  return
}
URL lang characterSet og:locale
https://www.github.com en UTF-8
https://www.hbo.com/about/faqs en UTF-8
https://www.bbc.co.uk/cymrufyw cy UTF-8 cy_GB
https://www.jp.playstation.com ja-JP UTF-8 ja_JP
https://ja.wikipedia.org/wiki/富士山 ja UTF-8
http://www.jah.ne.jp/~hanhan4/imasara/8lakes/ EUC-JP

Maybe it's enough to just check lang? Benefit is that it is the same format as the languages are stored in Settings.plist

There's also a possibility that elements within the page are given a lang attribute, so it's better to start at the click and go up the DOM to the closest lang attribute.

var langClosest = e.closest('[lang]').attr('lang') //closest lang attribute wrapping what was clicked

What if our logic gets it wrong? The user still sees the translation! No worries.

from polyglot.

gingerbeardman avatar gingerbeardman commented on May 25, 2024

Agreed. This is a difficult problem to solve satisfactorily. I will give it more thought.

from polyglot.

gingerbeardman avatar gingerbeardman commented on May 25, 2024

I was thinking it is possible to guess encoding of text using JavaScript or Obj-C (now that the extension is native) with quick initial check to see if it only contains ASCII bytes.

Background
https://unicodebook.readthedocs.io/guess_encoding.html

JavaScript
https://github.com/aadsm/jschardet

Obj-C (Foundation)
https://developer.apple.com/documentation/foundation/nsstring/1413576-stringencodingfordata?language=objc

from polyglot.

stale avatar stale commented on May 25, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from polyglot.

gingerbeardman avatar gingerbeardman commented on May 25, 2024

Let's still do this.

from polyglot.

gingerbeardman avatar gingerbeardman commented on May 25, 2024

I still run into this problem.

I think perhaps my issues would mostly be solved switching off Polyglot for contents of input/textarea?

from polyglot.

uetchy avatar uetchy commented on May 25, 2024

Putting "On/off" toggle switch inside textarea (as Grammarly does) is one of our options.
Screen Shot 2020-03-18 at 19 49 38

from polyglot.

gingerbeardman avatar gingerbeardman commented on May 25, 2024

I will look into how that works.

from polyglot.

AntonUspishnyi avatar AntonUspishnyi commented on May 25, 2024

Hi there.
I have Safari in English, but I want translate English to Russian?
How can I do this?

from polyglot.

gingerbeardman avatar gingerbeardman commented on May 25, 2024

@AntonUspehov did you set your preferences in the Polyglot app?

See readme > setup > step 3

from polyglot.

gingerbeardman avatar gingerbeardman commented on May 25, 2024

This does not work reliably for me?

eg. in my eBay.co.uk messages I select part of a message and that triggers Polyglot?

from polyglot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.