Python django.utils.translation 模块,get_language_from_request() 实例源码

我们从Python开源项目中,提取了以下30个代码示例,用于说明如何使用django.utils.translation.get_language_from_request()

项目:nrp    作者:django-rea    | 项目源码 | 文件源码
def create(cls, request=None, **kwargs):
        create_email = kwargs.pop("create_email", True)
        confirm_email = kwargs.pop("confirm_email", None)
        account = cls(**kwargs)
        if "language" not in kwargs:
            if request is None:
                account.language = settings.LANGUAGE_CODE
            else:
                account.language = translation.get_language_from_request(request, check_path=True)
        account.save()
        if create_email and account.user.email:
            kwargs = {"primary": True}
            if confirm_email is not None:
                kwargs["confirm"] = confirm_email
            EmailAddress.objects.add_email(account.user, account.user.email, **kwargs)
        return account
项目:wagtail_room_booking    作者:Tamriel    | 项目源码 | 文件源码
def create(cls, request=None, **kwargs):
        create_email = kwargs.pop("create_email", True)
        confirm_email = kwargs.pop("confirm_email", None)
        account = cls(**kwargs)
        if "language" not in kwargs:
            if request is None:
                account.language = settings.LANGUAGE_CODE
            else:
                account.language = translation.get_language_from_request(request, check_path=True)
        account.save()
        if create_email and account.user.email:
            kwargs = {"primary": True}
            if confirm_email is not None:
                kwargs["confirm"] = confirm_email
            EmailAddress.objects.add_email(account.user, account.user.email, **kwargs)
        return account
项目:edx-enterprise    作者:edx    | 项目源码 | 文件源码
def get_global_context(request):
    """
    Get the set of variables that are needed by default across views.
    """
    platform_name = get_configuration_value("PLATFORM_NAME", settings.PLATFORM_NAME)
    return {
        'LMS_SEGMENT_KEY': settings.LMS_SEGMENT_KEY,
        'LANGUAGE_CODE': get_language_from_request(request),
        'tagline': get_configuration_value(
            "ENTERPRISE_TAGLINE",
            getattr(settings, "ENTERPRISE_TAGLINE", '')  # Remove the `getattr` when setting is upstreamed.
        ),
        'platform_description': get_configuration_value(
            "PLATFORM_DESCRIPTION",
            getattr(settings, "PLATFORM_DESCRIPTION", '')  # Remove `getattr` when variable is upstreamed.
        ),
        'LMS_ROOT_URL': settings.LMS_ROOT_URL,
        'platform_name': platform_name,
        'header_logo_alt_text': _('{platform_name} home page').format(platform_name=platform_name),
    }
项目:mes    作者:osess    | 项目源码 | 文件源码
def create(cls, request=None, **kwargs):
        create_email = kwargs.pop("create_email", True)
        confirm_email = kwargs.pop("confirm_email", None)
        account = cls(**kwargs)
        if "language" not in kwargs:
            if request is None:
                account.language = settings.LANGUAGE_CODE
            else:
                account.language = translation.get_language_from_request(request, check_path=True)
        account.save()
        if create_email and account.user.email:
            kwargs = {"primary": True}
            if confirm_email is not None:
                kwargs["confirm"] = confirm_email
            EmailAddress.objects.add_email(account.user, account.user.email, **kwargs)
        return account
项目:mos-horizon    作者:Mirantis    | 项目源码 | 文件源码
def add_logout_reason(request, response, reason):
    # Store the translated string in the cookie
    lang = translation.get_language_from_request(request)
    with translation.override(lang):
        reason = six.text_type(reason)
        if six.PY2:
            reason = reason.encode('utf-8')
        response.set_cookie('logout_reason', reason, max_age=10)
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def process_request(self, request):
        language = translation.get_language_from_request(
            request, check_path=self.is_language_prefix_patterns_used)
        translation.activate(language)
        request.LANGUAGE_CODE = translation.get_language()
