Skip to content

Commit

Permalink
Use system locale for default request language
Browse files Browse the repository at this point in the history
Remove en_US as the default language when no header is provided, and use
None instead. Upon translation None will be defaulted to system locale
as it was before API translation changes.

fixes bug 1214476

Change-Id: Ic33c94c29993ceb944d7c22d2e754cb938db7503
  • Loading branch information
mrodden committed Sep 30, 2013
1 parent a6bc12c commit bac116e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
11 changes: 8 additions & 3 deletions nova/api/openstack/wsgi.py
Expand Up @@ -179,10 +179,15 @@ def get_content_type(self):
return content_type

def best_match_language(self):
"""Determine language for returned response."""
"""Determine the best available language for the request.
: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
return self.accept_language.best_match(
gettextutils.get_available_languages('nova'),
default_match='en_US')
gettextutils.get_available_languages('nova'))


class ActionDispatcher(object):
Expand Down
2 changes: 1 addition & 1 deletion nova/tests/api/openstack/test_faults.py
Expand Up @@ -60,7 +60,7 @@ def raiser(*args, **kwargs):

self.assertIn("I've been translated!", unicode(response.body))
mock_get_localized.assert_any_call(
u'Should be translated.', 'en_US')
u'Should be translated.', None)


class TestFaults(test.NoDBTestCase):
Expand Down
11 changes: 10 additions & 1 deletion nova/tests/api/openstack/test_wsgi.py
Expand Up @@ -143,7 +143,16 @@ def test_none_found(self):
request = wsgi.Request.blank('/')
accepted = 'nb-no'
request.headers = {'Accept-Language': accepted}
self.assertEqual(request.best_match_language(), 'en_US')
self.assertIs(request.best_match_language(), None)

def test_no_lang_header(self):
self.stubs.Set(gettextutils, 'get_available_languages',
fakes.fake_get_available_languages)

request = wsgi.Request.blank('/')
accepted = ''
request.headers = {'Accept-Language': accepted}
self.assertIs(request.best_match_language(), None)


class ActionDispatcherTest(test.NoDBTestCase):
Expand Down

0 comments on commit bac116e

Please sign in to comment.