Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing default language, and improve translator #288

Merged
merged 2 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 9 additions & 3 deletions app/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)