2018-09-03 16:43:55 +08:00
|
|
|
from django.conf import settings
|
|
|
|
from django.utils.translation.trans_real import language_code_re
|
|
|
|
|
|
|
|
from . import Error, Tags, register
|
|
|
|
|
2018-09-06 19:49:25 +08:00
|
|
|
E001 = Error(
|
2019-03-08 06:40:58 +08:00
|
|
|
'You have provided an invalid value for the LANGUAGE_CODE setting: {}.',
|
2018-09-06 19:49:25 +08:00
|
|
|
id='translation.E001',
|
|
|
|
)
|
|
|
|
|
2018-09-03 16:43:55 +08:00
|
|
|
|
|
|
|
@register(Tags.translation)
|
|
|
|
def check_setting_language_code(app_configs, **kwargs):
|
2019-03-08 06:40:58 +08:00
|
|
|
"""Error if LANGUAGE_CODE setting is invalid."""
|
|
|
|
tag = settings.LANGUAGE_CODE
|
|
|
|
if not isinstance(tag, str) or not language_code_re.match(tag):
|
|
|
|
return [Error(E001.msg.format(tag), id=E001.id)]
|
2018-09-06 19:49:25 +08:00
|
|
|
return []
|