Skip to content

Commit

Permalink
reenable startup logging
Browse files Browse the repository at this point in the history
Bugfixes from refactoring and merge
  • Loading branch information
OzzieIsaacs committed Apr 26, 2022
1 parent e7464f2 commit 2e007a1
Show file tree
Hide file tree
Showing 14 changed files with 2,005 additions and 2,015 deletions.
9 changes: 4 additions & 5 deletions cps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@
from .MyLoginManager import MyLoginManager
from flask_principal import Principal

from . import logger
from .cli import CliParameter
from .constants import CONFIG_DIR
from .reverseproxy import ReverseProxied
from .server import WebServer
from .dep_check import dependency_check
from . import services
from .updater import Updater
from .babel import babel, BABEL_TRANSLATIONS
from .babel import babel
from . import config_sql
from . import logger
from . import cache_buster
from . import ub, db

Expand Down Expand Up @@ -157,8 +156,8 @@ def create_app():
web_server.init_app(app, config)

babel.init_app(app)
BABEL_TRANSLATIONS.update(str(item) for item in babel.list_translations())
BABEL_TRANSLATIONS.add('en')

from . import services

if services.ldap:
services.ldap.init_app(app, config)
Expand Down
1,491 changes: 748 additions & 743 deletions cps/admin.py

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions cps/babel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from babel import Locale as LC
from babel import Locale
from babel import negotiate_locale
from flask_babel import Babel
from babel.core import UnknownLocaleError
Expand All @@ -9,7 +9,7 @@
log = logger.create()

babel = Babel()
BABEL_TRANSLATIONS = set()


@babel.localeselector
def get_locale():
Expand All @@ -23,8 +23,18 @@ def get_locale():
if request.accept_languages:
for x in request.accept_languages.values():
try:
preferred.append(str(LC.parse(x.replace('-', '_'))))
preferred.append(str(Locale.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)
return negotiate_locale(preferred or ['en'], get_available_translations())


def get_user_locale_language(user_language):
return Locale.parse(user_language).get_language_name(get_locale())

def get_available_locale():
return [Locale('en')] + babel.list_translations()

def get_available_translations():
return set(str(item) for item in get_available_locale())
Loading

0 comments on commit 2e007a1

Please sign in to comment.