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

fix:bundled_resources #297

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions ovos_workshop/locale/en/cancel.voc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cancel
nevermind
forget it
25 changes: 18 additions & 7 deletions ovos_workshop/resource_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
from typing import List, Optional, Tuple, Dict, Any

from langcodes import tag_distance
from ovos_config.config import Configuration
from ovos_config.locations import get_xdg_data_save_path
from ovos_utils import flatten_list
from ovos_utils.bracket_expansion import expand_options
from ovos_utils.dialog import MustacheDialogRenderer, load_dialogs
from ovos_utils.log import LOG, log_deprecation
from ovos_utils.log import LOG

SkillResourceTypes = namedtuple(
"SkillResourceTypes",
Expand Down Expand Up @@ -164,6 +163,14 @@ def __init__(self, resource_type: str, file_extension: str,
self.language = language
self.base_directory = None
self.user_directory = None
self.workshop_directory = None

def locate_workshop_directory(self):
if not self.language:
return
for path in locate_lang_directories(self.language, dirname(__file__)):
self.workshop_directory = path
return
JarbasAl marked this conversation as resolved.
Show resolved Hide resolved

def locate_lang_directories(self, skill_directory):
if not self.language:
Expand Down Expand Up @@ -300,6 +307,13 @@ def _locate(self) -> Optional[str]:
if file_name in file_names:
file_path = Path(directory, file_name)

# check ovos-workshop resources
if file_path is None:
walk_directory = str(self.resource_type.workshop_directory)
for directory, _, file_names in walk(walk_directory):
if file_name in file_names:
file_path = Path(directory, file_name)
JarbasAl marked this conversation as resolved.
Show resolved Hide resolved

if file_path is None:
LOG.debug(f"Could not find resource file {file_name} for lang: {self.resource_type.language}")

Expand Down Expand Up @@ -602,6 +616,7 @@ def _define_resource_types(self) -> SkillResourceTypes:
if self.skill_id:
resource_type.locate_user_directory(self.skill_id)
resource_type.locate_base_directory(self.skill_directory)
resource_type.locate_workshop_directory()
return SkillResourceTypes(**resource_types)

def load_json_file(self, name: str = "skill.json") -> Dict[str, str]:
Expand Down Expand Up @@ -882,11 +897,7 @@ def _make_unique_regex_group(regexes: List[str],

class CoreResources(SkillResources):
def __init__(self, language):
try:
from mycroft import MYCROFT_ROOT_PATH
directory = f"{MYCROFT_ROOT_PATH}/mycroft/res"
except ImportError:
directory = f"{dirname(__file__)}/res"
directory = f"{dirname(__file__)}/locale"
super().__init__(directory, language)


Expand Down
7 changes: 4 additions & 3 deletions ovos_workshop/skills/ovos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1842,7 +1842,7 @@ def on_fail_default(utterance):
return dialog

def is_cancel(utterance):
return self.voc_match(utterance, 'cancel')
return self.voc_match(utterance, 'cancel', lang=session.lang)

def validator_default(utterance):
# accept anything except 'cancel'
Expand Down Expand Up @@ -2527,10 +2527,11 @@ def _get_dialog(phrase: str, lang: str, context: Optional[dict] = None) -> str:
Returns:
str: a randomized and/or translated version of the phrase
"""
filename = f"{dirname(dirname(__file__))}/res/text/{lang.split('-')[0]}/{phrase}.dialog"
lang = standardize_lang_tag(lang).split('-')[0]
filename = f"{dirname(dirname(__file__))}/locale/{lang}/{phrase}.dialog"

if not isfile(filename):
LOG.debug('Resource file not found: {}'.format(filename))
LOG.debug(f'Resource file not found: {filename}')
JarbasAl marked this conversation as resolved.
Show resolved Hide resolved
return phrase

stache = MustacheDialogRenderer()
Expand Down
Loading