Advertisement
Guest User

Find false use of variables in Drupal .po file

a guest
Sep 20th, 2010
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. #!/usr/bin/python
  2. # encoding: utf-8
  3.  
  4. import re, sys, polib
  5.  
  6. if len(sys.argv)==1:
  7.     print 'Usage: filename'
  8.     sys.exit(0)
  9. else:
  10.     filename = sys.argv[1]
  11.  
  12. # Open file
  13. po = polib.pofile(filename)
  14.  
  15. for e in po:
  16.     msgid = getattr(e, 'msgid')
  17.     msgstr = getattr(e, 'msgstr')
  18.    
  19.     if msgstr != "" and re.search('(?P<varname>[@%!][a-z_-]{1,}).', msgid):
  20.         # Found a possible variable
  21.         match = re.findall('(?P<varname>[@%!][a-z_-]{1,})', msgid)
  22.         for i in match:
  23.             if re.search('%s[^a-z]|%s$'%(i,i),msgstr):
  24.                 #print "%s is correct" % (i)
  25.                 pass
  26.             else:
  27.                 print ""
  28.                 print 'Variable %s has been changed' % (i)
  29.                 print u"msgid  → %s" % (msgid)
  30.                 print u"msgstr → %s" % (msgstr)
  31.                 print ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement