aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2020-12-01 22:59:27 +0100
committerFlorian Dold <florian@dold.me>2020-12-01 22:59:27 +0100
commit0decce2ef9665cf46ea1e5cf08d12cb8c1fd679c (patch)
tree6cbaa7a53a0fa0b8a157852a57864b04f7bdef5f
parent76bbc33ea45cd415081f34ae93109fe5c9718fe2 (diff)
downloadwww_shared-0decce2ef9665cf46ea1e5cf08d12cb8c1fd679c.tar.gz
www_shared-0decce2ef9665cf46ea1e5cf08d12cb8c1fd679c.zip
also normalize tuples for gettext calls
-rw-r--r--i18nfix.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/i18nfix.py b/i18nfix.py
index 69fe177..e1d5bb4 100644
--- a/i18nfix.py
+++ b/i18nfix.py
@@ -16,24 +16,31 @@ import re
16import jinja2.ext 16import jinja2.ext
17 17
18 18
19def normalize(message): 19def normalize_str(message):
20 message = message.strip() 20 message = message.strip()
21 # collapse whitespaces (including newlines) into one space. 21 # collapse whitespaces (including newlines) into one space.
22 message = re.sub("\s+", " ", message) 22 message = re.sub("\s+", " ", message)
23 return message 23 return message
24 24
25 25
26def normalize(message):
27 if isinstance(message, str):
28 return normalize_str(message)
29 elif isinstance(message, tuple):
30 return tuple([normalize_str(x) for x in message])
31
32
26def babel_extract(fileobj, keywords, comment_tags, options): 33def babel_extract(fileobj, keywords, comment_tags, options):
27 res = jinja2.ext.babel_extract(fileobj, keywords, comment_tags, options) 34 res = jinja2.ext.babel_extract(fileobj, keywords, comment_tags, options)
28 for lineno, funcname, message, comments in res: 35 for lineno, funcname, message, comments in res:
29 message = normalize(message) 36 yield lineno, funcname, normalize(message), comments
30 yield lineno, funcname, message, comments
31 37
32 38
33def wrap_gettext(f): 39def wrap_gettext(f):
34 """ 40 """
35 Call gettext with whitespace normalized. 41 Call gettext with whitespace normalized.
36 """ 42 """
43
37 def wrapper(message): 44 def wrapper(message):
38 message = normalize(message) 45 message = normalize(message)
39 return f(message) 46 return f(message)