Skip to content

Commit

Permalink
fix: pronunciation
Browse files Browse the repository at this point in the history
  • Loading branch information
ssut committed Nov 22, 2024
1 parent 9d7fea0 commit 2c8c165
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions googletrans/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,17 @@ async def translate(

pron = origin
try:
pron = data[0][1][-2]
# Get pronunciation from [0][1][3] which contains romanized pronunciation
if data[0][1] and len(data[0][1]) > 3:
pron = data[0][1][3]
# Fallback to previous methods if not found
elif data[0][1] and len(data[0][1]) > 2:
pron = data[0][1][2]
elif data[0][1] and len(data[0][1]) >= 2:
pron = data[0][1][-2]
except Exception: # pragma: nocover
pass

if pron is None:
try:
pron = data[0][1][2]
except: # pragma: nocover # noqa: E722
pass

if dest in EXCLUDES and pron == origin:
pron = translated

Expand Down

0 comments on commit 2c8c165

Please # to comment.