changeset 404:3844451f7a30

Added warning for non-string _() markup (which is also ignored)
author Jürgen Hermann <jhermann@users.sourceforge.net>
date Thu, 22 Nov 2001 01:15:26 +0000
parents 82a5757d01eb
children f0b234ce301f
files tools/pygettext.py
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/tools/pygettext.py	Thu Nov 22 00:25:11 2001 +0000
+++ b/tools/pygettext.py	Thu Nov 22 01:15:26 2001 +0000
@@ -9,7 +9,7 @@
     import fintl
     _ = fintl.gettext
 except ImportError:
-    def _(s): return s
+    _ = lambda s: s
 
 
 __doc__ = _("""pygettext -- Python equivalent of xgettext(1)
@@ -138,6 +138,7 @@
 import sys
 import time
 import getopt
+import token
 import tokenize
 
 __version__ = '1.1'
@@ -274,7 +275,12 @@
             self.__state = self.__waiting
         elif ttype == tokenize.STRING:
             self.__data.append(safe_eval(tstring))
-        # TBD: should we warn if we seen anything else?
+        elif ttype not in [tokenize.COMMENT, token.INDENT, token.DEDENT,
+                           token.NEWLINE, tokenize.NL]:
+            # warn if we seen anything else than STRING or whitespace
+            print >>sys.stderr, _('*** %(file)s:%(lineno)s: Seen unexpected token "%(token)s"') % {
+                'token': tstring, 'file': self.__curfile, 'lineno': self.__lineno}
+            self.__state = self.__waiting
 
     def set_filename(self, filename):
         self.__curfile = filename
@@ -459,3 +465,6 @@
     main()
     # some more test strings
     _(u'a unicode string')
+    _('*** Seen unexpected token "%(token)s"' % {'token': 'test'})
+    _('more' 'than' 'one' 'string')
+

Roundup Issue Tracker: http://roundup-tracker.org/