def get_fallback_locale(doc, request):
 translated_locales = doc.translations.values_list('locale', flat=True).exclude(current_revision=None)
 accept_header = (request.META.get('HTTP_ACCEPT_LANGUAGE') or '')
 header_locales = parse_accept_lang_header(accept_header)
 all_accepted_locales = []
 all_accepted_locales.append(request.LANGUAGE_CODE)
 all_accepted_locales.extend(header_locales)
 for locale in all_accepted_locales:
  if (locale == settings.WIKI_DEFAULT_LANGUAGE):
   return None
  elif (locale in translated_locales):
   return locale
  elif (settings.NON_SUPPORTED_LOCALES.get(locale) in translated_locales):
   return settings.NON_SUPPORTED_LOCALES[locale]
  for fallback in FALLBACK_LOCALES.get(locale, []):
   if (fallback in translated_locales):
    return fallback
 return None

def get_fallback_locale ( doc , request ) : translated_locales = doc . translations . values_list ( 'locale' , flat = True ) . exclude ( current_revision = None ) accept_header = ( request . META . get ( 'HTTP_ACCEPT_LANGUAGE' ) or '' ) header_locales = parse_accept_lang_header ( accept_header ) all_accepted_locales = [ ] all_accepted_locales . append ( request . LANGUAGE_CODE ) all_accepted_locales . extend ( header_locales ) for locale in all_accepted_locales : if ( locale == settings . WIKI_DEFAULT_LANGUAGE ) : return None elif ( locale in translated_locales ) : return locale elif ( settings . NON_SUPPORTED_LOCALES . get ( locale ) in translated_locales ) : return settings . NON_SUPPORTED_LOCALES [ locale ] for fallback in FALLBACK_LOCALES . get ( locale , [ ] ) : if ( fallback in translated_locales ) : return fallback return None
get best fallback local based on locale mapping .