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: Improved regexp some more Created April 22, 2015, 2:42 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..24fead4a9cbfa0e0c5df304fc7ea32de5d200f34 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,14 @@ 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
+ r"{{(?:(?!}}).)*}}" # Nested translation
+ r")*?)"
+ 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