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


Python i18n.set_language方法代碼示例

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


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

示例1: get

# 需要導入模塊: from django.views import i18n [as 別名]
# 或者: from django.views.i18n import set_language [as 別名]
def get(self, request):
        """
            In the HTML template we'd like to work with simple links
            however the view which actually switches the language needs
            to be called via POST so we simulate that here!

            If the URL doesn't explicitly specify language then we turn-off
            translation mode by switching back to browser preferred language.
        """
        browser_lang = self.get_browser_language(request)
        post_body = "%s=%s" % (i18n.LANGUAGE_QUERY_PARAMETER,
                               request.GET.get(i18n.LANGUAGE_QUERY_PARAMETER, browser_lang))
        request.META['REQUEST_METHOD'] = 'POST'
        request.META['CONTENT_LENGTH'] = len(post_body)
        request.META['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'

        post_request = request.__class__(request.META)
        # pylint: disable=protected-access
        post_request._post = http.QueryDict(post_body, encoding=post_request._encoding)

        return i18n.set_language(post_request) 
開發者ID:kiwitcms,項目名稱:Kiwi,代碼行數:23,代碼來源:views.py

示例2: post

# 需要導入模塊: from django.views import i18n [as 別名]
# 或者: from django.views.i18n import set_language [as 別名]
def post(self, request, *args, **kwargs):
        if 'nav_menu' in request.session:
            del request.session['nav_menu']
        return set_language(request) 
開發者ID:stormsha,項目名稱:StormOnline,代碼行數:6,代碼來源:language.py


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