Coder Social home page Coder Social logo

How to use about get-med HOT 2 CLOSED

serebrov avatar serebrov commented on August 30, 2024
How to use

from get-med.

Comments (2)

serebrov avatar serebrov commented on August 30, 2024

These scripts were written around 5 years ago and google translate UI has changed, so they are not fully functional.
I did some review and cleanup, the translation by url still works, so as the gethtml.py script. What it does is: download the HTML, save it, pass the html file URL to google translate (for example, http://translate.google.com/translate?hl=en&sl=auto&tl=ru&u=https://math.stackexchange.com/questions/2093425/equation-of-a-plane-passing-through-intersection-of-two-planes-and-parallel-to-a), download and save the translated page.
The "core" translation feature is this function:

get-med/browser.py

Lines 110 to 120 in 4d96dca

def translate_page(browser, url):
t_url = 'http://translate.google.com/translate?hl=en&sl=auto&tl=ru&u=' + urllib.quote(url)
r = browser.open(t_url)
soup = BeautifulSoup(r.read())
t_url = soup.find_all('iframe')[0].get('src')
if t_url[0:4] != 'http':
t_url = 'http://translate.google.com' + t_url
try:
return download_page(browser, t_url, url)
except Exception as e:
print 'Can not translate page: ' + url + 't_url: ' + t_url + ' error: ' + str(e)

For PDFs I've did this: download PDF, convert it to html, translate html via google translate (the getpdf.py) - this doesn't work now because I was using the form on the google translate page and it now works differently than before.
But now the translation by URL also works for PDFs (for example
http://translate.google.com/translate?hl=en&sl=auto&tl=ru&u=http://pages.mtu.edu/~fmorriso/MathType-tipstricks-full.pdf), so you can quite easily adopt the approach used for htmls (or even use the gethtml.py script directly).

Note: I am not 100% sure, but I think the automated usage of google translate may violate Google TOS. It might be OK to translate few files for your personal use in a way I did here, but you shouldn't use this approach in the commercial software, instead use the translation API: https://cloud.google.com/translate/docs/

from get-med.

zaixi avatar zaixi commented on August 30, 2024

Thanks, this can already help me, I just translate a few PDFs personally.

from get-med.

Related Issues (1)

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.