Skip to content

Commit

Permalink
Only try to match accepted languages if request context is available
Browse files Browse the repository at this point in the history
Prevents tests from failing.
  • Loading branch information
homeworkprod committed Jul 1, 2021
1 parent d9f9114 commit 87d4f40
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions byceps/util/l10n.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ def get_current_user_locale() -> Optional[str]:
if (user is not None) and (user.locale is not None):
return user.locale

# Try to match user agent's accepted languages.
languages = [locale.language for locale in get_locales()]
return request.accept_languages.best_match(languages)
if request:
# Try to match user agent's accepted languages.
languages = [locale.language for locale in get_locales()]
return request.accept_languages.best_match(languages)

return None


BASE_LOCALE = Locale('en')
Expand Down

0 comments on commit 87d4f40

Please sign in to comment.