473,386 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Re: Babelfish translation ...

Stef Mientki <stef.mientki <atgmail.comwrites:
Although it works functionally,
it can take lots of time waiting for the translation.

What I basically do is, after selecting a new string to be translated:

kwds = { 'trtext' : line_to_be_translated, 'lp' :'en_nl'}
soup = BeautifulSoup (urlopen(url, urlencode ( kwds ) ) )
translation= soup.find ( 'div', style='padding:0.6em;' ).string
self.Editor_Babel.SetLabel ( translation )
You should give lxml.html a try.

http://codespeak.net/lxml/

It can parse directly from HTTP URLs (no need to go through urlopen), and it
frees the GIL while parsing, so it will become efficient to create a little
Thread that doesn't do more than parsing the web site, as in (untested):

def read_bablefish(text, lang, result):
url = BABLEFISH_URL + '?' + urlencode({'trtext':text, 'lp':lang})
page = lxml.html.parse(url)
for div in page.iter('div'):
style = div.get('style')
if style is not None and 'padding:0.6em;' in style:
result.append(
lxml.html.tostring(div, method="text", with_tail=False))

result = []
thread = threading.Thread(target=read_bablefish,
args=("...", "en_nl", result))
thread.start()
while thread.isAlive():
# ... do other stuff
if result:
print result[0]

Stefan
Jul 17 '08 #1
0 1002

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Matt | last post by:
Short Description: The Translation Hub is not picking up the TNS names file. I'm using Oracle 9ids. It doesn't work for any users and it has never worked since it's been installed. Long...
40
by: Chiwa | last post by:
Hey, Expression: Math.floor(x * 100) / 100 x= 4.1 gives 4.09, why in gods name? While other values for x don't give a problem. Thx in advance
5
by: Haines Brown | last post by:
I suspect this is a FAQ, but as a guide to my further investigation, I wondered what the options are for providing readers of my web pages with the ability to translate the pages into their own...
7
by: Steven T. Hatton | last post by:
Is there anything that gives a good description of how source code is converted into a translation unit, then object code, and then linked. I'm particularly interested in understanding why putting...
7
by: Peter Eisentraut | last post by:
Greetings. The official PostgreSQL documentation has been translated to German and has been published as a book by verlag moderne industrie/mitp ("PostgreSQL: Das offizielle Handbuch", ISBN...
4
by: Chris Croughton | last post by:
Does a translation unit have to have at least one externally visible declaration or function definition to be valid? As I read the standard, it doesn't: it must have at least one declaration or...
1
by: me | last post by:
The following page... http://www.lenoxlaser.com/pinholephotography/pinhole_photography_cameras.html ....has a "babelfish to translate this page click a link" icon. I want to put one on my...
0
by: Stef Mientki | last post by:
hello, I've build a translation tool, to translate all strings in a python source file. As a extra gadget I added translation through Babel Fish, using beautifulsoup. Although it works...
0
by: Stef Mientki | last post by:
thanks Stefan, both lxml and threading works perfect. One small problem, "with_tail" was not recognized as a valid keyword. cheers, Stef Stefan Behnel wrote:
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.