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

Unified Diff: cms/converters.py

Issue 5242593268989952: Issue 2340 - Don`t generate pages if less than 30% have been translated (Closed)
Patch Set: Addressed comments Created April 17, 2015, 6:20 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 | « cms/bin/generate_static_pages.py ('k') | cms/utils.py » ('j') | 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
@@ -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,
« no previous file with comments | « cms/bin/generate_static_pages.py ('k') | cms/utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld