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

Side by Side Diff: cms/converters.py

Issue 29912578: Issue 7048 - Fix erroneous markup escaping in translation strings (Closed) Base URL: https://hg.adblockplus.org/cms
Patch Set: Created Oct. 16, 2018, 10:37 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/expected_output/de/translate-tmpl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 # Handle duplicated strings 143 # Handle duplicated strings
144 if default: 144 if default:
145 self._seen_defaults[(page, name)] = (default, comment) 145 self._seen_defaults[(page, name)] = (default, comment)
146 else: 146 else:
147 try: 147 try:
148 default, comment = self._seen_defaults[(page, name)] 148 default, comment = self._seen_defaults[(page, name)]
149 except KeyError: 149 except KeyError:
150 raise Exception('Text not yet defined for string {} on page' 150 raise Exception('Text not yet defined for string {} on page'
151 ' {}'.format(name, page)) 151 ' {}'.format(name, page))
152 152
153 full_default = default
153 # Extract tag attributes from default string 154 # Extract tag attributes from default string
154 default, saved_attributes, fixed_strings = ( 155 default, saved_attributes, fixed_strings = (
155 self._attribute_parser.parse(default, self._params['page'])) 156 self._attribute_parser.parse(default, self._params['page']))
156 157
157 # Get translation 158 # Get translation
158 locale = self._params['locale'] 159 locale = self._params['locale']
159 if locale == self._params['defaultlocale']: 160 if locale == self._params['defaultlocale']:
160 result = default 161 result = default
161 elif name in localedata: 162 elif name in localedata:
162 result = localedata[name].strip() 163 result = localedata[name].strip()
164 # If the string is present in default locale, but not in the
165 # current one, we will get the value from default locale here.
166 # If it happens to contain attributes on any tags, those need
167 # to be stripped, otherwise the attribute substitution below won't
168 # work. Luckily, we already have the default translation string
169 # with attributes stripped -- it's the value of `default`.
170 if result == full_default.strip():
171 result = default
163 else: 172 else:
164 result = default 173 result = default
165 self.missing_translations += 1 174 self.missing_translations += 1
166 self.total_translations += 1 175 self.total_translations += 1
167 176
168 # Perform callback with the string if required, e.g. for the 177 # Perform callback with the string if required, e.g. for the
169 # translations script 178 # translations script
170 callback = self._params['localized_string_callback'] 179 callback = self._params['localized_string_callback']
171 if callback: 180 if callback:
172 callback(page, locale, name, result, comment, fixed_strings) 181 callback(page, locale, name, result, comment, fixed_strings)
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 stack[-1]['subitems'].append(item) 532 stack[-1]['subitems'].append(item)
524 stack.append(item) 533 stack.append(item)
525 return structured 534 return structured
526 535
527 536
528 converters = { 537 converters = {
529 'html': RawConverter, 538 'html': RawConverter,
530 'md': MarkdownConverter, 539 'md': MarkdownConverter,
531 'tmpl': TemplateConverter, 540 'tmpl': TemplateConverter,
532 } 541 }
OLDNEW
« no previous file with comments | « no previous file | tests/expected_output/de/translate-tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld