• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python i18n.get_i18n函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中webapp2_extras.i18n.get_i18n函数的典型用法代码示例。如果您正苦于以下问题:Python get_i18n函数的具体用法?Python get_i18n怎么用?Python get_i18n使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_i18n函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get

 def get(self, url, event='2012'):
   session = model.SessionTalk.query(ndb.AND(model.SessionTalk.event == event, model.SessionTalk.url == url)).fetch(1)[0]
   speakers = [ sp.get() for sp in session.speaker ]
   # work depending on locale
   locale = self.session['locale']
   if self.request.get('locale'):
     locale = self.request.get('locale')
     i18n.get_i18n().set_locale(locale)
   if locale[0:2] == "de":
     session.title = session.title_de
     session.abstract = session.abstract_de
     session.requirements = session.requirements_de
     for sp in speakers:
       sp.bio = sp.bio_de
     for link in session.link:
       link.text = link.text_de
     if session.language:
       session.languagetext = languagetext_de[session.language]
     if session.level:
       session.leveltext = leveltext_de[session.level]
   else:
     session.title = session.title_en
     session.abstract = session.abstract_en
     session.requirements = session.requirements_en
     for sp in speakers:
       sp.bio = sp.bio_en
     for link in session.link:
       link.text = link.text_en
     if session.language:
       session.languagetext = languagetext_en[session.language]
     if session.level:
       session.leveltext = leveltext_en[session.level]
   self.prep_html_response('session.html', {'event':event, 'session':session, 'speakers':speakers})
开发者ID:helmuthb,项目名称:devfest-at-site,代码行数:33,代码来源:index.py


示例2: test_format_datetime

    def test_format_datetime(self):
        value = datetime.datetime(2009, 11, 10, 16, 36, 5)

        self.assertEqual(
            i18n.format_datetime(value, format='short'),
            u'11/10/09, 4:36 PM'
        )
        self.assertEqual(
            i18n.format_datetime(value, format='medium'),
            u'Nov 10, 2009, 4:36:05 PM'
        )
        self.assertEqual(
            i18n.format_datetime(value, format='long'),
            u'November 10, 2009 at 4:36:05 PM +0000'
        )

        # self.assertEqual(i18n.format_datetime(value, format='full'),
        # u'Tuesday, November 10, 2009 4:36:05 PM World (GMT) Time')

        self.assertEqual(
            i18n.format_datetime(value, format='full'),
            u'Tuesday, November 10, 2009 at 4:36:05 PM GMT+00:00'
        )

        i18n.get_i18n().set_timezone('America/Chicago')
        self.assertEqual(
            i18n.format_datetime(value, format='short'),
            u'11/10/09, 10:36 AM'
        )
开发者ID:GoogleCloudPlatform,项目名称:webapp2,代码行数:29,代码来源:extras_i18n_test.py


示例3: draw_page

    def draw_page(self, template_name, **render_data):
        if (get_application_id() == "the-hat-international") or (get_application_id() == "the-hat-dev"):
            dev = True
        else:
            dev = None
        template = self.jinja2().environment.get_template("{}.html".format(template_name))
        render_data["dev"] = dev
        render_data["user_link"] = (
            users.create_logout_url("/") if self.user else users.create_login_url(self.request.url)
        )
        if self.user:
            render_data["user_email"] = users.get_current_user().email()
        else:
            render_data["user_email"] = None
        render_data["is_admin"] = users.is_current_user_admin()
        curr_channel = ndb.Key(NotificationChannel, "notifications").get()
        render_data["token"] = curr_channel.channel_token if curr_channel else None

        if self.user:
            locale = self.user_key.get().localization
        else:
            locale = "ru_RU"

        i18n.get_i18n().set_locale(locale)

        self.response.write(template.render(render_data))
开发者ID:parallel-p,项目名称:thehat,代码行数:26,代码来源:__init__.py


示例4: init_model

    def init_model(self):
        # Set the requested locale.        
        locale = self.request.GET.get('locale')
        if locale:
            logging.debug("locale provided as parameter: %s", locale)
            i18n.get_i18n().set_locale(locale)
        else:
            i18n.get_i18n().set_locale(self.get_requested_locale())
            
        logging.info("locale set to %s", i18n.get_i18n().locale)
        
        user = users.get_current_user()

        modl = dict()
        strings.add_to_model(modl)
        operations.add_to_model(modl)
                    
        if user:
            modl['user'] = {
                'email': user.email(),
                'nickname': user.nickname(),
                'id': user.user_id()
            }
            modl['email'] = user.email()
            modl['login_url'] = '#'
            modl['logout_url'] = users.create_logout_url(self.request.uri)

        else :
            modl['user'] = 'null'
            modl['email'] = ''
            modl['login_url'] = users.create_login_url(self.request.uri)
            modl['logout_url'] = '#'

        return modl;
开发者ID:jbelis,项目名称:mathdash,代码行数:34,代码来源:handler.py


示例5: get

    def get(self):
        locale = self.request.GET.get('locale', 'en_US')
        i18n.get_i18n().set_locale(locale)

        template_values = {}
        template = JINJA_ENVIRONMENT.get_template('index.html')
        self.response.write(template.render(template_values))
开发者ID:rafaelmv,项目名称:i18n-GAE,代码行数:7,代码来源:main.py


示例6: test_format_datetime_pt_BR

    def test_format_datetime_pt_BR(self):
        i18n.get_i18n().set_locale('pt_BR')
        value = datetime.datetime(2009, 11, 10, 16, 36, 5)

        self.assertEqual(
            i18n.format_datetime(value, format='short'),
            u'10/11/09 16:36'
        )
        self.assertEqual(
            i18n.format_datetime(value, format='medium'),
            u'10 de nov de 2009 16:36:05'
        )
        # self.assertEqual(i18n.format_datetime(value, format='long'),
        # u'10 de novembro de 2009 16:36:05 +0000')
        self.assertEqual(
            i18n.format_datetime(value, format='long'),
            u'10 de novembro de 2009 16:36:05 +0000'
        )
        # self.assertEqual(i18n.format_datetime(value, format='full'),
        # u'terça-feira, 10 de novembro de 2009
        # 16h36min05s Horário Mundo (GMT)')
        self.assertEqual(
            i18n.format_datetime(value, format='full'),
            u'ter\xe7a-feira, 10 de novembro de 2009 16:36:05 GMT+00:00'
        )
开发者ID:GoogleCloudPlatform,项目名称:webapp2,代码行数:25,代码来源:extras_i18n_test.py


示例7: render_template

    def render_template(self, filename, params=None):
        if not params:
            params = {}

        # override locale if set in params
        if params and 'locale' in params.keys():
            i18n.get_i18n().set_locale(params['locale'])

        is_superuser = False
        if self.user:
            is_superuser = self.user.is_superuser

        is_betatester = False
        if self.user:
            is_betatester = self.user.is_betatester

        params['the_user'] = self.user
        params['the_user_is_superuser'] = is_superuser
        params['the_user_is_betatester'] = is_betatester
        if self.user:
            params['the_user_addgigbandlist'] = self.user.get_add_gig_band_list(self, self.user.key)
        params['logout_link'] = self.uri_for('logout')
        if self.user is not None and not self.user.seen_welcome:
            params['welcome'] = True

        # handle MOTD
        if self.user is not None:
            motd = motd_db.get_motd_object()
            if motd and (self.user.seen_motd_time is None or self.user.seen_motd_time < motd.last_update):
                params['motd'] = motd.value

        self.render_response(filename, params)
开发者ID:SecondLiners,项目名称:GO2,代码行数:32,代码来源:requestmodel.py


示例8: send_the_new_member_email

def send_the_new_member_email(the_locale, the_email_address, new_member, the_band):

    if not mail.is_email_valid(the_email_address):
        return False
        
    i18n.get_i18n().set_locale(the_locale)
        
    message = mail.EmailMessage()
    message.sender = SENDER_EMAIL
    message.to = the_email_address
    message.subject = _('Gig-o-Matic New Member for band {0})').format(the_band.name)
