* Fixed catalogs' charset values not being recognized (ticket #66).
* Fixed fuzzy matching when updating message catalogs (ticket #82).
- * Fixed bug in catalog updating, that in some cases pulled in
- translations from different catalogs based on the same template.
+ * Fixed bug in catalog updating, that in some cases pulled in translations
+ from different catalogs based on the same template.
+ * Location lines in PO files do no longer get wrapped at hyphens in file
+ names (ticket #79).
Version 0.9.1
from StringIO import StringIO
import sys
import tempfile
-import textwrap
from babel import __version__ as VERSION
from babel import Locale, localedata
set
except NameError:
from sets import Set as set
-from textwrap import wrap
from babel import __version__ as VERSION
from babel.messages.catalog import Catalog, Message
-from babel.util import LOCALTZ
+from babel.util import wraptext, LOCALTZ
__all__ = ['read_po', 'write_po']
__docformat__ = 'restructuredtext en'
def _write_comment(comment, prefix=''):
lines = comment
if width and width > 0:
- lines = wrap(comment, width, break_long_words=False)
+ lines = wraptext(comment, width)
for line in lines:
_write('#%s %s\n' % (prefix, line.strip()))
if width and width > 0:
lines = []
for line in comment_header.splitlines():
- lines += wrap(line, width=width, subsequent_indent='# ',
- break_long_words=False)
+ lines += wraptext(line, width=width,
+ subsequent_indent='# ')
comment_header = u'\n'.join(lines) + u'\n'
_write(comment_header)
#
#, fuzzy''', '\n'.join(buf.getvalue().splitlines()[:7]))
+ def test_wrap_locations_with_hyphens(self):
+ catalog = Catalog()
+ catalog.add(u'foo', locations=[
+ ('doupy/templates/base/navmenu.inc.html.py', 60)
+ ])
+ catalog.add(u'foo', locations=[
+ ('doupy/templates/job-offers/helpers.html', 22)
+ ])
+ buf = StringIO()
+ pofile.write_po(buf, catalog, omit_header=True)
+ self.assertEqual('''#: doupy/templates/base/navmenu.inc.html.py:60
+#: doupy/templates/job-offers/helpers.html:22
+msgid "foo"
+msgstr ""''', buf.getvalue().strip())
+
def test_pot_with_translator_comments(self):
catalog = Catalog()
catalog.add(u'foo', locations=[('main.py', 1)],
set
except NameError:
from sets import Set as set
+import textwrap
import time
-__all__ = ['distinct', 'pathmatch', 'relpath', 'odict', 'UTC', 'LOCALTZ']
+__all__ = ['distinct', 'pathmatch', 'relpath', 'wraptext', 'odict', 'UTC',
+ 'LOCALTZ']
__docformat__ = 'restructuredtext en'
def distinct(iterable):
return match is not None
+class TextWrapper(textwrap.TextWrapper):
+ wordsep_re = re.compile(
+ r'(\s+|' # any whitespace
+ r'(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))' # em-dash
+ )
+
+
+def wraptext(text, width=70, initial_indent='', subsequent_indent=''):
+ """Simple wrapper around the ``textwrap.wrap`` function in the standard
+ library. This version does not wrap lines on hyphens in words.
+
+ :param text: the text to wrap
+ :param width: the maximum line width
+ :param initial_indent: string that will be prepended to the first line of
+ wrapped output
+ :param subsequent_indent: string that will be prepended to all lines save
+ the first of wrapped output
+ :return: a list of lines
+ :rtype: `list`
+ """
+ wrapper = TextWrapper(width=width, initial_indent=initial_indent,
+ subsequent_indent=subsequent_indent,
+ break_long_words=False)
+ return wrapper.wrap(text)
+
+
class odict(dict):
"""Ordered dict implementation.