forked from janeczku/calibre-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored web.py to shrink size of file
- Loading branch information
1 parent
47414ad
commit e7464f2
Showing
27 changed files
with
639 additions
and
581 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from babel import Locale as LC | ||
from babel import negotiate_locale | ||
from flask_babel import Babel | ||
from babel.core import UnknownLocaleError | ||
from flask import request, g | ||
|
||
from . import logger | ||
|
||
log = logger.create() | ||
|
||
babel = Babel() | ||
BABEL_TRANSLATIONS = set() | ||
|
||
@babel.localeselector | ||
def get_locale(): | ||
# if a user is logged in, use the locale from the user settings | ||
user = getattr(g, 'user', None) | ||
if user is not None and hasattr(user, "locale"): | ||
if user.name != 'Guest': # if the account is the guest account bypass the config lang settings | ||
return user.locale | ||
|
||
preferred = list() | ||
if request.accept_languages: | ||
for x in request.accept_languages.values(): | ||
try: | ||
preferred.append(str(LC.parse(x.replace('-', '_')))) | ||
except (UnknownLocaleError, ValueError) as e: | ||
log.debug('Could not parse locale "%s": %s', x, e) | ||
|
||
return negotiate_locale(preferred or ['en'], BABEL_TRANSLATIONS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.