當前位置: 首頁>>代碼示例>>Python>>正文


Python translation.get_language_from_request方法代碼示例

本文整理匯總了Python中django.utils.translation.get_language_from_request方法的典型用法代碼示例。如果您正苦於以下問題:Python translation.get_language_from_request方法的具體用法?Python translation.get_language_from_request怎麽用?Python translation.get_language_from_request使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.utils.translation的用法示例。


在下文中一共展示了translation.get_language_from_request方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: tracker_context

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import get_language_from_request [as 別名]
def tracker_context(request, qdict=None):
    starttime = datetime.datetime.now()
    language = translation.get_language_from_request(request)
    translation.activate(language)
    request.LANGUAGE_CODE = translation.get_language()
    profile = None
    qdict = qdict or {}
    qdict.update(
        {
            'djangoversion': dv(),
            'pythonversion': pv(),
            'user': request.user,
            'profile': profile,
            'next': request.POST.get('next', request.GET.get('next', request.path)),
            'starttime': starttime,
            'events': tracker.models.Event.objects.all(),
            'settings': settings,
        }
    )
    qdict.setdefault('event', viewutil.get_event(None))
    qdict.setdefault('user', request.user)
    return qdict 
開發者ID:GamesDoneQuick,項目名稱:donation-tracker,代碼行數:24,代碼來源:common.py

示例2: redirect_homepage

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import get_language_from_request [as 別名]
def redirect_homepage(self, request):
        if request.path not in settings.REDIRECTED_PATHS:
            return

        language = get_language_from_request(request)

        if language not in self.LANGUAGES:
            language = settings.DEFAULT_LANGUAGE

        querystring = request.META.get('QUERY_STRING', '')
        if querystring:
            querystring = '?' + querystring

        return HttpResponseRedirect(
            ''.join([
                'http://', language, '.', settings.BASE_DOMAIN,
                request.path, querystring
            ])
        ) 
開發者ID:arguman,項目名稱:arguman.org,代碼行數:21,代碼來源:middleware.py

示例3: get_language_from_request

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import get_language_from_request [as 別名]
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 
開發者ID:evernote,項目名稱:zing,代碼行數:20,代碼來源:override.py

示例4: retrieve

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import get_language_from_request [as 別名]
def retrieve(self, request, pk, version, kind):
        """
        Return a single item by ID
        """
        # Wrap the ES get in a try/catch to we control the exception we emit — it would
        # raise and end up in a 500 error otherwise
        try:
            query_response = ES_CLIENT.get(
                index=self._meta.indexer.index_name,
                doc_type=self._meta.indexer.document_type,
                id=pk,
            )
        except NotFoundError:
            raise NotFound

        # Format a clean category object as a response
        return Response(
            self._meta.indexer.format_es_object_for_api(
                query_response,
                # Get the best language we can return multilingual fields in
                get_language_from_request(request),
            )
        ) 
開發者ID:openfun,項目名稱:richie,代碼行數:25,代碼來源:categories.py

示例5: process_request

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import get_language_from_request [as 別名]
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() 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:8,代碼來源:locale.py

示例6: process_request

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import get_language_from_request [as 別名]
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() 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:11,代碼來源:locale.py

示例7: hijack_translation

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import get_language_from_request [as 別名]
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 
開發者ID:evernote,項目名稱:zing,代碼行數:11,代碼來源:override.py

示例8: autocomplete

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import get_language_from_request [as 別名]
def autocomplete(self, request, version, kind):
        """
        Use the "completion" field on the categories mapping & objects to provide autocomplete
        functionality through an API endpoint.
        We cannot reuse the `AutocompleteMixin` as it does not handle "kinds" as categories need.
        """
        # Get a hold of the relevant indexer
        indexer = self._meta.indexer

        # Query our specific ES completion field
        autocomplete_query_response = ES_CLIENT.search(
            index=indexer.index_name,
            doc_type=indexer.document_type,
            body={
                "suggest": {
                    "categories": {
                        "prefix": request.query_params["query"],
                        "completion": {
                            "contexts": {"kind": [kind]},
                            "field": "complete.{:s}".format(
                                get_language_from_request(request)
                            ),
                        },
                    }
                }
            },
        )

        # Build a response array from the list of completion options
        return Response(
            [
                indexer.format_es_document_for_autocomplete(
                    option, get_language_from_request(request)
                )
                for option in autocomplete_query_response["suggest"]["categories"][0][
                    "options"
                ]
            ]
        ) 
開發者ID:openfun,項目名稱:richie,代碼行數:41,代碼來源:categories.py

示例9: autocomplete

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import get_language_from_request [as 別名]
def autocomplete(self, request, version):
        """
        Use the "completion" field on the organization mapping & objects to provide autocomplete
        functionality through an API endpoint.
        """
        # This mixin is intended to be used on ViewSets. It requires a _meta attribute holding
        # the relevant indexer
        indexer = self._meta.indexer

        # Query our specific ES completion field
        autocomplete_query_response = ES_CLIENT.search(
            index=indexer.index_name,
            doc_type=indexer.document_type,
            body={
                "suggest": {
                    "organizations": {
                        "prefix": request.query_params["query"],
                        "completion": {
                            "field": "complete.{:s}".format(
                                get_language_from_request(request)
                            )
                        },
                    }
                }
            },
        )

        # Build a response array from the list of completion options
        return Response(
            [
                indexer.format_es_document_for_autocomplete(
                    option, get_language_from_request(request)
                )
                for option in autocomplete_query_response["suggest"]["organizations"][
                    0
                ]["options"]
            ]
        ) 
開發者ID:openfun,項目名稱:richie,代碼行數:40,代碼來源:viewsets.py

示例10: process_request

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import get_language_from_request [as 別名]
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() 
開發者ID:drexly,項目名稱:openhgsenti,代碼行數:7,代碼來源:locale.py

示例11: get_language_for_user

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import get_language_from_request [as 別名]
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) 
開發者ID:madre,項目名稱:devops,代碼行數:10,代碼來源:middleware.py

示例12: create

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import get_language_from_request [as 別名]
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
        return account 
開發者ID:madre,項目名稱:devops,代碼行數:17,代碼來源:models.py

示例13: __init__

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import get_language_from_request [as 別名]
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) 
開發者ID:madre,項目名稱:devops,代碼行數:9,代碼來源:models.py

示例14: get_global_context

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import get_language_from_request [as 別名]
def get_global_context(request, enterprise_customer=None):
    """
    Get the set of variables that are needed by default across views.
    """
    platform_name = get_configuration_value("PLATFORM_NAME", settings.PLATFORM_NAME)
    # pylint: disable=no-member
    context = {
        'enterprise_customer': enterprise_customer,
        'LMS_SEGMENT_KEY': settings.LMS_SEGMENT_KEY,
        'LANGUAGE_CODE': get_language_from_request(request),
        'tagline': get_configuration_value("ENTERPRISE_TAGLINE", settings.ENTERPRISE_TAGLINE),
        'platform_description': get_configuration_value(
            "PLATFORM_DESCRIPTION",
            settings.PLATFORM_DESCRIPTION,
        ),
        'LMS_ROOT_URL': settings.LMS_ROOT_URL,
        'platform_name': platform_name,
        'header_logo_alt_text': _('{platform_name} home page').format(platform_name=platform_name),
        'welcome_text': constants.WELCOME_TEXT.format(platform_name=platform_name),
    }

    if enterprise_customer is not None:
        context.update({
            'enterprise_welcome_text': constants.ENTERPRISE_WELCOME_TEXT.format(
                enterprise_customer_name=enterprise_customer.name,
                platform_name=platform_name,
                strong_start='<strong>',
                strong_end='</strong>',
                line_break='<br/>',
                privacy_policy_link_start="<a href='{pp_url}' target='_blank'>".format(
                    pp_url=get_configuration_value('PRIVACY', 'https://www.edx.org/edx-privacy-policy', type='url'),
                ),
                privacy_policy_link_end="</a>",
            ),
        })

    return context 
開發者ID:edx,項目名稱:edx-enterprise,代碼行數:39,代碼來源:views.py

示例15: language

# 需要導入模塊: from django.utils import translation [as 別名]
# 或者: from django.utils.translation import get_language_from_request [as 別名]
def language(self):
        return get_language_from_request(self.request, check_path=True) 
開發者ID:divio,項目名稱:djangocms-rest-api,代碼行數:4,代碼來源:utils.py


注:本文中的django.utils.translation.get_language_from_request方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。