From c9298b2bf0fd0b907b09532b8b76324ef0ecd80b Mon Sep 17 00:00:00 2001 From: Pierre M Date: Fri, 14 Jul 2023 14:45:21 +0200 Subject: [PATCH 1/2] getdefaultlocale() may return (None, "UTF-8") --- metar_taf_parser/commons/i18n.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/metar_taf_parser/commons/i18n.py b/metar_taf_parser/commons/i18n.py index b273e2b..ca8fa81 100644 --- a/metar_taf_parser/commons/i18n.py +++ b/metar_taf_parser/commons/i18n.py @@ -7,7 +7,10 @@ localedir = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../locale') langAvailable = os.listdir(localedir) -lang = locale.getdefaultlocale()[0][:2] +loc = locale.getdefaultlocale() +lang = 'en' +if loc is not None and loc[0] is not None and len(loc[0]) >= 2: + lang = loc[0][:2] if lang not in langAvailable: lang = 'en' t = gettext.translation(domain='messages', localedir=localedir, fallback=True, languages=[lang]) From a0d8ea2dfb2d7b65323650ec85146e30dc90fb74 Mon Sep 17 00:00:00 2001 From: Pierre M Date: Tue, 25 Jul 2023 12:05:27 +0200 Subject: [PATCH 2/2] getdefaultlocale() may return (None, "UTF-8"), getdefaultlocale() is deprecated, using getlocale() instead --- metar_taf_parser/commons/i18n.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metar_taf_parser/commons/i18n.py b/metar_taf_parser/commons/i18n.py index ca8fa81..890a1be 100644 --- a/metar_taf_parser/commons/i18n.py +++ b/metar_taf_parser/commons/i18n.py @@ -7,7 +7,7 @@ localedir = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../locale') langAvailable = os.listdir(localedir) -loc = locale.getdefaultlocale() +loc = locale.getlocale() lang = 'en' if loc is not None and loc[0] is not None and len(loc[0]) >= 2: lang = loc[0][:2]