Use system locale when Accept-Language header is not provided
Remove en_US as the default language when no header is provided, and use None instead. Upon translation None will be defaulted to system as it was before the translation changes. Fixes bug: #1214476 Change-Id: I0fe22c526710e69ae0731e7d0b42170e6f3a8523
This commit is contained in:
parent
6008e688a1
commit
7588653daa
@ -100,8 +100,7 @@ class RequestTestCase(base.BaseTestCase):
|
||||
self.assertTrue(self.req.context.is_admin)
|
||||
|
||||
def test_best_match_language(self):
|
||||
# Here we test that we are actually invoking language negotiation
|
||||
# by webop and also that the default locale always available is en-US
|
||||
# Test that we are actually invoking language negotiation by webop
|
||||
request = wsgi.Request.blank('/')
|
||||
gettextutils.get_available_languages = mock.MagicMock()
|
||||
gettextutils.get_available_languages.return_value = ['known-language',
|
||||
@ -109,9 +108,18 @@ class RequestTestCase(base.BaseTestCase):
|
||||
request.headers['Accept-Language'] = 'known-language'
|
||||
language = request.best_match_language()
|
||||
self.assertEqual(language, 'known-language')
|
||||
|
||||
# If the Accept-Leader is an unknown language, missing or empty,
|
||||
# the best match locale should be None
|
||||
request.headers['Accept-Language'] = 'unknown-language'
|
||||
language = request.best_match_language()
|
||||
self.assertEqual(language, 'en_US')
|
||||
self.assertEqual(language, None)
|
||||
request.headers['Accept-Language'] = ''
|
||||
language = request.best_match_language()
|
||||
self.assertEqual(language, None)
|
||||
request.headers.pop('Accept-Language')
|
||||
language = request.best_match_language()
|
||||
self.assertEqual(language, None)
|
||||
|
||||
|
||||
class ResourceTestCase(base.BaseTestCase):
|
||||
|
@ -301,10 +301,15 @@ class Request(webob.Request):
|
||||
return None
|
||||
|
||||
def best_match_language(self):
|
||||
"""Determine language for returned response."""
|
||||
"""Determines best available locale from the Accept-Language header.
|
||||
|
||||
:returns: the best language match or None if the 'Accept-Language'
|
||||
header was not available in the request.
|
||||
"""
|
||||
if not self.accept_language:
|
||||
return None
|
||||
all_languages = gettextutils.get_available_languages('neutron')
|
||||
return self.accept_language.best_match(all_languages,
|
||||
default_match='en_US')
|
||||
return self.accept_language.best_match(all_languages)
|
||||
|
||||
@property
|
||||
def context(self):
|
||||
|
Loading…
Reference in New Issue
Block a user