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

Unified Diff: cms/converters.py

Issue 29317015: Issue 2625 - [cms] Crowdin synchronisation script (Closed)
Patch Set: Slightly simplified request exception logic Created July 12, 2015, 5:47 a.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
Index: cms/converters.py
diff --git a/cms/converters.py b/cms/converters.py
index 8f602f3f36149a3b70ac17f6054197a84756b056..7760af626dd0563c198877337471fbbb912d0304 100644
--- a/cms/converters.py
+++ b/cms/converters.py
@@ -125,7 +125,7 @@ class Converter:
params[name.strip()] = value.strip()
params[key] = "".join(lines)
- def localize_string(self, name, default, localedata, escapes):
+ def localize_string(self, page, name, default, comment, localedata, escapes):
def escape(s):
return re.sub(r".",
lambda match: escapes.get(match.group(0), match.group(0)),
@@ -147,6 +147,12 @@ class Converter:
self.missing_translations += 1
self.total_translations += 1
+ # Perform callback with the string if required, e.g. for the translations script
+ if self._params["localized_string_callback"]:
Sebastian Noack 2015/07/14 11:31:08 I would rather not duplicate the key lookup: ca
kzar 2015/07/14 12:54:31 Done.
+ self._params["localized_string_callback"](page, locale, name, result,
+ comment, fixed_strings)
+
+
# Insert fixed strings
for i, fixed_string in enumerate(fixed_strings, 1):
result = result.replace("{%d}" % i, fixed_string)
@@ -185,9 +191,8 @@ class Converter:
name, comment, default = match.groups()
default = to_html(default).strip()
- # Note: We currently ignore the comment, it is only relevant when
- # generating the master translation.
- return self.localize_string(name, default, self._params["localedata"], escapes)
+ return self.localize_string(self._params["page"], name, default,
+ comment, self._params["localedata"], escapes)
return re.sub(
r"{{\s*"
@@ -352,15 +357,17 @@ class TemplateConverter(Converter):
return result
def translate(self, default, name, comment=None):
- # Note: We currently ignore the comment, it is only relevant when
- # generating the master translation.
- localedata = self._params["localedata"]
- return jinja2.Markup(self.localize_string(name, default, localedata, html_escapes))
+ return jinja2.Markup(self.localize_string(
+ self._params["page"], name, default, comment,
+ self._params["localedata"], html_escapes
+ ))
def get_string(self, name, page):
localedata = self._params["source"].read_locale(self._params["locale"], page)
default = localedata[name]
- return jinja2.Markup(self.localize_string(name, default, localedata, html_escapes))
+ return jinja2.Markup(self.localize_string(
+ page, name, default, "", localedata, html_escapes
+ ))
def get_page_content(self, page, locale=None):
from cms.utils import get_page_params
« cms/bin/translate.py ('K') | « cms/bin/translate.py ('k') | cms/sources.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld