<% online_help_token = self.online_help_token() if hasattr(self, 'online_help_token') else None %>
<%include file="widgets/header.html" args="online_help_token=online_help_token" />
diff --git a/common/djangoapps/pipeline_mako/templates/static_content.html b/common/djangoapps/pipeline_mako/templates/static_content.html
index 9deb58e7b6..b237e3c86b 100644
--- a/common/djangoapps/pipeline_mako/templates/static_content.html
+++ b/common/djangoapps/pipeline_mako/templates/static_content.html
@@ -27,6 +27,7 @@ except:
% endfor
%endif
%def>
+
<%def name='js(group)'>
% if settings.FEATURES['USE_DJANGO_PIPELINE']:
${compressed_js(group)}
@@ -37,6 +38,15 @@ except:
%endif
%def>
+## A language-direction indicator, suitable for use in class="" attributes,
+## for example:
+##
+##
+##
+<%def name="dir_rtl()"><%
+ return 'rtl' if get_language_bidi() else 'ltr'
+%>%def>
+
<%def name="include(path)"><%
from django.template.loaders.filesystem import _loader
source, template_path = _loader.load_template_source(path)
diff --git a/lms/djangoapps/courseware/tests/test_i18n.py b/lms/djangoapps/courseware/tests/test_i18n.py
index e1f2503c32..a67442e64b 100644
--- a/lms/djangoapps/courseware/tests/test_i18n.py
+++ b/lms/djangoapps/courseware/tests/test_i18n.py
@@ -9,19 +9,40 @@ from django.test.utils import override_settings
@attr('shard_1')
-@override_settings(LANGUAGES=(('eo', 'Esperanto'),))
+@override_settings(LANGUAGES=[('eo', 'Esperanto'), ('ar', 'Arabic')])
class I18nTestCase(TestCase):
"""
Tests for i18n
"""
+ def assert_tag_has_attr(self, content, tag, attname, value):
+ """Assert that a tag in `content` has a certain value in a certain attribute."""
+ regex = r"""<{tag} [^>]*\b{attname}=['"]([\w\d ]+)['"][^>]*>""".format(tag=tag, attname=attname)
+ match = re.search(regex, content)
+ self.assertTrue(match, "Couldn't find desired tag in %r" % content)
+ attvalues = match.group(1).split()
+ self.assertIn(value, attvalues)
+
def test_default_is_en(self):
response = self.client.get('/')
- self.assertIn('', response.content)
+ self.assert_tag_has_attr(response.content, "html", "lang", "en")
self.assertEqual(response['Content-Language'], 'en')
- self.assertTrue(re.search('
', response.content))
+ self.assert_tag_has_attr(response.content, "body", "class", "lang_en")
def test_esperanto(self):
response = self.client.get('/', HTTP_ACCEPT_LANGUAGE='eo')
- self.assertIn('', response.content)
+ self.assert_tag_has_attr(response.content, "html", "lang", "eo")
self.assertEqual(response['Content-Language'], 'eo')
- self.assertTrue(re.search('', response.content))
+ self.assert_tag_has_attr(response.content, "body", "class", "lang_eo")
+
+ def test_switching_languages_bidi(self):
+ response = self.client.get('/')
+ self.assert_tag_has_attr(response.content, "html", "lang", "en")
+ self.assertEqual(response['Content-Language'], 'en')
+ self.assert_tag_has_attr(response.content, "body", "class", "lang_en")
+ self.assert_tag_has_attr(response.content, "body", "class", "ltr")
+
+ response = self.client.get('/', HTTP_ACCEPT_LANGUAGE='ar')
+ self.assert_tag_has_attr(response.content, "html", "lang", "ar")
+ self.assertEqual(response['Content-Language'], 'ar')
+ self.assert_tag_has_attr(response.content, "body", "class", "lang_ar")
+ self.assert_tag_has_attr(response.content, "body", "class", "rtl")
diff --git a/lms/templates/certificates/certificate-base.html b/lms/templates/certificates/certificate-base.html
index e4f8cb9091..cf19f3855a 100644
--- a/lms/templates/certificates/certificate-base.html
+++ b/lms/templates/certificates/certificate-base.html
@@ -1,17 +1,15 @@
+<%namespace name='static' file='/static_content.html'/>
<%! from django.utils.translation import ugettext as _ %>
<%! import mako.runtime %>
<% mako.runtime.UNDEFINED = '' %>
<%
- # set doc language direction
- from django.utils.translation import get_language_bidi
- dir_rtl = 'rtl' if get_language_bidi() else 'ltr'
document_body_class = document_body_class_append if document_body_class_append else ''
%>
-
+
@@ -21,7 +19,7 @@
<%include file="_assets-primary.html" />
-
+
${self.body()}
diff --git a/lms/templates/main.html b/lms/templates/main.html
index 4b3b9d1e83..1115dcab34 100644
--- a/lms/templates/main.html
+++ b/lms/templates/main.html
@@ -4,17 +4,14 @@
from django.core.urlresolvers import reverse
from django.utils.http import urlquote_plus
from django.utils.translation import ugettext as _
-from django.utils.translation import get_language_bidi
from microsite_configuration import microsite
from microsite_configuration import page_title_breadcrumbs
from branding import api as branding_api
-
-dir_rtl = 'rtl' if get_language_bidi() else 'ltr'
%>
-
+
% if responsive:
@@ -131,8 +128,8 @@ dir_rtl = 'rtl' if get_language_bidi() else 'ltr'
-
-