Git Product home page Git Product logo

py_translator's Introduction

🛠️ This repository was created using the GitUpload.

Languages:
Deutsch | English | Spanish | French | Italian | Russian


Version = 2.1.9
Library name = py_translator
Title = Free Google Translate API
Keywords = Google API Cloud Translate, google api translate free

Info

The end goal is a simple application for translating text in the terminal. Text can be generated interactively or programmatically in the shell environment. Through command line arguments, file descriptors or pipes generating translated output that can be piped to a file or displayed on the terminal.

Also, you can check our additional library with Google Cloud API

https://pypi.org/project/google-api-translate/

Features

  • Made for Python 3 but still works on Python 2
  • Fast and easy to install, easy to use
  • Supports translation from any language
  • Highly composable interface, the power of Unix pipes and filters.
  • Simple API and documentation

Hot to install

pip3 install py_translator==2.1.9

How to use

from py_translator import Translator
s = Translator().translate(text='Hello my friend', dest='es').text
print(s)

With proxy

from py_translator import Translator
proxy = {
        'http': 'http://username:[email protected]:1234',
        'https': 'http://username:[email protected]:1234',
}
s = Translator(proxies=proxy).translate(text='Hello my friend', dest='es').text
print(s)

Shell

translate [--flags] [source] dest

html translation

Python

from py_translator import TEXTLIB
s = TEXTLIB().translator(is_html=False, text='Hello my friend', lang_to='cn', proxy=False)
print(s)

With proxy

from py_translator import TEXTLIB
proxy = [
    'http://username:[email protected]:1234',
    'http://username:[email protected]:1234',
]

s = TEXTLIB().translator(is_html=False, text='Hello my friend', lang_to='cn', proxy=proxy)
print(s)

With multithreading

from py_translator import TEXTLIB

#with massTranslator()
s = TEXTLIB().massTranslator(is_html=False, text='Hello my friend', lang_to='cn', proxy=False)
print(s)

Examples

Hello World from English to Traditional Chinese

$ translate en zh-TW <<< 'Hello World!'
你好世界!
Just as easily specify a source language by providing it as first argument
#Translate Hello from French to English
$ translate fr en <<< 'Bonjour, comment allez-vous!'
Hello, how are you?

Smart Language Detection

Omitting the source language will try to detect it based on the text content

$ translate fr <<< 'I think therefore I am'
Je pense donc je suis

Romanified Transliteration

$ translate --translit en ko <<< 'Want to fight!'
ssaugo sip-eo!

$ translate --translit en zh-TW <<< 'Kidding, we should be friends'
Kāiwánxiào, wǒmen yīnggāi shì péngyǒu

Redirect from File

$ translate zh-TW < 'alice.txt'

阿麗思道:「你不是說你要告訴你的歷史嗎?告訴我你為甚麼恨—那個—那些—C和D,」
她末了兩個字母輕輕兒地說的,怕回來又得罪了牠。

那老鼠對著阿麗思嘆了一口氣道,「唉﹗我的身世說來可真是又長又苦又委屈呀—」

阿麗思聽了,瞧著那老鼠的尾巴說,「你這尾是曲啊﹗可是為甚麼又叫它苦呢﹗」
她就一頭聽著那老鼠說話,一頭在在心上納悶,所以她聽的那老鼠講的「尾曲」
的歷史是差不多像這個樣了的
....

Chaining together Pipes

#Multiple Chaining
$ echo 'What is love?' | translate en zh-TW | translate zh-TW ko | translate ko fr | translate fr en
What is love?

Be Creative!

#Grocery List
$ cat << BUY | translate ko
Celery
Milk
Eggs
Bread
Cereal
BUY

셀러리
우유
달걀
빵
시리얼

Support

Python 3

Documentation

Find the latest documentation http://pythonhosted.org/py-translate/


🛠️ This repository was created using the GitUpload.

py_translator's People

Contributors

falconws avatar markolofsen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

py_translator's Issues

List index out of range

CODE:
from py_translator import Translator
translator = Translator()
trans = translator.translate('안녕하세요.')
print(trans.text)

ERROR:
Traceback (most recent call last):
File "cleanTweet.py", line 3, in
trans = translator.translate('안녕하세요.')
File "D:\Documents\Code\Storm\src\flask\venv\lib\site-packages\py_translator\client.py", line 172, in translate
data = self._translate(text, dest, src)
File "D:\Documents\Code\Storm\src\flask\venv\lib\site-packages\py_translator\client.py", line 75, in _translate
token = self.token_acquirer.do(text)
File "D:\Documents\Code\Storm\src\flask\venv\lib\site-packages\py_translator\gtoken.py", line 184, in do
self._update()
File "D:\Documents\Code\Storm\src\flask\venv\lib\site-packages\py_translator\gtoken.py", line 56, in _update
self.tkk = self.RE_TKK.findall(r.text)[0]
IndexError: list index out of range

Python version: 3.4.0 (VM) / 3.7.0 (Host)
Pip version: 1.5.4 (VM) / 10.0.1 (Host)
Py-translator version: 1.8.9

Error when installing py-translator

Hi I'm trying to install py translator using pip however I'm getting the following error:

error in py_translator setup command: Invalid environment marker: python_version >= "3.0"

Not sure why this occurs as my python is > 3.0; any suggestions on how I can fix this?

Python version: 3.4.0
Pip version: 1.5.4
Py-translator version: 1.8.9

Missing requirements

When doing a translation you'll get an error because of uninstalled package:

File "/Users/guydipietro/PycharmProjects/CastleTestUtils/ctvenv/lib/python2.7/site-packages/CastleTestUtils/VoiceUtils/text_to_speech/text_to_speech.py", line 2, in
from py_translator import Translator
File "/Users/guydipietro/PycharmProjects/CastleTestUtils/ctvenv/lib/python2.7/site-packages/py_translator/init.py", line 8, in
from .html_connector import TEXTLIB
File "/Users/guydipietro/PycharmProjects/CastleTestUtils/ctvenv/lib/python2.7/site-packages/py_translator/html_connector.py", line 1, in
from .html_translator import superTranslator, massTranslator, setProxy
File "/Users/guydipietro/PycharmProjects/CastleTestUtils/ctvenv/lib/python2.7/site-packages/py_translator/html_translator.py", line 5, in
from langdetect import detect
ImportError: No module named langdetect

Thread error

I got threading error with below code

code:
TEXTLIB().translator(is_html=False, text='aplomb', lang_to='zh-TW', proxy=False)

error message:
image

dead py_translator?

invoke py_translator.Translator().translate method, an error occured.

  File "/usr/local/lib/python3.6/dist-packages/py_translator/client.py", line 172, in translate
    data = self._translate(text, dest, src)
  File "/usr/local/lib/python3.6/dist-packages/py_translator/client.py", line 75, in _translate
    token = self.token_acquirer.do(text)
  File "/usr/local/lib/python3.6/dist-packages/py_translator/gtoken.py", line 184, in do
    self._update()
  File "/usr/local/lib/python3.6/dist-packages/py_translator/gtoken.py", line 56, in _update
    self.tkk = self.RE_TKK.findall(r.text)[0]

gtoken? right?

by the way, an error occurs also command line not only python code.

$ translate fr <<< 'I think therefore I am'
Traceback (most recent call last):
  File "/home/user/projects/a_soft/venv/lib/python3.6/site-packages/translate/coroutines.py", line 170, in spool
    stream = yield
GeneratorExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/projects/a_soft/venv/lib/python3.6/site-packages/translate/coroutines.py", line 145, in set_task
    task = yield
GeneratorExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/projects/a_soft/venv/bin/translate", line 11, in <module>
    sys.exit(main())
  File "/home/user/projects/a_soft/venv/lib/python3.6/site-packages/translate/__main__.py", line 115, in main
    return source(spool(set_task(translate, translit=args.translit)), args.text)
  File "/home/user/projects/a_soft/venv/lib/python3.6/site-packages/translate/coroutines.py", line 204, in source
    return target.close()
  File "/home/user/projects/a_soft/venv/lib/python3.6/site-packages/translate/coroutines.py", line 180, in spool
    iterable.close()
  File "/home/user/projects/a_soft/venv/lib/python3.6/site-packages/translate/coroutines.py", line 149, in set_task
    list(map(stream, workers.map(translator, queue)))
  File "/usr/lib/python3.6/concurrent/futures/_base.py", line 586, in result_iterator
    yield fs.pop().result()
  File "/usr/lib/python3.6/concurrent/futures/_base.py", line 432, in result
    return self.__get_result()
  File "/usr/lib/python3.6/concurrent/futures/_base.py", line 384, in __get_result
    raise self._exception
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/user/projects/a_soft/venv/lib/python3.6/site-packages/translate/translator.py", line 51, in connection
    response.raise_for_status()
  File "/home/user/projects/a_soft/venv/lib/python3.6/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 503 Server Error: Service Unavailable for url: https://translate.google.com/translate_a/single?client=a&ie=utf-8&oe=utf-8&dt=t&tl=fr&q=I+think+therefore+I+am%0A

sre_constants.error: multiple repeat at position 97

File "/usr/lib/python3.6/site-packages/py_translator/html_connector.py", line 43, in translator
return superTranslator().html(text, lang_to)
File "/usr/lib/python3.6/site-packages/py_translator/html_translator.py", line 217, in html
text = self.tagsReplacer(direction='in', text=text)
File "/usr/lib/python3.6/site-packages/py_translator/html_translator.py", line 164, in tagsReplacer
text = re.sub(link, '(111{})'.format(i), text)
File "/usr/lib64/python3.6/re.py", line 191, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "/usr/lib64/python3.6/re.py", line 301, in _compile
p = sre_compile.compile(pattern, flags)
File "/usr/lib64/python3.6/sre_compile.py", line 562, in compile
p = sre_parse.parse(p, flags)
File "/usr/lib64/python3.6/sre_parse.py", line 855, in parse
p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
File "/usr/lib64/python3.6/sre_parse.py", line 416, in _parse_sub
not nested and not items))
File "/usr/lib64/python3.6/sre_parse.py", line 619, in _parse
source.tell() - here + len(this))
sre_constants.error: multiple repeat at position 97

Exception JSONDecodeError

Hi, I'm trying to run the basic usage example from py-translator's official page and I'm getting the following error:

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Code:

from py_translator import Translator
s = Translator().translate(text='Hello my friend', dest='es').text
print(s)

Python version: 3.5.2
py-translator 1.8.9

dead py_translator again?

#7

packages/py_translator/gtoken.py", line 56, in _update
    self.tkk = self.RE_TKK.findall(r.text)[0]
IndexError: list index out of range

happened this error again.

raise JSONDecodeError

Hi, my code is just simply as follows:

import py_translator
from py_translator import Translator
translator = Translator()
translator.translate('bonjour')

I would like to test the package and the text is so short within the limit. But it raise error:
raise JSONDecodeError("Expecting value", s, err.value) from None

and the error message is
JSONDecodeError: Expecting value

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.