#     message.body = u"""
# Hello! A new member {0} has signed up for your band {1}. Please log in and
# confirm the membership.
# 
# http://gig-o-matic.appspot.com/band_info.html?bk={2}
# 
# Thanks,
# The Gig-o-Matic Team
# 
#     """.format(new_member.name, the_band.name, the_band.key.urlsafe())
    message.body = _('new_member_email').format(new_member.name, the_band.name, the_band.key.urlsafe())

    try:
        message.send()
    except:
        logging.error('failed to send email!')
        
    return True        
开发者ID:ChaoticNoise,项目名称:GO2,代码行数:29,代码来源:goemail.py


示例9: get

  def get(self):
    locale = self.request.GET.get('locale', 'en_US')
    i18n.get_i18n().set_locale(locale)

    template_values = {}
    template = jinja_environment.get_template('index.html')
    self.response.out.write(template.render(template_values))
开发者ID:siongui,项目名称:obsoleted-pali,代码行数:7,代码来源:main.py


示例10: render_template

    def render_template(self, filename, params=None):

        if params and "locale" in params.keys():
            locale = params["locale"]
        elif self.user:
            if self.user.preferences.locale:
                locale = self.user.preferences.locale
        else:
            locale = None

        i18n.get_i18n().set_locale(locale)

        if not params:
            params = {}

        is_superuser = False
        if self.user:
            is_superuser = self.user.is_superuser

        is_betatester = False
        if self.user:
            is_betatester = self.user.is_betatester

        params["the_user"] = self.user
        params["the_user_is_superuser"] = is_superuser
        params["the_user_is_betatester"] = is_betatester
        if self.user:
            params["the_user_addgigbandlist"] = self.user.get_add_gig_band_list(self, self.user.key)
        params["logout_link"] = self.uri_for("logout")
        if self.user is not None and not self.user.seen_welcome:
            params["welcome"] = True
        if self.user is not None and not self.user.seen_motd:
            params["motd"] = motd_db.get_motd()
        self.render_response(filename, params)
开发者ID:ChaoticNoise,项目名称:GO2,代码行数:34,代码来源:requestmodel.py


示例11: get

    def get(self):
        locale = getUserLocale(self.request.GET.get("locale"), self.request.headers.get("accept_language"))
        i18n.get_i18n().set_locale(locale)

        titleword = u""
        mainviewDivInnerHTML = None
        if self.request.path.startswith("/canon"):
            if isValidCanonUrl(self.request.path):
                titleword = getTitleInfo(self.request.path)
                mainviewDivInnerHTML = getMainViewInnerHTML(self.request.path)
            else:
                self.error(404)
                self.response.out.write("Page Not Found!")
                return

        devjs = self.request.GET.get("devjs")
        if devjs not in ["yes", "no"]:
            devjs = None
        if devjs == None:
            if os.environ["SERVER_SOFTWARE"].startswith("Development"):
                devjs = "yes"
            else:
                devjs = "no"

        template_values = {
            "titleword": titleword,
            "locale": "%s~%s" % (locale, self.request.headers.get("accept_language")),
            "mainviewDivInnerHTML": mainviewDivInnerHTML,
            "devjs": devjs,
        }

        template = jinja_environment.get_template("index.html")
        self.response.out.write(template.render(template_values))
开发者ID:wisperwinter,项目名称:pali,代码行数:33,代码来源:main.py


示例12: get

    def get(self, teachId):
        if not self.loggedIn():
            self.redirect("/")
            return
        values = self.getValues()
        i18n.get_i18n().set_locale(self.getLanguage())

        teacher = db.Teacher.get_by_id(long(teachId))
        lang = self.request.get("lang", None)
        if lang is not None:
            teacher.setLanguage(lang)
            referrer = self.request.headers.get('referer')
            if referrer:
                return self.redirect(referrer)
            return self.redirect("/")

        if not teachId or not teacher:
            self.redirect("/")
        else:

            own = teachId == str(self.getUserId())
            values["own"] = own
            values["teacher"] = teacher
            values["username"] = self.getUserName()
            values["subjects"] = ", ".join([s.name for s in db.Subject.getSubjectsByTeacher(teacher.key)])

            template = JINJA_ENVIRONMENT.get_template('/view/profile/index.html')
            self.response.write(template.render(values))
