Skip to content
Snippets Groups Projects
Commit 6d50ff7b authored by Dave St.Germain's avatar Dave St.Germain
Browse files

Set the html language to the browser's specified language

parent b615de57
Branches
Tags
No related merge requests found
......@@ -113,6 +113,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request',
'django.core.context_processors.static',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.i18n',
'django.contrib.auth.context_processors.auth', # this is required for admin
'django.core.context_processors.csrf',
'dealer.contrib.django.staff.context_processor', # access git revision
......@@ -165,12 +166,13 @@ MIDDLEWARE_CLASSES = (
'django.contrib.messages.middleware.MessageMiddleware',
'track.middleware.TrackMiddleware',
'edxmako.middleware.MakoMiddleware',
# Detects user-requested locale from 'accept-language' header in http request
'django.middleware.locale.LocaleMiddleware',
'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
'ratelimitbackend.middleware.RateLimitMiddleware',
......
......@@ -3,10 +3,10 @@
<%namespace name='static' file='static_content.html'/>
<!doctype html>
<!--[if IE 7]><html class="ie7 lte9 lte8 lte7"><![endif]-->
<!--[if IE 8]><html class="ie8 lte9 lte8"><![endif]-->
<!--[if IE 9]><html class="ie9 lte9"><![endif]-->
<!--[if gt IE 9]><!--><html><!--<![endif]-->
<!--[if IE 7]><html class="ie7 lte9 lte8 lte7" lang="${LANGUAGE_CODE}"><![endif]-->
<!--[if IE 8]><html class="ie8 lte9 lte8" lang="${LANGUAGE_CODE}"><![endif]-->
<!--[if IE 9]><html class="ie9 lte9" lang="${LANGUAGE_CODE}"><![endif]-->
<!--[if gt IE 9]><!--><html lang="${LANGUAGE_CODE}"><!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
......@@ -32,7 +32,7 @@
<%block name="header_extras"></%block>
</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>
<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 = (
'django.core.context_processors.request',
'django.core.context_processors.static',
'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.core.context_processors.csrf',
......@@ -635,7 +635,6 @@ MIDDLEWARE_CLASSES = (
'django.contrib.messages.middleware.MessageMiddleware',
'track.middleware.TrackMiddleware',
'edxmako.middleware.MakoMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'course_wiki.course_nav.Middleware',
......@@ -651,6 +650,8 @@ MIDDLEWARE_CLASSES = (
# catches any uncaught RateLimitExceptions and returns a 403 instead of a 500
'ratelimitbackend.middleware.RateLimitMiddleware',
# needs to run after locale middleware (or anything that modifies the request context)
'edxmako.middleware.MakoMiddleware',
# For A/B testing
'waffle.middleware.WaffleMiddleware',
......
......@@ -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.
GITHUB_REPO_ROOT = ENV_ROOT / "data"
USE_I18N = True
XQUEUE_INTERFACE = {
"url": "http://sandbox-xqueue.edx.org",
......
<!doctype html>
<html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300' rel='stylesheet' type='text/css'>
......
<!DOCTYPE html>
<%! from django.utils.translation import ugettext as _ %>
<html>
<html lang="${LANGUAGE_CODE}">
<head>
## "edX" should not be translated
<%block name="title"><title>edX</title></%block>
......
......@@ -2,7 +2,7 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<html lang="${LANGUAGE_CODE}">
<head>
<title>${_("External Authentication failed")}</title>
</head>
......
......@@ -22,10 +22,10 @@
</%def>
<!DOCTYPE html>
<!--[if IE 7]><html class="ie ie7 lte9 lte8 lte7" lang="en-us"><![endif]-->
<!--[if IE 8]><html class="ie ie8 lte9 lte8" lang="en-us"><![endif]-->
<!--[if IE 9]><html class="ie ie9 lte9" lang="en-us"><![endif]-->
<!--[if gt IE 9]><!--><html 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="${LANGUAGE_CODE}"><![endif]-->
<!--[if IE 9]><html class="ie ie9 lte9" lang="${LANGUAGE_CODE}"><![endif]-->
<!--[if gt IE 9]><!--><html lang="${LANGUAGE_CODE}"><!--<![endif]-->
<head>
<%block name="title">
% if stanford_theme_enabled():
......@@ -102,7 +102,7 @@
</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>
<%include file="mathjax_accessible.html" />
......
<!DOCTYPE html>
{% load compressed %}{% load sekizai_tags i18n %}{% load url from future %}{% load staticfiles %}
<html>
<html lang="{{LANGUAGE_CODE}}">
<head>
{# "edX" should *not* be translated #}
{% block title %}<title>edX</title>{% endblock %}
......@@ -28,7 +28,7 @@
<meta name="path_prefix" content="{{EDX_ROOT_URL}}">
</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>
{% include "navigation.html" %}
<section class="content-wrapper" id="content">
......
<%namespace name='static' file='static_content.html'/>
<!DOCTYPE html>
<!--[if IE 7]><html class="ie ie7 lte9 lte8 lte7 view-iframe"><![endif]-->
<!--[if IE 8]><html class="ie ie8 lte9 lte8 view-iframe"><![endif]-->
<!--[if IE 9]><html class="ie ie9 lte9 view-iframe"><![endif]-->
<!--[if gt IE 9]><!--><html class="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" lang="${LANGUAGE_CODE}"><![endif]-->
<!--[if IE 9]><html class="ie ie9 lte9 view-iframe" lang="${LANGUAGE_CODE}"><![endif]-->
<!--[if gt IE 9]><!--><html class="view-iframe" lang="${LANGUAGE_CODE}"><!--<![endif]-->
<head>
<%block name="title"></%block>
......
......@@ -2,7 +2,7 @@
{% load compressed %}
{% load staticfiles %}
<!DOCTYPE html>
<html>
<html lang="{{LANGUAGE_CODE}}">
<head>
<title>{% trans "Your Password Reset is Complete" %}</title>
......
......@@ -2,7 +2,7 @@
{% load compressed %}
{% load staticfiles %}
<!DOCTYPE html>
<html>
<html lang="{{LANGUAGE_CODE}}">
<head>
<title>
......
<!DOCTYPE html>
{% load wiki_tags i18n %}{% load compressed %}
<html>
<html lang="{{LANGUAGE_CODE}}">
<head>
{% compressed_css 'course' %}
{% compressed_js 'main_vendor' %}
......
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