Unverified Commit 18fcd70f by Brian Beggs Committed by GitHub

Merge pull request #49 from open-craft/MCKIN-7023-template-l10n

[MCKIN-7023] Ensures that default template tags are loaded for Django 1.11
parents 436576de 8ba72515
...@@ -35,7 +35,7 @@ def package_data(pkg, root_list): ...@@ -35,7 +35,7 @@ def package_data(pkg, root_list):
setup( setup(
name='xblock-utils', name='xblock-utils',
version='1.1.0', version='1.1.1',
description='Various utilities for XBlocks', description='Various utilities for XBlocks',
packages=[ packages=[
'xblockutils', 'xblockutils',
......
{% load l10n %}
{{ 1000|localize }}
{{ 1000|unlocalize }}
...@@ -90,6 +90,12 @@ mUlTi_LiNe TrAnSlAtIoN: This is a fine name ...@@ -90,6 +90,12 @@ mUlTi_LiNe TrAnSlAtIoN: This is a fine name
""" """
expected_localized_template = u"""\
1000
1000
"""
example_id = "example-unique-id" example_id = "example-unique-id"
expected_filled_js_template = u"""\ expected_filled_js_template = u"""\
...@@ -167,6 +173,14 @@ class TestResourceLoader(unittest.TestCase): ...@@ -167,6 +173,14 @@ class TestResourceLoader(unittest.TestCase):
s = loader.render_django_template("data/trans_django_template.txt", example_context) s = loader.render_django_template("data/trans_django_template.txt", example_context)
self.assertEquals(s, expected_not_translated_template) self.assertEquals(s, expected_not_translated_template)
def test_render_django_template_localized(self):
# Test that default template tags like l10n are loaded
loader = ResourceLoader(__name__)
s = loader.render_django_template("data/l10n_django_template.txt",
context=example_context,
i18n_service=MockI18nService())
self.assertEquals(s, expected_localized_template)
def test_render_mako_template(self): def test_render_mako_template(self):
loader = ResourceLoader(__name__) loader = ResourceLoader(__name__)
s = loader.render_mako_template("data/simple_mako_template.txt", example_context) s = loader.render_mako_template("data/simple_mako_template.txt", example_context)
......
...@@ -68,7 +68,11 @@ class ResourceLoader(object): ...@@ -68,7 +68,11 @@ class ResourceLoader(object):
engine = Engine() engine = Engine()
else: else:
# Django>1.8 Engine can load the extra templatetag libraries itself # Django>1.8 Engine can load the extra templatetag libraries itself
engine = Engine(libraries=libraries) # but we have to override the default installed libraries.
from django.template.backends.django import get_installed_libraries
installed_libraries = get_installed_libraries()
installed_libraries.update(libraries)
engine = Engine(libraries=installed_libraries)
template_str = self.load_unicode(template_path) template_str = self.load_unicode(template_path)
template = Template(template_str, engine=engine) template = Template(template_str, engine=engine)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment