JourneyJoker/frontend/validators.py

11 lines
447 B
Python
Raw Permalink Normal View History

from django.core.exceptions import ValidationError
from django.conf import settings
from django.utils.translation import gettext_lazy as _
class LanguageValidator:
def __call__(self, value):
for language, _ in settings.LANGUAGES:
if language.startswith(value):
return
raise ValidationError(_("This is not a valid language code supported by this project."), code='invalid', params={'value': value})