Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: cms/converters.py

Issue 6440550915899392: Issue 2139 - Allow nested translations for tag attributes. (Closed)
Patch Set: Rebased on top of Wladimir's changes for link resolving. Created April 21, 2015, 4:19 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cms/converters.py
diff --git a/cms/converters.py b/cms/converters.py
index 3650dd135ad4097f3b1e49ed55b9e79d591da15d..6dce67a831f20b8fbb2df1700c9acc674852f445 100644
--- a/cms/converters.py
+++ b/cms/converters.py
@@ -143,10 +143,16 @@ class Converter:
# Insert attributes
result = escape(result)
+ def stringify_attribute((name, value)):
+ return '%s="%s"' % (
+ escape(name),
+ escape(self.insert_localized_strings(value, escapes))
+ )
+
for tag in self.whitelist:
saved = saved_attributes.get(tag, [])
for attrs in saved:
- attrs = map(lambda (name, value): '%s="%s"' % (escape(name), escape(value)), attrs)
+ attrs = map(stringify_attribute, attrs)
result = re.sub(
r"%s([^<>]*?)%s" % (re_escape("<%s>" % tag), re_escape("</%s>" % tag)),
r'<%s%s>\1</%s>' % (tag, " " + " ".join(attrs) if attrs else "", tag),
@@ -169,7 +175,12 @@ class Converter:
return self.localize_string(name, default, self._params["localedata"], escapes)
return re.sub(
- r"\{\{\s*([\w\-]+)(?:\[(.*?)\])?\s+(.*?)\}\}",
+ r"\{\{\s*"
+ r"([\w\-]+)" # String ID
+ r"(?:\[(.*?)\])?" # Optional comment
+ r"\s+"
+ r"((?:[^\{]|\{(?!\{)|\{\{(?:[^\}]|\}(?!\}))*?\}\})*?)" # Translatable text
Wladimir Palant 2015/04/22 13:52:24 Yes, this line isn't very readable now. How about
kzar 2015/04/22 14:46:06 Nice, that looks much better and still seems to wo
+ r"\}\}",
lookup_string,
text,
flags=re.S
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld