Skip to content

Commit

Permalink
fix:lang_dir_crawling (#289)
Browse files Browse the repository at this point in the history
* fix:lang_dir_crawling

finding default resource file directories wasn't quite right

* @coderabbitai review
  • Loading branch information
JarbasAl authored Nov 15, 2024
1 parent 5dc5467 commit 420c675
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions ovos_workshop/resource_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ def locate_base_directories(skill_directory: str,


def locate_lang_directories(lang: str, skill_directory: str,
resource_subdirectory: Optional[str] = None) -> \
List[Path]:
resource_subdirectory: Optional[str] = None) -> List[Path]:
"""
Locate all possible resource directories found in the given skill_directory
for the specified language
Expand Down Expand Up @@ -214,32 +213,22 @@ def locate_base_directory(self, skill_directory: str) -> Optional[str]:
the skill's directory for the resource type or None if not found
"""
resource_subdirectory = self._get_resource_subdirectory()

if not self.language:
self._locate_base_no_lang(skill_directory, resource_subdirectory)
return

# check for lang resources shipped by the skill
possible_directories = [Path(skill_directory, "locale", self.language)]
possible_directories = []
if resource_subdirectory:
possible_directories += [
Path(skill_directory, resource_subdirectory, self.language),
Path(skill_directory, resource_subdirectory)
]
subdirectory_path = Path(skill_directory).joinpath(resource_subdirectory)
possible_directories += self.locate_lang_directories(str(subdirectory_path))
possible_directories += self.locate_lang_directories(skill_directory)

for directory in possible_directories:
if directory.exists():
self.base_directory = directory
return

# check for subdialects of same language as a fallback
# eg, language is set to en-au but only en-us resources are available
similar_dialect_directories = self.locate_lang_directories(skill_directory)
for directory in similar_dialect_directories:
if directory.exists():
self.base_directory = directory
return

# check for lang resources defined by the user
# user data is usually meant as an override for skill data
# but it may be the only data source in some rare instances
Expand Down

0 comments on commit 420c675

Please sign in to comment.