comparison babel/messages/pofile.py @ 585:5c9dba5dd311 trunk

handle irregular multi-line msgstr (no "" as first line) gracefully (#171)
author fschwarz
date Sat, 04 Aug 2012 23:10:41 +0000
parents 3fd7fb953633
children 46410022772a
comparison
equal deleted inserted replaced
584:e0454b9c125c 585:5c9dba5dd311
73 73
74 :param string: the string to denormalize 74 :param string: the string to denormalize
75 :return: the denormalized string 75 :return: the denormalized string
76 :rtype: `unicode` or `str` 76 :rtype: `unicode` or `str`
77 """ 77 """
78 if string.startswith('""'): 78 if '\n' in string:
79 lines = [] 79 escaped_lines = string.splitlines()
80 for line in string.splitlines()[1:]: 80 if string.startswith('""'):
81 lines.append(unescape(line)) 81 escaped_lines = escaped_lines[1:]
82 lines = map(unescape, escaped_lines)
82 return ''.join(lines) 83 return ''.join(lines)
83 else: 84 else:
84 return unescape(string) 85 return unescape(string)
85 86
86 def read_po(fileobj, locale=None, domain=None, ignore_obsolete=False): 87 def read_po(fileobj, locale=None, domain=None, ignore_obsolete=False):
108 >>> for message in catalog: 109 >>> for message in catalog:
109 ... if message.id: 110 ... if message.id:
110 ... print (message.id, message.string) 111 ... print (message.id, message.string)
111 ... print ' ', (message.locations, message.flags) 112 ... print ' ', (message.locations, message.flags)
112 ... print ' ', (message.user_comments, message.auto_comments) 113 ... print ' ', (message.user_comments, message.auto_comments)
113 (u'foo %(name)s', '') 114 (u'foo %(name)s', u'')
114 ([(u'main.py', 1)], set([u'fuzzy', u'python-format'])) 115 ([(u'main.py', 1)], set([u'fuzzy', u'python-format']))
115 ([], []) 116 ([], [])
116 ((u'bar', u'baz'), ('', '')) 117 ((u'bar', u'baz'), (u'', u''))
117 ([(u'main.py', 3)], set([])) 118 ([(u'main.py', 3)], set([]))
118 ([u'A user comment'], [u'An auto comment']) 119 ([u'A user comment'], [u'An auto comment'])
119 120
120 :param fileobj: the file-like object to read the PO file from 121 :param fileobj: the file-like object to read the PO file from
121 :param locale: the locale identifier or `Locale` object, or `None` 122 :param locale: the locale identifier or `Locale` object, or `None`
Copyright (C) 2012-2017 Edgewall Software