Just a simple exploration of the goslate module (uses the Google Translate API) to translate some common languages. However, some IDE's create character problems.

Note: Your computer has to be connected to the Internet to access Google.

Edited by vegaseat

''' google_translate101.py
experimenting with the Google Translate API

Goslate: Free Google Translate API
download goslate.py from ...
info ...

some language codes
English = 'en'
German = 'de'
French = 'fr'
Spanish = 'es'
Dutch = 'nl'
Swedish = 'sv'
Finnish = 'fi'

be careful which IDE you use
Spyder, IEP and IDLE are okay
PyScripter will screw up some of the foreign characters

tested with Python33  by  vegaseat  06nov2014

import goslate

gs = goslate.Goslate()

# translate a given string to the language given by the code
print(gs.translate('hello world', 'de'))  # Hallo Welt
print(gs.translate('hello world', 'fr'))  # Bonjour tout le monde
print(gs.translate('hello world', 'es'))  # hola mundo
print(gs.translate('hello world', 'nl'))  # hallo wereld
print(gs.translate('hello world', 'sv'))  # hallå världen
print(gs.translate('hello world', 'fi'))  # Hei maailma


text = '''\
Good morning!
I hope you have all slept well.
# translate(text, target_language, source_language=u'')
# english to german
print(gs.translate(text, 'de', 'en'))

Guten Morgen!
Ich hoffe, Sie haben alle gut geschlafen.

# english to dutch
print(gs.translate(text, 'nl', 'en'))

Ik hoop dat jullie allemaal goed geslapen.


# more stuff ...

# romanized Chinese
gs_roman = goslate.Goslate(goslate.WRITING_ROMAN)
print(gs_roman.translate('hello world', 'zh'))  # Nǐ hǎo shìjiè

# detect the language code of a given string
print(gs.detect('hello world'))  # en
2 Years
Discussion Span
Last Post by Ekta_1

This is very confusing. This may be a dumb question, but I have no idea what is going on while I desire so as much to become a computer programmer. Is this an example of Python coding and how did you know what to type in to get the program to output what you wanted?


A code snippet is an example of working code that brings up an interesting aspect of Python programming. An English language string is given and then tanslated into several other languages. The translated string is printed out. You could apply the concept to one of your programs.

You need to learn the basics of Python first to start to understand what is going on.

Edited by ZZucker


But after running for a couple of times it starts throwing 503 service unavailable error. How to deal with that? If the google has a paid service, it must be measures to block these kind of requests.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.