项目:zing    作者:evernote    | 项目源码 | 文件源码
def get_language_from_request(request, check_path=False):
    """Try to get the user's preferred language by first checking the
    cookie and then by checking the HTTP language headers.

    If all fails, try fall back to default language.
    """
    supported = dict(supported_langs())
    for lang_getter in (get_lang_from_session,
                        get_lang_from_cookie,
                        get_lang_from_http_header):
        lang = lang_getter(request, supported)
        if lang is not None:
            return lang
    from django.conf import settings
    return settings.LANGUAGE_CODE
项目:zing    作者:evernote    | 项目源码 | 文件源码
def hijack_translation():
    """Sabotage Django's fascist linguistical regime."""
    # Override functions that check if language is known to Django
    translation.check_for_language = lambda lang_code: True
    trans_real.check_for_language = lambda lang_code: True
    translation.get_language_from_request = get_language_from_request

    # Override django's inadequate bidi detection
    translation.get_language_bidi = get_language_bidi

    # We hijack gettext functions to install the safe variable formatting
    # override
    override_gettext(gettext)
项目:djangocms-rest-view    作者:nephila    | 项目源码 | 文件源码
def language(self):
        return get_language_from_request(self.request, check_path=True)
项目:nrp    作者:django-rea    | 项目源码 | 文件源码
def __init__(self, request=None):
        self.user = AnonymousUser()
        self.timezone = settings.TIME_ZONE
        if request is None:
            self.language = settings.LANGUAGE_CODE
        else:
            self.language = translation.get_language_from_request(request, check_path=True)
项目:nrp    作者:django-rea    | 项目源码 | 文件源码
def get_language_for_user(self, request):
        if request.user.is_authenticated():
            try:
                account = Account.objects.get(user=request.user)
                return account.language
            except Account.DoesNotExist:
                pass
        return translation.get_language_from_request(request)
项目:wagtail_room_booking    作者:Tamriel    | 项目源码 | 文件源码
def __init__(self, request=None):
        self.user = AnonymousUser()
        self.timezone = settings.TIME_ZONE
        if request is None:
            self.language = settings.LANGUAGE_CODE
        else:
            self.language = translation.get_language_from_request(request, check_path=True)
项目:wagtail_room_booking    作者:Tamriel    | 项目源码 | 文件源码
def get_language_for_user(self, request):
        if request.user.is_authenticated():
            try:
                account = Account.objects.get(user=request.user)
                return account.language
            except Account.DoesNotExist:
                pass
        return translation.get_language_from_request(request)
项目:DjangoBlog    作者:0daybug    | 项目源码 | 文件源码
def process_request(self, request):
        check_path = self.is_language_prefix_patterns_used()
        language = translation.get_language_from_request(
            request, check_path=check_path)
        translation.activate(language)
        request.LANGUAGE_CODE = translation.get_language()
项目:trydjango18    作者:lucifer-yqh    | 项目源码 | 文件源码
def process_request(self, request):
        check_path = self.is_language_prefix_patterns_used()
        language = translation.get_language_from_request(
            request, check_path=check_path)
        translation.activate(language)
        request.LANGUAGE_CODE = translation.get_language()
项目:trydjango18    作者:wei0104    | 项目源码 | 文件源码
def process_request(self, request):
        check_path = self.is_language_prefix_patterns_used()
        language = translation.get_language_from_request(
            request, check_path=check_path)
        translation.activate(language)
        request.LANGUAGE_CODE = translation.get_language()
项目:drapo    作者:andgein    | 项目源码 | 文件源码
def process_request(self, request):
        language = translation.get_language_from_request(request)
        translation.activate(language)
        request.LANGUAGE_CODE = translation.get_language()
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
def process_request(self, request):
        urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF)
        i18n_patterns_used, prefixed_default_language = is_language_prefix_patterns_used(urlconf)
        language = translation.get_language_from_request(request, check_path=i18n_patterns_used)
        language_from_path = translation.get_language_from_path(request.path_info)
        if not language_from_path and i18n_patterns_used and not prefixed_default_language:
            language = settings.LANGUAGE_CODE
        translation.activate(language)
        request.LANGUAGE_CODE = translation.get_language()
