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

Patch translation bugs #221

Merged
merged 2 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions neon_core/processing_modules/text/modules/translator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,23 @@ def __init__(self, name="utterance_translator", priority=5):
self.lang_detector = DetectorFactory.create()
self.translator = TranslatorFactory.create()

def parse(self, utterances, lang="en-us"):
def parse(self, utterances, lang=None):
metadata = []
for idx, ut in enumerate(utterances):
try:
original = ut
detected_lang = self.lang_detector.detect(original)
LOG.debug("Detected language: {lang}".format(lang=detected_lang))
if lang and detected_lang != lang.split('-', 1)[0]:
LOG.warning(f"Specified lang: {lang} but detected {detected_lang}")
else:
LOG.debug(f"Detected language: {detected_lang}")
if detected_lang != self.language_config["internal"].split("-")[0]:
utterances[idx] = self.translator.translate(original,
self.language_config["internal"])
self.language_config["internal"], lang.split('-', 1)[0]
or detected_lang)
# add language metadata to context
metadata += [{
"source_lang": lang,
"source_lang": lang or self.language_config['internal'],
"detected_lang": detected_lang,
"internal": self.language_config["internal"],
"was_translated": detected_lang != self.language_config["internal"].split("-")[0],
Expand Down
5 changes: 5 additions & 0 deletions neon_core/skills/intent_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ def handle_utterance(self, message):
self.bus.emit(reply)
return

# TODO: Try the original lang and fallback to translation
# If translated, make sure message.data['lang'] is updated
if message.context.get("translation_data",
[{}])[0].get("was_translated"):
message.data["lang"] = self.language_config["internal"]
# now pass our modified message to Mycroft
# TODO: Consider how to implement 'and' parsing and converse DM
super().handle_utterance(message)
Expand Down