Skip to content

Commit 7d71d96

Browse files
committed
make sure language has code for translation
1 parent a6c6168 commit 7d71d96

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

scratchattach/other/other_apis.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Other Scratch API-related functions"""
22

33
import json
4-
import warnings
54

65
from ..utils import commons
76
from ..utils.exceptions import BadRequest, InvalidLanguage, InvalidTTSGender
@@ -157,7 +156,10 @@ def translate(language: str | Languages, text: str = "hello"):
157156
lang = language
158157

159158
if not isinstance(lang, Language):
160-
raise InvalidLanguage(f"{language} is not a supported translate language")
159+
raise InvalidLanguage(f"{language} is not a language")
160+
161+
if lang.code is None:
162+
raise InvalidLanguage(f"{lang} is not a valid translate language")
161163

162164
response_json = requests.get(
163165
f"https://translate-service.scratch.mit.edu/translate?language={lang.code}&text={text}").json()

0 commit comments

Comments
 (0)