Skip to content

Commit

Permalink
Fallback to 'en-us' when resource fails
Browse files Browse the repository at this point in the history
When mycroft_skill.find_resource fails to load a resource for self.lang
fall back to lang 'en-us'
as most skills/resources are available in english by default.

==== Fixed Issues ====
MycroftAI#2120
  • Loading branch information
domcross committed Nov 22, 2019
1 parent fc78470 commit 79f00e3
Showing 1 changed file with 15 additions and 2 deletions.
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:
# 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):
"""Find 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

0 comments on commit 79f00e3

Please sign in to comment.