Skip to content

Commit 46a9e00

Browse files
committed
chore(docs): update for v4.0.0
1 parent c6930e3 commit 46a9e00

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

README.rst

+39-25
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ Googletrans
44
|GitHub license| |travis status| |Documentation Status| |PyPI version|
55
|Coverage Status| |Code Climate|
66

7-
ANNOUNCEMENT: `v4.0 is planned <https://github.com/ssut/py-googletrans/issues/411>`_.
8-
97
Googletrans is a **free** and **unlimited** python library that
108
implemented Google Translate API. This uses the `Google Translate Ajax
119
API <https://translate.google.com>`__ to make calls to such methods as
@@ -78,14 +76,21 @@ source language.
7876

7977
.. code:: python
8078
79+
>>> import asyncio
8180
>>> from googletrans import Translator
82-
>>> translator = Translator()
83-
>>> translator.translate('안녕하세요.')
84-
# <Translated src=ko dest=en text=Good evening. pronunciation=Good evening.>
85-
>>> translator.translate('안녕하세요.', dest='ja')
86-
# <Translated src=ko dest=ja text=こんにちは。 pronunciation=Kon'nichiwa.>
87-
>>> translator.translate('veritas lux mea', src='la')
88-
# <Translated src=la dest=en text=The truth is my light pronunciation=The truth is my light>
81+
>>>
82+
>>> async def translate_text():
83+
... async with Translator() as translator:
84+
... result = await translator.translate('안녕하세요.')
85+
... print(result) # <Translated src=ko dest=en text=Good evening. pronunciation=Good evening.>
86+
...
87+
... result = await translator.translate('안녕하세요.', dest='ja')
88+
... print(result) # <Translated src=ko dest=ja text=こんにちは。 pronunciation=Kon'nichiwa.>
89+
...
90+
... result = await translator.translate('veritas lux mea', src='la')
91+
... print(result) # <Translated src=la dest=en text=The truth is my light pronunciation=The truth is my light>
92+
...
93+
>>> asyncio.run(translate_text())
8994
9095
Customize service URL
9196
~~~~~~~~~~~~~~~~~~~~~
@@ -125,12 +130,16 @@ for arrays as well.
125130

126131
.. code:: python
127132
128-
>>> translations = translator.translate(['The quick brown fox', 'jumps over', 'the lazy dog'], dest='ko')
129-
>>> for translation in translations:
130-
... print(translation.origin, ' -> ', translation.text)
131-
# The quick brown fox -> 빠른 갈색 여우
132-
# jumps over -> 이상 점프
133-
# the lazy dog -> 게으른 개
133+
>>> async def translate_bulk():
134+
... async with Translator() as translator:
135+
... translations = await translator.translate(['The quick brown fox', 'jumps over', 'the lazy dog'], dest='ko')
136+
... for translation in translations:
137+
... print(translation.origin, ' -> ', translation.text)
138+
... # The quick brown fox -> 빠른 갈색 여우
139+
... # jumps over -> 이상 점프
140+
... # the lazy dog -> 게으른 개
141+
...
142+
>>> asyncio.run(translate_bulk())
134143
135144
Language detection
136145
~~~~~~~~~~~~~~~~~~
@@ -140,16 +149,21 @@ a given sentence.
140149

141150
.. code:: python
142151
143-
>>> from googletrans import Translator
144-
>>> translator = Translator()
145-
>>> translator.detect('이 문장은 한글로 쓰여졌습니다.')
146-
# <Detected lang=ko confidence=0.27041003>
147-
>>> translator.detect('この文章は日本語で書かれました。')
148-
# <Detected lang=ja confidence=0.64889508>
149-
>>> translator.detect('This sentence is written in English.')
150-
# <Detected lang=en confidence=0.22348526>
151-
>>> translator.detect('Tiu frazo estas skribita en Esperanto.')
152-
# <Detected lang=eo confidence=0.10538048>
152+
>>> async def detect_languages():
153+
... async with Translator() as translator:
154+
... result = await translator.detect('이 문장은 한글로 쓰여졌습니다.')
155+
... print(result) # <Detected lang=ko confidence=0.27041003>
156+
...
157+
... result = await translator.detect('この文章は日本語で書かれました。')
158+
... print(result) # <Detected lang=ja confidence=0.64889508>
159+
...
160+
... result = await translator.detect('This sentence is written in English.')
161+
... print(result) # <Detected lang=en confidence=0.22348526>
162+
...
163+
... result = await translator.detect('Tiu frazo estas skribita en Esperanto.')
164+
... print(result) # <Detected lang=eo confidence=0.10538048>
165+
...
166+
>>> asyncio.run(detect_languages())
153167
154168
GoogleTrans as a command line application
155169
-----------------------------------------

0 commit comments

Comments
 (0)