comparison tools/pygettext.py @ 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 a930feb07dc4
children f0b234ce301f
comparison
equal deleted inserted replaced
403:82a5757d01eb 404:3844451f7a30
7 # for selftesting 7 # for selftesting
8 try: 8 try:
9 import fintl 9 import fintl
10 _ = fintl.gettext 10 _ = fintl.gettext
11 except ImportError: 11 except ImportError:
12 def _(s): return s 12 _ = lambda s: s
13 13
14 14
15 __doc__ = _("""pygettext -- Python equivalent of xgettext(1) 15 __doc__ = _("""pygettext -- Python equivalent of xgettext(1)
16 16
17 Many systems (Solaris, Linux, Gnu) provide extensive tools that ease the 17 Many systems (Solaris, Linux, Gnu) provide extensive tools that ease the
136 136
137 import os 137 import os
138 import sys 138 import sys
139 import time 139 import time
140 import getopt 140 import getopt
141 import token
141 import tokenize 142 import tokenize
142 143
143 __version__ = '1.1' 144 __version__ = '1.1'
144 145
145 default_keywords = ['_'] 146 default_keywords = ['_']
272 else: 273 else:
273 linenos.append(entry) 274 linenos.append(entry)
274 self.__state = self.__waiting 275 self.__state = self.__waiting
275 elif ttype == tokenize.STRING: 276 elif ttype == tokenize.STRING:
276 self.__data.append(safe_eval(tstring)) 277 self.__data.append(safe_eval(tstring))
277 # TBD: should we warn if we seen anything else? 278 elif ttype not in [tokenize.COMMENT, token.INDENT, token.DEDENT,
279 token.NEWLINE, tokenize.NL]:
280 # warn if we seen anything else than STRING or whitespace
281 print >>sys.stderr, _('*** %(file)s:%(lineno)s: Seen unexpected token "%(token)s"') % {
282 'token': tstring, 'file': self.__curfile, 'lineno': self.__lineno}
283 self.__state = self.__waiting
278 284
279 def set_filename(self, filename): 285 def set_filename(self, filename):
280 self.__curfile = filename 286 self.__curfile = filename
281 287
282 def write(self, fp): 288 def write(self, fp):
457 463
458 if __name__ == '__main__': 464 if __name__ == '__main__':
459 main() 465 main()
460 # some more test strings 466 # some more test strings
461 _(u'a unicode string') 467 _(u'a unicode string')
468 _('*** Seen unexpected token "%(token)s"' % {'token': 'test'})
469 _('more' 'than' 'one' 'string')
470

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