开发者ID:khvilaboa,项目名称:Calify,代码行数:28,代码来源:profile.py


示例13: test_format_scientific

 def test_format_scientific(self):
     i18n.get_i18n().set_locale('en_US')
     self.assertEqual(i18n.format_scientific(10000), u'1E4')
     self.assertEqual(
         i18n.format_scientific(1234567, u'##0E00'),
         u'1.23E06'
     )
开发者ID:GoogleCloudPlatform,项目名称:webapp2,代码行数:7,代码来源:extras_i18n_test.py


示例14: create_jinja_environment

def create_jinja_environment(loader, locale=None, autoescape=True):
    """Create proper jinja environment."""

    cache = None
    if CAN_USE_JINJA2_TEMPLATE_CACHE.value:
        prefix = 'jinja2:bytecode:%s:/' % models.MemcacheManager.get_namespace()
        cache = JinjaBytecodeCache(prefix)

    jinja_environment = jinja2.Environment(
        autoescape=autoescape, finalize=finalize,
        extensions=['jinja2.ext.i18n'], bytecode_cache=cache, loader=loader)

    jinja_environment.filters['js_string'] = js_string

    if locale:
        i18n.get_i18n().set_locale(locale)
        jinja_environment.install_gettext_translations(i18n)

    old_handle_exception = jinja_environment.handle_exception

    def _handle_exception(exc_info=None, rendered=False, source_hint=None):
        """Handle template exception."""
        traceback.print_exc(exc_info)
        result = old_handle_exception(exc_info, rendered, source_hint)
        return result

    jinja_environment.handle_exception = _handle_exception

    return jinja_environment
开发者ID:danieldalonzo,项目名称:coursebuilder-core,代码行数:29,代码来源:jinja_utils.py


示例15: set_locale

    def set_locale(self, force=None):
        locales = self.app.config.get('locales')
        # disable i18n if config.locales array is empty or None
        if not locales:
            return None
        # 1. force locale if provided
        locale = force
        if locale not in locales:
            # 2. retrieve locale from url query string
            locale = self.request.get("hl", None)
            if locale not in locales:
                # 3. retrieve locale from cookie
                locale = self.request.cookies.get('hl', None)
                if locale not in locales:
                    # 4. retrieve locale from accept language header
                    #locale = get_locale_from_accept_header(self.request)
                    if locale not in locales:
                        # 5. detect locale from IP address location
                        territory = get_territory_from_ip(self) or 'ZZ'
                        locale = str(Locale.negotiate(territory, locales))
                        if locale not in locales:
                            # 6. use default locale
                            locale = self.request.GET.get('locale', 'en_US')

        i18n.get_i18n().set_locale(locale)
        logger.info('locale is {0}'.format(locale))
        # save locale in cookie with 26 weeks expiration (in seconds)
        self.response.set_cookie('hl', locale, max_age=15724800)
        return locale
开发者ID:7kfpun,项目名称:gae-boilerplate,代码行数:29,代码来源:base.py


示例16: set_locale

def set_locale(cls, force=None):
    """
    retrieve locale from a prioritized list of sources and then set locale and save it
    cls: self object
    force: a locale to force set (ie 'en_US')
    return: locale
    """
    # 1. force locale if provided
    locale = force
    if locale not in AVAILABLE_LOCALES:
        # 2. retrieve locale from url query string
        locale = cls.request.get("hl", None)
        if locale not in AVAILABLE_LOCALES:
            # 3. retrieve locale from cookie
            locale = utils.read_cookie(cls, "hl")
            if locale not in AVAILABLE_LOCALES:
                # 4. retrieve locale from accept language header
                locale = get_locale_from_accept_header(cls)
                if locale not in AVAILABLE_LOCALES:
                    # 5. detect locale from IP address location
                    locale = get_locale_from_territory(get_territory_from_ip(cls))
                    if locale not in AVAILABLE_LOCALES:
                        # 6. use default locale
                        locale = AVAILABLE_LOCALES[0]
    # convert unicode locale to string for headers
    locale = str(locale)
    i18n.get_i18n().set_locale(locale)
    # save locale in cookie with 26 weeks expiration (in seconds)
    utils.write_cookie(cls, "hl", locale, "/", 15724800)
    return locale
