mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Refs #29713 -- Improved error message from translation system check.
This commit is contained in:
parent
ccf870ebf5
commit
570402ffd7
3 changed files with 53 additions and 61 deletions
|
@ -1,39 +1,41 @@
|
|||
from django.core.checks.translation import check_setting_language_code
|
||||
from django.core.checks.translation import E001, check_setting_language_code
|
||||
from django.test import SimpleTestCase, override_settings
|
||||
|
||||
|
||||
class TranslationCheckTests(SimpleTestCase):
|
||||
|
||||
@override_settings(LANGUAGE_CODE="eu")
|
||||
def test_valid_language_code_format_ll_only(self):
|
||||
result = check_setting_language_code(None)
|
||||
self.assertEqual(len(result), 0)
|
||||
def test_valid_language_code(self):
|
||||
tags = (
|
||||
'en', # language
|
||||
'mas', # language
|
||||
'sgn-ase', # language+extlang
|
||||
'fr-CA', # language+region
|
||||
'es-419', # language+region
|
||||
'zh-Hans', # language+script
|
||||
'ca-ES-valencia', # language+region+variant
|
||||
# FIXME: The following should be invalid:
|
||||
'sr@latin', # language+script
|
||||
)
|
||||
for tag in tags:
|
||||
with self.subTest(tag), override_settings(LANGUAGE_CODE=tag):
|
||||
self.assertEqual(check_setting_language_code(None), [])
|
||||
|
||||
@override_settings(LANGUAGE_CODE="eü")
|
||||
def test_invalid_language_code_format_ll_only(self):
|
||||
result = check_setting_language_code(None)
|
||||
self.assertEqual(len(result), 1)
|
||||
error = result[0]
|
||||
self.assertEqual(error.id, 'translation.E001')
|
||||
self.assertEqual(error.msg, (
|
||||
"LANGUAGE_CODE in settings.py is eü. It should be in the form ll or ll-cc where ll is the language and cc "
|
||||
"is the country. Examples include: it, de-at, es, pt-br. The full set of language codes specifications is "
|
||||
"outlined by https://en.wikipedia.org/wiki/IETF_language_tag#Syntax_of_language_tags"
|
||||
))
|
||||
|
||||
@override_settings(LANGUAGE_CODE="en-US")
|
||||
def test_valid_language_code_format_ll_cc(self):
|
||||
result = check_setting_language_code(None)
|
||||
self.assertEqual(len(result), 0)
|
||||
|
||||
@override_settings(LANGUAGE_CODE="en_US")
|
||||
def test_invalid_language_code_format_ll_cc(self):
|
||||
result = check_setting_language_code(None)
|
||||
self.assertEqual(len(result), 1)
|
||||
error = result[0]
|
||||
self.assertEqual(error.id, 'translation.E001')
|
||||
self.assertEqual(error.msg, (
|
||||
"LANGUAGE_CODE in settings.py is en_US. It should be in the form ll or ll-cc where ll is the language and "
|
||||
"cc is the country. Examples include: it, de-at, es, pt-br. The full set of language codes specifications "
|
||||
"is outlined by https://en.wikipedia.org/wiki/IETF_language_tag#Syntax_of_language_tags"
|
||||
))
|
||||
def test_invalid_language_code(self):
|
||||
tags = (
|
||||
'eü', # non-latin characters.
|
||||
'en_US', # locale format.
|
||||
'en--us', # empty subtag.
|
||||
'-en', # leading separator.
|
||||
'en-', # trailing separator.
|
||||
'en-US.UTF-8', # language tag w/ locale encoding.
|
||||
'en_US.UTF-8', # locale format - languate w/ region and encoding.
|
||||
'ca_ES@valencia', # locale format - language w/ region and variant.
|
||||
# FIXME: The following should be invalid:
|
||||
# 'sr@latin', # locale instead of language tag.
|
||||
)
|
||||
for tag in tags:
|
||||
with self.subTest(tag), override_settings(LANGUAGE_CODE=tag):
|
||||
result = check_setting_language_code(None)
|
||||
self.assertEqual(result, [E001])
|
||||
self.assertEqual(result[0].id, 'translation.E001')
|
||||
self.assertEqual(result[0].msg, 'You have provided an invalid value for the LANGUAGE_CODE setting.')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue