Skip to content

Commit

Permalink
Ensure that when 'lang' option is set and i18n is enabled lang is use…
Browse files Browse the repository at this point in the history
…d as fallback
  • Loading branch information
amol- committed Aug 5, 2014
1 parent 4a0c2dc commit f80de5a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions tests/test_i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def setup(self):
conf['paths']['root'] = 'tests'
conf['i18n_enabled'] = True
conf['use_sessions'] = True
conf['lang'] = None
conf['beaker.session.key'] = 'tg_test_session'
conf['beaker.session.secret'] = 'this-is-some-secret'
conf.renderers = ['json']
Expand Down Expand Up @@ -197,3 +198,10 @@ def test_force_lang(self):
def test_get_lang_no_session(self):
r = self.app.get('/get_lang?skip_lang=1', extra_environ={})
assert '[]' in r, r.body

def test_get_lang_supported_with_default_lang(self):
tg.config['lang'] = 'kr'
r = self.app.get('/get_supported_lang?skip_lang=1',
headers={'Accept-Language': 'ru,en,de;q=0.5'})
langs = r.json['lang']
assert langs == ['ru', 'de', 'kr'], langs
2 changes: 1 addition & 1 deletion tg/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def setup_i18n(tgl=None):
else: #pragma: no cover
languages = []

languages.extend(map(sanitize_language_code, tgl.request.plain_languages))
languages.extend(map(sanitize_language_code, tgl.request.languages))
set_temporary_lang(languages, tgl=tgl)


Expand Down
2 changes: 1 addition & 1 deletion tg/request_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def controller_url(self):
def plain_languages(self):
return self.languages_best_match()

@property
@cached_property
def languages(self):
return self.languages_best_match(self._language)

Expand Down

0 comments on commit f80de5a

Please sign in to comment.