开发者ID:grisaitis,项目名称:gae-puns,代码行数:30,代码来源:i18n.py


示例17: set_locale

def set_locale(cls, force=None):
    """
    retrieve locale from a prioritized list of sources and then set locale and save it
    cls: self object
    force: a locale to force set (ie 'en_US')
    return: locale as string or None if i18n should be disabled
    """
    # disable i18n if config.locales array is empty or None
    if not config.locales:
        return None
    # 1. force locale if provided
    locale = force
    if locale not in config.locales:
        # 2. retrieve locale from url query string
        locale = cls.request.get("hl", None)
        if locale not in config.locales:
            # 3. retrieve locale from cookie
            locale = cls.request.cookies.get('hl', None)
            if locale not in config.locales:
                # 4. retrieve locale from accept language header
                locale = get_locale_from_accept_header(cls.request)
                if locale not in config.locales:
                    # 5. detect locale from IP address location
                    territory = get_territory_from_ip(cls) or 'ZZ'
                    locale = str(Locale.negotiate(territory, config.locales))
                    if locale not in config.locales:
                        # 6. use default locale
                        locale = i18n.get_store().default_locale
    i18n.get_i18n().set_locale(locale)
    # save locale in cookie with 26 weeks expiration (in seconds)
    cls.response.set_cookie('hl', locale, max_age = 15724800)
    return locale
开发者ID:StackGeek,项目名称:stackgeek-gaeb,代码行数:32,代码来源:i18n.py


示例18: render

 def render(self, template, locale=None, *a, **params):
     if not locale:
         locale = self.session.get('locale')
     if not locale:
         locale = detectLocale(self.request.headers.get('accept_language'))
     i18n.get_i18n().set_locale(locale)
     self.write(self.render_str(template, locale=locale, *a, **params))
开发者ID:clashboom,项目名称:nvt,代码行数:7,代码来源:main.py


示例19: __init__

    def __init__(self, request, response):
        self.initialize(request, response)
        
        locale = self.request.GET.get ('locale', 'en_US')
        i18n.get_i18n ().set_locale (locale)

        self.user = users.get_current_user ()

        self.adaythere = ADayThere ()
        self.adaythere.add_meta_tags ([
            { "charset":"UTF-8" },
            { "http-equiv":"X-UA-Compatible", "content":"IE=edge" },
            { "name":"description", "content":"A social media site that celebrates the joys of place." },
            { "name":"viewport", "content":"initial-scale=1"}
        ])

        self.adaythere.add_links ([
            { "rel":"stylesheet", "href":"css/bootstrap.css" },
            { "rel":"stylesheet", "href":"css/adaythere.css" }
        ])


        maps = Maps ()

        self.adaythere.add_script_tags_for_body ([
            { "src":"js/jquery-1.11.0-beta2.js" },
            { "src":"js/angular/angular.min.js" },
            { "src":"js/angular/angular-route.min.js" },
            { "src":"js/ui-bootstrap-tpls-0.10.0.min.js" },
            { "src": maps.get_script_src () },
            { "src":"js/adaythere.js" },
            { "src":"https://apis.google.com/js/platform.js", "async":None, "defer":None }
        ])
开发者ID:softsprocket,项目名称:adaythere,代码行数:33,代码来源:main.py


示例20: test_format_percent

    def test_format_percent(self):
        i18n.get_i18n().set_locale('en_US')
        self.assertEqual(i18n.format_percent(0.34), u'34%')
        self.assertEqual(i18n.format_percent(25.1234), u'2,512%')
        self.assertEqual(i18n.format_percent(25.1234, u'#,##0\u2030'), u'25,123\u2030')

        i18n.get_i18n().set_locale('sv_SE')
        self.assertEqual(i18n.format_percent(25.1234), u'2\xa0512\xa0%')
开发者ID:mark0978,项目名称:webapp-improved,代码行数:8,代码来源:i18n_test.py



注:本文中的webapp2_extras.i18n.get_i18n函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python i18n.ngettext函数代码示例发布时间:2022-05-26
下一篇:
Python i18n._函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap