From 3d75fea35fd87552f7ff261ab0f0591a8ee50214 Mon Sep 17 00:00:00 2001 From: miro Date: Tue, 19 Nov 2024 19:58:27 +0000 Subject: [PATCH 1/3] fix:bundled_resources --- .../text => locale}/az/word_connectors.json | 0 .../text => locale}/ca/word_connectors.json | 0 .../{res/text => locale}/cs/noise_words.list | 0 .../text => locale}/cs/word_connectors.json | 0 .../text => locale}/da/word_connectors.json | 0 .../{res/text => locale}/de/noise_words.list | 0 .../text => locale}/de/word_connectors.json | 0 ovos_workshop/locale/en/cancel.voc | 3 +++ .../{res/text => locale}/en/noise_words.list | 0 .../text => locale}/en/skill.error.dialog | 0 .../text => locale}/en/word_connectors.json | 0 .../text => locale}/es/word_connectors.json | 0 .../text => locale}/fa/word_connectors.json | 0 .../text => locale}/gl/word_connectors.json | 0 .../text => locale}/it/word_connectors.json | 0 .../text => locale}/nl/skill.error.dialog | 0 .../text => locale}/nl/word_connectors.json | 0 .../text => locale}/pl/word_connectors.json | 0 .../text => locale}/pt/word_connectors.json | 0 .../{res/text => locale}/ru/noise_words.list | 0 .../text => locale}/sl/word_connectors.json | 0 .../text => locale}/uk/word_connectors.json | 0 ovos_workshop/resource_files.py | 25 +++++++++++++------ ovos_workshop/skills/ovos.py | 7 +++--- 24 files changed, 25 insertions(+), 10 deletions(-) rename ovos_workshop/{res/text => locale}/az/word_connectors.json (100%) rename ovos_workshop/{res/text => locale}/ca/word_connectors.json (100%) rename ovos_workshop/{res/text => locale}/cs/noise_words.list (100%) rename ovos_workshop/{res/text => locale}/cs/word_connectors.json (100%) rename ovos_workshop/{res/text => locale}/da/word_connectors.json (100%) rename ovos_workshop/{res/text => locale}/de/noise_words.list (100%) rename ovos_workshop/{res/text => locale}/de/word_connectors.json (100%) create mode 100644 ovos_workshop/locale/en/cancel.voc rename ovos_workshop/{res/text => locale}/en/noise_words.list (100%) rename ovos_workshop/{res/text => locale}/en/skill.error.dialog (100%) rename ovos_workshop/{res/text => locale}/en/word_connectors.json (100%) rename ovos_workshop/{res/text => locale}/es/word_connectors.json (100%) rename ovos_workshop/{res/text => locale}/fa/word_connectors.json (100%) rename ovos_workshop/{res/text => locale}/gl/word_connectors.json (100%) rename ovos_workshop/{res/text => locale}/it/word_connectors.json (100%) rename ovos_workshop/{res/text => locale}/nl/skill.error.dialog (100%) rename ovos_workshop/{res/text => locale}/nl/word_connectors.json (100%) rename ovos_workshop/{res/text => locale}/pl/word_connectors.json (100%) rename ovos_workshop/{res/text => locale}/pt/word_connectors.json (100%) rename ovos_workshop/{res/text => locale}/ru/noise_words.list (100%) rename ovos_workshop/{res/text => locale}/sl/word_connectors.json (100%) rename ovos_workshop/{res/text => locale}/uk/word_connectors.json (100%) diff --git a/ovos_workshop/res/text/az/word_connectors.json b/ovos_workshop/locale/az/word_connectors.json similarity index 100% rename from ovos_workshop/res/text/az/word_connectors.json rename to ovos_workshop/locale/az/word_connectors.json diff --git a/ovos_workshop/res/text/ca/word_connectors.json b/ovos_workshop/locale/ca/word_connectors.json similarity index 100% rename from ovos_workshop/res/text/ca/word_connectors.json rename to ovos_workshop/locale/ca/word_connectors.json diff --git a/ovos_workshop/res/text/cs/noise_words.list b/ovos_workshop/locale/cs/noise_words.list similarity index 100% rename from ovos_workshop/res/text/cs/noise_words.list rename to ovos_workshop/locale/cs/noise_words.list diff --git a/ovos_workshop/res/text/cs/word_connectors.json b/ovos_workshop/locale/cs/word_connectors.json similarity index 100% rename from ovos_workshop/res/text/cs/word_connectors.json rename to ovos_workshop/locale/cs/word_connectors.json diff --git a/ovos_workshop/res/text/da/word_connectors.json b/ovos_workshop/locale/da/word_connectors.json similarity index 100% rename from ovos_workshop/res/text/da/word_connectors.json rename to ovos_workshop/locale/da/word_connectors.json diff --git a/ovos_workshop/res/text/de/noise_words.list b/ovos_workshop/locale/de/noise_words.list similarity index 100% rename from ovos_workshop/res/text/de/noise_words.list rename to ovos_workshop/locale/de/noise_words.list diff --git a/ovos_workshop/res/text/de/word_connectors.json b/ovos_workshop/locale/de/word_connectors.json similarity index 100% rename from ovos_workshop/res/text/de/word_connectors.json rename to ovos_workshop/locale/de/word_connectors.json diff --git a/ovos_workshop/locale/en/cancel.voc b/ovos_workshop/locale/en/cancel.voc new file mode 100644 index 00000000..a28866e8 --- /dev/null +++ b/ovos_workshop/locale/en/cancel.voc @@ -0,0 +1,3 @@ +cancel +nevermind +forget it \ No newline at end of file diff --git a/ovos_workshop/res/text/en/noise_words.list b/ovos_workshop/locale/en/noise_words.list similarity index 100% rename from ovos_workshop/res/text/en/noise_words.list rename to ovos_workshop/locale/en/noise_words.list diff --git a/ovos_workshop/res/text/en/skill.error.dialog b/ovos_workshop/locale/en/skill.error.dialog similarity index 100% rename from ovos_workshop/res/text/en/skill.error.dialog rename to ovos_workshop/locale/en/skill.error.dialog diff --git a/ovos_workshop/res/text/en/word_connectors.json b/ovos_workshop/locale/en/word_connectors.json similarity index 100% rename from ovos_workshop/res/text/en/word_connectors.json rename to ovos_workshop/locale/en/word_connectors.json diff --git a/ovos_workshop/res/text/es/word_connectors.json b/ovos_workshop/locale/es/word_connectors.json similarity index 100% rename from ovos_workshop/res/text/es/word_connectors.json rename to ovos_workshop/locale/es/word_connectors.json diff --git a/ovos_workshop/res/text/fa/word_connectors.json b/ovos_workshop/locale/fa/word_connectors.json similarity index 100% rename from ovos_workshop/res/text/fa/word_connectors.json rename to ovos_workshop/locale/fa/word_connectors.json diff --git a/ovos_workshop/res/text/gl/word_connectors.json b/ovos_workshop/locale/gl/word_connectors.json similarity index 100% rename from ovos_workshop/res/text/gl/word_connectors.json rename to ovos_workshop/locale/gl/word_connectors.json diff --git a/ovos_workshop/res/text/it/word_connectors.json b/ovos_workshop/locale/it/word_connectors.json similarity index 100% rename from ovos_workshop/res/text/it/word_connectors.json rename to ovos_workshop/locale/it/word_connectors.json diff --git a/ovos_workshop/res/text/nl/skill.error.dialog b/ovos_workshop/locale/nl/skill.error.dialog similarity index 100% rename from ovos_workshop/res/text/nl/skill.error.dialog rename to ovos_workshop/locale/nl/skill.error.dialog diff --git a/ovos_workshop/res/text/nl/word_connectors.json b/ovos_workshop/locale/nl/word_connectors.json similarity index 100% rename from ovos_workshop/res/text/nl/word_connectors.json rename to ovos_workshop/locale/nl/word_connectors.json diff --git a/ovos_workshop/res/text/pl/word_connectors.json b/ovos_workshop/locale/pl/word_connectors.json similarity index 100% rename from ovos_workshop/res/text/pl/word_connectors.json rename to ovos_workshop/locale/pl/word_connectors.json diff --git a/ovos_workshop/res/text/pt/word_connectors.json b/ovos_workshop/locale/pt/word_connectors.json similarity index 100% rename from ovos_workshop/res/text/pt/word_connectors.json rename to ovos_workshop/locale/pt/word_connectors.json diff --git a/ovos_workshop/res/text/ru/noise_words.list b/ovos_workshop/locale/ru/noise_words.list similarity index 100% rename from ovos_workshop/res/text/ru/noise_words.list rename to ovos_workshop/locale/ru/noise_words.list diff --git a/ovos_workshop/res/text/sl/word_connectors.json b/ovos_workshop/locale/sl/word_connectors.json similarity index 100% rename from ovos_workshop/res/text/sl/word_connectors.json rename to ovos_workshop/locale/sl/word_connectors.json diff --git a/ovos_workshop/res/text/uk/word_connectors.json b/ovos_workshop/locale/uk/word_connectors.json similarity index 100% rename from ovos_workshop/res/text/uk/word_connectors.json rename to ovos_workshop/locale/uk/word_connectors.json diff --git a/ovos_workshop/resource_files.py b/ovos_workshop/resource_files.py index 53909cd8..9f55683e 100644 --- a/ovos_workshop/resource_files.py +++ b/ovos_workshop/resource_files.py @@ -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", @@ -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 def locate_lang_directories(self, skill_directory): if not self.language: @@ -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) + if file_path is None: LOG.debug(f"Could not find resource file {file_name} for lang: {self.resource_type.language}") @@ -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]: @@ -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) diff --git a/ovos_workshop/skills/ovos.py b/ovos_workshop/skills/ovos.py index ffcd7704..18ad7337 100644 --- a/ovos_workshop/skills/ovos.py +++ b/ovos_workshop/skills/ovos.py @@ -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' @@ -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}') return phrase stache = MustacheDialogRenderer() From 0f348cb53a7da617f671b559bb4fb377f047fa24 Mon Sep 17 00:00:00 2001 From: miro Date: Tue, 19 Nov 2024 20:10:03 +0000 Subject: [PATCH 2/3] fix:locale --- ovos_workshop/skills/common_query_skill.py | 2 +- ovos_workshop/skills/ovos.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ovos_workshop/skills/common_query_skill.py b/ovos_workshop/skills/common_query_skill.py index 6839b5e4..405d9d9a 100644 --- a/ovos_workshop/skills/common_query_skill.py +++ b/ovos_workshop/skills/common_query_skill.py @@ -69,7 +69,7 @@ def __init__(self, *args, **kwargs): lang = self.lang.split("-")[0] noise_words_filepath = f"text/{lang}/noise_words.list" - default_res = f"{dirname(dirname(__file__))}/res/text/{lang}" \ + default_res = f"{dirname(dirname(__file__))}/locale/{lang}" \ f"/noise_words.list" noise_words_filename = \ resolve_resource_file(noise_words_filepath, diff --git a/ovos_workshop/skills/ovos.py b/ovos_workshop/skills/ovos.py index 18ad7337..be9206d7 100644 --- a/ovos_workshop/skills/ovos.py +++ b/ovos_workshop/skills/ovos.py @@ -2122,13 +2122,13 @@ def voc_match(self, utt: str, voc_filename: str, lang: Optional[str] = None, requested. The method first checks in the current Skill's .voc files and secondly - in the "res/text" folder of mycroft-core. The result is cached to + in the "locale" folder of ovos-workshop. The result is cached to avoid hitting the disk each time the method is called. Args: utt (str): Utterance to be tested - voc_filename (str): Name of vocabulary file (e.g. 'yes' for - 'res/text/en-us/yes.voc') + voc_filename (str): Name of vocabulary file (e.g. 'cancel' for + 'locale/en-us/cancel.voc') lang (str): Language code, defaults to self.lang exact (bool): Whether the vocab must exactly match the utterance @@ -2551,7 +2551,8 @@ def _get_word(lang, connector): Returns: str: translated version of resource name """ - res_file = f"{dirname(dirname(__file__))}/res/text/{lang}" \ + lang = standardize_lang_tag(lang).split("-")[0] + res_file = f"{dirname(dirname(__file__))}/locale/{lang}" \ f"/word_connectors.json" if not os.path.isfile(res_file): LOG.warning(f"untranslated file: {res_file}") From c51b2b04ad3594edc639c2156ea6f7c55389d7d0 Mon Sep 17 00:00:00 2001 From: miro Date: Tue, 19 Nov 2024 20:11:25 +0000 Subject: [PATCH 3/3] @coderabbitai review --- ovos_workshop/resource_files.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ovos_workshop/resource_files.py b/ovos_workshop/resource_files.py index 9f55683e..bce9bcc2 100644 --- a/ovos_workshop/resource_files.py +++ b/ovos_workshop/resource_files.py @@ -308,7 +308,7 @@ def _locate(self) -> Optional[str]: file_path = Path(directory, file_name) # check ovos-workshop resources - if file_path is None: + if file_path is None and self.resource_type.workshop_directory is not None: walk_directory = str(self.resource_type.workshop_directory) for directory, _, file_names in walk(walk_directory): if file_name in file_names: