[Wolves] SQL problem

sparkes sparkes at phreaker.net
Wed Mar 17 12:37:29 GMT 2004


On Wed, 2004-03-17 at 11:36, sparkes wrote:

> I am willing to write a script to do this for you for a very reasonable
> amount if this project needs this functionality.  I can deliver it this
> afternoon ;-)
dam didn't bite, never mind.

Here is some code that will translate welsh->english or english->welsh
your money would have brought better error checking when the site is
timing out and a windows executable if that was the platform your server
is running on.

I would use this to add the translation to the table when data is first
added so the natural language and the machine translation are both
contained in the tables you are using.

Do me a favour, if you find this code useful for what sounds like a well
paying project remember an unemployed developer donated it for free ;-)

sparkes

#!/usr/bin/env python2.3
#(c)2004 Steve Parkes (sparkes at westmids.biz)
#released under the GPL v2 
#translate simple strings using transexp
#example usage english to welsh ./welshtrans.py -t wel -f eng -s"from
english to welsh translation"
#example usage welsh to english ./welshtrans.py -t eng -f wel -s"chan
Saesneg at Cymraeg chyfieithiad"
#these examples prove that automatic translation is never perfect but
usable

from optparse import OptionParser
import  urllib, os

def translate(text,lang_to, lang_from):
    params = urllib.urlencode({'topframe': 'yes', 'to': lang_to, 'from':
lang_from,'text':text,'url':'','type':'text','keyb':'none','Submit.x':57,'Submit.y':21})
    f =
urllib.urlopen("http://www.tranexp.com:2000/Translate/result.shtml",
params)
    trans = f.read()
    leftstrip = trans.find("""name="translation" """ )
    rightstrip = trans.find("</textarea>",leftstrip)
    trans = trans[leftstrip+len("""name="translation"  """):rightstrip]
    return trans

parser = OptionParser(usage="%prog -f $FROM -t $TO -n $FILENAME",
version="%prog 0.1")
parser.add_option("-t", "--to ", help="translate file to",
action="store", type="string", dest="lang_to")
parser.add_option("-f", "--from",help="translate file
from",action="store", dest="lang_from", type="string")
parser.add_option("-s", "--string",help="string to translate to
translate",action="store", dest="text", type="string")
(options, args) = parser.parse_args()

print translate(options.text,options.lang_to,options.lang_from)







More information about the Wolves mailing list