Index: cms/converters.py |
=================================================================== |
--- a/cms/converters.py |
+++ b/cms/converters.py |
@@ -102,16 +102,18 @@ class AttributeParser(HTMLParser.HTMLPar |
def handle_entityref(self, name): |
self._append_text(self.unescape("&%s;" % name)) |
def handle_charref(self, name): |
self._append_text(self.unescape("&#%s;" % name)) |
class Converter: |
whitelist = set(["a", "em", "strong"]) |
+ missing_translations = 0 |
+ total_translations = 0 |
def __init__(self, params, key="pagedata"): |
self._params = params |
self._key = key |
self._attribute_parser = AttributeParser(self.whitelist) |
# Read in any parameters specified at the beginning of the file |
lines = params[key].splitlines(True) |
@@ -128,20 +130,24 @@ class Converter: |
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 |
locale = self._params["locale"] |
- if locale != self._params["defaultlocale"] and name in localedata: |
+ if locale == self._params["defaultlocale"]: |
+ result = default |
+ elif name in localedata: |
result = localedata[name].strip() |
else: |
result = default |
+ self.missing_translations += 1 |
+ self.total_translations += 1 |
# 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)): |
@@ -206,17 +212,20 @@ class Converter: |
def resolve_includes(self, text): |
def resolve_include(match): |
global converters |
name = match.group(1) |
for format, converter_class in converters.iteritems(): |
if self._params["source"].has_include(name, format): |
self._params["includedata"] = self._params["source"].read_include(name, format) |
converter = converter_class(self._params, key="includedata") |
- return converter() |
+ result = converter() |
+ self.missing_translations += converter.missing_translations |
+ self.total_translations += converter.total_translations |
+ return result |
raise Exception("Failed to resolve include %s on page %s" % (name, self._params["page"])) |
return re.sub( |
r'%s\?\s*include\s+([^\s<>"]+)\s*\?%s' % ( |
self.include_start_regex, |
self.include_end_regex |
), |
resolve_include, |