]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Applied patch by Ramiro Morales for more extensive detection of Python string formatt...
authorChristopher Lenz <cmlenz@gmail.com>
Fri, 20 Jul 2007 12:52:40 +0000 (12:52 +0000)
committerChristopher Lenz <cmlenz@gmail.com>
Fri, 20 Jul 2007 12:52:40 +0000 (12:52 +0000)
ChangeLog
babel/messages/catalog.py
babel/messages/tests/catalog.py

index a6caeb364007a1e1381b1c8fa83b27958fcc3023..c9e05fbe0e5f00856118eb45918657c88b45e689 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,8 @@ http://svn.edgewall.org/repos/babel/tags/0.9.0/
  * Numerous Python message extractor fixes: it now handles nested function
    calls within a gettext function call correctly, uses the correct line number
    for multi-line function calls, and other small fixes (tickets #38 and #39).
+ * Improved support for detecting Python string formatting fields in message
+   strings (ticket #57).
 
 
 Version 0.8.1
index 208e8bae9e282ffa02c2bdd60da1a87606540bce..a68605f576b11bb280b52cee5989a7f84872c763 100644 (file)
@@ -33,7 +33,7 @@ from babel.util import odict, LOCALTZ, UTC, FixedOffsetTimezone
 __all__ = ['Message', 'Catalog', 'TranslationError']
 __docformat__ = 'restructuredtext en'
 
-PYTHON_FORMAT = re.compile(r'\%(\([\w]+\))?[diouxXeEfFgGcrs]')
+PYTHON_FORMAT = re.compile(r'\%(\([\w]+\))?([-#0\ +])?(\*|[\d]+)?(\.(\*|[\d]+))?([hlL])?[diouxXeEfFgGcrs]')
 
 
 class Message(object):
index e9c577c8ef52d9f458c344131aba9de46861cc86..fda576a24d8581cbce0509b12e1b5d4f44126a28 100644 (file)
@@ -23,6 +23,17 @@ class MessageTestCase(unittest.TestCase):
         assert catalog.PYTHON_FORMAT.search('foo %d bar')
         assert catalog.PYTHON_FORMAT.search('foo %s bar')
         assert catalog.PYTHON_FORMAT.search('foo %r bar')
+        assert catalog.PYTHON_FORMAT.search('foo %(name).1f')
+        assert catalog.PYTHON_FORMAT.search('foo %(name)3.3f')
+        assert catalog.PYTHON_FORMAT.search('foo %(name)3f')
+        assert catalog.PYTHON_FORMAT.search('foo %(name)06d')
+        assert catalog.PYTHON_FORMAT.search('foo %(name)Li')
+        assert catalog.PYTHON_FORMAT.search('foo %(name)#d')
+        assert catalog.PYTHON_FORMAT.search('foo %(name)-4.4hs')
+        assert catalog.PYTHON_FORMAT.search('foo %(name)*.3f')
+        assert catalog.PYTHON_FORMAT.search('foo %(name).*f')
+        assert catalog.PYTHON_FORMAT.search('foo %(name)3.*f')
+        assert catalog.PYTHON_FORMAT.search('foo %(name)*.*f')
 
     def test_translator_comments(self):
         mess = catalog.Message('foo', user_comments=['Comment About `foo`'])