| 460 | self.__freshmodule = 1 |
| 461 | |
| 462 | def write(self, fp): |
| 463 | options = self.__options |
| 464 | timestamp = time.strftime('%Y-%m-%d %H:%M%z') |
| 465 | encoding = fp.encoding if fp.encoding else 'UTF-8' |
| 466 | print(pot_header % {'time': timestamp, 'version': __version__, |
| 467 | 'charset': encoding, |
| 468 | 'encoding': '8bit'}, file=fp) |
| 469 | # Sort the entries. First sort each particular entry's keys, then |
| 470 | # sort all the entries by their first item. |
| 471 | reverse = {} |
| 472 | for k, v in self.__messages.items(): |
| 473 | keys = sorted(v.keys()) |
| 474 | reverse.setdefault(tuple(keys), []).append((k, v)) |
| 475 | rkeys = sorted(reverse.keys()) |
| 476 | for rkey in rkeys: |
| 477 | rentries = reverse[rkey] |
| 478 | rentries.sort() |
| 479 | for k, v in rentries: |
| 480 | # If the entry was gleaned out of a docstring, then add a |
| 481 | # comment stating so. This is to aid translators who may wish |
| 482 | # to skip translating some unimportant docstrings. |
| 483 | isdocstring = any(v.values()) |
| 484 | # k is the message string, v is a dictionary-set of (filename, |
| 485 | # lineno) tuples. We want to sort the entries in v first by |
| 486 | # file name and then by line number. |
| 487 | v = sorted(v.keys()) |
| 488 | if not options.writelocations: |
| 489 | pass |
| 490 | # location comments are different b/w Solaris and GNU: |
| 491 | elif options.locationstyle == options.SOLARIS: |
| 492 | for filename, lineno in v: |
| 493 | d = {'filename': filename, 'lineno': lineno} |
| 494 | print(_( |
| 495 | '# File: %(filename)s, line: %(lineno)d') % d, file=fp) |
| 496 | elif options.locationstyle == options.GNU: |
| 497 | # fit as many locations on one line, as long as the |
| 498 | # resulting line length doesn't exceed 'options.width' |
| 499 | locline = '#:' |
| 500 | for filename, lineno in v: |
| 501 | d = {'filename': filename, 'lineno': lineno} |
| 502 | s = _(' %(filename)s:%(lineno)d') % d |
| 503 | if len(locline) + len(s) <= options.width: |
| 504 | locline = locline + s |
| 505 | else: |
| 506 | print(locline, file=fp) |
| 507 | locline = "#:" + s |
| 508 | if len(locline) > 2: |
| 509 | print(locline, file=fp) |
| 510 | if isdocstring: |
| 511 | print('#, docstring', file=fp) |
| 512 | print('msgid', normalize(k, encoding), file=fp) |
| 513 | print('msgstr ""\n', file=fp) |
| 514 | |
| 515 | |
| 516 | def main(): |