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

Unified Diff: cms/converters.py

Issue 4802066526502912: Issue 2323 - Make sure to always resolve links in translatable strings (Closed)
Patch Set: Added hreflang attribute Created April 15, 2015, 7:23 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
===================================================================
--- a/cms/converters.py
+++ b/cms/converters.py
@@ -127,31 +127,39 @@ class Converter:
s, flags=re.S)
def re_escape(s):
return re.escape(escape(s))
# Extract tag attributes from default string
default, saved_attributes, fixed_strings = self._attribute_parser.parse(default, self._params["page"])
# Get translation
- if self._params["locale"] != self._params["defaultlocale"] and name in localedata:
+ locale = self._params["locale"]
+ if locale != self._params["defaultlocale"] and name in localedata:
result = localedata[name].strip()
else:
result = default
# Insert fixed strings
for i in range(len(fixed_strings)):
result = re.sub(r"\{%d\}" % (i + 1), fixed_strings[i], result, 1)
# Insert attributes
result = escape(result)
+ def stringify_attribute((name, value)):
+ if name == "href":
+ link_locale, link = self._params["source"].resolve_link(value, locale)
+ if link:
+ return 'href="%s" hreflang="%s"' % (escape(link), escape(link_locale))
+ return '%s="%s"' % (escape(name), escape(value))
+
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), tag),
result, 1, flags=re.S
)
result = re.sub(
r"%s([^<>]*?)%s" % (re_escape("<%s>" % tag), re_escape("</%s>" % tag)),
r"<%s>\1</%s>" % (tag, tag),
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld