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

Delta Between Two Patch Sets: cms/converters.py

Issue 6440550915899392: Issue 2139 - Allow nested translations for tag attributes. (Closed)
Left Patch Set: Rebased on top of Wladimir's changes for link resolving. Created April 21, 2015, 4:19 p.m.
Right Patch Set: Improved regexp some more Created April 22, 2015, 2:42 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 def insert_localized_strings(self, text, escapes, to_html=lambda s: s): 168 def insert_localized_strings(self, text, escapes, to_html=lambda s: s):
169 def lookup_string(match): 169 def lookup_string(match):
170 name, comment, default = match.groups() 170 name, comment, default = match.groups()
171 default = to_html(default).strip() 171 default = to_html(default).strip()
172 172
173 # Note: We currently ignore the comment, it is only relevant when 173 # Note: We currently ignore the comment, it is only relevant when
174 # generating the master translation. 174 # generating the master translation.
175 return self.localize_string(name, default, self._params["localedata"], esc apes) 175 return self.localize_string(name, default, self._params["localedata"], esc apes)
176 176
177 return re.sub( 177 return re.sub(
178 r"\{\{\s*" 178 r"{{\s*"
179 r"([\w\-]+)" # String ID 179 r"([\w\-]+)" # String ID
180 r"(?:\[(.*?)\])?" # Optional comment 180 r"(?:\[(.*?)\])?" # Optional comment
181 r"\s+" 181 r"\s+"
182 r"((?:[^\{]|\{(?!\{)|\{\{(?:[^\}]|\}(?!\}))*?\}\})*?)" # Translatable text 182 r"((?:(?!{{).|" # Translatable text
Wladimir Palant 2015/04/22 13:52:24 Yes, this line isn't very readable now. How about
kzar 2015/04/22 14:46:06 Nice, that looks much better and still seems to wo
183 r"\}\}", 183 r"{{(?:(?!}}).)*}}" # Nested translation
184 r")*?)"
185 r"}}",
184 lookup_string, 186 lookup_string,
185 text, 187 text,
186 flags=re.S 188 flags=re.S
187 ) 189 )
188 190
189 def process_links(self, text): 191 def process_links(self, text):
190 def process_link(match): 192 def process_link(match):
191 pre, attr, url, post = match.groups() 193 pre, attr, url, post = match.groups()
192 url = jinja2.Markup(url).unescape() 194 url = jinja2.Markup(url).unescape()
193 195
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 stack.pop() 395 stack.pop()
394 stack[-1]["subitems"].append(item) 396 stack[-1]["subitems"].append(item)
395 stack.append(item) 397 stack.append(item)
396 return structured 398 return structured
397 399
398 converters = { 400 converters = {
399 "html": RawConverter, 401 "html": RawConverter,
400 "md": MarkdownConverter, 402 "md": MarkdownConverter,
401 "tmpl": TemplateConverter, 403 "tmpl": TemplateConverter,
402 } 404 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld