def _get_culture_for_request(self, request):
"""
Gets the culture to use for a given request.
"""
if "GET" == request.method:
culture = request.match_info.get("culture")
if culture:
if not self._is_supported_culture(culture):
# the given culture is not supported; the user could have changed a url by hand
# raise an exception to redirect to a proper url
raise InvalidCultureException()
return culture
user = request.user
if user and not user.anonymous and self._is_supported_culture(user.culture):
return user.culture
if "POST" == request.method:
# check custom headers
culture_header = request.headers.get("X-Request-Culture")
if self._is_supported_culture(culture_header):
return culture_header
culture_cookie = request.cookies.get("culture")
if self._is_supported_culture(culture_cookie):
return culture_cookie
评论列表
文章目录