diff --git a/CHANGELOG.md b/CHANGELOG.md index ec5b91e..374f0f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,12 @@ # Changelog -## [0.3.4a1](https://github.com/OpenVoiceOS/ovos-utils/tree/0.3.4a1) (2024-10-16) +## [0.3.5a1](https://github.com/OpenVoiceOS/ovos-utils/tree/0.3.5a1) (2024-10-16) -[Full Changelog](https://github.com/OpenVoiceOS/ovos-utils/compare/0.3.3...0.3.4a1) +[Full Changelog](https://github.com/OpenVoiceOS/ovos-utils/compare/0.3.4...0.3.5a1) **Merged pull requests:** -- fix:standardize\_lang [\#281](https://github.com/OpenVoiceOS/ovos-utils/pull/281) ([JarbasAl](https://github.com/JarbasAl)) +- fix:standardize\_lang [\#283](https://github.com/OpenVoiceOS/ovos-utils/pull/283) ([JarbasAl](https://github.com/JarbasAl)) diff --git a/ovos_utils/lang/__init__.py b/ovos_utils/lang/__init__.py index 439d30b..e9d89c5 100644 --- a/ovos_utils/lang/__init__.py +++ b/ovos_utils/lang/__init__.py @@ -1,13 +1,16 @@ from os import listdir from os.path import isdir, join -from langcodes import tag_distance, standardize_tag as std +from typing import Optional + +from langcodes import tag_distance, standardize_tag as std + from ovos_utils.file_utils import resolve_resource_file -def standardize_lang_tag(lang_code, macro=True): +def standardize_lang_tag(lang_code: str, macro=True) -> str: """https://langcodes-hickford.readthedocs.io/en/sphinx/index.html""" try: - return std(lang_code, macro=macro) + return str(std(lang_code, macro=macro)) except: if macro: return lang_code.split("-")[0].lower() @@ -17,7 +20,7 @@ def standardize_lang_tag(lang_code, macro=True): return lang_code.lower() -def get_language_dir(base_path, lang="en-US"): +def get_language_dir(base_path: str, lang: str ="en-US") -> Optional[str]: """ checks for all language variations and returns best path """ lang = standardize_lang_tag(lang) @@ -33,11 +36,12 @@ def get_language_dir(base_path, lang="en-US"): # 1- 3 -> These codes indicate a minor regional difference. # 4 - 10 -> These codes indicate a significant but unproblematic regional difference. if score < 10: - candidates.append((f, score)) - + candidates.append((f"{base_path}/{f}", score)) + if not candidates: + return None # sort by distance to target lang code candidates = sorted(candidates, key=lambda k: k[1]) - return candidates[0] + return candidates[0][0] def translate_word(name, lang='en-US'): diff --git a/ovos_utils/version.py b/ovos_utils/version.py index 94bf32b..67bb1b7 100644 --- a/ovos_utils/version.py +++ b/ovos_utils/version.py @@ -1,6 +1,6 @@ # START_VERSION_BLOCK VERSION_MAJOR = 0 VERSION_MINOR = 3 -VERSION_BUILD = 4 -VERSION_ALPHA = 0 +VERSION_BUILD = 5 +VERSION_ALPHA = 1 # END_VERSION_BLOCK