Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Config handling for language modules #74

Merged
merged 8 commits into from
Sep 16, 2022
8 changes: 4 additions & 4 deletions ovos_plugin_manager/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def create(config=None):
if clazz is None:
raise ValueError(f'Language Detection plugin {lang_module} not found')
LOG.info(f'Loaded the Language Detection plugin {lang_module}')
return clazz()
return clazz(config=config.get(lang_module))
except Exception:
# The Language Detection backend failed to start.
LOG.exception('The selected Language Detection plugin could not be loaded!')
Expand Down Expand Up @@ -114,8 +114,8 @@ def create(config=None):
if "language" in config:
config = config["language"]
lang_module = config.get("translation_module", "libretranslate_plug")
if lang_module in OVOSLangDetectionFactory.MAPPINGS:
lang_module = OVOSLangDetectionFactory.MAPPINGS[lang_module]
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"
Expand All @@ -125,7 +125,7 @@ def create(config=None):
if clazz is None:
raise ValueError(f'Language Translation plugin {lang_module} not found')
LOG.info(f'Loaded the Language Translation plugin {lang_module}')
return clazz()
return clazz(config=config.get(lang_module))
except Exception:
# The Language Detection backend failed to start.
LOG.exception('The selected Language Translation plugin could not be loaded!')
Expand Down
18 changes: 12 additions & 6 deletions ovos_plugin_manager/templates/language.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from ovos_config.config import Configuration


class LanguageDetector:
def __init__(self, config=None):
self.config = config or {}
self.default_language = self.config.get("lang") or "en-us"
config_core = Configuration()
self.config = config or config_core.get('language')
NeonDaniel marked this conversation as resolved.
Show resolved Hide resolved
self.default_language = config_core.get("lang") or "en-us"
# hint_language: str E.g., 'it' boosts Italian
self.hint_language = self.config.get("hint_lang") or self.default_language
self.hint_language = self.config.get("hint_lang") or \
self.config.get('user') or self.default_language
# boost score for this language
self.boost = self.config.get("boost")

Expand All @@ -18,11 +22,13 @@ def detect_probs(self, text):

class LanguageTranslator:
def __init__(self, config=None):
self.config = config or {}
config_core = Configuration()
self.config = config or config_core.get('language')
NeonDaniel marked this conversation as resolved.
Show resolved Hide resolved
# translate from, unless specified/detected otherwise
self.default_language = self.config.get("lang") or "en-us"
self.default_language = config_core.get("lang") or "en-us"
# translate to
self.internal_language = self.config.get("lang") or "en-us"
self.internal_language = self.config.get("internal") or \
self.default_language or "en-us"

def translate(self, text, target=None, source=None):
return text
Expand Down