Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Issue 2120 - Fallback to 'en-us' when resource loading fails #2392

Closed
wants to merge 4 commits into from
Closed
Changes from 2 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
17 changes: 15 additions & 2 deletions mycroft/skills/mycroft_skill/mycroft_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,22 @@ def find_resource(self, res_name, res_dirname=None):
Returns:
string: The full path to the resource file or None if not found
"""
result = self._find_resource(res_name, self.lang, res_dirname)
if not result:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add and self.lang != 'en-us' to this if-statement so it doesn't try to get English resources twice if the file is missing.

# when resource not found try fallback to en-us
LOG.warning(
"Resource '{}' for lang '{}' not found: trying 'en-us'"
.format(res_name, self.lang)
)
result = self._find_resource(res_name, 'en-us', res_dirname)
return result

def _find_resource(self, res_name, lang, res_dirname=None):
"""Finds a resource by name, lang and dir
"""
if res_dirname:
# Try the old translated directory (dialog/vocab/regex)
path = join(self.root_dir, res_dirname, self.lang, res_name)
path = join(self.root_dir, res_dirname, lang, res_name)
if exists(path):
return path

Expand All @@ -687,7 +700,7 @@ def find_resource(self, res_name, res_dirname=None):
return path

# New scheme: search for res_name under the 'locale' folder
root_path = join(self.root_dir, 'locale', self.lang)
root_path = join(self.root_dir, 'locale', lang)
for path, _, files in walk(root_path):
if res_name in files:
return join(path, res_name)
Expand Down