1π
β
To this point:
This way also allows me to activate and disable languages on the fly (if for example a language file contains grammar mistakes).
I would recommend to not do it because you should not alter settings at runtime: https://docs.djangoproject.com/en/1.7/topics/settings/#altering-settings-at-runtime.
One strategy you may want to consider is overriding process_request in django.middleware.locale.LocaleMiddleware to set the LANGUAGE_CODE to a default such as EN if it is not an active language in your table.
class CustomLocaleMiddleware(LocaleMiddleware):
def process_request(self, request):
...
lang = languages.objects.get(identifier=translation.get_language())
if lang:
if not lang.active:
request.LANGUAGE_CODE = 'en'
else:
request.LANGUAGE_CODE = translation.get_language()
else:
request.LANGUAGE_CODE = translation.get_language()
You would want to compensate for prefered language codes like en-us, de-at
π€Zach
Source:stackexchange.com