[PATCH] i18n: Fix startup failure if LANG has invalid value

6 views
Skip to first unread message

Mads Kiilerich

unread,
Jul 15, 2024, 7:47:16 PM (12 days ago) Jul 15
to thg...@googlegroups.com
# HG changeset patch
# User Mads Kiilerich <ma...@kiilerich.com>
# Date 1721086899 -7200
# Tue Jul 16 01:41:39 2024 +0200
# Branch stable
# Node ID 2a04200f98b3c28444a6c5cda3774206776be5da
# Parent 11f1ce257da48fff304e25599428114675f8a06d
i18n: Fix startup failure if LANG has invalid value

An invalid LANG value would make locale.getdefaultlocale raise a ValueError
when i18n.py was imported, causing a confusing failure like:

File "tortoisehg/hgqt/run.py", line 47, in <module>
from ..util.i18n import agettext as _
ImportError: cannot import name 'agettext' from 'tortoisehg.util.i18n'

diff --git a/tortoisehg/util/i18n.py b/tortoisehg/util/i18n.py
--- a/tortoisehg/util/i18n.py
+++ b/tortoisehg/util/i18n.py
@@ -49,7 +49,12 @@ def setlanguage(lang: Optional[str] = No
opts['languages'] = (lang,)
t = gettext.translation('tortoisehg', paths.get_locale_path(),
fallback=True, **opts)
- language = lang if lang else locale.getdefaultlocale(_localeenvs)[0]
+ if not lang:
+ try:
+ lang = locale.getdefaultlocale(_localeenvs)[0]
+ except ValueError: # 'unknown locale: %s'
+ lang = None
+ language = lang

setlanguage()


Yuya Nishihara

unread,
Jul 16, 2024, 3:55:33 AM (11 days ago) Jul 16
to Mads Kiilerich, thg...@googlegroups.com
On Tue, 16 Jul 2024 01:47:05 +0200, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <ma...@kiilerich.com>
> # Date 1721086899 -7200
> # Tue Jul 16 01:41:39 2024 +0200
> # Branch stable
> # Node ID 2a04200f98b3c28444a6c5cda3774206776be5da
> # Parent 11f1ce257da48fff304e25599428114675f8a06d
> i18n: Fix startup failure if LANG has invalid value

Queued for stable, thanks.
Reply all
Reply to author
Forward
0 new messages