1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-24 18:47:23 +00:00

Fix auto detection of locale

This commit is contained in:
Ozzieisaacs 2020-02-01 13:38:11 +01:00
parent 00dafe3121
commit 5255085de1

View File

@ -116,14 +116,13 @@ def get_locale():
if user.nickname != 'Guest': # if the account is the guest account bypass the config lang settings if user.nickname != 'Guest': # if the account is the guest account bypass the config lang settings
return user.locale return user.locale
preferred = set() preferred = list()
if request.accept_languages: if request.accept_languages:
for x in request.accept_languages.values(): for x in request.accept_languages.values():
try: try:
preferred.add(str(LC.parse(x.replace('-', '_')))) preferred.append(str(LC.parse(x.replace('-', '_'))))
except (UnknownLocaleError, ValueError) as e: except (UnknownLocaleError, ValueError) as e:
log.warning('Could not parse locale "%s": %s', x, e) log.debug('Could not parse locale "%s": %s', x, e)
# preferred.append('en')
return negotiate_locale(preferred or ['en'], _BABEL_TRANSLATIONS) return negotiate_locale(preferred or ['en'], _BABEL_TRANSLATIONS)