Beginnings of attribute filtering.

This commit is contained in:
Eric S. Raymond 2009-03-31 00:59:42 +00:00
parent 8f3b65075c
commit c20896690c

View File

@ -10,15 +10,15 @@ from wesnoth.wmliterator import *
vctypes = (".svn", ".git") vctypes = (".svn", ".git")
def interesting(fn): def cfgfile(fn):
"Is a file interesting for conversion purposes?" "Is a file interesting for translation purposes?"
return fn.endswith(".cfg") return fn.endswith(".cfg")
def allcfgfiles(dir): def allcfgfiles(dir):
"Get the names of all interesting files under dir." "Get the names of all cfgfile files under dir."
datafiles = [] datafiles = []
if not os.path.isdir(dir): if not os.path.isdir(dir):
if interesting(dir): if cfgfile(dir):
if not os.path.exists(dir): if not os.path.exists(dir):
sys.stderr.write("wmllint: %s does not exist\n" % dir) sys.stderr.write("wmllint: %s does not exist\n" % dir)
else: else:
@ -29,7 +29,7 @@ def allcfgfiles(dir):
if vcsubdir in dirs: if vcsubdir in dirs:
dirs.remove(vcsubdir) dirs.remove(vcsubdir)
for name in files: for name in files:
if interesting(os.path.join(root, name)): if cfgfile(os.path.join(root, name)):
datafiles.append(os.path.join(root, name)) datafiles.append(os.path.join(root, name))
return map(os.path.normpath, datafiles) return map(os.path.normpath, datafiles)
@ -47,6 +47,13 @@ class WmllintIterator(WmlIterator):
# Swiped code ends here # Swiped code ends here
def interesting(text):
"Is the given text line interesting to render as part of a context?"
# Ignore translatables, those are guaranteed to be nearby
if re.search('_ *"', text):
return False
return True
if __name__ == "__main__": if __name__ == "__main__":
def help(): def help():
sys.stderr.write("""\ sys.stderr.write("""\
@ -168,13 +175,27 @@ Usage: wmlxgettext [options] dirpath
continue continue
for nav in WmllintIterator(lines, fn): for nav in WmllintIterator(lines, fn):
handle_element(nav, fn) handle_element(nav, fn)
# Generate a report from the dictionary. # Debugging output
if verbose:
print "Translatables:" print "Translatables:"
for (translatable, context) in translatables: for (translatable, context) in translatables:
print "%s: %s" % (translatable, context) print "%s: %s" % (translatable, context)
print "Contexts:" print "Contexts:"
for (key, value) in contexts.items(): for (key, value) in contexts.items():
print key, "->", value print key, "->", value
# Generate a report from the translattables
for (translatable, context) in translatables:
attribs = ""
for (tag, file, line) in context[:-1]:
for (key, value) in contexts.items():
value = filter(interesting, value)
if key[0] == tag and key[1] == file and key[2] == line:
attribs = " has " + ", ".join(value)
print "%s, line %d: %s%s" % (file, line, tag, attribs)
print "%s, line %d: %s" % (context[-1][1], context[-1][2], context[-1][0])
print 'msgid "%s"' % translatable
print 'msgstr ""'
print ""
except KeyboardInterrupt: except KeyboardInterrupt:
print >>sys.stderr, "wmlxgettext: aborted." print >>sys.stderr, "wmlxgettext: aborted."