def get_language_from_request(request):
 global _accepted
 from django.conf import settings
 supported = dict(settings.LANGUAGES)
 if hasattr(request, 'session'):
  lang_code = request.session.get('django_language', None)
  if ((lang_code in supported) and (lang_code is not None) and check_for_language(lang_code)):
   return lang_code
 lang_code = request.COOKIES.get(settings.LANGUAGE_COOKIE_NAME)
 if (lang_code and (lang_code not in supported)):
  lang_code = lang_code.split('-')[0]
 if (lang_code and (lang_code in supported) and check_for_language(lang_code)):
  return lang_code
 accept = request.META.get('HTTP_ACCEPT_LANGUAGE', '')
 for (accept_lang, unused) in parse_accept_lang_header(accept):
  if (accept_lang == '*'):
   break
  normalized = locale.locale_alias.get(to_locale(accept_lang, True))
  if (not normalized):
   continue
  normalized = normalized.split('.')[0]
  if (normalized in _accepted):
   return _accepted[normalized]
  for (lang, dirname) in ((accept_lang, normalized), (accept_lang.split('-')[0], normalized.split('_')[0])):
   if (lang.lower() not in supported):
    continue
   for path in all_locale_paths():
    if os.path.exists(os.path.join(path, dirname, 'LC_MESSAGES', 'django.mo')):
     _accepted[normalized] = lang
     return lang
 return settings.LANGUAGE_CODE

def get_language_from_request ( request ) : global _accepted from django . conf import settings supported = dict ( settings . LANGUAGES ) if hasattr ( request , 'session' ) : lang_code = request . session . get ( 'django_language' , None ) if ( ( lang_code in supported ) and ( lang_code is not None ) and check_for_language ( lang_code ) ) : return lang_code lang_code = request . COOKIES . get ( settings . LANGUAGE_COOKIE_NAME ) if ( lang_code and ( lang_code not in supported ) ) : lang_code = lang_code . split ( '-' ) [ 0 ] if ( lang_code and ( lang_code in supported ) and check_for_language ( lang_code ) ) : return lang_code accept = request . META . get ( 'HTTP_ACCEPT_LANGUAGE' , '' ) for ( accept_lang , unused ) in parse_accept_lang_header ( accept ) : if ( accept_lang == '*' ) : break normalized = locale . locale_alias . get ( to_locale ( accept_lang , True ) ) if ( not normalized ) : continue normalized = normalized . split ( '.' ) [ 0 ] if ( normalized in _accepted ) : return _accepted [ normalized ] for ( lang , dirname ) in ( ( accept_lang , normalized ) , ( accept_lang . split ( '-' ) [ 0 ] , normalized . split ( '_' ) [ 0 ] ) ) : if ( lang . lower ( ) not in supported ) : continue for path in all_locale_paths ( ) : if os . path . exists ( os . path . join ( path , dirname , 'LC_MESSAGES' , 'django.mo' ) ) : _accepted [ normalized ] = lang return lang return settings . LANGUAGE_CODE
analyzes the request to find what language the user wants the system to show .