def select_locale_by_request(self, request, locales=()):
        """Choose an user's locales by request."""
        default_locale = locales and locales[0] or self.cfg.default_locale

        if len(locales) == 1 or 'ACCEPT-LANGUAGE' not in request.headers:
            return default_locale

        ulocales = [
            (q, locale_delim_re.split(v)[0])
            for v, q in parse_accept_header(request.headers['ACCEPT-LANGUAGE'])
        ]
        ulocales.sort()
        ulocales.reverse()

        for locale in locales:
            for _, ulocale in ulocales:
                ulocale = locale_delim_re.split(ulocale)[0]
                if ulocale.lower() == locale.lower():
                    return ulocale

        return ulocales[0][1]
def select_locale_by_request ( self , request , locales = ( ) ) : default_locale = locales and locales [ 0 ] or self . cfg . default_locale if len ( locales ) == 1 or 'ACCEPT-LANGUAGE' not in request . headers : return default_locale ulocales = [ ( q , locale_delim_re . split ( v ) [ 0 ] ) for v , q in parse_accept_header ( request . headers [ 'ACCEPT-LANGUAGE' ] ) ] ulocales . sort ( ) ulocales . reverse ( ) for locale in locales : for _ , ulocale in ulocales : ulocale = locale_delim_re . split ( ulocale ) [ 0 ] if ulocale . lower ( ) == locale . lower ( ) : return ulocale return ulocales [ 0 ] [ 1 ]
Choose an user's locales by request.