mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Refs #27795 -- Stopped converting integer format settings to str in JS/JSON i18n views
Thanks Tim Graham for the review.
This commit is contained in:
@@ -4,6 +4,14 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p id="formats">
|
||||
<script type="text/javascript">
|
||||
document.write("DATE_INPUT_FORMATS is an " + typeof get_format("DATE_INPUT_FORMATS") + "; ");
|
||||
document.write("DECIMAL_SEPARATOR is a " + typeof get_format("DECIMAL_SEPARATOR") + "; ");
|
||||
document.write("FIRST_DAY_OF_WEEK is a " + typeof get_format("FIRST_DAY_OF_WEEK") + ";");
|
||||
</script>
|
||||
</p>
|
||||
|
||||
<p id="gettext">
|
||||
<script type="text/javascript">
|
||||
document.write(gettext("Remove"));
|
||||
|
||||
@@ -11,6 +11,7 @@ from django.urls import reverse
|
||||
from django.utils.translation import (
|
||||
LANGUAGE_SESSION_KEY, get_language, override,
|
||||
)
|
||||
from django.views.i18n import get_formats
|
||||
|
||||
from ..urls import locale_dir
|
||||
|
||||
@@ -183,6 +184,14 @@ class SetLanguageTests(TestCase):
|
||||
@override_settings(ROOT_URLCONF='view_tests.urls')
|
||||
class I18NViewTests(SimpleTestCase):
|
||||
"""Test django.views.i18n views other than set_language."""
|
||||
@override_settings(LANGUAGE_CODE='de')
|
||||
def test_get_formats(self):
|
||||
formats = get_formats()
|
||||
# Test 3 possible types in get_formats: integer, string, and list.
|
||||
self.assertEqual(formats['FIRST_DAY_OF_WEEK'], 0)
|
||||
self.assertEqual(formats['DECIMAL_SEPARATOR'], '.')
|
||||
self.assertEqual(formats['TIME_INPUT_FORMATS'], ['%H:%M:%S', '%H:%M:%S.%f', '%H:%M'])
|
||||
|
||||
def test_jsi18n(self):
|
||||
"""The javascript_catalog can be deployed with language settings"""
|
||||
for lang_code in ['es', 'fr', 'ru']:
|
||||
@@ -214,6 +223,8 @@ class I18NViewTests(SimpleTestCase):
|
||||
data = json.loads(response.content.decode())
|
||||
self.assertIn('catalog', data)
|
||||
self.assertIn('formats', data)
|
||||
self.assertEqual(data['formats']['TIME_INPUT_FORMATS'], ['%H:%M:%S', '%H:%M:%S.%f', '%H:%M'])
|
||||
self.assertEqual(data['formats']['FIRST_DAY_OF_WEEK'], 0)
|
||||
self.assertIn('plural', data)
|
||||
self.assertEqual(data['catalog']['month name\x04May'], 'Mai')
|
||||
self.assertIn('DATETIME_FORMAT', data['formats'])
|
||||
@@ -398,6 +409,11 @@ class I18nSeleniumTests(SeleniumTestCase):
|
||||
self.assertEqual(elem.text, "1 Resultat")
|
||||
elem = self.selenium.find_element_by_id("npgettext_plur")
|
||||
self.assertEqual(elem.text, "455 Resultate")
|
||||
elem = self.selenium.find_element_by_id("formats")
|
||||
self.assertEqual(
|
||||
elem.text,
|
||||
"DATE_INPUT_FORMATS is an object; DECIMAL_SEPARATOR is a string; FIRST_DAY_OF_WEEK is a number;"
|
||||
)
|
||||
|
||||
@modify_settings(INSTALLED_APPS={'append': ['view_tests.app1', 'view_tests.app2']})
|
||||
@override_settings(LANGUAGE_CODE='fr')
|
||||
|
||||
Reference in New Issue
Block a user