def get_locale_from_accept_header(request):
 header = request.headers.get('Accept-Language', '')
 parsed = parse_accept_language_header(header)
 if (parsed is None):
  return None
 pairs_sorted_by_q = sorted(parsed.items(), key=(lambda (lang, q): q), reverse=True)
 locale = Locale.negotiate([lang for (lang, q) in pairs_sorted_by_q], request.app.config.get('locales'), sep='_')
 return str(locale)

def get_locale_from_accept_header ( request ) : header = request . headers . get ( 'Accept-Language' , '' ) parsed = parse_accept_language_header ( header ) if ( parsed is None ) : return None pairs_sorted_by_q = sorted ( parsed . items ( ) , key = ( lambda ( lang , q ) : q ) , reverse = True ) locale = Locale . negotiate ( [ lang for ( lang , q ) in pairs_sorted_by_q ] , request . app . config . get ( 'locales' ) , sep = '_' ) return str ( locale )
detect locale from request .