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

Python i18n.ngettext函数代码示例

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

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



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

示例1: __init__

    def __init__(self, app, config=None):
        """Initializes the Jinja2 object.

        :param app:
            A :class:`webapp2.WSGIApplication` instance.
        :param config:
            A dictionary of configuration values to be overridden. See
            the available keys in :data:`default_config`.
        """
        self.config = config = app.config.load_config(
            self.config_key,
            default_values=default_config,
            user_values=config,
            required_keys=None
        )
        kwargs = config['environment_args'].copy()
        enable_i18n = 'jinja2.ext.i18n' in kwargs.get('extensions', [])

        if 'loader' not in kwargs:
            template_path = config['template_path']
            compiled_path = config['compiled_path']
            use_compiled = not app.debug or config['force_compiled']

            if compiled_path and use_compiled:
                # Use precompiled templates loaded from a module or zip.
                kwargs['loader'] = _jinja2.ModuleLoader(compiled_path)
            else:
                # Parse templates for every new environment instances.
                kwargs['loader'] = _jinja2.FileSystemLoader(template_path)

        # Initialize the environment.
        env = _jinja2.Environment(**kwargs)

        if config['globals']:
            env.globals.update(config['globals'])

        if config['filters']:
            env.filters.update(config['filters'])

        if enable_i18n:
            # Install i18n.
            from webapp2_extras import i18n
            env.install_gettext_callables(
                lambda x: i18n.gettext(x),
                lambda s, p, n: i18n.ngettext(s, p, n),
                newstyle=True)
            env.filters.update({
                'format_date':      i18n.format_date,
                'format_time':      i18n.format_time,
                'format_datetime':  i18n.format_datetime,
                'format_timedelta': i18n.format_timedelta,
            })

        self.environment = env
开发者ID:GoogleCloudPlatform,项目名称:webapp2,代码行数:54,代码来源:jinja2.py


示例2: test_ngettext_with_variables

 def test_ngettext_with_variables(self):
     self.assertEqual(i18n.ngettext('One foo %(foo)s', 'Many foos %(foo)s', 1), u'One foo %(foo)s')
     self.assertEqual(i18n.ngettext('One foo %(foo)s', 'Many foos %(foo)s', 2), u'Many foos %(foo)s')
     self.assertEqual(i18n.ngettext('One foo %(foo)s', 'Many foos %(foo)s', 1, foo='bar'), u'One foo bar')
     self.assertEqual(i18n.ngettext('One foo %(foo)s', 'Many foos %(foo)s', 2, foo='bar'), u'Many foos bar')
     self.assertEqual(i18n.ngettext('One foo %(foo)s', 'Many foos %(foo)s', 1) % {'foo': 'bar'}, u'One foo bar')
     self.assertEqual(i18n.ngettext('One foo %(foo)s', 'Many foos %(foo)s', 2) % {'foo': 'bar'}, u'Many foos bar')
开发者ID:mark0978,项目名称:webapp-improved,代码行数:7,代码来源:i18n_test.py


示例3: __init__

    def __init__(self, app):
        config = app.config[__name__]
        kwargs = config['environment_args'].copy()
        enable_i18n = 'jinja2.ext.i18n' in kwargs.get('extensions', [])

        if 'loader' not in kwargs:
            template_path = config['template_path']
            compiled_path = config['compiled_path']
            use_compiled = not app.debug or config['force_compiled']

            if compiled_path and use_compiled:
                # Use precompiled templates loaded from a module or zip.
                kwargs['loader'] = jinja2.ModuleLoader(compiled_path)
            else:
                # Parse templates for every new environment instances.
                kwargs['loader'] = jinja2.FileSystemLoader(template_path)

        # Initialize the environment.
        env = jinja2.Environment(**kwargs)

        if config['globals']:
            env.globals.update(config['globals'])

        if config['filters']:
            env.filters.update(config['filters'])

        if enable_i18n:
            # Install i18n.
            from webapp2_extras import i18n
            env.install_gettext_callables(
                lambda x: i18n.gettext(x),
                lambda s, p, n: i18n.ngettext(s, p, n),
                newstyle=True)
            env.filters.update({
                'format_date':      i18n.format_date,
                'format_time':      i18n.format_time,
                'format_datetime':  i18n.format_datetime,
                'format_timedelta': i18n.format_timedelta,
            })

        self.environment = env
开发者ID:mark0978,项目名称:webapp-improved,代码行数:41,代码来源:jinja2.py


示例4: DISPLAY_NAME_TOO_LONG_SHORTEN

def DISPLAY_NAME_TOO_LONG_SHORTEN( length ): return ngettext( "It is too long. Please ensure it is maximum %(length)s character long.", "It is too long. Please ensure it is maximum %(length)s characters long.", length, length = length )

# forums
def POST_DELETED_DISPLAY(): return _( "[Deleted post]" )
开发者ID:charlf,项目名称:enkiWS,代码行数:4,代码来源:textmessages.py


示例5: DISPLAY_NAME_TOO_SHORT_LENGTHEN

def DISPLAY_NAME_TOO_SHORT_LENGTHEN( length ): return ngettext( "It is too short. Please ensure it is at least %(length)s character long.", "It is too short. Please ensure it is at least %(length)s characters long.", length, length = length )
def DISPLAY_NAME_TOO_LONG_SHORTEN( length ): return ngettext( "It is too long. Please ensure it is maximum %(length)s character long.", "It is too long. Please ensure it is maximum %(length)s characters long.", length, length = length )
开发者ID:charlf,项目名称:enkiWS,代码行数:2,代码来源:textmessages.py


