Skip to content

Commit

Permalink
Merge from 3.x: PR #7159
Browse files Browse the repository at this point in the history
Fixes #7051
Fixes #6886
  • Loading branch information
ccordoba12 committed May 20, 2018
2 parents e21d5ef + bd63d83 commit 5a9f81a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
16 changes: 15 additions & 1 deletion spyder/app/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def main():
os.environ['QT_SCALE_FACTOR'] = ''
os.environ['QT_SCREEN_SCALE_FACTORS'] = ''

# Prevent Spyder from crashing in macOS if locale is not defined
if sys.platform == 'darwin':
# Prevent Spyder from crashing in macOS if locale is not defined
LANG = os.environ.get('LANG')
LC_ALL = os.environ.get('LC_ALL')
if bool(LANG) and not bool(LC_ALL):
Expand All @@ -110,6 +110,20 @@ def main():

os.environ['LANG'] = LANG
os.environ['LC_ALL'] = LC_ALL
else:
# Prevent our kernels to crash when Python fails to identify
# the system locale.
# Fixes issue 7051.
try:
from locale import getlocale
getlocale()
except ValueError:
# This can fail on Windows. See issue 6886
try:
os.environ['LANG'] = 'C'
os.environ['LC_ALL'] = 'C'
except Exception:
pass

if CONF.get('main', 'single_instance') and not options.new_instance \
and not options.reset_config_files and not running_in_mac_app():
Expand Down
27 changes: 18 additions & 9 deletions spyder/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,27 @@ def get_translation(modname, dirname=None):
"""Return translation callback for module *modname*"""
if dirname is None:
dirname = modname

def translate_dumb(x):
"""Dumb function to not use translations."""
if not is_unicode(x):
return to_text_string(x, "utf-8")
return x

locale_path = get_module_data_path(dirname, relpath="locale",
attr_name='LOCALEPATH')
# If LANG is defined in ubuntu, a warning message is displayed, so in unix
# systems we define the LANGUAGE variable.

# If LANG is defined in Ubuntu, a warning message is displayed,
# so in Unix systems we define the LANGUAGE variable.
language = load_lang_conf()
if os.name == 'nt':
os.environ["LANG"] = language # Works on Windows
# Trying to set LANG on Windows can fail when Spyder is
# run with admin privileges.
# Fixes issue 6886
try:
os.environ["LANG"] = language # Works on Windows
except Exception:
return translate_dumb
else:
os.environ["LANGUAGE"] = language # Works on Linux

Expand All @@ -387,12 +401,7 @@ def translate_gettext(x):
else:
return to_text_string(y, "utf-8")
return translate_gettext
except IOError as _e: # analysis:ignore
# Not using translations
def translate_dumb(x):
if not is_unicode(x):
return to_text_string(x, "utf-8")
return x
except Exception:
return translate_dumb

# Translation callback
Expand Down

0 comments on commit 5a9f81a

Please sign in to comment.