项目:DjangoCMS    作者:farhan711    | 项目源码 | 文件源码
def dispatch(self, request, *args, **kwargs):
        self.language_code = get_language_from_request(request, check_path=True)
        response = super(WizardViewMixin, self).dispatch(
            request, *args, **kwargs)
        return response
项目:liberator    作者:libscie    | 项目源码 | 文件源码
def process_request(self, request):
        urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF)
        i18n_patterns_used, prefixed_default_language = is_language_prefix_patterns_used(urlconf)
        language = translation.get_language_from_request(request, check_path=i18n_patterns_used)
        language_from_path = translation.get_language_from_path(request.path_info)
        if not language_from_path and i18n_patterns_used and not prefixed_default_language:
            language = settings.LANGUAGE_CODE
        translation.activate(language)
        request.LANGUAGE_CODE = translation.get_language()
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def process_request(self, request):
        language = translation.get_language_from_request(
            request, check_path=self.is_language_prefix_patterns_used)
        translation.activate(language)
        request.LANGUAGE_CODE = translation.get_language()
项目:djangocms-rest-api    作者:divio    | 项目源码 | 文件源码
def language(self):
        return get_language_from_request(self.request, check_path=True)
项目:mes    作者:osess    | 项目源码 | 文件源码
def __init__(self, request=None):
        self.user = AnonymousUser()
        self.timezone = settings.TIME_ZONE
        if request is not None:
            self.language = get_language_from_request(request)
        else:
            self.language = settings.LANGUAGE_CODE
项目:mes    作者:osess    | 项目源码 | 文件源码
def get_language_for_user(self, request):
        if request.user.is_authenticated():
            try:
                account = Account.objects.get(user=request.user)
                return account.language
            except Account.DoesNotExist:
                pass
        return translation.get_language_from_request(request)
项目:mes    作者:osess    | 项目源码 | 文件源码
def __init__(self, request=None):
        self.user = AnonymousUser()
        self.timezone = settings.TIME_ZONE
        if request is None:
            self.language = settings.LANGUAGE_CODE
        else:
            self.language = translation.get_language_from_request(request, check_path=True)
项目:mes    作者:osess    | 项目源码 | 文件源码
def get_language_for_user(self, request):
        if request.user.is_authenticated():
            try:
                account = Account.objects.get(user=request.user)
                return account.language
            except Account.DoesNotExist:
                pass
        return translation.get_language_from_request(request)
项目:mes    作者:osess    | 项目源码 | 文件源码
def get_language_for_user(self, request):
        if request.user.is_authenticated():
            try:
                account = Account.objects.get(user=request.user)
                return account.language
            except Account.DoesNotExist:
                pass
        return translation.get_language_from_request(request)
项目:django-next-train    作者:bitpixdigital    | 项目源码 | 文件源码
def process_request(self, request):
        language = translation.get_language_from_request(
            request, check_path=self.is_language_prefix_patterns_used)
        translation.activate(language)
        request.LANGUAGE_CODE = translation.get_language()
项目:LatinSounds_AppEnviaMail    作者:G3ek-aR    | 项目源码 | 文件源码
def process_request(self, request):
        urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF)
        i18n_patterns_used, prefixed_default_language = is_language_prefix_patterns_used(urlconf)
        language = translation.get_language_from_request(request, check_path=i18n_patterns_used)
        language_from_path = translation.get_language_from_path(request.path_info)
        if not language_from_path and i18n_patterns_used and not prefixed_default_language:
            language = settings.LANGUAGE_CODE
        translation.activate(language)
        request.LANGUAGE_CODE = translation.get_language()
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def process_request(self, request):
        check_path = self.is_language_prefix_patterns_used()
        language = translation.get_language_from_request(
            request, check_path=check_path)
        translation.activate(language)
        request.LANGUAGE_CODE = translation.get_language()