diff options
author | Sergey Kolosov <m17.admin@gmail.com> | 2015-06-05 15:10:28 +0100 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2015-08-05 09:05:21 -0400 |
commit | 244404227e8a1c5e241658ef0df789a28ed3bbc6 (patch) | |
tree | 749c5e86ee0894161e9328e7673561eebaf3a2de /tests/view_tests | |
parent | e8cd65f8297928d3fa7ad3d338953a4423028713 (diff) | |
download | django-244404227e8a1c5e241658ef0df789a28ed3bbc6.tar.gz |
Fixed #22404 -- Added a view that exposes i18n catalog as a JSON
Added django.views.i18n.json_catalog() view, which returns a JSON
response containing translations, formats, and a plural expression
for the specified language.
Diffstat (limited to 'tests/view_tests')
-rw-r--r-- | tests/view_tests/tests/test_i18n.py | 29 | ||||
-rw-r--r-- | tests/view_tests/urls.py | 1 |
2 files changed, 30 insertions, 0 deletions
diff --git a/tests/view_tests/tests/test_i18n.py b/tests/view_tests/tests/test_i18n.py index 886c10f5fc..a10a3bc7e1 100644 --- a/tests/view_tests/tests/test_i18n.py +++ b/tests/view_tests/tests/test_i18n.py @@ -105,6 +105,20 @@ class I18NTests(TestCase): # Message with context (msgctxt) self.assertContains(response, '"month name\\u0004May": "mai"', 1) + def test_jsoni18n(self): + """ + The json_catalog returns the language catalog and settings as JSON. + """ + with override('de'): + response = self.client.get('/jsoni18n/') + data = json.loads(response.content.decode('utf-8')) + self.assertIn('catalog', data) + self.assertIn('formats', data) + self.assertIn('plural', data) + self.assertEqual(data['catalog']['month name\x04May'], 'Mai') + self.assertIn('DATETIME_FORMAT', data['formats']) + self.assertEqual(data['plural'], '(n != 1)') + @override_settings(ROOT_URLCONF='view_tests.urls') class JsI18NTests(SimpleTestCase): @@ -127,6 +141,21 @@ class JsI18NTests(SimpleTestCase): response = self.client.get('/jsi18n/') self.assertNotContains(response, 'esto tiene que ser traducido') + def test_jsoni18n_with_missing_en_files(self): + """ + Same as above for the json_catalog view. Here we also check for the + expected JSON format. + """ + with self.settings(LANGUAGE_CODE='es'), override('en-us'): + response = self.client.get('/jsoni18n/') + data = json.loads(response.content.decode('utf-8')) + self.assertIn('catalog', data) + self.assertIn('formats', data) + self.assertIn('plural', data) + self.assertEqual(data['catalog'], {}) + self.assertIn('DATETIME_FORMAT', data['formats']) + self.assertIsNone(data['plural']) + def test_jsi18n_fallback_language(self): """ Let's make sure that the fallback language is still working properly diff --git a/tests/view_tests/urls.py b/tests/view_tests/urls.py index 4215a4b26a..e8f2855c98 100644 --- a/tests/view_tests/urls.py +++ b/tests/view_tests/urls.py @@ -84,6 +84,7 @@ urlpatterns = [ url(r'^jsi18n_admin/$', i18n.javascript_catalog, js_info_dict_admin), url(r'^jsi18n_template/$', views.jsi18n), url(r'^jsi18n_multi_catalogs/$', views.jsi18n_multi_catalogs), + url(r'^jsoni18n/$', i18n.json_catalog, js_info_dict), # Static views url(r'^site_media/(?P<path>.*)$', static.serve, {'document_root': media_dir}), |