diff --git a/django/contrib/gis/templates/gis/google/google-map.js b/django/contrib/gis/templates/gis/google/google-map.js
index 06f11e3..9eac3a4 100644
|
a
|
b
|
|
| 1 | 1 | {% autoescape off %} |
| | 2 | {% noloc %} |
| 2 | 3 | {% block vars %}var geodjango = {};{% for icon in icons %} |
| 3 | 4 | var {{ icon.varname }} = new GIcon(G_DEFAULT_ICON); |
| 4 | 5 | {% if icon.image %}{{ icon.varname }}.image = "{{ icon.image }}";{% endif %} |
| … |
… |
var {{ icon.varname }} = new GIcon(G_DEFAULT_ICON);
|
| 32 | 33 | alert("Sorry, the Google Maps API is not compatible with this browser."); |
| 33 | 34 | } |
| 34 | 35 | } |
| 35 | | {% endblock load %}{% endblock functions %}{% endautoescape %} |
| | 36 | {% endblock load %}{% endblock functions %}{% endnoloc %}{% endautoescape %} |
diff --git a/django/template/__init__.py b/django/template/__init__.py
index c316786..d51c773 100644
|
a
|
b
|
def _render_value_in_context(value, context):
|
| 825 | 825 | means escaping, if required, and conversion to a unicode object. If value |
| 826 | 826 | is a string, it is expected to have already been translated. |
| 827 | 827 | """ |
| 828 | | value = localize(value) |
| | 828 | if '_no_l10n' not in context: |
| | 829 | value = localize(value) |
| 829 | 830 | value = force_unicode(value) |
| 830 | 831 | if (context.autoescape and not isinstance(value, SafeData)) or isinstance(value, EscapeData): |
| 831 | 832 | return escape(value) |
diff --git a/django/template/debug.py b/django/template/debug.py
index c21fb50..2f5715d 100644
|
a
|
b
|
class DebugVariableNode(VariableNode):
|
| 87 | 87 | def render(self, context): |
| 88 | 88 | try: |
| 89 | 89 | output = self.filter_expression.resolve(context) |
| 90 | | output = localize(output) |
| | 90 | if '_no_l10n' not in context: |
| | 91 | output = localize(output) |
| 91 | 92 | output = force_unicode(output) |
| 92 | 93 | except TemplateSyntaxError, e: |
| 93 | 94 | if not hasattr(e, 'source'): |
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index 1b07413..4be54f5 100644
|
a
|
b
|
class WithNode(Node):
|
| 433 | 433 | context.pop() |
| 434 | 434 | return output |
| 435 | 435 | |
| | 436 | class NoLocalizationNode(Node): |
| | 437 | def __init__(self, nodelist): |
| | 438 | self.nodelist = nodelist |
| | 439 | |
| | 440 | def __repr__(self): |
| | 441 | return "<NoLocalizationNode>" |
| | 442 | |
| | 443 | def render(self, context): |
| | 444 | context['_no_l10n'] = True |
| | 445 | output = self.nodelist.render(context) |
| | 446 | del context['_no_l10n'] |
| | 447 | return output |
| | 448 | |
| 436 | 449 | #@register.tag |
| 437 | 450 | def autoescape(parser, token): |
| 438 | 451 | """ |
| … |
… |
def do_with(parser, token):
|
| 1216 | 1229 | parser.delete_first_token() |
| 1217 | 1230 | return WithNode(var, name, nodelist) |
| 1218 | 1231 | do_with = register.tag('with', do_with) |
| | 1232 | |
| | 1233 | @register.tag('noloc') |
| | 1234 | def do_noloc(parser, token): |
| | 1235 | """ |
| | 1236 | Temporarely deactivates localization inside of this block, e.g. |
| | 1237 | to avoid rendering syntactically incorrect JavaScript code. |
| | 1238 | """ |
| | 1239 | bits = list(token.split_contents()) |
| | 1240 | if len(bits) != 1: |
| | 1241 | raise TemplateSyntaxError("%r doesn't take any arguments" % bits[0]) |
| | 1242 | nodelist = parser.parse(('endnoloc',)) |
| | 1243 | parser.delete_first_token() |
| | 1244 | return NoLocalizationNode(nodelist) |
diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt
index 70f0ffd..077caec 100644
|
a
|
b
|
Load a custom template tag set.
|
| 639 | 639 | |
| 640 | 640 | See :doc:`Custom tag and filter libraries </howto/custom-template-tags>` for more information. |
| 641 | 641 | |
| | 642 | .. templatetag:: noloc |
| | 643 | |
| | 644 | noloc |
| | 645 | ~~~~~ |
| | 646 | |
| | 647 | .. versionadded:: 1.3 |
| | 648 | |
| | 649 | Deactivates localization of variables in the contained block. |
| | 650 | |
| | 651 | While localization of variables is generally useful, sometimes it has undesirable |
| | 652 | effects, e.g. when you render JavaScript code through the template system. Consider this |
| | 653 | template code:: |
| | 654 | |
| | 655 | var pi = {{ 3.1415 }}; |
| | 656 | |
| | 657 | If localization is enabled, the output from this template is not syntetically correct |
| | 658 | JavaScript in some locales (e.g. German):: |
| | 659 | |
| | 660 | var pi = 3,1415; |
| | 661 | |
| | 662 | To avoid this issue, wrap the affected template code in a ``{% noloc %}`` tag:: |
| | 663 | |
| | 664 | {% noloc %} |
| | 665 | var pi = {{ 3.1415 }}; |
| | 666 | {% endnoloc %} |
| | 667 | |
| 642 | 668 | .. templatetag:: now |
| 643 | 669 | |
| 644 | 670 | now |
diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
index 4aa52b6..f5bcdee 100644
|
a
|
b
|
class FormattingTests(TestCase):
|
| 453 | 453 | settings.FORMAT_MODULE_PATH = old_format_module_path |
| 454 | 454 | deactivate() |
| 455 | 455 | |
| | 456 | def test_noloc_templatetag(self): |
| | 457 | """ |
| | 458 | Tests the {% noloc %} templatetag |
| | 459 | """ |
| | 460 | activate('de-de') |
| | 461 | context = Context({'the_var': 3.14 }) |
| | 462 | template = Template("{{ the_var }};{% noloc %}{{ the_var }};{% endnoloc %}{{ the_var }}") |
| | 463 | old_debug = settings.TEMPLATE_DEBUG |
| | 464 | try: |
| | 465 | for debug in (True, False): |
| | 466 | settings.TEMPLATE_DEBUG = debug |
| | 467 | settings.USE_L10N = True |
| | 468 | self.assertEqual(template.render(context), '3,14;3.14;3,14') |
| | 469 | finally: |
| | 470 | deactivate() |
| | 471 | settings.TEMPLATE_DEBUG = old_debug |
| | 472 | |
| 456 | 473 | class MiscTests(TestCase): |
| 457 | 474 | |
| 458 | 475 | def test_parse_spec_http_header(self): |
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index 6683ebb..0e060c3 100644
|
a
|
b
|
class Templates(unittest.TestCase):
|
| 375 | 375 | activate(vals[1]['LANGUAGE_CODE']) |
| 376 | 376 | else: |
| 377 | 377 | activate('en-us') |
| 378 | | |
| | 378 | old_l10n = settings.USE_L10N |
| | 379 | settings.USE_L10N = vals[1].get('USE_L10N', old_l10n) |
| 379 | 380 | for invalid_str, result in [('', normal_string_result), |
| 380 | 381 | (expected_invalid_str, invalid_string_result)]: |
| 381 | 382 | settings.TEMPLATE_STRING_IF_INVALID = invalid_str |
| … |
… |
class Templates(unittest.TestCase):
|
| 408 | 409 | if 'LANGUAGE_CODE' in vals[1]: |
| 409 | 410 | deactivate() |
| 410 | 411 | |
| | 412 | settings.USE_L10N = old_l10n |
| | 413 | |
| 411 | 414 | if template.invalid_var_format_string: |
| 412 | 415 | expected_invalid_str = 'INVALID' |
| 413 | 416 | template.invalid_var_format_string = False |
| … |
… |
class Templates(unittest.TestCase):
|
| 1122 | 1125 | # translation of singular form in russian (#14126) |
| 1123 | 1126 | 'i18n27': ('{% load i18n %}{% blocktrans count number as counter %}1 result{% plural %}{{ counter }} results{% endblocktrans %}', {'number': 1, 'LANGUAGE_CODE': 'ru'}, u'1 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442'), |
| 1124 | 1127 | |
| | 1128 | ### L10N ### |
| | 1129 | |
| | 1130 | # test the {% noloc %} tag |
| | 1131 | 'l10n01': ('{{ the_var }};{% noloc %}{{ the_var }};{% endnoloc %}{{ the_var }}', {'the_var': 3.14, 'LANGUAGE_CODE': 'de-de', 'USE_L10N': True}, u'3,14;3.14;3,14'), |
| 1125 | 1132 | ### HANDLING OF TEMPLATE_STRING_IF_INVALID ################################### |
| 1126 | 1133 | |
| 1127 | 1134 | 'invalidstr01': ('{{ var|default:"Foo" }}', {}, ('Foo','INVALID')), |