return wrapped
-def do_reversed():
+def do_reverse():
"""
Return a reversed list of the sequence filtered. You can use this
for example for reverse iteration:
.. sourcecode:: jinja
- {% for item in seq|reversed %}
+ {% for item in seq|reverse %}
{{ item|e }}
{% endfor %}
"""
'default': do_default,
'join': do_join,
'count': do_count,
- 'reversed': do_reversed,
+ 'reverse': do_reverse,
'center': do_center,
'title': do_title,
'capitalize': do_capitalize,
break
# normal data
else:
- if replacements:
- data = data.replace('%', '%%')
- buf.append(data)
+ buf.append(data.replace('%', '%%'))
except StopIteration:
raise TemplateSyntaxError('unexpected end of translation section',
:license: BSD, see LICENSE for more details.
"""
import re
+from jinja.nodes import Trans
from jinja.datastructure import safe_types, Markup
re.compile('(&|<|>)')
)
+
def escape(x, attribute=False):
"""
Escape an object x which is converted to unicode first.
return x
return Markup(_escape_res[not attribute].sub(lambda m:
_escape_pairs[m.group()], unicode(x)))
+
+
+
+def find_translations(environment, source):
+ """
+ Find all translatable strings in a template and yield
+ them as (lineno, singular, plural) tuples. If a plural
+ section does not exist it will be None.
+ """
+ queue = [environment.parse(source)]
+ while queue:
+ node = queue.pop()
+ if node.__class__ is Trans:
+ yield node.lineno, node.singular, node.plural
+ queue.extend(node.getChildNodes())