Commit 0dcf0c7a authored by Michal Čihař's avatar Michal Čihař

Detect invalid locales and activate English on error

This is needed since Django 1.9.1 and
https://code.djangoproject.com/ticket/26050.

Fixes rb#449
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 74054fc4
......@@ -25,6 +25,7 @@ from weblate.trans.models import Project, SubProject, Translation
from weblate.lang.models import Language
from django.shortcuts import get_object_or_404
import django.utils.translation
from django.utils.translation import trans_real
def get_translation(request, project, subproject, lang, skip_acl=False):
......@@ -101,9 +102,13 @@ def try_set_language(lang):
try:
django.utils.translation.activate(lang)
# workaround for https://code.djangoproject.com/ticket/26050
# pylint: disable=W0212
if trans_real.catalog()._catalog is None:
raise Exception('Invalid language!')
except Exception:
# Ignore failure on activating language
pass
django.utils.translation.activate('en')
try:
return Language.objects.get(code=lang)
except Language.DoesNotExist:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment