Example #1
0
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)
Example #2
0
    def __init__(self, config):
        """Initializes the Jinja2 object.

        example_config = {
            'environment_args': {'extensions': JINJA2_EXTENSIONS,
                                 'autoescape': config.settings.getboolean('jinja2_env_autoescape',
                                                                          section=FRONTEND),},
            'theme_base_template_path': config.settings.getlist('theme_base_template_path', section=FRONTEND),
            'enable_i18n': 'jinja2.ext.i18n' in JINJA2_EXTENSIONS,
            'global_vars': {},
            'filters': {},
            'tests': {},
        }
        """
        try:
            config['environment_args']['loader'] = jinja2.FileSystemLoader(config['theme_base_template_path'])
        except KeyError:
            config['environment_args'] = {
                'loader': jinja2.FileSystemLoader(config['theme_base_template_path'])
            }

        # Initialize the environment.
        self.environment = jinja2.Environment(**config['environment_args'])

        self.environment.globals.update({'getattr': getattr})
        try:
            if isinstance(config['global_vars'], dict):
                self.environment.globals.update(config['global_vars'])
        except KeyError:
            # No global vars set in config
            pass

        try:
            if isinstance(config['filters'], dict):
                self.environment.filters.update(config['filters'])
        except KeyError:
            # No filters set in config
            pass

        try:
            if isinstance(config['tests'], dict):
                self.environment.filters.update(config['tests'])
        except KeyError:
            # No tests set in config
            pass

        if config['enable_i18n']:
            # Install i18n.
            from webapp2_extras import i18n
            self.environment.install_gettext_callables(
                lambda x: i18n.gettext(x),
                lambda s, p, n: i18n.ngettext(s, p, n),
                newstyle=True)
            self.environment.filters.update({
                'format_date':      i18n.format_date,
                'format_time':      i18n.format_time,
                'format_datetime':  i18n.format_datetime,
                'format_timedelta': i18n.format_timedelta,
            })
Example #3
0
    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
Example #4
0
    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
Example #5
0
 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')
Example #6
0
    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
Example #7
0
 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')
Example #8
0
 def test_ngettext_with_variables(self):
     self.assertEqual(
         i18n.ngettext("One foo %(foo)s", "Many foos %(foo)s", 1), "One foo %(foo)s"
     )
     self.assertEqual(
         i18n.ngettext("One foo %(foo)s", "Many foos %(foo)s", 2),
         "Many foos %(foo)s",
     )
     self.assertEqual(
         i18n.ngettext("One foo %(foo)s", "Many foos %(foo)s", 1, foo="bar"),
         "One foo bar",
     )
     self.assertEqual(
         i18n.ngettext("One foo %(foo)s", "Many foos %(foo)s", 2, foo="bar"),
         "Many foos bar",
     )
     self.assertEqual(
         i18n.ngettext("One foo %(foo)s", "Many foos %(foo)s", 1) % {"foo": "bar"},
         "One foo bar",
     )
     self.assertEqual(
         i18n.ngettext("One foo %(foo)s", "Many foos %(foo)s", 2) % {"foo": "bar"},
         "Many foos bar",
     )
Example #9
0
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." )
Example #10
0
 def test_ngettext(self):
     self.assertEqual(i18n.ngettext("One foo", "Many foos", 1), "One foo")
     self.assertEqual(i18n.ngettext("One foo", "Many foos", 2), "Many foos")
Example #11
0
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)
Example #12
0
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)
Example #13
0
def UNIT_DAY(nr):
    return ngettext("day", "days", nr)
Example #14
0
def UNIT_MINUTE(nr):
    return ngettext("minute", "minutes", nr)
Example #15
0
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 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')
Example #17
0
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 )
Example #18
0
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" )
Example #19
0
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)
Example #20
0
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)
Example #21
0
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." )
Example #22
0
def UNIT_SECOND(nr):
    return ngettext("second", "seconds", nr)
Example #23
0
def UNIT_SECOND( nr ): return ngettext( "second", "seconds", nr )
def UNIT_MINUTE( nr ): return ngettext( "minute", "minutes", nr )
Example #24
0
def UNIT_HOUR(nr):
    return ngettext("hour", "hours", nr)
Example #25
0
def UNIT_MINUTE( nr ): return ngettext( "minute", "minutes", nr )
def UNIT_HOUR( nr ): return ngettext( "hour", "hours", nr )
Example #26
0
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)
Example #27
0
def UNIT_HOUR( nr ): return ngettext( "hour", "hours", nr )
def UNIT_DAY( nr ): return ngettext( "day", "days", nr )
Example #28
0
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)
Example #29
0
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" )
Example #30
0
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)
Example #31
0
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 )
Example #32
0
 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')
Example #33
0
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 )
Example #34
0
 def ngettext(self, singular, plural, num):
     """Ngettext handler."""
     return ngettext(singular, plural, num)
Example #35
0
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]" )
 def ngettext(self, singular, plural, n):
     return ngettext(singular, plural, n)
Example #37
0
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" )