X Tutup
Skip to content

Commit c83f10a

Browse files
committed
Handle locale.setlocale error.
If locale.setlocale throws an exception this most probably means that the users environment is fucked up. In this case an error message is printed to stderr and the C locale is used as fallback. This is not an optimal solution at all since the user might see the error message only after he quit bpython. It seems to be common to fall back to the C locale and continue as if nothing has happened, so we do the same. Closes: #217
1 parent da01433 commit c83f10a

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

bpython/cli.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,6 @@ def main_curses(scr, args, config, interactive=True, locals_=None,
18611861

18621862

18631863
def main(args=None, locals_=None, banner=None):
1864-
locale.setlocale(locale.LC_ALL, "")
18651864
translations.init()
18661865

18671866

bpython/translations/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import gettext
2+
import locale
23
import os.path
3-
from sys import version_info
4+
import sys
45

56
from bpython import package_dir
67

78
translator = None
89

9-
if version_info >= (3, 0):
10+
if sys.version_info >= (3, 0):
1011
def _(message):
1112
return translator.gettext(message)
1213
else:
@@ -15,6 +16,15 @@ def _(message):
1516

1617

1718
def init(locale_dir=None, languages=None):
19+
try:
20+
locale.setlocale(locale.LC_ALL, '')
21+
except locale.Error:
22+
# This means that the user's environment is broken. Let's just continue
23+
# with the default C locale.
24+
sys.stderr.write("Error: Your locale settings are not supported by "
25+
"the system. Using the fallback 'C' locale instead. "
26+
"Please fix your locale settings.\n")
27+
1828
global translator
1929
if locale_dir is None:
2030
locale_dir = os.path.join(package_dir, 'translations')

bpython/translations/de/LC_MESSAGES/bpython.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ msgstr ""
2626

2727
#: bpython/args.py:63
2828
msgid "Use CONFIG instead of default config file."
29-
msgstr ""
29+
msgstr "Verwende CONFIG antatt der standardmäßigen Konfigurationsdatei."
3030

3131
#: bpython/args.py:65
3232
msgid "Drop to bpython shell after running file instead of exiting."
@@ -38,7 +38,7 @@ msgstr ""
3838

3939
#: bpython/args.py:70
4040
msgid "Print version and exit."
41-
msgstr ""
41+
msgstr "Zeige Versionsinformationen an und beende."
4242

4343
#: bpython/cli.py:303 bpython/urwid.py:550
4444
msgid "y"

bpython/urwid.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,6 @@ def tab(self, back=False):
10981098
self._completion_update_suppressed = False
10991099

11001100
def main(args=None, locals_=None, banner=None):
1101-
locale.setlocale(locale.LC_ALL, "")
11021101
translations.init()
11031102

11041103
# TODO: maybe support displays other than raw_display?

0 commit comments

Comments
 (0)
X Tutup