aboutsummaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-11-12 17:10:54 +0000
committerng0 <ng0@n0.is>2019-11-12 17:10:54 +0000
commit4a4839075452c7527ce87775d08428e5cb433957 (patch)
tree75e07f5b928d4d9e8befe62e4148671f88631b05 /inc
parent001b40be95558105c2c08377408a46d44cc82247 (diff)
downloadwww-4a4839075452c7527ce87775d08428e5cb433957.tar.gz
www-4a4839075452c7527ce87775d08428e5cb433957.zip
move jinja2 ext to inc.
Diffstat (limited to 'inc')
-rw-r--r--inc/i18nfix.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/inc/i18nfix.py b/inc/i18nfix.py
new file mode 100644
index 00000000..7f326ba6
--- /dev/null
+++ b/inc/i18nfix.py
@@ -0,0 +1,41 @@
1#!/usr/bin/env python3
2#
3# Copyright (C) 2017, 2018 GNUnet e.V.
4#
5# Copying and distribution of this file, with or without modification,
6# are permitted in any medium without royalty provided the copyright
7# notice and this notice are preserved. This file is offered as-is,
8# without any warranty.
9
10"""
11Extract translations from a Jinja2 template, stripping leading newlines.
12
13@author Florian Dold
14"""
15
16import re
17import jinja2.ext
18
19
20def normalize(message):
21 message = message.strip()
22 # collapse whitespaces (including newlines) into one space.
23 message = re.sub("\s+", " ", message)
24 return message
25
26
27def babel_extract(fileobj, keywords, comment_tags, options):
28 res = jinja2.ext.babel_extract(fileobj, keywords, comment_tags, options)
29 for lineno, funcname, message, comments in res:
30 message = normalize(message)
31 yield lineno, funcname, message, comments
32
33
34def wrap_gettext(f):
35 """
36 Call gettext with whitespace normalized.
37 """
38 def wrapper(message):
39 message = normalize(message)
40 return f(message)
41 return wrapper