LEFT | RIGHT |
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 def localize_string(self, page, name, default, comment, localedata, escapes): | 129 def localize_string(self, page, name, default, comment, localedata, escapes): |
130 def escape(s): | 130 def escape(s): |
131 return re.sub(r".", | 131 return re.sub(r".", |
132 lambda match: escapes.get(match.group(0), match.group(0)), | 132 lambda match: escapes.get(match.group(0), match.group(0)), |
133 s, flags=re.S) | 133 s, flags=re.S) |
134 def re_escape(s): | 134 def re_escape(s): |
135 return re.escape(escape(s)) | 135 return re.escape(escape(s)) |
136 | 136 |
137 # Handle duplicated strings | 137 # Handle duplicated strings |
138 if default: | 138 if default: |
139 self._seen_defaults[(page, name)] = default | 139 self._seen_defaults[(page, name)] = (default, comment) |
140 else: | 140 else: |
141 try: | 141 try: |
142 default = self._seen_defaults[(page, name)] | 142 default, comment = self._seen_defaults[(page, name)] |
143 except KeyError: | 143 except KeyError: |
144 raise Exception("Text not yet defined for string %s on page %s" % | 144 raise Exception("Text not yet defined for string %s on page %s" % |
145 (name, page)) | 145 (name, page)) |
146 | 146 |
147 # Extract tag attributes from default string | 147 # Extract tag attributes from default string |
148 default, saved_attributes, fixed_strings = self._attribute_parser.parse(defa
ult, self._params["page"]) | 148 default, saved_attributes, fixed_strings = self._attribute_parser.parse(defa
ult, self._params["page"]) |
149 | 149 |
150 # Get translation | 150 # Get translation |
151 locale = self._params["locale"] | 151 locale = self._params["locale"] |
152 if locale == self._params["defaultlocale"]: | 152 if locale == self._params["defaultlocale"]: |
153 result = default | 153 result = default |
154 elif name in localedata: | 154 elif name in localedata: |
155 result = localedata[name].strip() | 155 result = localedata[name].strip() |
156 else: | 156 else: |
157 result = default | 157 result = default |
158 self.missing_translations += 1 | 158 self.missing_translations += 1 |
159 self.total_translations += 1 | 159 self.total_translations += 1 |
160 | 160 |
161 if default: | 161 # Perform callback with the string if required, e.g. for the translations sc
ript |
162 # Perform callback with the string if required, | 162 callback = self._params["localized_string_callback"] |
163 # e.g. for the translations script | 163 if callback: |
164 callback = self._params["localized_string_callback"] | 164 callback(page, locale, name, result, comment, fixed_strings) |
165 if callback: | 165 |
166 callback(page, locale, name, result, comment, fixed_strings) | |
167 | 166 |
168 # Insert fixed strings | 167 # Insert fixed strings |
169 for i, fixed_string in enumerate(fixed_strings, 1): | 168 for i, fixed_string in enumerate(fixed_strings, 1): |
170 result = result.replace("{%d}" % i, fixed_string) | 169 result = result.replace("{%d}" % i, fixed_string) |
171 | 170 |
172 # Insert attributes | 171 # Insert attributes |
173 result = escape(result) | 172 result = escape(result) |
174 def stringify_attribute((name, value)): | 173 def stringify_attribute((name, value)): |
175 return '%s="%s"' % ( | 174 return '%s="%s"' % ( |
176 escape(name), | 175 escape(name), |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 stack.pop() | 417 stack.pop() |
419 stack[-1]["subitems"].append(item) | 418 stack[-1]["subitems"].append(item) |
420 stack.append(item) | 419 stack.append(item) |
421 return structured | 420 return structured |
422 | 421 |
423 converters = { | 422 converters = { |
424 "html": RawConverter, | 423 "html": RawConverter, |
425 "md": MarkdownConverter, | 424 "md": MarkdownConverter, |
426 "tmpl": TemplateConverter, | 425 "tmpl": TemplateConverter, |
427 } | 426 } |
LEFT | RIGHT |