diff --git a/genshi/filters/i18n.py b/genshi/filters/i18n.py
|
a
|
b
|
|
| 270 | 270 | search_text = False |
| 271 | 271 | skip = 0 |
| 272 | 272 | i18n_msg = I18N_NAMESPACE['msg'] |
| | 273 | i18n_comment = I18N_NAMESPACE['comment'] |
| 273 | 274 | xml_lang = XML_NAMESPACE['lang'] |
| 274 | 275 | |
| 275 | 276 | for kind, data, pos in stream: |
| … |
… |
|
| 295 | 296 | if text: |
| 296 | 297 | yield pos[1], None, text |
| 297 | 298 | else: |
| 298 | | for lineno, funcname, text in self.extract( |
| | 299 | for lineno, funcname, text, comments in self.extract( |
| 299 | 300 | _ensure(value), gettext_functions, |
| 300 | 301 | search_text=False): |
| 301 | | yield lineno, funcname, text |
| | 302 | yield lineno, funcname, text, comments |
| 302 | 303 | |
| 303 | 304 | if msgbuf: |
| 304 | 305 | msgbuf.append(kind, data, pos) |
| … |
… |
|
| 307 | 308 | if params and type(params) is list: # event tuple |
| 308 | 309 | params = params[0][1] |
| 309 | 310 | msgbuf = MessageBuffer(params, pos[1]) |
| | 311 | if i18n_comment in attrs and msgbuf: |
| | 312 | msgbuf.comments.append(attrs.get(i18n_comment)) |
| 310 | 313 | |
| 311 | 314 | elif not skip and search_text and kind is TEXT: |
| 312 | 315 | if not msgbuf: |
| 313 | 316 | text = data.strip() |
| 314 | 317 | if text and filter(None, [ch.isalpha() for ch in text]): |
| 315 | | yield pos[1], None, text |
| | 318 | yield pos[1], None, text, [] |
| 316 | 319 | else: |
| 317 | 320 | msgbuf.append(kind, data, pos) |
| 318 | 321 | |
| 319 | 322 | elif not skip and msgbuf and kind is END: |
| 320 | 323 | msgbuf.append(kind, data, pos) |
| 321 | 324 | if not msgbuf.depth: |
| 322 | | yield msgbuf.lineno, None, msgbuf.format() |
| | 325 | yield msgbuf.lineno, None, msgbuf.format(), msgbuf.comments |
| 323 | 326 | msgbuf = None |
| 324 | 327 | |
| 325 | 328 | elif kind is EXPR or kind is EXEC: |
| … |
… |
|
| 327 | 330 | msgbuf.append(kind, data, pos) |
| 328 | 331 | for funcname, strings in extract_from_code(data, |
| 329 | 332 | gettext_functions): |
| 330 | | yield pos[1], funcname, strings |
| | 333 | yield pos[1], funcname, strings, [] |
| 331 | 334 | |
| 332 | 335 | elif kind is SUB: |
| 333 | 336 | subkind, substream = data |
| 334 | 337 | messages = self.extract(substream, gettext_functions, |
| 335 | 338 | search_text=search_text and not skip, |
| 336 | 339 | msgbuf=msgbuf) |
| 337 | | for lineno, funcname, text in messages: |
| 338 | | yield lineno, funcname, text |
| | 340 | for lineno, funcname, text, comments in messages: |
| | 341 | yield lineno, funcname, text, comments |
| 339 | 342 | |
| 340 | 343 | |
| 341 | 344 | class MessageBuffer(object): |
| … |
… |
|
| 360 | 363 | self.depth = 1 |
| 361 | 364 | self.order = 1 |
| 362 | 365 | self.stack = [0] |
| | 366 | self.comments = [] |
| 363 | 367 | |
| 364 | 368 | def append(self, kind, data, pos): |
| 365 | 369 | """Append a stream event to the buffer. |
| … |
… |
|
| 545 | 549 | tmpl = template_class(fileobj, filename=getattr(fileobj, 'name', None), |
| 546 | 550 | encoding=encoding) |
| 547 | 551 | translator = Translator(None, ignore_tags, include_attrs, extract_text) |
| 548 | | for lineno, func, message in translator.extract(tmpl.stream, |
| 549 | | gettext_functions=keywords): |
| 550 | | yield lineno, func, message, [] |
| | 552 | for lineno, func, message, comments in translator.extract( |
| | 553 | tmpl.stream, gettext_functions=keywords): |
| | 554 | yield lineno, func, message, comments |