Skip to content

Commit

Permalink
fix error dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Nov 14, 2024
1 parent d723218 commit dd19f58
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from ovos_number_parser import pronounce_number, extract_number
from ovos_plugin_manager.language import OVOSLangTranslationFactory, OVOSLangDetectionFactory
from ovos_utils import camel_case_split, classproperty
from ovos_utils.dialog import get_dialog, MustacheDialogRenderer
from ovos_utils.dialog import MustacheDialogRenderer
from ovos_utils.events import EventContainer, EventSchedulerInterface
from ovos_utils.events import get_handler_name, create_wrapper
from ovos_utils.file_utils import FileWatcher
Expand Down Expand Up @@ -1014,11 +1014,9 @@ def _upload_settings(self):
"""
Upload settings to a remote backend if configured.
"""
if self.settings_manager and self.config_core.get("skills",
{}).get("sync2way"):
if self.settings_manager and self.config_core.get("skills", {}).get("sync2way"):
# upload new settings to backend
generate = self.config_core.get("skills", {}).get("autogen_meta",
True)
generate = self.config_core.get("skills", {}).get("autogen_meta", True)
# this will check global sync flag
self.settings_manager.upload(generate)
if generate:
Expand Down Expand Up @@ -1588,7 +1586,7 @@ def _on_event_error(self, error: str, message: Message, handler_info: str,
# Convert "MyFancySkill" to "My Fancy Skill" for speaking
handler_name = camel_case_split(self.name)
msg_data = {'skill': handler_name}
speech = get_dialog('skill.error', self.lang, msg_data)
speech = _get_dialog('skill.error', self.lang, msg_data)
if speak_errors:
self.speak(speech)
self.log.exception(error)
Expand Down Expand Up @@ -2532,6 +2530,33 @@ def __init__(self, skill: OVOSSkill):
ui_directories=ui_directories)


def _get_dialog(phrase: str, lang: str, context: Optional[dict] = None) -> str:
"""
Looks up a resource file for the given phrase in the specified language.
Meant only for resources bundled with ovos-workshop and shared across skills
Args:
phrase (str): resource phrase to retrieve/translate
lang (str): the language to use
context (dict): values to be inserted into the string
Returns:
str: a randomized and/or translated version of the phrase
"""
filename = f"{dirname(dirname(__file__))}/res/text/{lang.split('-')[0]}/{phrase}.dialog"

if not isfile(filename):
LOG.debug('Resource file not found: {}'.format(filename))
return phrase

stache = MustacheDialogRenderer()
stache.load_template_file('template', filename)
if not context:
context = {}
return stache.render('template', context)


def _get_word(lang, connector):
""" Helper to get word translations
Expand Down

0 comments on commit dd19f58

Please sign in to comment.