Skip to content

Commit 2c8c165

Browse files
committed
fix: pronunciation
1 parent 9d7fea0 commit 2c8c165

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

googletrans/client.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,17 @@ async def translate(
289289

290290
pron = origin
291291
try:
292-
pron = data[0][1][-2]
292+
# Get pronunciation from [0][1][3] which contains romanized pronunciation
293+
if data[0][1] and len(data[0][1]) > 3:
294+
pron = data[0][1][3]
295+
# Fallback to previous methods if not found
296+
elif data[0][1] and len(data[0][1]) > 2:
297+
pron = data[0][1][2]
298+
elif data[0][1] and len(data[0][1]) >= 2:
299+
pron = data[0][1][-2]
293300
except Exception: # pragma: nocover
294301
pass
295302

296-
if pron is None:
297-
try:
298-
pron = data[0][1][2]
299-
except: # pragma: nocover # noqa: E722
300-
pass
301-
302303
if dest in EXCLUDES and pron == origin:
303304
pron = translated
304305

0 commit comments

Comments
 (0)