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: Give query_params a default value Created July 16, 2015, 12:47 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/translate.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
diff --git a/cms/converters.py b/cms/converters.py
index 8f602f3f36149a3b70ac17f6054197a84756b056..afa4ee4f31ef51cf1d39ffa7453154a5b51a2f9e 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
+ callback = self._params["localized_string_callback"]
+ if callback:
+ 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
« no previous file with comments | « cms/bin/translate.py ('k') | cms/sources.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld