= commited on
Commit ·
c754d32
1
Parent(s): 418aed1
added support for linguee.
Browse filesFiles changed (8)
- HISTORY.rst+1-1
- README.rst+28-9
- deep_translator/__init__.py+3-3
- deep_translator/tests/test_deep_translator.py+19-7
- docs/usage.rst+28-9
- examples/trans.py+14-1
- setup.cfg+1-1
- setup.py+1-1
1 unmodified line23455671 unmodified lineHistory=======
0.1.4 stable release0.3.1 stable release---------------------
48 unmodified lines49505152525354555657585956575863596065666162636465667167686970717273747576777879808182838485868788899091929348 unmodified lines
.. code-block:: python
from deep_translator import GoogleTranslator from deep_translator import GoogleTranslator, PonsTranslator, LingueeTranslator
english_text = 'happy coding'
# first create a GoogleTranslator object with source and target language # then use the translate function to translate a text. # All language are supported. Basic example:
result_german = GoogleTranslator(source='auto', target='de').translate(payload=english_text)
# Alternatively, you can pass languages by their name: result_german = GoogleTranslator(source='english', target='german').translate(payload=english_text) translated = GoogleTranslator(source='english', target='german').translate(payload=english_text)
##################### or maybe you want to translate a text file ? ############################# translated_text = GoogleTranslator(source='auto', target='german').translate_file('path/to/file') # or maybe you want to translate a text file ? translated = GoogleTranslator(source='auto', target='german').translate_file('path/to/file')
# or maybe you have many sentences in different languages and want to automate the translation process translated = GoogleTranslator(source='auto', target='de').translate_sentences(your_list_of_sentences)
###################### or use Pons as a translator ###########################
or maybe you would like to use the Pons translator: Pons.com
.. code-block:: python
word = 'good' translated_word = PonsTranslator(source='english', target='french').translate(word)
# set the argument return_all to True if you want to get all synonyms of the word to translate translated_word = PonsTranslator(source='english', target='french').translate(word, return_all=True)
Alternatively deep_translator now supports the Linguee translator:
.. code-block:: python
word = 'good' translated_word = LingueeTranslator(source='english', target='french').translate(word)
# set the argument return_all to True if you want to get all synonyms of the word to translate translated_word = PonsTranslator(source='english', target='french').translate(word, return_all=True)
Take a look in the examples folder for more :)
Please contribute and give me a feedback if you found the package useful/helpful or you are using it :)1 unmodified line234567889101011111 unmodified line
from .google_trans import GoogleTranslatorfrom .pons import PonsTranslatorfrom .linguee import LingueeTranslator
__author__ = """Nidhal Baccouri"""__email__ = 'nidhalbacc@gmail.com'__version__ = '0.1.3'__version__ = '0.3.1'
__all__ = [GoogleTranslator, PonsTranslator]__all__ = [GoogleTranslator, PonsTranslator, LingueeTranslator]6 unmodified lines789101011121314151615161718192021222324252627281 unmodified line30313224252627333435363738396 unmodified lines
@pytest.fixturedef response():def google_translator(): """Sample pytest fixture.
See more at: http://doc.pytest.org/en/latest/fixture.html """ translator = GoogleTranslator(target='en') assert translator.translate(payload='좋은') == "good" return GoogleTranslator(target='en')
def test_content(google_translator): """Sample pytest test function with the pytest fixture as an argument.""" # from bs4 import BeautifulSoup # assert 'GitHub' in BeautifulSoup(response.content).title.string assert google_translator.translate(payload='좋은') == "good"
def test_inputs(): with pytest.raises(exceptions.LanguageNotSupportedException): GoogleTranslator(source="", target="")
1 unmodified line GoogleTranslator(source="auto", target="nothing")
def test_content(response): """Sample pytest test function with the pytest fixture as an argument.""" # from bs4 import BeautifulSoup # assert 'GitHub' in BeautifulSoup(response.content).title.stringdef test_payload(google_translator): with pytest.raises(exceptions.NotValidPayload): google_translator.translate(payload="") with pytest.raises(exceptions.NotValidPayload): google_translator.translate(payload=123)
1 unmodified line23455687891012131415111218132014151617181920212223242526272228293031323334353637383940414243441 unmodified lineUsage=====
.. code-block:: python
from deep_translator import GoogleTranslator, PonsTranslator from deep_translator import GoogleTranslator, PonsTranslator, LingueeTranslator
english_text = 'happy coding'
# first create a GoogleTranslator object with source and target language # then use the translate function to translate a text. # All language are supported. Basic example:
result_german = GoogleTranslator(source='auto', target='de').translate(payload=english_text)
# Alternatively, you can pass languages by their name: result_german = GoogleTranslator(source='english', target='german').translate(payload=english_text) translated = GoogleTranslator(source='english', target='german').translate(payload=english_text)
# or maybe you want to translate a text file ? translated = GoogleTranslator(source='auto', target='german').translate_file('path/to/file')
# or maybe you have many sentences in different languages and want to automate the translation process translated = GoogleTranslator(source='auto', target='de').translate_sentences(your_list_of_sentences)
or maybe you would like to use the Pons translator: Pons.com
.. code-block:: python
###################### Use Pons as a translator ########################### word = 'good' translated_word = PonsTranslator(source='english', target='french').translate(word)
# set the argument return_all to True if you want to get all synonyms of the word to translate translated_word = PonsTranslator(source='english', target='french').translate(word, return_all=True)
Alternatively deep_translator now supports the Linguee translator:
.. code-block:: python
word = 'good' translated_word = LingueeTranslator(source='english', target='french').translate(word)
# set the argument return_all to True if you want to get all synonyms of the word to translate translated_word = PonsTranslator(source='english', target='french').translate(word, return_all=True)11234567891011121314151617181920212223from deep_translator import GoogleTranslatorfrom deep_translator import GoogleTranslator, PonsTranslator, LingueeTranslator
# examples using google translate
english_text = 'happy coding'chinese_text = '這很好'
result_german = GoogleTranslator(source='english', target='german').translate(payload=english_text)result_french = GoogleTranslator(source='auto', target='french').translate(payload=chinese_text)
print(f"original english text: {english_text} | translated text: {result_german}") # result: fröhliche Codierungprint(f"original chinese text: {chinese_text} | translated text: {result_french}") # result: C' est bon
# examples using linguee:text = 'cute'translated = LingueeTranslator(source='english', target='german').translate(word=text)print("Using Linguee ==> the translated text: ", translated)
# examples using pons:text = 'good'translated = PonsTranslator(source='english', target='arabic').translate(word=text)print("using Pons ==> the translated text: ", translated)122345[bumpversion]current_version = 0.1.3current_version = 0.3.1commit = Truetag = True
50 unmodified lines5152535454555650 unmodified lines test_suite='tests', tests_require=test_requirements, url='https://github.com/nidhaloff/deep_translator', version='0.1.3', version='0.3.1', zip_safe=False,)HISTORY.rst+1-1
README.rst+28-9
deep_translator/__init__.py+3-3
deep_translator/tests/test_deep_translator.py+19-7
docs/usage.rst+28-9
examples/trans.py+14-1
setup.cfg+1-1
setup.py+1-1