= 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 line2345671 unmodified lineHistory=======0.1.4 stable release---------------------1 unmodified line2345671 unmodified lineHistory=======0.3.1 stable release---------------------
48 unmodified lines495051525354555657585960616263646566676869707172737448 unmodified lines.. code-block:: pythonfrom deep_translator import GoogleTranslatorenglish_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)##################### or maybe you want to translate a text file ? #############################translated_text = 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 processtranslated = GoogleTranslator(source='auto', target='de').translate_sentences(your_list_of_sentences)###################### or use Pons as a translator ###########################word = 'good'translated_word = PonsTranslator(source='english', target='french').translate(word)48 unmodified lines49505152535455565758596061626364656667686970717273747576777879808182838485868788899091929348 unmodified lines.. code-block:: pythonfrom deep_translator import GoogleTranslator, PonsTranslator, LingueeTranslatorenglish_text = 'happy coding'result_german = GoogleTranslator(source='auto', target='de').translate(payload=english_text)# Alternatively, you can pass languages by their name: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 processtranslated = 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:: pythonword = '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 translatetranslated_word = PonsTranslator(source='english', target='french').translate(word, return_all=True)Alternatively deep_translator now supports the Linguee translator:.. code-block:: pythonword = '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 translatetranslated_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 line2345678910111 unmodified linefrom .google_trans import GoogleTranslatorfrom .pons import PonsTranslator__author__ = """Nidhal Baccouri"""__email__ = 'nidhalbacc@gmail.com'__version__ = '0.1.3'__all__ = [GoogleTranslator,PonsTranslator]1 unmodified line2345678910111 unmodified linefrom .google_trans import GoogleTranslatorfrom .pons import PonsTranslatorfrom .linguee import LingueeTranslator__author__ = """Nidhal Baccouri"""__email__ = 'nidhalbacc@gmail.com'__version__ = '0.3.1'__all__ = [GoogleTranslator, PonsTranslator, LingueeTranslator]
6 unmodified lines789101112131415161718191 unmodified line212223242526276 unmodified lines@pytest.fixturedef response():"""Sample pytest fixture.See more at: http://doc.pytest.org/en/latest/fixture.html"""translator = GoogleTranslator(target='en')assert translator.translate(payload='좋은') == "good"with pytest.raises(exceptions.LanguageNotSupportedException):GoogleTranslator(source="", target="")1 unmodified lineGoogleTranslator(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.string6 unmodified lines789101112131415161718192021222324252627281 unmodified line303132333435363738396 unmodified lines@pytest.fixturedef google_translator():"""Sample pytest fixture.See more at: http://doc.pytest.org/en/latest/fixture.html"""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.stringassert google_translator.translate(payload='좋은') == "good"def test_inputs():with pytest.raises(exceptions.LanguageNotSupportedException):GoogleTranslator(source="", target="")1 unmodified lineGoogleTranslator(source="auto", target="nothing")def 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 line23456789101112131415161718192021222324251 unmodified lineUsage=====.. code-block:: pythonfrom deep_translator import GoogleTranslator, PonsTranslatorenglish_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)###################### Use Pons as a translator ###########################word = 'good'translated_word = PonsTranslator(source='english', target='french').translate(word)1 unmodified line2345678910111213141516171819202122232425262728293031323334353637383940414243441 unmodified lineUsage=====.. code-block:: pythonfrom deep_translator import GoogleTranslator, PonsTranslator, LingueeTranslatorenglish_text = 'happy coding'result_german = GoogleTranslator(source='auto', target='de').translate(payload=english_text)# Alternatively, you can pass languages by their name: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 processtranslated = 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:: pythonword = '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 translatetranslated_word = PonsTranslator(source='english', target='french').translate(word, return_all=True)Alternatively deep_translator now supports the Linguee translator:.. code-block:: pythonword = '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 translatetranslated_word = PonsTranslator(source='english', target='french').translate(word, return_all=True)
12345678910from deep_translator import GoogleTranslatorenglish_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 bon1234567891011121314151617181920212223from deep_translator import GoogleTranslator, PonsTranslator, LingueeTranslator# examples using google translateenglish_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)
12345[bumpversion]current_version = 0.1.3commit = Truetag = True12345[bumpversion]current_version = 0.3.1commit = Truetag = True
50 unmodified lines51525354555650 unmodified linestest_suite='tests',tests_require=test_requirements,url='https://github.com/nidhaloff/deep_translator',version='0.1.3',zip_safe=False,)50 unmodified lines51525354555650 unmodified linestest_suite='tests',tests_require=test_requirements,url='https://github.com/nidhaloff/deep_translator',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