diff 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
line wrap: on
line diff
--- a/babel/messages/catalog.py
+++ b/babel/messages/catalog.py
@@ -607,6 +607,7 @@
 
         >>> catalog = Catalog()
         >>> catalog.add(u'foo')
+        <Message ...>
         >>> catalog[u'foo']
         <Message u'foo' (flags: [])>
 
@@ -626,10 +627,14 @@
         :param lineno: the line number on which the msgid line was found in the
                        PO file, if any
         :param context: the message context
+        :return: the newly added message
+        :rtype: `Message`
         """
-        self[id] = Message(id, string, list(locations), flags, auto_comments,
-                           user_comments, previous_id, lineno=lineno,
-                           context=context)
+        message = Message(id, string, list(locations), flags, auto_comments,
+                          user_comments, previous_id, lineno=lineno,
+                          context=context)
+        self[id] = message
+        return message
 
     def check(self):
         """Run various validation checks on the translations in the catalog.
@@ -672,13 +677,19 @@
         >>> from babel.messages import Catalog
         >>> template = Catalog()
         >>> template.add('green', locations=[('main.py', 99)])
+        <Message ...>
         >>> template.add('blue', locations=[('main.py', 100)])
+        <Message ...>
         >>> template.add(('salad', 'salads'), locations=[('util.py', 42)])
+        <Message ...>
         >>> catalog = Catalog(locale='de_DE')
         >>> catalog.add('blue', u'blau', locations=[('main.py', 98)])
+        <Message ...>
         >>> catalog.add('head', u'Kopf', locations=[('util.py', 33)])
+        <Message ...>
         >>> catalog.add(('salad', 'salads'), (u'Salat', u'Salate'),
         ...             locations=[('util.py', 38)])
+        <Message ...>
 
         >>> catalog.update(template)
         >>> len(catalog)
Copyright (C) 2012-2017 Edgewall Software