# HG changeset patch # User jruigrok # Date 1270544706 0 # Node ID 8941027e8b223cb417f16159e82284911bf90e8a # Parent fb4e025f3410b22301b11d83c77f6004ec0ca0a4 Merged revisions 467 via svnmerge from http://svn.edgewall.org/repos/babel/trunk ........ r467 | palgarvio | 2009-01-10 23:42:01 +0100 (za, 10 jan 2009) | 2 lines Fuzzy matching regarding plurals should *NOT* be checked against `len(message.id)` because this is always 2, instead, it's should be checked against `catalog.num_plurals`. ........ diff --git a/0.9.x/ChangeLog b/0.9.x/ChangeLog --- a/0.9.x/ChangeLog +++ b/0.9.x/ChangeLog @@ -4,6 +4,9 @@ * Fixed the case where messages containing square brackets would break with an unpack error. + * Backport of r467: Fuzzy matching regarding plurals should *NOT* be checked + against len(message.id) because this is always 2, instead, it's should be + checked against catalog.num_plurals (ticket #212). Version 0.9.4 diff --git a/0.9.x/babel/messages/catalog.py b/0.9.x/babel/messages/catalog.py --- a/0.9.x/babel/messages/catalog.py +++ b/0.9.x/babel/messages/catalog.py @@ -679,7 +679,7 @@ message.string = tuple( [message.string] + ([u''] * (len(message.id) - 1)) ) - elif len(message.string) != len(message.id): + elif len(message.string) != self.num_plurals: fuzzy = True message.string = tuple(message.string[:len(oldmsg.string)]) elif isinstance(message.string, (list, tuple)): diff --git a/0.9.x/babel/messages/tests/catalog.py b/0.9.x/babel/messages/tests/catalog.py --- a/0.9.x/babel/messages/tests/catalog.py +++ b/0.9.x/babel/messages/tests/catalog.py @@ -11,6 +11,7 @@ # individuals. For the exact contribution history, see the revision # history and logs, available at http://babel.edgewall.org/log/. +import copy import doctest import unittest @@ -183,6 +184,19 @@ cat.update(tmpl, no_fuzzy_matching=True) self.assertEqual(2, len(cat.obsolete)) + def test_fuzzy_matching_regarding_plurals(self): + cat = catalog.Catalog() + cat.add(('foo', 'foh'), ('foo', 'foh')) + ru = copy.copy(cat) + ru.locale = 'ru_RU' + ru.update(cat) + self.assertEqual(True, ru['foo'].fuzzy) + ru = copy.copy(cat) + ru.locale = 'ru_RU' + ru['foo'].string = ('foh', 'fohh', 'fohhh') + ru.update(cat) + self.assertEqual(False, ru['foo'].fuzzy) + def test_update_no_template_mutation(self): tmpl = catalog.Catalog() tmpl.add('foo')