Created
May 7, 2012 23:06
-
-
Save phatduckk/2631269 to your computer and use it in GitHub Desktop.
ghetto python script to run translations of a single word through google
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import urllib2 | |
langs = { | |
"en": "English", | |
"la": "Latin", | |
"af": "Afrikaans", | |
"sq": "Albanian", | |
"ar": "Arabic", | |
"hy": "Armenian", | |
"az": "Azerbaijani", | |
"eu": "Basque", | |
"be": "Belarusian", | |
"bn": "Bengali", | |
"bg": "Bulgarian", | |
"ca": "Catalan", | |
"zh-CN": "Chinese", | |
"hr": "Croatian", | |
"cs": "Czech", | |
"da": "Danish", | |
"nl": "Dutch", | |
"en": "English", | |
"eo": "Esperanto", | |
"et": "Estonian", | |
"tl": "Filipino", | |
"fi": "Finnish", | |
"fr": "French", | |
"gl": "Galician", | |
"ka": "Georgian", | |
"de": "German", | |
"el": "Greek", | |
"gu": "Gujarati", | |
"ht": "Haitian Creole", | |
"iw": "Hebrew", | |
"hi": "Hindi", | |
"hu": "Hungarian", | |
"is": "Icelandic", | |
"id": "Indonesian", | |
"ga": "Irish", | |
"it": "Italian", | |
"ja": "Japanese", | |
"kn": "Kannada", | |
"ko": "Korean", | |
"la": "Latin", | |
"lv": "Latvian", | |
"lt": "Lithuanian", | |
"mk": "Macedonian", | |
"ms": "Malay", | |
"mt": "Maltese", | |
"no": "Norwegian", | |
"fa": "Persian", | |
"pl": "Polish", | |
"pt": "Portuguese", | |
"ro": "Romanian", | |
"ru": "Russian", | |
"sr": "Serbian", | |
"sk": "Slovak", | |
"sl": "Slovenian", | |
"es": "Spanish", | |
"sw": "Swahili", | |
"sv": "Swedish", | |
"ta": "Tamil", | |
"te": "Telugu", | |
"th": "Thai", | |
"tr": "Turkish", | |
"uk": "Ukrainian", | |
"ur": "Urdu", | |
"vi": "Vietnamese", | |
"cy": "Welsh", | |
"yi": "Yiddish", | |
} | |
url = "http://translate.google.com/translate_a/t?client=t&text=%s&hl=en&sl=en&tl=%s&multires=1&prev=btn&ssel=0&tsel=0&sc=1" | |
headers = {'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'} | |
for e, lang in langs.iteritems(): | |
u = url % (sys.argv[1], e) | |
req = urllib2.Request(u, "", headers) | |
response = urllib2.urlopen(req) | |
json = response.read() | |
parts = json.split(",") | |
if parts: | |
translated = parts[0].replace("\"", "").replace("[", "") | |
print "%14s: %s" % (lang, translated) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage: python this_script.py word_to_translate