@@ -4,8 +4,6 @@ Googletrans
4
4
|GitHub license | |travis status | |Documentation Status | |PyPI version |
5
5
|Coverage Status | |Code Climate |
6
6
7
- ANNOUNCEMENT: `v4.0 is planned <https://github.com/ssut/py-googletrans/issues/411 >`_.
8
-
9
7
Googletrans is a **free ** and **unlimited ** python library that
10
8
implemented Google Translate API. This uses the `Google Translate Ajax
11
9
API <https://translate.google.com> `__ to make calls to such methods as
@@ -78,14 +76,21 @@ source language.
78
76
79
77
.. code :: python
80
78
79
+ >> > import asyncio
81
80
>> > 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())
89
94
90
95
Customize service URL
91
96
~~~~~~~~~~~~~~~~~~~~~
@@ -125,12 +130,16 @@ for arrays as well.
125
130
126
131
.. code :: python
127
132
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())
134
143
135
144
Language detection
136
145
~~~~~~~~~~~~~~~~~~
@@ -140,16 +149,21 @@ a given sentence.
140
149
141
150
.. code :: python
142
151
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())
153
167
154
168
GoogleTrans as a command line application
155
169
-----------------------------------------
0 commit comments