'Return a locale code that we support on the site using the
user\'s Accept Language header to determine which is best.  This
mostly follows the RFCs but read bug 439568 for details.'

def get_language(self, request):

    data = (request.GET or request.POST)
    if ('lang' in data):
        lang = data['lang'].lower()
        if (lang in settings.LANGUAGE_URL_MAP):
            return settings.LANGUAGE_URL_MAP[lang]
        prefix = lang.split('-')[0]
        if (prefix in settings.LANGUAGE_URL_MAP):
            return settings.LANGUAGE_URL_MAP[prefix]
    accept = request.META.get('HTTP_ACCEPT_LANGUAGE', '')
    return lang_from_accept_header(accept)
