Mercurial > babel > old > mirror
comparison babel/messages/catalog.py @ 546:10de195cfb04
catalog.add() now returns the message instance (closes #245)
author | fschwarz |
---|---|
date | Sat, 19 Mar 2011 19:28:59 +0000 |
parents | e93f68837913 |
children | 274f9a6485d4 |
comparison
equal
deleted
inserted
replaced
543:1d386483ccb6 | 546:10de195cfb04 |
---|---|
605 user_comments=(), previous_id=(), lineno=None, context=None): | 605 user_comments=(), previous_id=(), lineno=None, context=None): |
606 """Add or update the message with the specified ID. | 606 """Add or update the message with the specified ID. |
607 | 607 |
608 >>> catalog = Catalog() | 608 >>> catalog = Catalog() |
609 >>> catalog.add(u'foo') | 609 >>> catalog.add(u'foo') |
610 <Message ...> | |
610 >>> catalog[u'foo'] | 611 >>> catalog[u'foo'] |
611 <Message u'foo' (flags: [])> | 612 <Message u'foo' (flags: [])> |
612 | 613 |
613 This method simply constructs a `Message` object with the given | 614 This method simply constructs a `Message` object with the given |
614 arguments and invokes `__setitem__` with that object. | 615 arguments and invokes `__setitem__` with that object. |
624 :param previous_id: the previous message ID, or a ``(singular, plural)`` | 625 :param previous_id: the previous message ID, or a ``(singular, plural)`` |
625 tuple for pluralizable messages | 626 tuple for pluralizable messages |
626 :param lineno: the line number on which the msgid line was found in the | 627 :param lineno: the line number on which the msgid line was found in the |
627 PO file, if any | 628 PO file, if any |
628 :param context: the message context | 629 :param context: the message context |
629 """ | 630 :return: the newly added message |
630 self[id] = Message(id, string, list(locations), flags, auto_comments, | 631 :rtype: `Message` |
631 user_comments, previous_id, lineno=lineno, | 632 """ |
632 context=context) | 633 message = Message(id, string, list(locations), flags, auto_comments, |
634 user_comments, previous_id, lineno=lineno, | |
635 context=context) | |
636 self[id] = message | |
637 return message | |
633 | 638 |
634 def check(self): | 639 def check(self): |
635 """Run various validation checks on the translations in the catalog. | 640 """Run various validation checks on the translations in the catalog. |
636 | 641 |
637 For every message which fails validation, this method yield a | 642 For every message which fails validation, this method yield a |
670 """Update the catalog based on the given template catalog. | 675 """Update the catalog based on the given template catalog. |
671 | 676 |
672 >>> from babel.messages import Catalog | 677 >>> from babel.messages import Catalog |
673 >>> template = Catalog() | 678 >>> template = Catalog() |
674 >>> template.add('green', locations=[('main.py', 99)]) | 679 >>> template.add('green', locations=[('main.py', 99)]) |
680 <Message ...> | |
675 >>> template.add('blue', locations=[('main.py', 100)]) | 681 >>> template.add('blue', locations=[('main.py', 100)]) |
682 <Message ...> | |
676 >>> template.add(('salad', 'salads'), locations=[('util.py', 42)]) | 683 >>> template.add(('salad', 'salads'), locations=[('util.py', 42)]) |
684 <Message ...> | |
677 >>> catalog = Catalog(locale='de_DE') | 685 >>> catalog = Catalog(locale='de_DE') |
678 >>> catalog.add('blue', u'blau', locations=[('main.py', 98)]) | 686 >>> catalog.add('blue', u'blau', locations=[('main.py', 98)]) |
687 <Message ...> | |
679 >>> catalog.add('head', u'Kopf', locations=[('util.py', 33)]) | 688 >>> catalog.add('head', u'Kopf', locations=[('util.py', 33)]) |
689 <Message ...> | |
680 >>> catalog.add(('salad', 'salads'), (u'Salat', u'Salate'), | 690 >>> catalog.add(('salad', 'salads'), (u'Salat', u'Salate'), |
681 ... locations=[('util.py', 38)]) | 691 ... locations=[('util.py', 38)]) |
692 <Message ...> | |
682 | 693 |
683 >>> catalog.update(template) | 694 >>> catalog.update(template) |
684 >>> len(catalog) | 695 >>> len(catalog) |
685 3 | 696 3 |
686 | 697 |