Skip to content

Commit

Permalink
better translate fallback module handling (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
emphasize authored Apr 29, 2023
1 parent 68ec25f commit 9eb9f07
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions ovos_plugin_manager/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,20 @@ def create(config=None):
lang_module = OVOSLangDetectionFactory.MAPPINGS[lang_module]

clazz = load_lang_detect_plugin(lang_module)
if clazz is None and lang_module != "libretranslate_detection_plug":
lang_module = "libretranslate_detection_plug"
LOG.error(f'Language Translation plugin {lang_module} not found\n'
f'Falling back to libretranslate plugin')
clazz = load_tx_plugin("libretranslate_detection_plug")
if clazz is None:
raise ValueError(f'Language Detection plugin {lang_module} not found')
raise ValueError
LOG.info(f'Loaded the Language Detection plugin {lang_module}')
return clazz(config=get_plugin_config(config, "language", lang_module))
except Exception:
# The Language Detection backend failed to start.
LOG.exception('The selected Language Detection plugin could not be loaded!')
# The Language Detection backend failed to start, fall back if appropriate.
if lang_module != "libretranslate_detection_plug":
lang_module = "libretranslate_detection_plug"
LOG.error(f'Language Translation plugin {lang_module} not found\n'
f'Falling back to libretranslate plugin')
clazz = load_tx_plugin("libretranslate_detection_plug")
if clazz:
return clazz(config=get_plugin_config(config, "language", lang_module))

raise


Expand Down Expand Up @@ -121,16 +123,18 @@ def create(config=None):
if lang_module in OVOSLangTranslationFactory.MAPPINGS:
lang_module = OVOSLangTranslationFactory.MAPPINGS[lang_module]
clazz = load_tx_plugin(lang_module)
if clazz is None and lang_module != "libretranslate_plug":
lang_module = "libretranslate_plug"
LOG.error(f'Language Translation plugin {lang_module} not found\n'
f'Falling back to libretranslate plugin')
clazz = load_tx_plugin("libretranslate_plug")
if clazz is None:
raise ValueError(f'Language Translation plugin {lang_module} not found')
raise ValueError
LOG.info(f'Loaded the Language Translation plugin {lang_module}')
return clazz(config=get_plugin_config(config, "language", lang_module))
except Exception:
# The Language Detection backend failed to start.
LOG.exception('The selected Language Translation plugin could not be loaded!')
# The Language Detection backend failed to start, fall back if appropriate.
if lang_module != "libretranslate_plug":
lang_module = "libretranslate_plug"
LOG.error(f'Language Translation plugin {lang_module} not found\n'
f'Falling back to libretranslate plugin')
clazz = load_tx_plugin("libretranslate_plug")
if clazz:
return clazz(config=get_plugin_config(config, "language", lang_module))

raise

0 comments on commit 9eb9f07

Please sign in to comment.