def jinja2_babel_extract(fileobj, keywords, comment_tags, options): """Custom babel_extract for Jinja. Hooks on to Jinja's babel_extract and handles whitespace within ``{% trans %}`` tags. """ for lineno, func, message, comments in babel_extract(fileobj, keywords, comment_tags, options): if isinstance(message, tuple): message = tuple(trim_inner_whitespace(x) if isinstance(x, basestring) else x for x in message) else: message = trim_inner_whitespace(message) yield lineno, func, message, comments
def jinja2_babel_extract(fileobj, keywords, comment_tags, options): """Custom babel_extract for Jinja. Hooks on to Jinja's babel_extract and handles whitespace within ``{% trans %}`` tags. """ for lineno, func, message, comments in babel_extract(fileobj, keywords, comment_tags, options): if isinstance(message, tuple): message = tuple(trim_inner_whitespace(x) if isinstance(x, basestring) else x for x in message) else: message = trim_inner_whitespace(message) yield lineno, func, message, comments
def jinja2_babel_extract(fileobj, keywords, comment_tags, options): """Custom babel_extract for Jinja. Hooks on to Jinja's babel_extract and handles whitespace within ``{% trans %}`` tags. """ for lineno, func, message, comments in babel_extract( fileobj, keywords, comment_tags, options): yield lineno, func, trim_inner_whitespace(message), comments
def _wrap(*args, **kwargs): """ Returns either a translated string or a lazy-translatable object, depending on whether there is a session language or not (respectively) """ # TODO: Remove this once there's proper support in upstream Jinja # https://github.com/pallets/jinja/pull/683 if func_name == 'ungettext': args = (trim_inner_whitespace(args[0]), trim_inner_whitespace(args[1])) + args[2:] else: args = tuple(trim_inner_whitespace(arg) for arg in args) if has_request_context() or func_name != 'ugettext': # straight translation return gettext_unicode(*args, func_name=func_name, plugin_name=plugin_name, force_unicode=force_unicode, **kwargs) else: # otherwise, defer translation to eval time return lazy_gettext(*args, plugin_name=plugin_name)
def _wrap(*args, **kwargs): """ Returns either a translated string or a lazy-translatable object, depending on whether there is a session language or not (respectively) """ # TODO: Remove this once there's proper support in upstream Jinja # https://github.com/pallets/jinja/pull/683 if func_name == 'ungettext': args = (trim_inner_whitespace( args[0]), trim_inner_whitespace(args[1])) + args[2:] else: args = tuple(trim_inner_whitespace(arg) for arg in args) if has_request_context() or func_name != 'ugettext': # straight translation return gettext_unicode(*args, func_name=func_name, plugin_name=plugin_name, force_unicode=force_unicode, **kwargs) else: # otherwise, defer translation to eval time return lazy_gettext(*args, plugin_name=plugin_name)