@@ -149,14 +149,24 @@ def scratch_team_members() -> dict:
149
149
150
150
151
151
def translate (language : str | Languages , text : str = "hello" ):
152
- if language .lower () not in Languages .all_of ("code" , str .lower ):
153
- if language .lower () in Languages .all_of ("name" , str .lower ):
154
- language = Languages .find (language .lower (), apply_func = str .lower ).code
152
+ lang = language
153
+ if isinstance (language , str ):
154
+ if language .lower () in Languages .all_of ("code" , str .lower ):
155
+ lang = Languages .find (language .lower (), "code" , apply_func = str .lower )
156
+
157
+ elif language .lower () in Languages .all_of ("name" , str .lower ):
158
+ lang = Languages .find (language .lower (), apply_func = str .lower )
159
+
160
+ elif isinstance (language , Languages ):
161
+ lang = language .value
162
+ else :
163
+ # The code will work so long as the language has a 'code' attribute, however, this is bad practice.
164
+ warnings .warn (f"{ language } is not { str } or { Languages } , but { type (language )} ." )
155
165
156
- lang = Languages .find (language , "code" , str .lower )
157
166
if lang is None :
158
167
raise ValueError (f"{ language } is not a supported translate language" )
159
168
169
+ print (lang .__dict__ )
160
170
response_json = requests .get (
161
171
f"https://translate-service.scratch.mit.edu/translate?language={ lang .code } &text={ text } " ).json ()
162
172
0 commit comments