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 May 6, 2015, 5: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/sources.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
@@ -106,16 +106,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 = {"a", "em", "strong", "code", "span"}
+ 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)
@@ -131,20 +133,25 @@ 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"]:
+ 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, fixed_string in enumerate(fixed_strings, 1):
result = result.replace("{%d}" % i, fixed_string)
# Insert attributes
result = escape(result)
def stringify_attribute((name, value)):
@@ -215,17 +222,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/sources.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld