Skip to content

Commit

Permalink
Default to en-us if locale detection fails
Browse files Browse the repository at this point in the history
  • Loading branch information
EhsanKia committed Jun 19, 2020
1 parent 5744ad4 commit 169d546
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,12 @@ def _detect_locale(item_rows: numpy.ndarray, locale: str) -> str:
# If locale is already specified, return as is.
return locale

# Handle automatic langauge detection.
osd_data = pytesseract.image_to_osd(
Image.fromarray(item_rows), output_type=pytesseract.Output.DICT)
# run script detection.
try:
osd_data = pytesseract.image_to_osd(
Image.fromarray(item_rows), output_type=pytesseract.Output.DICT)
except pytesseract.TesseractError:
return 'en-us'

possible_locales = SCRIPT_MAP.get(osd_data['script'])
assert possible_locales, 'Failed to automatically detect language.'
Expand Down

0 comments on commit 169d546

Please sign in to comment.