Commit b18945d1 by davestgermain

Merge pull request #2332 from edx/dstgermain/a11y-html-lang

Set the HTML language to the browser's specified language
parents a6b97b40 6d50ff7b
...@@ -113,6 +113,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( ...@@ -113,6 +113,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request', 'django.core.context_processors.request',
'django.core.context_processors.static', 'django.core.context_processors.static',
'django.contrib.messages.context_processors.messages', 'django.contrib.messages.context_processors.messages',
'django.core.context_processors.i18n',
'django.contrib.auth.context_processors.auth', # this is required for admin 'django.contrib.auth.context_processors.auth', # this is required for admin
'django.core.context_processors.csrf', 'django.core.context_processors.csrf',
'dealer.contrib.django.staff.context_processor', # access git revision 'dealer.contrib.django.staff.context_processor', # access git revision
...@@ -165,12 +166,13 @@ MIDDLEWARE_CLASSES = ( ...@@ -165,12 +166,13 @@ MIDDLEWARE_CLASSES = (
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'track.middleware.TrackMiddleware', 'track.middleware.TrackMiddleware',
'edxmako.middleware.MakoMiddleware',
# Detects user-requested locale from 'accept-language' header in http request # Detects user-requested locale from 'accept-language' header in http request
'django.middleware.locale.LocaleMiddleware', 'django.middleware.locale.LocaleMiddleware',
'django.middleware.transaction.TransactionMiddleware', 'django.middleware.transaction.TransactionMiddleware',
# needs to run after locale middleware (or anything that modifies the request context)
'edxmako.middleware.MakoMiddleware',
# catches any uncaught RateLimitExceptions and returns a 403 instead of a 500 # catches any uncaught RateLimitExceptions and returns a 403 instead of a 500
'ratelimitbackend.middleware.RateLimitMiddleware', 'ratelimitbackend.middleware.RateLimitMiddleware',
......
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
<%namespace name='static' file='static_content.html'/> <%namespace name='static' file='static_content.html'/>
<!doctype html> <!doctype html>
<!--[if IE 7]><html class="ie7 lte9 lte8 lte7"><![endif]--> <!--[if IE 7]><html class="ie7 lte9 lte8 lte7" lang="${LANGUAGE_CODE}"><![endif]-->
<!--[if IE 8]><html class="ie8 lte9 lte8"><![endif]--> <!--[if IE 8]><html class="ie8 lte9 lte8" lang="${LANGUAGE_CODE}"><![endif]-->
<!--[if IE 9]><html class="ie9 lte9"><![endif]--> <!--[if IE 9]><html class="ie9 lte9" lang="${LANGUAGE_CODE}"><![endif]-->
<!--[if gt IE 9]><!--><html><!--<![endif]--> <!--[if gt IE 9]><!--><html lang="${LANGUAGE_CODE}"><!--<![endif]-->
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<%block name="header_extras"></%block> <%block name="header_extras"></%block>
</head> </head>
<body class="<%block name='bodyclass'></%block> hide-wip"> <body class="<%block name='bodyclass'></%block> hide-wip lang_${LANGUAGE_CODE}">
<a class="nav-skip" href="#content">${_("Skip to this view's content")}</a> <a class="nav-skip" href="#content">${_("Skip to this view's content")}</a>
<script type="text/javascript"> <script type="text/javascript">
......
"""
Tests i18n in courseware
"""
from django.test import TestCase
from django.test.utils import override_settings
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
import re
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE, LANGUAGES=(('eo', 'Esperanto'),))
class I18nTestCase(TestCase):
"""
Tests for i18n
"""
def test_default_is_en(self):
response = self.client.get('/')
self.assertIn('<html lang="en">', response.content)
self.assertEqual(response['Content-Language'], 'en')
self.assertTrue(re.search('<body.*class=".*lang_en">', response.content))
def test_esperanto(self):
response = self.client.get('/', HTTP_ACCEPT_LANGUAGE='eo')
self.assertIn('<html lang="eo">', response.content)
self.assertEqual(response['Content-Language'], 'eo')
self.assertTrue(re.search('<body.*class=".*lang_eo">', response.content))
...@@ -277,7 +277,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( ...@@ -277,7 +277,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request', 'django.core.context_processors.request',
'django.core.context_processors.static', 'django.core.context_processors.static',
'django.contrib.messages.context_processors.messages', 'django.contrib.messages.context_processors.messages',
#'django.core.context_processors.i18n', 'django.core.context_processors.i18n',
'django.contrib.auth.context_processors.auth', # this is required for admin 'django.contrib.auth.context_processors.auth', # this is required for admin
'django.core.context_processors.csrf', 'django.core.context_processors.csrf',
...@@ -635,7 +635,6 @@ MIDDLEWARE_CLASSES = ( ...@@ -635,7 +635,6 @@ MIDDLEWARE_CLASSES = (
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'track.middleware.TrackMiddleware', 'track.middleware.TrackMiddleware',
'edxmako.middleware.MakoMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'course_wiki.course_nav.Middleware', 'course_wiki.course_nav.Middleware',
...@@ -651,6 +650,8 @@ MIDDLEWARE_CLASSES = ( ...@@ -651,6 +650,8 @@ MIDDLEWARE_CLASSES = (
# catches any uncaught RateLimitExceptions and returns a 403 instead of a 500 # catches any uncaught RateLimitExceptions and returns a 403 instead of a 500
'ratelimitbackend.middleware.RateLimitMiddleware', 'ratelimitbackend.middleware.RateLimitMiddleware',
# needs to run after locale middleware (or anything that modifies the request context)
'edxmako.middleware.MakoMiddleware',
# For A/B testing # For A/B testing
'waffle.middleware.WaffleMiddleware', 'waffle.middleware.WaffleMiddleware',
......
...@@ -73,6 +73,7 @@ COMMON_TEST_DATA_ROOT = COMMON_ROOT / "test" / "data" ...@@ -73,6 +73,7 @@ COMMON_TEST_DATA_ROOT = COMMON_ROOT / "test" / "data"
# Where the content data is checked out. This may not exist on jenkins. # Where the content data is checked out. This may not exist on jenkins.
GITHUB_REPO_ROOT = ENV_ROOT / "data" GITHUB_REPO_ROOT = ENV_ROOT / "data"
USE_I18N = True
XQUEUE_INTERFACE = { XQUEUE_INTERFACE = {
"url": "http://sandbox-xqueue.edx.org", "url": "http://sandbox-xqueue.edx.org",
......
<!doctype html> <!doctype html>
<html> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300' rel='stylesheet' type='text/css'> <link href='http://fonts.googleapis.com/css?family=Open+Sans:300' rel='stylesheet' type='text/css'>
......
<!DOCTYPE html> <!DOCTYPE html>
<%! from django.utils.translation import ugettext as _ %> <%! from django.utils.translation import ugettext as _ %>
<html> <html lang="${LANGUAGE_CODE}">
<head> <head>
## "edX" should not be translated ## "edX" should not be translated
<%block name="title"><title>edX</title></%block> <%block name="title"><title>edX</title></%block>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"> "http://www.w3.org/TR/html4/strict.dtd">
<html> <html lang="${LANGUAGE_CODE}">
<head> <head>
<title>${_("External Authentication failed")}</title> <title>${_("External Authentication failed")}</title>
</head> </head>
......
...@@ -22,10 +22,10 @@ ...@@ -22,10 +22,10 @@
</%def> </%def>
<!DOCTYPE html> <!DOCTYPE html>
<!--[if IE 7]><html class="ie ie7 lte9 lte8 lte7" lang="en-us"><![endif]--> <!--[if IE 7]><html class="ie ie7 lte9 lte8 lte7" lang="${LANGUAGE_CODE}"><![endif]-->
<!--[if IE 8]><html class="ie ie8 lte9 lte8" lang="en-us"><![endif]--> <!--[if IE 8]><html class="ie ie8 lte9 lte8" lang="${LANGUAGE_CODE}"><![endif]-->
<!--[if IE 9]><html class="ie ie9 lte9" lang="en-us"><![endif]--> <!--[if IE 9]><html class="ie ie9 lte9" lang="${LANGUAGE_CODE}"><![endif]-->
<!--[if gt IE 9]><!--><html lang="en-us"><!--<![endif]--> <!--[if gt IE 9]><!--><html lang="${LANGUAGE_CODE}"><!--<![endif]-->
<head> <head>
<%block name="title"> <%block name="title">
% if stanford_theme_enabled(): % if stanford_theme_enabled():
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
</head> </head>
<body class="<%block name='bodyclass'/>"> <body class="<%block name='bodyclass'/> lang_${LANGUAGE_CODE}">
<a class="nav-skip" href="#content">${_("Skip to this view's content")}</a> <a class="nav-skip" href="#content">${_("Skip to this view's content")}</a>
<%include file="mathjax_accessible.html" /> <%include file="mathjax_accessible.html" />
......
<!DOCTYPE html> <!DOCTYPE html>
{% load compressed %}{% load sekizai_tags i18n %}{% load url from future %}{% load staticfiles %} {% load compressed %}{% load sekizai_tags i18n %}{% load url from future %}{% load staticfiles %}
<html> <html lang="{{LANGUAGE_CODE}}">
<head> <head>
{# "edX" should *not* be translated #} {# "edX" should *not* be translated #}
{% block title %}<title>edX</title>{% endblock %} {% block title %}<title>edX</title>{% endblock %}
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
<meta name="path_prefix" content="{{EDX_ROOT_URL}}"> <meta name="path_prefix" content="{{EDX_ROOT_URL}}">
</head> </head>
<body class="{% block bodyclass %}{% endblock %}"> <body class="{% block bodyclass %}{% endblock %} lang_{{LANGUAGE_CODE}}">
<a class="nav-skip" href="#content">{% trans "Skip to this view's content" %}</a> <a class="nav-skip" href="#content">{% trans "Skip to this view's content" %}</a>
{% include "navigation.html" %} {% include "navigation.html" %}
<section class="content-wrapper" id="content"> <section class="content-wrapper" id="content">
......
<%namespace name='static' file='static_content.html'/> <%namespace name='static' file='static_content.html'/>
<!DOCTYPE html> <!DOCTYPE html>
<!--[if IE 7]><html class="ie ie7 lte9 lte8 lte7 view-iframe"><![endif]--> <!--[if IE 7]><html class="ie ie7 lte9 lte8 lte7 view-iframe" lang="${LANGUAGE_CODE}"><![endif]-->
<!--[if IE 8]><html class="ie ie8 lte9 lte8 view-iframe"><![endif]--> <!--[if IE 8]><html class="ie ie8 lte9 lte8 view-iframe" lang="${LANGUAGE_CODE}"><![endif]-->
<!--[if IE 9]><html class="ie ie9 lte9 view-iframe"><![endif]--> <!--[if IE 9]><html class="ie ie9 lte9 view-iframe" lang="${LANGUAGE_CODE}"><![endif]-->
<!--[if gt IE 9]><!--><html class="view-iframe"><!--<![endif]--> <!--[if gt IE 9]><!--><html class="view-iframe" lang="${LANGUAGE_CODE}"><!--<![endif]-->
<head> <head>
<%block name="title"></%block> <%block name="title"></%block>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
{% load compressed %} {% load compressed %}
{% load staticfiles %} {% load staticfiles %}
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="{{LANGUAGE_CODE}}">
<head> <head>
<title>{% trans "Your Password Reset is Complete" %}</title> <title>{% trans "Your Password Reset is Complete" %}</title>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
{% load compressed %} {% load compressed %}
{% load staticfiles %} {% load staticfiles %}
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="{{LANGUAGE_CODE}}">
<head> <head>
<title> <title>
......
<!DOCTYPE html> <!DOCTYPE html>
{% load wiki_tags i18n %}{% load compressed %} {% load wiki_tags i18n %}{% load compressed %}
<html> <html lang="{{LANGUAGE_CODE}}">
<head> <head>
{% compressed_css 'course' %} {% compressed_css 'course' %}
{% compressed_js 'main_vendor' %} {% compressed_js 'main_vendor' %}
......
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