Commits

Anonymous committed 2172100

Ported [305] to 0.9.x branch.

  • Participants
  • Parent commits e4c88f5
  • Branches stable-0.9.x

Comments (0)

Files changed (3)

+Version 0.9.1
+http://svn.edgewall.org/repos/babel/tags/0.9.1/
+(?, from branches/stable/0.9.x)
+
+ * Fixed catalog updating when a message is merged that was previously simple 
+   but now has a plural form, for example by moving from `gettext` to 
+   `ngettext`, or vice versa.
+ * Fixed time formatting for 12 am and 12 pm.
+ * Fixed output encoding of the `pybabel --list-locales` command.
+
+
 Version 0.9
 http://svn.edgewall.org/repos/babel/tags/0.9.0/
 (Aug 20 2007, from branches/stable/0.9.x)

File babel/messages/catalog.py

             self.fuzzy = message.fuzzy
         else:
             if isinstance(id, (list, tuple)):
-                assert isinstance(message.string, (list, tuple))
+                assert isinstance(message.string, (list, tuple)), \
+                    'Expected sequence but got %s' % type(message.string)
             self._messages[key] = message
 
     def add(self, id, string=None, locations=(), flags=(), auto_comments=(),
         messages = self._messages
         self._messages = odict()
 
+        def _merge(message, oldkey, newkey):
+            fuzzy = False
+            oldmsg = messages.pop(oldkey)
+            if oldkey != newkey:
+                fuzzy = True
+                if isinstance(oldmsg.id, basestring):
+                    message.previous_id = [oldmsg.id]
+                else:
+                    message.previous_id = list(oldmsg.id)
+            message.string = oldmsg.string
+            if isinstance(message.id, (list, tuple)):
+                if not isinstance(message.string, (list, tuple)):
+                    fuzzy = True
+                    message.string = tuple(
+                        [message.string] + ([u''] * (len(message.id) - 1))
+                    )
+                elif len(message.string) != len(message.id):
+                    fuzzy = True
+                    message.string = tuple(message.string[:len(oldmsg.string)])
+            elif isinstance(message.string, (list, tuple)):
+                fuzzy = True
+                message.string = message.string[0]
+            message.flags |= oldmsg.flags
+            if fuzzy:
+                message.flags |= set([u'fuzzy'])
+            self[message.id] = message
+
         for message in template:
             if message.id:
                 key = self._key_for(message.id)
                 if key in messages:
-                    oldmsg = messages.pop(key)
-                    message.string = oldmsg.string
-                    message.flags |= oldmsg.flags
-                    self[message.id] = message
-
+                    _merge(message, key, key)
                 else:
                     if no_fuzzy_matching is False:
                         # do some fuzzy matching with difflib
                         matches = get_close_matches(key.lower().strip(),
                             [self._key_for(msgid) for msgid in messages], 1)
                         if matches:
-                            oldmsg = messages.pop(matches[0])
-                            message.string = oldmsg.string
-                            message.flags |= oldmsg.flags | set([u'fuzzy'])
-                            if isinstance(oldmsg.id, basestring):
-                                message.previous_id = [oldmsg.id]
-                            else:
-                                message.previous_id = list(oldmsg.id)
-                            self[message.id] = message
+                            _merge(message, matches[0], key)
                             continue
 
                     self[message.id] = message

File babel/messages/tests/catalog.py

         cat.add('foo', locations=[('foo.py', 1)])
         self.assertEqual([('foo.py', 1)], cat['foo'].locations)
 
+    def test_update_message_changed_to_plural(self):
+        cat = catalog.Catalog()
+        cat.add(u'foo', u'Voh')
+        tmpl = catalog.Catalog()
+        tmpl.add((u'foo', u'foos'))
+        cat.update(tmpl)
+        self.assertEqual((u'Voh', ''), cat['foo'].string)
+        assert cat['foo'].fuzzy
+
+    def test_update_message_changed_to_simple(self):
+        cat = catalog.Catalog()
+        cat.add((u'foo' u'foos'), (u'Voh', u'Vöhs'))
+        tmpl = catalog.Catalog()
+        tmpl.add(u'foo')
+        cat.update(tmpl)
+        self.assertEqual(u'Voh', cat['foo'].string)
+        assert cat['foo'].fuzzy
+
     def test_update_message_updates_comments(self):
         cat = catalog.Catalog()
         cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 5)])