示例6: DISPLAY_NAME_WRONG_LENGTH

def DISPLAY_NAME_WRONG_LENGTH( length ): return ngettext( "Your name is %(length)s character long.", "Your name is %(length)s characters long.", length, length = length )
def DISPLAY_NAME_TOO_SHORT_LENGTHEN( length ): return ngettext( "It is too short. Please ensure it is at least %(length)s character long.", "It is too short. Please ensure it is at least %(length)s characters long.", length, length = length )
开发者ID:charlf,项目名称:enkiWS,代码行数:2,代码来源:textmessages.py


示例7: UNIT_DAY

def UNIT_DAY( nr ): return ngettext( "day", "days", nr )

# emails
def SEND_EMAIL_LOGIN_ATTEMPT_WITH_YOUR_EMAIL_NO_PW_SUBJECT(): return _( "Attempt to log in with your email" )
开发者ID:charlf,项目名称:enkiWS,代码行数:4,代码来源:textmessages.py


示例8: UNIT_HOUR

def UNIT_HOUR( nr ): return ngettext( "hour", "hours", nr )
def UNIT_DAY( nr ): return ngettext( "day", "days", nr )
开发者ID:charlf,项目名称:enkiWS,代码行数:2,代码来源:textmessages.py


示例9: GAME_CONNECTION_TOKEN

def GAME_CONNECTION_TOKEN( token, minutes ): return ngettext( 'Your single-use game connect code is valid for <b>%(minutes)s minute</b>. <h1><b><font face="monospace">%(token)s</font></b></h1>', 'Your single-use game connect code is valid for <b>%(minutes)s minutes</b>. <h1><b><font face="monospace">%(token)s</font></b></h1>', minutes, minutes = minutes, token = token )
def NAME_NEEDED(): return _( "A name is needed" )
开发者ID:juliettef,项目名称:enkiWS,代码行数:2,代码来源:textmessages.py


示例10: UNIT_SECOND

def UNIT_SECOND( nr ): return ngettext( "second", "seconds", nr )
def UNIT_MINUTE( nr ): return ngettext( "minute", "minutes", nr )
开发者ID:charlf,项目名称:enkiWS,代码行数:2,代码来源:textmessages.py


示例11: PW_ENSURE_MIN_LENGTH

def PW_ENSURE_MIN_LENGTH( length ): return ngettext( "Please ensure your password is at least %(length)s character long.", "Please ensure your password is at least %(length)s characters long.", length, length = length)
def CURRENT_EMAIL(): return _( "This is your current email." )
开发者ID:charlf,项目名称:enkiWS,代码行数:2,代码来源:textmessages.py


示例12: PW_TOO_SHORT

def PW_TOO_SHORT( length ): return ngettext( "Your password is %(length)s character long: it is too short.", "Your password is %(length)s characters long: it is too short.", length, length = length )
def PW_ENSURE_MIN_LENGTH( length ): return ngettext( "Please ensure your password is at least %(length)s character long.", "Please ensure your password is at least %(length)s characters long.", length, length = length)
开发者ID:charlf,项目名称:enkiWS,代码行数:2,代码来源:textmessages.py


示例13: POST_BODY_TOO_LONG

def POST_BODY_TOO_LONG( exceed ): return ngettext( "Your post is too long by %(exceed)s character.", "Your post is too long by %(exceed)s characters.", exceed, exceed = exceed )
def FAIL_THREAD_SUBMISSION(): return _( "Thread submission failed. Please try again." )
开发者ID:charlf,项目名称:enkiWS,代码行数:2,代码来源:textmessages.py


示例14: THREAD_TITLE_TOO_LONG

def THREAD_TITLE_TOO_LONG( exceed ): return ngettext( "Your thread title is too long by %(exceed)s character.", "Your thread title is too long by %(exceed)s characters.", exceed, exceed = exceed )
def POST_BODY_TOO_LONG( exceed ): return ngettext( "Your post is too long by %(exceed)s character.", "Your post is too long by %(exceed)s characters.", exceed, exceed = exceed )
开发者ID:charlf,项目名称:enkiWS,代码行数:2,代码来源:textmessages.py


示例15: test_ngettext

 def test_ngettext(self):
     self.assertEqual(i18n.ngettext('One foo', 'Many foos', 1), u'One foo')
     self.assertEqual(
         i18n.ngettext('One foo', 'Many foos', 2), u'Many foos')
开发者ID:aswadrangnekar,项目名称:webapp-improved,代码行数:4,代码来源:i18n_test.py


示例16: UNIT_MINUTE

def UNIT_MINUTE( nr ): return ngettext( "minute", "minutes", nr )
def UNIT_HOUR( nr ): return ngettext( "hour", "hours", nr )
开发者ID:charlf,项目名称:enkiWS,代码行数:2,代码来源:textmessages.py


示例17: ngettext

 def ngettext(self, singular, plural, n):
     return ngettext(singular, plural, n)
开发者ID:snvandoorn,项目名称:gae-boilerplate-extentions,代码行数:2,代码来源:forms.py


示例18: DISPLAY_NAME_TOO_LONG_SHORTEN

def DISPLAY_NAME_TOO_LONG_SHORTEN( length ): return ngettext( "It is too long. Please ensure it is maximum %(length)s character long.", "It is too long. Please ensure it is maximum %(length)s characters long.", length, length = length )

# forums
def FORUMS(): return _( "Forums" )
开发者ID:juliettef,项目名称:enkiWS,代码行数:4,代码来源:textmessages.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python jinja2.get_jinja2函数代码示例发布时间:2022-05-26
下一篇:
Python i18n.get_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