changeset 454:8941027e8b22 stable

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`. ........
author jruigrok
date Tue, 06 Apr 2010 09:05:06 +0000
parents fb4e025f3410
children b9005e2e855d
files 0.9.x/ChangeLog 0.9.x/babel/messages/catalog.py 0.9.x/babel/messages/tests/catalog.py
diffstat 3 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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)):
--- 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')
Copyright (C) 2012-2017 Edgewall Software