]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
handle irregular multi-line msgstr (no "" as first line) gracefully (#171)
authorFelix Schwarz <felix.schwarz@oss.schwarz.eu>
Sat, 4 Aug 2012 23:10:41 +0000 (23:10 +0000)
committerFelix Schwarz <felix.schwarz@oss.schwarz.eu>
Sat, 4 Aug 2012 23:10:41 +0000 (23:10 +0000)
ChangeLog
babel/messages/pofile.py
babel/messages/tests/pofile.py

index fdbaed2ad3715fac3985566e8283bb8ead28f84e..d9bf07ade92c0b5cbe413be81858e61ef2dd663d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -43,7 +43,8 @@ http://svn.edgewall.org/repos/babel/tags/1.0.0/
    with more than 7 significant digits (#183)
  * fix format_date() with datetime parameter (#282, patch from Xavier Morel)
  * fix format_decimal() with small Decimal values (#214, patch from George Lund)
- * fix handling of messages containing '\\n' (#171)
+ * fix handling of messages containing '\\n' (#198)
+ * handle irregular multi-line msgstr (no "" as first line) gracefully (#171)
 
 
 Version 0.9.6
index a44a6914dffb74fdafadd0c8aa1a15e3bb80c853..5c21bec136772a88ad4fd4cc8fb82c7772c1576a 100644 (file)
@@ -75,10 +75,11 @@ def denormalize(string):
     :return: the denormalized string
     :rtype: `unicode` or `str`
     """
-    if string.startswith('""'):
-        lines = []
-        for line in string.splitlines()[1:]:
-            lines.append(unescape(line))
+    if '\n' in string:
+        escaped_lines = string.splitlines()
+        if string.startswith('""'):
+            escaped_lines = escaped_lines[1:]
+        lines = map(unescape, escaped_lines)
         return ''.join(lines)
     else:
         return unescape(string)
@@ -110,10 +111,10 @@ def read_po(fileobj, locale=None, domain=None, ignore_obsolete=False):
     ...         print (message.id, message.string)
     ...         print ' ', (message.locations, message.flags)
     ...         print ' ', (message.user_comments, message.auto_comments)
-    (u'foo %(name)s', '')
+    (u'foo %(name)s', u'')
       ([(u'main.py', 1)], set([u'fuzzy', u'python-format']))
       ([], [])
-    ((u'bar', u'baz'), ('', ''))
+    ((u'bar', u'baz'), (u'', u''))
       ([(u'main.py', 3)], set([]))
       ([u'A user comment'], [u'An auto comment'])
 
index 64d92742a3be9aa5d5cd8c5dd164042c3cd43550..bb3f54872ea44220de2915df666eceb08a1d2a5a 100644 (file)
@@ -539,6 +539,16 @@ class PofileFunctionsTestCase(unittest.TestCase):
         # regression test for #198
         self.assertEqual(r'\n', pofile.unescape(r'"\\n"'))
     
+    def test_denormalize_on_msgstr_without_empty_first_line(self):
+        # handle irregular multi-line msgstr (no "" as first line) 
+        # gracefully (#171)
+        msgstr = '"multi-line\\n"\n" translation"'
+        expected_denormalized = u'multi-line\n translation'
+        
+        self.assertEqual(expected_denormalized, pofile.denormalize(msgstr))
+        self.assertEqual(expected_denormalized, 
+                         pofile.denormalize('""\n' + msgstr))
+
 
 def suite():
     suite = unittest.TestSuite()