Commit 26413a57 by Jesse Zoldak Committed by GitHub

Merge pull request #14149 from edx/revert-13441-honorbrowserdefinedlangs

Revert "Honor browser defined language preferences when possible"
parents 790a642a 59623283
......@@ -39,15 +39,9 @@ class LanguagePreferenceMiddleware(object):
preferred_language = request.META.get('HTTP_ACCEPT_LANGUAGE', '')
lang_headers = [seq[0] for seq in parse_accept_lang_header(preferred_language)]
prefixes = [prefix.split("-")[0] for prefix in system_released_languages]
# Setting the session language to the browser language, if it is supported.
for browser_lang in lang_headers:
if browser_lang in system_released_languages:
pass
elif browser_lang in prefixes:
browser_lang = system_released_languages[prefixes.index(browser_lang)]
else:
continue
if request.session.get(LANGUAGE_SESSION_KEY, None) is None:
request.session[LANGUAGE_SESSION_KEY] = unicode(browser_lang)
break
if request.session.get(LANGUAGE_SESSION_KEY, None) is None:
request.session[LANGUAGE_SESSION_KEY] = unicode(browser_lang)
break
......@@ -100,30 +100,3 @@ class TestUserPreferenceMiddleware(TestCase):
set_user_preference(self.user, LANGUAGE_KEY, 'eo')
self.middleware.process_request(self.request)
self.assertEqual(get_user_preference(self.request.user, LANGUAGE_KEY), None)
@mock.patch(
'openedx.core.djangoapps.lang_pref.middleware.released_languages',
mock.Mock(return_value=[('eu-es', 'euskara (Espainia)'), ('en', 'english')])
)
def test_supported_browser_language_prefix_in_session(self):
"""
test: browser language should be set in user session if it's prefix is supported by system for
unathenticated users
"""
self.request.META['HTTP_ACCEPT_LANGUAGE'] = 'eu;q=1.0'
self.request.user = self.anonymous_user
self.middleware.process_request(self.request)
self.assertEqual(self.request.session.get(LANGUAGE_SESSION_KEY), 'eu-es') #pylint: disable=no-member
@mock.patch(
'openedx.core.djangoapps.lang_pref.middleware.released_languages',
mock.Mock(return_value=[('en', 'english')])
)
def test_unsupported_browser_language_prefix(self):
"""
test: browser language should not be set in user session if it's prefix is not supported by system.
"""
self.request.META['HTTP_ACCEPT_LANGUAGE']='eu;q=1.0'
self.request.user = self.anonymous_user
self.middleware.process_request(self.request)
self.assertNotEqual(self.request.session.get(LANGUAGE_SESSION_KEY), 'eu-es') # pylint: disable=no-member
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