From ccc49029b8d84cf3eaaa3593df6370329f7b14e1 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Fri, 29 Oct 2010 16:48:58 +0000 Subject: Fixed #14181 -- Added a template tag and filters to allow localization to be disabled in a template. Thanks to Benjamin Wohlwend for the work on the patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@14395 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/i18n/tests.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests') diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py index 4aa52b6b55..bac77b0dbc 100644 --- a/tests/regressiontests/i18n/tests.py +++ b/tests/regressiontests/i18n/tests.py @@ -453,6 +453,33 @@ class FormattingTests(TestCase): settings.FORMAT_MODULE_PATH = old_format_module_path deactivate() + def test_localize_templatetag_and_filter(self): + """ + Tests the {% localize %} templatetag + """ + context = Context({'value': 3.14 }) + template1 = Template("{% load l10n %}{% localize %}{{ value }}{% endlocalize %};{% localize on %}{{ value }}{% endlocalize %}") + template2 = Template("{% load l10n %}{{ value }};{% localize off %}{{ value }};{% endlocalize %}{{ value }}") + template3 = Template('{% load l10n %}{{ value }};{{ value|unlocalize }}') + template4 = Template('{% load l10n %}{{ value }};{{ value|localize }}') + output1 = '3,14;3,14' + output2 = '3,14;3.14;3,14' + output3 = '3,14;3.14' + output4 = '3.14;3,14' + old_localize = settings.USE_L10N + try: + activate('de') + settings.USE_L10N = False + self.assertEqual(template1.render(context), output1) + self.assertEqual(template4.render(context), output4) + settings.USE_L10N = True + self.assertEqual(template1.render(context), output1) + self.assertEqual(template2.render(context), output2) + self.assertEqual(template3.render(context), output3) + finally: + deactivate() + settings.USE_L10N = old_localize + class MiscTests(TestCase): def test_parse_spec_http_header(self): -- cgit v1.3