Choose English as the User interface language when a locale related environment variable is set to the C locale

Merge branch 'lc-messages-c' of https://github.com/vmiklos/calibre
This commit is contained in:
Kovid Goyal 2017-12-09 11:06:01 +05:30
commit 46d7dcdde9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -45,8 +45,16 @@ def get_system_locale():
traceback.print_exc()
if lang is None:
try:
lang = locale.getdefaultlocale(['LANGUAGE', 'LC_ALL', 'LC_CTYPE',
'LC_MESSAGES', 'LANG'])[0]
envvars = ['LANGUAGE', 'LC_ALL', 'LC_CTYPE', 'LC_MESSAGES', 'LANG']
lang = locale.getdefaultlocale(envvars)[0]
# lang is None in two cases: either the environment variable is not
# set or it's "C". Stop looking for a language in the latter case.
if lang is None:
for var in envvars:
if os.environ.get(var) == 'C':
lang = 'en_US'
break
except:
pass # This happens on Ubuntu apparently
if lang is None and 'LANG' in os.environ: # Needed for OS X