From 3c9abd214d7e6ecc3ab7766c3277939f127d0ae1 Mon Sep 17 00:00:00 2001 From: Mohamed Feddad Date: Fri, 17 Mar 2023 08:40:59 +0400 Subject: [PATCH 1/2] fix: default language missing session variable Resolves #287 --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index b22f077..0aa28b7 100644 --- a/app/main.py +++ b/app/main.py @@ -199,7 +199,7 @@ def inject_vars(): ar=ar, version=VERSION, str=str, - defLang=session.get('lang'), + defLang=session.get('lang', 'en'), getattr=getattr, settings=get_settings_cached(), Serial=Serial, From 8f60d2da5408444555e98ab1329d4df9e5436ac4 Mon Sep 17 00:00:00 2001 From: Mohamed Feddad Date: Fri, 17 Mar 2023 08:42:37 +0400 Subject: [PATCH 2/2] chore: improve translator lookup performance --- app/middleware.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/middleware.py b/app/middleware.py index d41c7aa..7bd41b6 100644 --- a/app/middleware.py +++ b/app/middleware.py @@ -105,6 +105,12 @@ def _handle_exception(self, exception): raise exception +class FasterTranslator(translator): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.languages = set(self.languages) + + # NOTE: Work around for flask imports and registering blueprints # currently needed for sql alchemy, login manager and flask-uploads @@ -113,9 +119,9 @@ def _handle_exception(self, exception): login_manager = LoginManager() login_manager.login_view = "login" files = UploadSet('files', ALL) -gtranslator = translator(cache=True, - skip_app=True, - service_urls=['translate.googleapis.com']) +gtranslator = FasterTranslator(cache=True, + skip_app=True, + service_urls=['translate.googleapis.com']) gTTs = RedisGtts(route=True, failsafe=True, logging=False) celery_app = LazyCelery() redis = Redis('redis', db=3)