Skip to content

Commit

Permalink
fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
lemisky committed Jul 7, 2021
1 parent cf3ac6f commit 7d2195b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ print(text.translatedText) # 谷歌翻译

### 二者的差异

| | 缺点 | 优点 |
| :-------------: | :------------------------------------------------------: | :---------: |
| Translate | 可能不稳定(使用频率), 需要更换`User-Agent`或者使用IP代理 | 可直接使用, |
| ApiKeyTranslate | 试用结束后, 需要`money`&单个字符串限制`102400`bytes | 无使用限制 |
| | 缺点 | 优点 |
| :-------------: | :------------------------------------------------------: | :--------: |
| Translate | 可能不稳定(使用频率), 需要更换`User-Agent`或者使用IP代理 | 可直接使用 |
| ApiKeyTranslate | 试用结束后, 需要`money`&单个字符串限制`102400`bytes | 无使用限制 |

#### 关于不稳定的问题

Expand Down
16 changes: 16 additions & 0 deletions pygtrans/Translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ def translate(
Batch test
Batch translation
"""

if not q:
return []

if isinstance(q, str):
if q == '':
return ''

response = self._translate(q=q, target=target, source=source, _format=_format, v='1.0')

if response.status_code == 200:
Expand Down Expand Up @@ -206,6 +214,14 @@ def translate_and_detect(
zh-CN
zh-CN
"""

if not q:
return []

if isinstance(q, str):
if q == '':
return ''

response = self._translate(q=q, target=target, source=source, _format=_format)

if response.status_code == 200:
Expand Down

0 comments on commit 7d2195b

Please sign in to comment.