diff --git a/setup.py b/setup.py
index e16ae17..2941cbd 100644
--- a/setup.py
+++ b/setup.py
@@ -66,7 +66,7 @@ def is_requirement(line):
README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
-VERSION = '2.1.1'
+VERSION = '2.1.2'
if sys.argv[-1] == 'tag':
print("Tagging the version on github:")
diff --git a/tests/unit/test_resources.py b/tests/unit/test_resources.py
index 9a7423a..8207dca 100644
--- a/tests/unit/test_resources.py
+++ b/tests/unit/test_resources.py
@@ -105,6 +105,23 @@
\
""".format(expected_filled_template)
+expected_filled_translated_js_template = u"""\
+\
+""".format(expected_translated_template)
+
+expected_filled_not_translated_js_template = u"""\
+\
+""".format(expected_not_translated_template)
+
+expected_filled_localized_js_template = u"""\
+\
+""".format(expected_localized_template)
another_template = u"""\
This is an even simpler xml template.
@@ -199,6 +216,27 @@ def test_render_js_template(self):
s = loader.render_js_template("data/simple_django_template.txt", example_id, example_context)
self.assertEqual(s, expected_filled_js_template)
+ def test_render_js_template_translated(self):
+ loader = ResourceLoader(__name__)
+ s = loader.render_js_template("data/trans_django_template.txt",
+ example_id,
+ context=example_context,
+ i18n_service=MockI18nService())
+ self.assertEqual(s, expected_filled_translated_js_template)
+
+ # Test that the language changes were reverted
+ s = loader.render_js_template("data/trans_django_template.txt", example_id, example_context)
+ self.assertEqual(s, expected_filled_not_translated_js_template)
+
+ def test_render_js_template_localized(self):
+ # Test that default template tags like l10n are loaded
+ loader = ResourceLoader(__name__)
+ s = loader.render_js_template("data/l10n_django_template.txt",
+ example_id,
+ context=example_context,
+ i18n_service=MockI18nService())
+ self.assertEqual(s, expected_filled_localized_js_template)
+
def test_load_scenarios(self):
loader = ResourceLoader(__name__)
scenarios = loader.load_scenarios_from_path("data")
diff --git a/xblockutils/resources.py b/xblockutils/resources.py
index e1bc9b0..34ee288 100644
--- a/xblockutils/resources.py
+++ b/xblockutils/resources.py
@@ -85,14 +85,14 @@ def render_template(self, template_path, context=None):
)
return self.render_django_template(template_path, context)
- def render_js_template(self, template_path, element_id, context=None):
+ def render_js_template(self, template_path, element_id, context=None, i18n_service=None):
"""
Render a js template.
"""
context = context or {}
return u"".format(
element_id,
- self.render_django_template(template_path, context)
+ self.render_django_template(template_path, context, i18n_service)
)
def load_scenarios_from_path(self, relative_scenario_dir, include_identifier=False):