diff options
author | Felix Schwarz <felix.schwarz@oss.schwarz.eu> | 2012-08-04 23:10:41 +0000 |
---|---|---|
committer | Felix Schwarz <felix.schwarz@oss.schwarz.eu> | 2012-08-04 23:10:41 +0000 |
commit | 1252964d3ab44b58f153021733c9cfcc16c45885 (patch) | |
tree | a55add007d0ae22813bc148c35a0d56507042013 /babel/messages | |
parent | 2610e85f428d4061dc603c547e3f1372cf51c573 (diff) | |
download | babel-1252964d3ab44b58f153021733c9cfcc16c45885.tar.gz |
handle irregular multi-line msgstr (no "" as first line) gracefully (#171)
Diffstat (limited to 'babel/messages')
-rw-r--r-- | babel/messages/pofile.py | 13 | ||||
-rw-r--r-- | babel/messages/tests/pofile.py | 10 |
2 files changed, 17 insertions, 6 deletions
diff --git a/babel/messages/pofile.py b/babel/messages/pofile.py index a44a691..5c21bec 100644 --- a/babel/messages/pofile.py +++ b/babel/messages/pofile.py @@ -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']) diff --git a/babel/messages/tests/pofile.py b/babel/messages/tests/pofile.py index 64d9274..bb3f548 100644 --- a/babel/messages/tests/pofile.py +++ b/babel/messages/tests/pofile.py @@ -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() |